Skip to content

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

Merged
MyvTsv merged 3 commits into
11.0/bugfixesfrom
fix_perf
Nov 25, 2026
Merged

MyvTsv merged 3 commits into
11.0/bugfixesfrom
fix_perf

Conversation

@TarekRemo

Copy link
Copy Markdown
Contributor

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.

@Rom1-B
Rom1-B requested review from a team, Herafia, MyvTsv and jdurand-teclib and removed request for a team November 18, 2026 15:07
Herafia
Herafia previously approved these changes Nov 20, 2026
jdurand-teclib
jdurand-teclib previously approved these changes Nov 23, 2026
@TarekRemo
TarekRemo dismissed stale reviews from jdurand-teclib and Herafia via f74e41d November 24, 2026 10:24
Comment thread ajax/gantt.php Outdated

if (isset($_REQUEST['getData'])) {
// Read-only request: release the session lock so that parallel requests are not serialized
session_write_close();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use Session::writeClose()

Comment thread front/projectsexport.php Outdated
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();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@TarekRemo
TarekRemo requested a review from MyvTsv November 24, 2026 11:00
@MyvTsv
MyvTsv merged commit ac59a29 into 11.0/bugfixes Nov 25, 2026
7 checks passed
@MyvTsv
MyvTsv deleted the fix_perf branch November 25, 2026 09:36
@glpi-project

glpi-project Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Backport-action backported this pull request in workflow run 45587042312.

Target Status
main ⚠️ Drafted with conflicts #260

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>
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.

4 participants