isCriticalTask major performance hit.

Using the isCriticalTask function is causing some major performance hits. We would like to add some styling to critical tasks but not have the whole highlight functionality. Right now it is causing the render time grow exponentially with the number of tasks. But at a high number of tasks, using the gantt.config.highlight_critical_path renders rather quickly. Is there something I’m missing? Or is there a way to return all critical tasks without iterating over every task?

Hi,
the current implementation of critical path calculation works quite ineffective on a medium/big sets of task.
Built-in config works faster because it’s applied during data rendering, when gantt does some other optimizations to speed up displaying.
You can try doing the same, by doing your calculations from onBeforeDataRender event - gantt will cache some calculated values since the data is not likely to change while it’s being displayed and all will work faster:

gantt.attachEvent("onBeforeDataRender", function(){ //.. do something });
docs.dhtmlx.com/gantt/api__gantt … event.html
If this approach doesn’t work for you - please clarify what you’re doing, we could come up with some solution

events.push(gantt.attachEvent("onBeforeGanttRender", function(){ if (!gantt.config.highlight_critical_path){ gantt.templates.task_class = function (start, end, task) { if (gantt.isCriticalTask(task)) { return "ganttItemBarCriticalPath"; } else { return ""; } } } }));

What we are doing is adding some extra css to critical tasks when we are not showing the critical path. It’s a little weird, but it’s what the client wants. On ~550 items without this code will load in less than 3 seconds. With this code it is taking over 30 seconds. Any suggestions?

Hi,
seems like that optimization is enabled only when highlight_critical_path is enabled.
Try enabling this option: gantt.config.optimize_render = true;
We’ll try to review the issue with critical path performance and it’s optimizations before next update and make it work more predictable

That worked like a charm! Seeing similar performance to the highlight now. Is there a reason I would ever want to not optimize the render?

Hi,
this option will be enabled by default starting next version of the gantt. It was initially disabled as a precaution for compatibility issues with the existing apps, but it seems that was not necessary