Repository navigation
Perf: remove the N+1 in the Gantt data, one chart render, assets only where used - #256
Merged
Merged
Conversation
Rom1-B
requested review from
a team,
Herafia,
MyvTsv and
jdurand-teclib
and removed request for
a team
November 18, 2026 15:07
Herafia
previously approved these changes
Nov 20, 2026
jdurand-teclib
previously approved these changes
Nov 23, 2026
TarekRemo
dismissed stale reviews from jdurand-teclib and Herafia
via
November 24, 2026 10:24
f74e41d
MyvTsv
reviewed
Nov 24, 2026
|
|
||
| if (isset($_REQUEST['getData'])) { | ||
| // Read-only request: release the session lock so that parallel requests are not serialized | ||
| session_write_close(); |
Contributor
There was a problem hiding this comment.
Can you use Session::writeClose()
| Session::checkRightsOr(Project::$rightname, [Project::READALL, Project::READMY]); | ||
|
|
||
| // Read-only request: release the session lock so that parallel requests are not serialized | ||
| session_write_close(); |
MyvTsv
approved these changes
Nov 25, 2026
Contributor
|
Backport-action backported this pull request in workflow run 45587042312.
|
2 of 4 tasks
TarekRemo
added a commit
that referenced
this pull request
Nov 25, 2026
…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)
Rom1-B
pushed a commit
that referenced
this pull request
Nov 25, 2026
…ts only where used (#260) Forward-port of #256 to `main`. ## Checklist before requesting a review *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. ## 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. --------- Co-authored-by: TarekRemo <tarekrummo64@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist before requesting a review
Please delete options that are not relevant.
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:
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.
ajax/gantt.phpon the hot projectProblems found
DataFactoryre-read every project and task it already had in memory, thencanViewItem()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()checkedisPluginActive()on every request: 2 extra queries per request.ajax/gantt.php(getData) andfront/projectsexport.phpkept the session locked while only reading it.Fixes
canViewItem()check), and parent task UUIDs come from the tasks already read.isPluginActive()check: core only calls the init of active plugins.session_write_close()in thegetDatabranch and in the export.Results
ajax/gantt.phpajax/gantt.phpprojectsexport.phpajax/gantt.phpgantt.phpserver time (ms, same session old/new code)gantt.phpserver time (ms, same session old/new code)Query counts are exact. A time gain is marked "not significant" when the min-max ranges of the runs overlap.