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.
catch exception > returns null
might as well just receive null > return null
has a if(ref != null){}else{} structure, able to handle a null value
Workaround
Attached LanguageDefinition class