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;
}
Insights from the user https://github.com/vpanfilov :