Performance issues for updateLabel() && modeling.connect()

Hello,

currently, I am using bpmn-js to automatically generate a BPMN diagram from a set of data. The set of data describes the task label, participant in which the task is allocated, and the label for the Data object & store reference.
I loop through my dataset and create the respective objects with the modeling object.
The algorithm works, yet it performs quite poorly. For a dataset with 50 tasks (and its attached data references) it takes about 20 seconds.
After some investigation, I noticed that if I remove the modeling.connect(…) and modeling.updateLabel(…) for the Data object reference and the data store reference, it “only” takes 12 seconds.
So I was wondering if anyone has encountered this problem before and if there is a workaround to reduce the processing time for these functions.

One solution would be using the bpmn-moddle library to create a XML, which I then import to bpmn-js. I have not tried this yet, and would be open to any other ideas or solutions.

This is a simplified version of my code for one loop:

const modeling = bpmnEditor.get("modeling");

//append new task to the previous Element of the participant
const task = modeling.appendShape(previousElement, {
      type: "bpmn:Task",
    });
modeling.updateLabel(task, taskLabel);


// create Data Object Reference with an offset to the task
const dataObject = modeling.createShape(
      {
        type: "bpmn:DataObjectReference",
      },
      {
        x: task.x + DATAOBJECT_OFFSET_X,
        y: task.y + DATAOBJECT_OFFSET_Y,
      },
      participant
    );
modeling.updateLabel(dataObject, label);
modeling.connect(task, dataObject);


// create Data Store Reference with an offset to the task and the Data Object
const dataStoreReference = modeling.createShape(
      {
        type: "bpmn:DataStoreReference",
      },
      {
        x: task.x + DATAOBJECT_OFFSET_X + 70,
        y: task.y + DATAOBJECT_OFFSET_Y,
      },
      participant
    );
modeling.updateLabel(dataStoreReference, label);
modeling.connect(task, dataStoreReference);

There is also the BPMN Model API in Camunda, which I have used previously to generate diagrams. Especially the fluent API is nice.

However, you would have to write and run Java, which might not be fine with your use case.

1 Like