Dear DHTMLX Gantt Support Team,
Greetings! I am using DHTMLX Gantt v7.1.3 Pro and have encountered performance challenges when working with large-scale projects (spanning 2-3 years). Despite following the recommendations in your Performance Guide, certain operations still block the main thread, leading to delays reported by users. Below are my questions and code snippets for clarity.
Issue 1: Slow Initial Calendar Configuration
export const configGlobalCalendar = (calendars: Map<number, GanttCalendar> | undefined): void => {
const globalCalendar = gantt.getCalendar(GLOBAL_CALENDAR_ID);
if (!calendars) {
globalCalendar.setWorkTime({
hours: [WORKDAY_START, WORKDAY_END],
days: [false, true, true, true, true, true, false],
});
return;
}
const workDays: GanttWorkDay[] = [...calendars.values()].flatMap((c) => c.work_days);
workDays.forEach((workDay) => {
if (workDay.duration === 0) {
globalCalendar.setWorkTime({ date: workDay.date, hours: false });
return;
}
const calculateEndHour = WORKDAY_START + workDay.duration;
globalCalendar.setWorkTime({ date: workDay.date, hours: [WORKDAY_START, calculateEndHour] });
});
};
Problem:
Looping through individual workdays (e.g., 2-3 years of data) and calling setWorkTime
for each day takes 3-10 seconds, blocking the UI. I temporarily deferred this with setTimeout
but seek a more robust solution.
Question 1:
Is there a batch method to configure multiple calendar dates at once, avoiding iterative setWorkTime
calls?
Issue 2: Slow Task Copy/Paste via addItem()
export const createGanttTask = (task: any, parent: number | string, index?: number, isNeedSelect?: boolean): number => {
const newTaskId = getTasksDatastore().addItem(task, index);
isNeedSelect && selectTask(newTaskId);
return newTaskId;
};
Problem:
Adding tasks via addItem()
takes 400–600 ms per task. Copying/pasting a section with 20 nested tasks causes significant delays.
Question 2:
Is there a batch insertion API or optimized workflow for adding multiple tasks simultaneously?
General Performance Strategy
Question 3:
For CPU-heavy operations (like calendar setup or task insertion), would you recommend:
- Using Web Workers for partial processing (even if Gantt itself cannot run in a worker)?
- Techniques like
requestIdleCallback
,requestAnimationFrame
, or chunkedsetTimeout
to avoid blocking the main thread? - Any other best practices for offloading work while ensuring Gantt updates correctly?
Additional Context:
- I am aware Gantt relies on the DOM and cannot run entirely in a Web Worker. However, I hope to isolate non-DOM logic (e.g., data preprocessing) in workers.
- Performance profiling confirms these operations are the primary bottlenecks.
Thank you for your time and expertise! I greatly appreciate any guidance to optimize these workflows.
Best regards,
Marat