Skip to content

Improve Performance - #149

Merged
Herafia merged 1 commit into
11.0/bugfixesfrom
perf_fix
Nov 24, 2026
Merged

Herafia merged 1 commit into
11.0/bugfixesfrom
perf_fix

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 (11.0/bugfixes), e2e database, plugin 1.20.4, debug mode and Xdebug off. Data injected in SQL:

Data Volume
glpi_locations 2 000, on 5 levels
glpi_computers, monitors, printers, network equipments, peripherals, phones, software, racks, enclosures, PDUs, passive devices 2 000 each (22 000 assets)
glpi_plugin_treeview_preferences 2 022 (one per user)

The assets are spread unevenly: 20 % in one location (2000, about 4 400 assets), 30 % in 19 other hot locations, 50 % one per type in the other locations.

Test scenarios

Each scenario: 1 warm-up run, then 5 measured runs (medians). SQL counted from the MariaDB log in a separate pass. Five other plugins stay active in both states.

ID Scenario
S0, S1 Central page, before and after the tree was opened (plugin inactive baseline)
S2 Computer form (plugin inactive baseline)
T1 Tree entry page (index.php)
T2 Tree root
T3 / T4 / T5 Tree opened on a typical location (121 nodes) / a hot one (451 nodes) / the very hot one (4 422 nodes)
T6 Config page, Tree view tab
W1 Create, move, trash and purge a computer (plugin inactive baseline)
W2 Save the plugin config

Problems found

  • left.php runs SELECT completename FROM glpi_locations WHERE id = ? once per asset type of every open location, and never uses the result: 44 of the 138 queries of a typical location.
  • It also creates one CSRF token per asset type and puts it in a GET search link: 44 tokens added to the session by each tree click.
  • The item queries use SELECT * on 11 wide asset tables while only the id, the name and the inventory number are read.
  • treeview.css is loaded on every GLPI page, but only the tree frame uses it.
  • glpi_plugin_treeview_preferences.users_id has no index: each login and profile change scans the whole table.
  • plugin_init_treeview() instantiates the 11 asset classes on every request to register the item hooks.

Fixes

  • Remove the unused completename query and the CSRF token from the search links.
  • Select only id, name and otherserial (when the table has it).
  • Remove the global ADD_CSS hook, and link treeview.css from left.php.
  • Add a users_id key to the preferences table (CREATE TABLE and an idempotent Migration::addKey for existing installs).
  • Register the item hooks on the static type list.

The tree output is unchanged: same nodes, byte for byte, on the four tree scenarios.

Results

Measure Before After Gain
Typical location (T3): SQL queries 138 94 +32 %
Hot location (T4): SQL queries 149 105 +30 %
Very hot location (T5): SQL queries 127 105 +17 %
T3: unused completename queries 44 0 +100 %
T3: CSRF tokens added to the session per click 44 0 +100 %
T5: SQL time, ms (single run) 36 27 +24 %
Resources loaded on every page except the tree frame 91 90 +1 %
Preferences lookup, rows examined 2 022 1 +100 %
Neutral, form and write pages: SQL queries (S0, S2, W1, W2) 560, 172, 1 454, 337 560, 171, 1 454, 337 0 %

@Rom1-B
Rom1-B requested review from a team, Herafia, MyvTsv and jdurand-teclib and removed request for a team November 18, 2026 15:09
Herafia
Herafia previously approved these changes Nov 20, 2026
jdurand-teclib
jdurand-teclib previously approved these changes Nov 23, 2026
@Herafia
Herafia merged commit e39e0ad into 11.0/bugfixes Nov 24, 2026
7 checks passed
@Herafia
Herafia deleted the perf_fix branch November 24, 2026 09:43
@glpi-project

glpi-project Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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

Target Status
main ⚠️ Drafted with conflicts #152

@glpi-project glpi-project Bot mentioned this pull request Nov 24, 2026
2 of 4 tasks
TarekRemo added a commit that referenced this pull request Nov 24, 2026
(cherry picked from commit e39e0ad)
Rom1-B pushed a commit that referenced this pull request Nov 24, 2026
Forward-port of #149 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 (`11.0/bugfixes`), e2e database, plugin 1.20.4, debug mode and
Xdebug off. Data injected in SQL:

| Data | Volume |
|---|---|
| glpi_locations | 2 000, on 5 levels |
| glpi_computers, monitors, printers, network equipments, peripherals,
phones, software, racks, enclosures, PDUs, passive devices | 2 000 each
(22 000 assets) |
| glpi_plugin_treeview_preferences | 2 022 (one per user) |

The assets are spread unevenly: 20 % in one location (2000, about 4 400
assets), 30 % in 19 other hot locations, 50 % one per type in the other
locations.

## Test scenarios

Each scenario: 1 warm-up run, then 5 measured runs (medians). SQL
counted from the MariaDB log in a separate pass. Five other plugins stay
active in both states.

| ID | Scenario |
|---|---|
| S0, S1 | Central page, before and after the tree was opened (plugin
inactive baseline) |
| S2 | Computer form (plugin inactive baseline) |
| T1 | Tree entry page (`index.php`) |
| T2 | Tree root |
| T3 / T4 / T5 | Tree opened on a typical location (121 nodes) / a hot
one (451 nodes) / the very hot one (4 422 nodes) |
| T6 | Config page, Tree view tab |
| W1 | Create, move, trash and purge a computer (plugin inactive
baseline) |
| W2 | Save the plugin config |

## Problems found

- `left.php` runs `SELECT completename FROM glpi_locations WHERE id = ?`
once per asset type of every open location, and never uses the result:
44 of the 138 queries of a typical location.
- It also creates one CSRF token per asset type and puts it in a GET
search link: 44 tokens added to the session by each tree click.
- The item queries use `SELECT *` on 11 wide asset tables while only the
id, the name and the inventory number are read.
- `treeview.css` is loaded on every GLPI page, but only the tree frame
uses it.
- `glpi_plugin_treeview_preferences.users_id` has no index: each login
and profile change scans the whole table.
- `plugin_init_treeview()` instantiates the 11 asset classes on every
request to register the item hooks.

## Fixes

- Remove the unused `completename` query and the CSRF token from the
search links.
- Select only `id`, `name` and `otherserial` (when the table has it).
- Remove the global `ADD_CSS` hook, and link `treeview.css` from
`left.php`.
- Add a `users_id` key to the preferences table (`CREATE TABLE` and an
idempotent `Migration::addKey` for existing installs).
- Register the item hooks on the static type list.

The tree output is unchanged: same nodes, byte for byte, on the four
tree scenarios.

## Results

| Measure | Before | After | Gain |
|---|---|---|---|
| Typical location (T3): SQL queries | 138 | 94 | +32 % |
| Hot location (T4): SQL queries | 149 | 105 | +30 % |
| Very hot location (T5): SQL queries | 127 | 105 | +17 % |
| T3: unused `completename` queries | 44 | 0 | +100 % |
| T3: CSRF tokens added to the session per click | 44 | 0 | +100 % |
| T5: SQL time, ms (single run) | 36 | 27 | +24 % |
| Resources loaded on every page except the tree frame | 91 | 90 | +1 %
|
| Preferences lookup, rows examined | 2 022 | 1 | +100 % |
| Neutral, form and write pages: SQL queries (S0, S2, W1, W2) | 560,
172, 1 454, 337 | 560, 171, 1 454, 337 | 0 % |

---------

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