Uploaded image for project: 'camunda BPM'
  1. camunda BPM
  2. CAM-8310

Improve performance when creating new model elements

    • Icon: Feature Request Feature Request
    • Resolution: Fixed
    • Icon: L3 - Default L3 - Default
    • 7.8.0, 7.8.0-alpha5
    • None
    • bpmn model api
    • None

      When

      • the new model element is created via ModelInstance#newInstance(elementClass);

      Then

      • AttributeImpl#updateIncomingReferences method must not be called

      So that

      • unnecessary code is not executed -> performance improves

      Additionaly:
      I can pass custom id to newInstance method and, again, AttributeImpl#updateIncomingReferences won't be called

        This is the controller panel for Smart Panels app

            [CAM-8310] Improve performance when creating new model elements

            Insights from the user https://github.com/vpanfilov :

            Hi, I use your BPMN model API to generate BPMN 2.0 XML file from custom JSON representation. I used your guide to create BPMN models. The issue is that your API becomes VERY slow for large models. For example, it took me about 20 seconds to generate model containing 45 tasks and 167 sequence flows.

            After some research I found out that main bottleneck was setting ID values for new elements. I used the following code from your guide:

            protected <T extends BpmnModelElementInstance> T createElement(
                BpmnModelElementInstance parentElement, String id, Class<T> elementClass) {
              T element = modelInstance.newInstance(elementClass);
              element.setAttributeValue("id", id, true);
              parentElement.addChildElement(element);
              return element;
            }
            

            In this code ID value is updating twice: setting random UUID in newInstance method and setting new value in setAttributeValue("id", id, true). During these updates updateIncomingReferences method is called, which updates all id references in other model elements.
            But what is the point of updating references for newly created elements?

            I achieved a HUGE performance improvement, when I rewrote createElement method like this:

             @SuppressWarnings("unchecked")
                protected <T extends BpmnModelElementInstance> T createElement(
                        BpmnModelElementInstance parentElement,
                        String id, Class<T> elementClass)
                {
                    ModelElementType modelElementType = this.modelInstance
                            .getModel().getType(elementClass);
                    ModelElementInstance element = modelElementType
                            .newInstance(this.modelInstance);
                    if (id != null) {
                        DomElement domElement = element.getDomElement();
                        domElement.setIdAttribute("id", id);
                    }
                    parentElement.addChildElement(element);
                    return (T) element;
                }
            

            Svetlana Dorokhova added a comment - Insights from the user https://github.com/vpanfilov : Hi, I use your BPMN model API to generate BPMN 2.0 XML file from custom JSON representation. I used your guide to create BPMN models. The issue is that your API becomes VERY slow for large models. For example, it took me about 20 seconds to generate model containing 45 tasks and 167 sequence flows. After some research I found out that main bottleneck was setting ID values for new elements. I used the following code from your guide: protected <T extends BpmnModelElementInstance> T createElement( BpmnModelElementInstance parentElement, String id, Class <T> elementClass) { T element = modelInstance.newInstance(elementClass); element.setAttributeValue( "id" , id, true ); parentElement.addChildElement(element); return element; } In this code ID value is updating twice: setting random UUID in newInstance method and setting new value in setAttributeValue("id", id, true). During these updates updateIncomingReferences method is called, which updates all id references in other model elements. But what is the point of updating references for newly created elements? I achieved a HUGE performance improvement, when I rewrote createElement method like this: @SuppressWarnings( "unchecked" ) protected <T extends BpmnModelElementInstance> T createElement( BpmnModelElementInstance parentElement, String id, Class <T> elementClass) { ModelElementType modelElementType = this .modelInstance .getModel().getType(elementClass); ModelElementInstance element = modelElementType .newInstance( this .modelInstance); if (id != null ) { DomElement domElement = element.getDomElement(); domElement.setIdAttribute( "id" , id); } parentElement.addChildElement(element); return (T) element; }

              svetlana.dorokhova Svetlana Dorokhova
              svetlana.dorokhova Svetlana Dorokhova
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: