Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-5181

Optimize the use of DefinitionNotFoundException when creating event queues

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Normal Normal
    • 9.6.3
    • 9.6.2
    • None
    • Security Level: Jimmy

      Steps to Reproduce

      Run attached sample with and without the override class LanguageDefinition

      test case:

      https://zkfiddle.org/sample/368ov90/1-Event-Queue-efficiency-DefinitionNotFoundException

      Current Result

      tested on local jetty ran project, with test case above (total 100K eventQueue lookups)

      Without override:

      Average browser page request around 6000ms

      Average processing time for eventQueues.lookup loops around (nano): 60000000 (nano 6*10^7)

       

      With override (removed ignored exception):

      Average browser page request around 500ms, i.e. a page request time difference of ~30 times on a blank page

      Average processing time for eventQueues.lookup loops around (nano): 500000 (nano 5*10^5) i.e. a processing time difference of ~100 times

      Expected Result

      If the DefinitionNotFoundException is not necessary (downstream methods can deal with null value),  throwing exceptions is not a good use of resources.

      Debug Information

      most of the delay in this case appear to be due to the fact that DesktopEventQueue creates a Dummy AbstractComponent when doing lookup:

      https://github.com/zkoss/zk/blob/master/zk/src/org/zkoss/zk/ui/event/impl/DesktopEventQueue.java#L50

       

      Since that AbstractComponent is created directly, when it instantiates it calls Impls.getDefinition to find its component definition:

      https://github.com/zkoss/zk/blob/master/zk/src/org/zkoss/zk/ui/AbstractComponent.java#L179

      Since "AbstractComponent"  is not a component which exists in component definition in ZK, this causes a DefinitionNotFoundException which is immediately ignored by Components.getDefinitionByDeviceType and doesn't reach console.

       

      As a single call, this doesn't make a lot of difference, but on a very complex UI, with a large number of users, the ignored exceptions may result in degraded performances.

       

      Creating an exception will cost processing time when creating the stacktrace (instantiating the exception) and printing the stacktrace.

      The DefinitionNotFoundException  created at org.zkoss.zk.ui.metainfo.LanguageDefinition.getComponentDefinition(Class) are ignored by downstream methods, so the stacktrace is never printed.

      The downstream methods also seem able to handle null values.

       

      https://github.com/zkoss/zk/blob/27f90007e4d63638036b059da0ce2cd608b9b597/zk/src/org/zkoss/zk/ui/Components.java#L210-L217

      catch exception > returns null

      might as well just receive null > return null

       

      https://github.com/zkoss/zk/blob/27f90007e4d63638036b059da0ce2cd608b9b597/zk/src/org/zkoss/zk/ui/metainfo/Parser.java#L479

      https://github.com/zkoss/zk/blob/27f90007e4d63638036b059da0ce2cd608b9b597/zk/src/org/zkoss/zk/ui/metainfo/Parser.java#L495

      has a if(ref != null){}else{} structure, able to handle a null value

      Workaround

      Attached LanguageDefinition class

            jumperchen jumperchen
            MDuchemin MDuchemin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: