Skip to content

[main] Perf: remove the N+1 in the Gantt data, one chart render, assets only where used - #260

Merged
Rom1-B merged 2 commits into
mainfrom
forward-port/256-to-main
Nov 25, 2026
Merged

Rom1-B merged 2 commits into
mainfrom
forward-port/256-to-main

Conversation

@glpi-project

@glpi-project glpi-project Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Forward-port of #256 to main.

Checklist before requesting a review

Please delete options that are not relevant.

  • I have performed a self-review of my code.
  • I have added tests (when available) that prove my fix is effective or that my feature works.
  • I have updated the CHANGELOG with a short functional description of the fix or new feature.
  • This change requires a documentation update.

Test data

GLPI 11.0.14-dev, e2e database, plugin 1.3.5, debug mode and Xdebug off. gantt has no table of its own, so the data was injected in SQL in the core project tables:

Table Rows
glpi_projects 500 (100 roots, 3 levels)
glpi_projecttasks 10 000 (27 % sub-tasks, 10 % milestones)
glpi_projecttasklinks 2 000

5 "hot" projects (1 %) hold half of the tasks: the Gantt of a hot project shows about 1 050 tasks. 28 root projects are on the global Gantt (about 4 000 tasks).

Test scenarios

Each scenario: 1 warm-up run, then 5 measured runs (medians). SQL counted from the MariaDB log in a separate pass.

ID Scenario
S0 Central page (neutral page)
S1 Project form, default tab
S2 Gantt tab of a typical project (about 45 tasks)
S3 Gantt tab of a hot project (about 1 050 tasks)
S4 Global Gantt (about 4 000 tasks)
S5 JSON export of the hot project
W1 Add, update and purge a task through ajax/gantt.php on the hot project

Problems found

  • DataFactory re-read every project and task it already had in memory, then canViewItem() re-read the project again: about 4 queries per task (4 699 queries for one hot Gantt, 20 440 for the global Gantt, 4 700 for the JSON export).
  • calculateProgress() redrew the whole chart once per task: the browser was frozen for 9.4 s on the hot project and 60.5 s on the global Gantt.
  • libs.js (940 KB, 283 KB gzip), the helper and the SCSS were loaded on every GLPI page.
  • plugin_init_gantt() checked isPluginActive() on every request: 2 extra queries per request.
  • ajax/gantt.php (getData) and front/projectsexport.php kept the session locked while only reading it.

Fixes

  • Build the Gantt items from the loaded records: the entity check is made on the record when the user can read all projects (users limited to their own projects keep the full canViewItem() check), and parent task UUIDs come from the tasks already read.
  • Render the chart once after the progress calculation.
  • Register the JS and CSS only on the project form and the global Gantt page.
  • Remove the isPluginActive() check: core only calls the init of active plugins.
  • Call session_write_close() in the getData branch and in the export.

Results

Measure Before After Gain
S3 hot Gantt: SQL queries of ajax/gantt.php 4 699 39 +99 %
S4 global Gantt: SQL queries of ajax/gantt.php 20 440 364 +98 %
S5 export: SQL queries of projectsexport.php 4 700 40 +99 %
S2 typical project: SQL queries of ajax/gantt.php 85 31 +64 %
S3 hot Gantt: SQL time (ms) 292 103 +65 %
S4 global Gantt: SQL time (ms) 567 48 +92 %
S3 hot Gantt: browser blocking time (ms) 9 400 174 +98 %
S4 global Gantt: browser blocking time (ms) 60 532 247 +100 %
S3 gantt.php server time (ms, same session old/new code) 183 54 +70 %
S4 gantt.php server time (ms, same session old/new code) 763 183 +76 %
S5 export server time (ms, same session old/new code) 191 50 +74 %
Extra SQL queries added by the plugin per request 4 2 +50 %
Resources the plugin adds to the neutral page 9 1 +89 %
Plugin assets on a cold load of a page without Gantt (KB, gzip) 292 0 +100 %

Query counts are exact. A time gain is marked "not significant" when the min-max ranges of the runs overlap.

@glpi-project

glpi-project Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin forward-port/256-to-main
git worktree add --checkout .worktree/forward-port/256-to-main forward-port/256-to-main
cd .worktree/forward-port/256-to-main
git reset --hard HEAD^
git cherry-pick -x ac59a29283ffae2a1879deab7e0c9534fed3c1d1

