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

java component creation performance (unnecessary exception handling)

XMLWordPrintable

      Steps to Reproduce

      Create a custom component class

      	public class MyZhtmlComp extends AbstractTag {
      		MyZhtmlComp() {
      			super("div");
      		}
      	}
      

      instantiate it using java code and add it to a page

      	@Override
      	public void doAfterCompose(Component comp) throws Exception {
      		final MyZhtmlComp myZhtmlComp = new MyZhtmlComp();
      		comp.appendChild(myZhtmlComp);
      	}
      

      Current Result

      Doing this many times will consume significant amounts of CPU time, caused by unnecessarily thrown,caught and ignored "DefinitionNotFoundException"s

      Expected Result

      avoid unnecessary exceptions

      Debug Info

      Root Cause

      the current PageImpl.getComponentDefinition catches and ignores 2 exceptions

      a new method _langdef.getComponentDefinitionIfAny(cls) that doesn't throw exceptions would allow a more efficient implementation in this case:

      	compdef = _langdef.getComponentDefinitionIfAny(cls);
      	if(compdef == null) {
      		return _langdef.getShadowDefinitionIfAny(cls);
      	}
      

      Workaround

      setting a component definition before instantiating the component prevents the search and exceptions

      	@Override
      	public void doAfterCompose(Component comp) throws Exception {
      		ComponentsCtrl.setCurrentInfo(ComponentsCtrl.DUMMY); //or an existing definition
      		final MyZhtmlComp myZhtmlComp = new MyZhtmlComp();
      		comp.appendChild(myZhtmlComp);
      	}
      

            CharlesQiu CharlesQiu
            cor3000 cor3000
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 4 hours
                4h
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 4 hours
                4h