Autoscheduling performance

I wrote a custom function to calculate per project critical paths and save the critical path status as well as the slack. When running the function using the ‘onAfterAutoSchedule’ event i’m getting very different performance when the ‘onAfterAutoSchedule’ is triggered by closing an inline editor vs after dragging the task. On the same task making the same change using drag and drop the execution time is ~100ms while using inline editor is ~2000ms. Looking at the performance tab in chrome it seems like the issue comes from the updates to the data processor. Do these two events handle updates differently?

Here is the code I am using to update the tasks

gantt.batchUpdate(() => {
      gantt.getTaskBy('project_id', projectId, { task: true, project: true }).forEach((task) => {
        let shouldUpdate = false;
        if (Boolean(task.critical_path) !== Boolean(criticalTasks[task.id])) {
          task.critical_path = Boolean(criticalTasks[task.id]);
          shouldUpdate = true;
        }
        if (Object.hasOwn(taskSlack, task.id)) {
          if (taskSlack[task.id].freeSlack !== task.free_slack) {
            task.free_slack = taskSlack[task.id].freeSlack;
            shouldUpdate = true;
          }
          if (taskSlack[task.id].totalSlack !== task.total_slack) {
            task.total_slack = taskSlack[task.id].totalSlack;
            shouldUpdate = true;
          }
        }
        if (shouldUpdate) {
          gantt.updateTask(task.id);
        }
      });
    }, true);

Update: I was able to improve the performance by using gantt._quickRefresh() on the batch update. I came across this function as the performance log showed that the filter function was slow and quick refresh skips it. It looks like the filter function is responsible for filtering tasks out that are outside of the timeframe. I’m sure this is not the best way to handle this so if someone has more information about how to better handle this

Hello,
If you use the updateTask method, Gantt needs to recalculate the slack and critical path. So, when you do that for several tasks at the same time, the performance is getting worse. The expected approach is to recalculate the slack and critical path for all tasks, then update them.
So, your code may look like this:

const updateTasks = [];
gantt.batchUpdate(() => {
    gantt.getTaskBy('project_id', projectId, { task: true, project: true }).forEach((task) => {
        let shouldUpdate = false;
        if (Boolean(task.critical_path) !== Boolean(criticalTasks[task.id])) {
            task.critical_path = Boolean(criticalTasks[task.id]);
            shouldUpdate = true;
        }
        if (Object.hasOwn(taskSlack, task.id)) {
            if (taskSlack[task.id].freeSlack !== task.free_slack) {
                task.free_slack = taskSlack[task.id].freeSlack;
                shouldUpdate = true;
            }
            if (taskSlack[task.id].totalSlack !== task.total_slack) {
                task.total_slack = taskSlack[task.id].totalSlack;
                shouldUpdate = true;
            }
        }
        if (shouldUpdate) {
            updateTasks.push(task.id)
        }
    });
}, true);
gantt.batchUpdate(() => {
    updateTasks.forEach(function(id){
        gantt.updateTask(id);
    })
}, true);