…y where used (#256)

*Please delete options that are not relevant.*

- [x] I have performed a self-review of my code.
- [ ] I have added tests (when available) that prove my fix is effective
or that my feature works.
- [x] I have updated the CHANGELOG with a short functional description
of the fix or new feature.
- [ ] This change requires a documentation update.

GLPI 11.0.14-dev, e2e database, plugin 1.3.5, debug mode and Xdebug off.
gantt has no table of its own, so the data was injected in SQL in the
core project tables:

| Table | Rows |
|---|---|
| glpi_projects | 500 (100 roots, 3 levels) |
| glpi_projecttasks | 10 000 (27 % sub-tasks, 10 % milestones) |
| glpi_projecttasklinks | 2 000 |

5 "hot" projects (1 %) hold half of the tasks: the Gantt of a hot
project shows about 1 050 tasks. 28 root projects are on the global
Gantt (about 4 000 tasks).

Each scenario: 1 warm-up run, then 5 measured runs (medians). SQL
counted from the MariaDB log in a separate pass.

| ID | Scenario |
|---|---|
| S0 | Central page (neutral page) |
| S1 | Project form, default tab |
| S2 | Gantt tab of a typical project (about 45 tasks) |
| S3 | Gantt tab of a hot project (about 1 050 tasks) |
| S4 | Global Gantt (about 4 000 tasks) |
| S5 | JSON export of the hot project |
| W1 | Add, update and purge a task through `ajax/gantt.php` on the hot
project |

- `DataFactory` re-read every project and task it already had in memory,
then `canViewItem()` re-read the project again: about 4 queries per task
(4 699 queries for one hot Gantt, 20 440 for the global Gantt, 4 700 for
the JSON export).
- `calculateProgress()` redrew the whole chart once per task: the
browser was frozen for 9.4 s on the hot project and 60.5 s on the global
Gantt.
- `libs.js` (940 KB, 283 KB gzip), the helper and the SCSS were loaded
on every GLPI page.
- `plugin_init_gantt()` checked `isPluginActive()` on every request: 2
extra queries per request.
- `ajax/gantt.php` (`getData`) and `front/projectsexport.php` kept the
session locked while only reading it.

- Build the Gantt items from the loaded records: the entity check is
made on the record when the user can read all projects (users limited to
their own projects keep the full `canViewItem()` check), and parent task
UUIDs come from the tasks already read.
- Render the chart once after the progress calculation.
- Register the JS and CSS only on the project form and the global Gantt
page.
- Remove the `isPluginActive()` check: core only calls the init of
active plugins.
- Call `session_write_close()` in the `getData` branch and in the
export.

| Measure | Before | After | Gain |
|---|---|---|---|
| S3 hot Gantt: SQL queries of `ajax/gantt.php` | 4 699 | 39 | +99 % |
| S4 global Gantt: SQL queries of `ajax/gantt.php` | 20 440 | 364 | +98
% |
| S5 export: SQL queries of `projectsexport.php` | 4 700 | 40 | +99 % |
| S2 typical project: SQL queries of `ajax/gantt.php` | 85 | 31 | +64 %
|
| S3 hot Gantt: SQL time (ms) | 292 | 103 | +65 % |
| S4 global Gantt: SQL time (ms) | 567 | 48 | +92 % |
| S3 hot Gantt: browser blocking time (ms) | 9 400 | 174 | +98 % |
| S4 global Gantt: browser blocking time (ms) | 60 532 | 247 | +100 % |
| S3 `gantt.php` server time (ms, same session old/new code) | 183 | 54
| +70 % |
| S4 `gantt.php` server time (ms, same session old/new code) | 763 | 183
| +76 % |
| S5 export server time (ms, same session old/new code) | 191 | 50 | +74
% |
| Extra SQL queries added by the plugin per request | 4 | 2 | +50 % |
| Resources the plugin adds to the neutral page | 9 | 1 | +89 % |
| Plugin assets on a cold load of a page without Gantt (KB, gzip) | 292
| 0 | +100 % |

Query counts are exact. A time gain is marked "not significant" when the
min-max ranges of the runs overlap.

(cherry picked from commit ac59a29)
@TarekRemo
TarekRemo force-pushed the forward-port/256-to-main branch from d4c6630 to 910cb5e Compare November 25, 2026 13:53
@TarekRemo
TarekRemo marked this pull request as ready for review November 25, 2026 14:30
@TarekRemo
TarekRemo requested review from a team, Rom1-B, RomainLvr and jdurand-teclib and removed request for a team November 25, 2026 14:30
@Rom1-B
Rom1-B merged commit 1ac275e into main Nov 25, 2026
7 checks passed
@Rom1-B
Rom1-B deleted the forward-port/256-to-main branch November 25, 2026 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants