Skip to content

Perf optimization - #1371

Open
stonebuzz wants to merge 6 commits into
11.0/bugfixesfrom
perf_optimization
Open

stonebuzz wants to merge 6 commits into
11.0/bugfixesfrom
perf_optimization

Conversation

@stonebuzz

Copy link
Copy Markdown
Contributor

Performance analysis: Additional fields (fields) 1.24.7

Description

The benchmark runs GLPI 11.0.14-dev (branch 11.0/bugfixes, commit 23a7f1bb61) in the e2e environment (e2e_testing, database glpi_e2e, served on http://localhost:8290), with the plugin fields 1.24.7 (branch 11.0/bugfixes, commit 5cc0bb2).
The GLPI debug mode is off, Xdebug is disabled, and Chrome is driven through the Playwright MCP, logged in as the super-admin glpi.
The plugin structure was created through the plugin forms: 10 containers (for Ticket and for Computer, one dom block of 15 fields and four tabs of 10 fields), 110 fields covering every field type, status overrides, display conditions, fr_FR label translations and 4 plugin columns in the ticket and computer lists.
Data was injected in SQL: 50 000 tickets (5 followups on the first 20), 2 000 computers, and one value row per item and per container in every plugin value table.
The hot items are ticket 1 (5 followups, all containers filled), ticket 2 (tab save) and computer 1.

Table Rows
glpi_tickets 50 000
glpi_tickets_users 100 000
glpi_itilfollowups 100
glpi_computers 2 000
glpi_plugin_fields_containers 10
glpi_plugin_fields_fields 110
glpi_plugin_fields_ticketticket{extra,alpha,beta,gamma,delta}s 50 000 each
glpi_plugin_fields_computerasset{extra,alpha,beta,gamma,delta}s 2 000 each
glpi_plugin_fields_profiles 80
glpi_plugin_fields_labeltranslations 240
glpi_plugin_fields_statusoverrides 16
glpi_plugin_fields_containerdisplayconditions 16

Scenarios, each replayed with one discarded warm-up run and 5 measured runs:

ID Scenario Baseline
S0 Neutral core page (/front/preference.php) yes
S1 Ticket 1 form, dom block and 5 followups yes
S2 Ticket 1 form, open the plugin tab "Ticket alpha" no
S3 Ticket 1 form, change the urgency (refresh of the dom block through ajax/container.php) no
S4 Computer 1 form, dom block with status overrides yes
S5 Computer 1 form, open the plugin tab "Asset alpha" no
S6 Ticket list with 4 plugin columns yes
S7 Computer list with 4 plugin columns yes
S8 Ticket list filtered on a plugin text field no
S9 Plugin container form, Fields tab no
W1 Ticket write cycle: create with dom values, update, trash and purge yes
W2 Computer write cycle: create with dom values, update, trash and purge yes
W3 Save the plugin tab "Ticket alpha" on ticket 2 no

SQL numbers come from the MariaDB slow log at a zero threshold during a separate pass (one run per scenario), split per HTTP request by connection, so the per-request attribution is approximate.
Display times, AJAX calls and weights come from the browser Performance API during the timing pass, with the SQL log off.
The baseline is the same scenario with the plugin deactivated (plugin:deactivate), its tables and data left in place.
First benchmark: 2026-11-25.
Re-run: 2026-11-25, plugin active only, same data, scenarios and number of runs, plugin at commit 12fed84 (branch perf_optimization, 5 local commits on top of 5cc0bb2).
Fixes applied: P1 itemtype in value lookups (c73d552), P3 label translations loaded once per request (444cc07), P4 activation state read from the boot list (db3e562), P5 field definitions memoized for list cells (2c71eb5), P6 containers read once per request at init (12fed84).
P2 (session release in ajax/container.php) and P7 (one join per container) were not applied, see the details.

SQL Queries

Element tested Before After Gain
S0 Neutral page (page and main tab): SQL queries 168 147 12.5 %
S0 Neutral page: SQL queries on plugin tables 25 11 56.0 %
Any HTTP request (AJAX included): SQL queries added by the plugin init 11 4 63.6 %
S1 Ticket form: SQL queries 910 598 34.3 %
S1 Ticket form: SQL queries on plugin tables 380 95 75.0 %
S1 Ticket form: label translation queries 266 3 98.9 %
S1 Ticket form: SQL time (ms) 152.9 108.4 29.1 %
S1 Ticket form: full scans of plugin value tables (count / ms) 2 / 28.1 0 / 0 100 %
S3 Ticket urgency change: SQL queries 1 096 741 32.4 %
S4 Computer form: SQL queries 379 225 40.6 %
S6 Ticket list: SQL queries 1 046 839 19.8 %
S6 Ticket list: SQL time (ms) 449.0 424.3 5.5 %
S7 Computer list: SQL queries 313 112 64.2 %
W1 Ticket write cycle: SQL queries 3 551 2 207 37.8 %
W1 Ticket write cycle: SQL time (ms) 589.4 378.8 35.7 %
W1 Ticket write cycle: full scans of plugin value tables (count / ms) 25 / 132.1 0 / 0 100 %
W2 Computer write cycle: SQL queries 1 560 958 38.6 %
W3 Tab save: full scans of plugin value tables (count / ms) 6 / 40.0 0 / 0 100 %

Conclusion: the fixes remove most of the SQL the plugin added.
The ticket form drops from 910 to 598 queries (443 without the plugin), the computer form from 379 to 225 (167 without) and the computer list from 313 to 112 (98 without), so the plugin share falls by two thirds on the ticket form and by 93 % on the computer list.
Label translations now cost one query per HTTP request instead of 120 to 266, list cells load each field definition once (4 queries instead of 80), and the plugin init runs 4 queries per HTTP request instead of 11.
No value table is scanned any more: the 25 full scans of the ticket write cycle (132 ms, 1.25 million rows) and the scans of every ticket display now use the unique index, which removes the only cost that grew with the data volume; the write cycle SQL time falls from 589 to 379 ms.
What remains is the core search cost of the plugin columns: the ticket list main query still joins one value table per column (S6 SQL time 424 ms against 252 ms without the plugin).

Response Time

Element tested Before After Gain
S0 Neutral page: fully loaded (ms) 228.7 231.0 -1.0 % (not significant)
S1 Ticket form: server time (ms) 91.6 96.3 -5.1 % (not significant)
S1 Ticket form: first contentful paint (ms) 216 216 0 % (not significant)
S1 Ticket form: fully loaded, AJAX included (ms) 777.6 756.2 2.8 % (not significant)
S1 Ticket form: plugin AJAX calls 1 1 0 %
S1 Ticket form: session lock wait, upper bound (ms) 366.7 335.0 8.6 % (not significant)
S1 Ticket form: total blocking time (ms) 70 67 4.3 % (not significant)
S2 Ticket plugin tab: fully loaded (ms) 683.7 646.6 5.4 % (not significant)
S3 Ticket urgency change: fully loaded (ms) 889.1 852.6 4.1 % (not significant)
S3 Ticket urgency change: plugin AJAX calls / KB 3 / 24.9 3 / 24.9 0 %
S4 Computer form: server time (ms) 95.9 87.6 8.7 % (not significant)
S4 Computer form: fully loaded (ms) 327.9 282.0 14.0 % (not significant)
S5 Computer plugin tab: fully loaded (ms) 357.1 454.9 -27.4 % (not significant)
S6 Ticket list: server time (ms) 475.6 473.7 0.4 % (not significant)
S6 Ticket list: fully loaded (ms) 784.8 790.2 -0.7 % (not significant)
S7 Computer list: server time (ms) 117.5 102.1 13.1 %
S7 Computer list: fully loaded (ms) 266.4 254.9 4.3 % (not significant)
S8 Ticket list filtered on a plugin field: fully loaded (ms) 452.8 438.1 3.2 % (not significant)
S9 Container form: fully loaded (ms) 275.2 229.3 16.7 % (not significant)
W1 Ticket write cycle: fully loaded resulting page (ms) 734.3 617.0 16.0 % (not significant)
W1 Ticket write cycle: session lock wait, upper bound (ms) 360.4 223.5 38.0 %
W2 Computer write cycle: fully loaded resulting page (ms) 275.5 273.1 0.9 % (not significant)
W3 Tab save: fully loaded resulting page (ms) 266.2 209.0 21.5 % (not significant)

Conclusion: the SQL savings translate into small display gains, most of them inside the run to run spread.
Two gains are significant: the computer list server time (117.5 to 102.1 ms, -13 %), where P3 and P5 removed 200 queries from a single request, and the session lock wait of the ticket write cycle (360 to 224 ms, -38 %), because ajax/container.php no longer scans the value table nor reads every label translation and so holds the session for a shorter time.
The ticket form is fully displayed after 756 ms against 778 ms before and 562 ms without the plugin: the remaining delay is the session lock of ajax/container.php (335 ms of lock wait), which P2 targeted and which was not applied.
The ticket list keeps its server time (474 ms against 292 ms without the plugin), as expected since P7 was not applied.
The S5 regression (357 to 455 ms) is not a server cost: every request of the page lasts as long as before, only the click on the tab, driven by the scenario steps after the page load, happens later in the after runs.

Details

S0 · Neutral core page

  • Plugin overhead: 168 queries against 132 (page 117 against 93, main tab 51 against 39), SQL time 21.1 ms against 25.7 ms, fully loaded 228.7 ms against 229.9 ms (not significant).
  • The S0 window of the active SQL pass also caught dashboard AJAX calls of the previous page (central.php), so only the page and main tab connections are counted.
  • Each HTTP request pays 11 extra queries, 6 of them on plugin tables: glpi_plugins lookups for isPluginActive('fields') and isPluginActive('datainjection'), SELECT DISTINCT itemtypes FROM glpi_plugin_fields_containers, the dom container lookup, getFromDB and field list of PluginFieldsQuestionType::hasAvailableFields(), then the tab container list and the profile rights of getEntries('tab').
  • Requests added by the plugin: front/locale.php?domain=fields (0.3 ms server, 5 KB body, cached).
  • Plugin assets: front/css.php?file=/plugins/fields/css/fields.scss (0 KB transferred, browser cache), loaded on every page.

S1 · Ticket form (hot ticket)

  • Plugin overhead: 910 queries against 443, SQL time 152.9 ms against 100.9 ms, server time 91.6 ms against 74.7 ms, fully loaded 777.6 ms [729 to 1 027] against 561.5 ms [546 to 608].
  • Requests added by the plugin: plugins/fields/ajax/container.php?action=get_fields_html (76 queries, 80 ms server, 8.3 KB transferred, 49 KB decoded) and front/locale.php?domain=fields.
  • Page request: 268 queries against 107; main tab (ajax/common.tabs.php): 351 queries against 187, 84.6 ms against 65.3 ms server.
  • Repeated query shapes: SELECT * FROM glpi_plugin_fields_labeltranslations WHERE itemtype = ? AND items_id = ? AND language = ? 266 times (128 on the page, 123 on the main tab, 15 in the plugin AJAX call); glpi_plugin_fields_containerdisplayconditions read by id 8 times and by container 4 times; glpi_plugin_fields_containers by name 4 times.
  • Slowest plugin queries: SELECT * FROM glpi_plugin_fields_ticketticketextras WHERE plugin_fields_containers_id = 1 AND items_id = 1 twice, 13.8 and 14.4 ms, 50 000 rows examined each.
  • EXPLAIN of that query: type ALL, no key, 50 000 rows; the same query with itemtype = 'Ticket' added: type const on itemtype_item_container, 1 row.
  • AJAX timeline: container.php, comments.php (x2) and actorinformation.php (x2) start within 60 ms of each other; with the plugin, actorinformation.php waits 88.9 ms and comments.php 76.8 ms (37.7 and 26.2 ms without), the signature of the session lock held by container.php.
  • Long tasks: 3 (93, 59 and 130 ms), total blocking time 70 ms against 0; the last one follows the insertion of the dom block, which contains a richtext field (TinyMCE initialization).
  • Failed requests: none.

S2, S3 · Ticket plugin tab and urgency change

  • S2 adds the tab content request (ajax/common.tabs.php, 65 queries, 27 on plugin tables) and 3 full scans of value tables (52.2 ms SQL in total).
  • S3 replays ajax/container.php twice after the urgency change (76 queries each, 61 ms server median), 3 plugin calls and 24.9 KB per page; 4 full scans (55.0 ms SQL).
  • No baseline: these interactions do not exist without the plugin.

S4, S5 · Computer form and plugin tab

  • Plugin overhead on S4: 379 queries against 167, server time 95.9 ms against 78.3 ms, fully loaded 327.9 ms against 245.9 ms, total blocking 15 ms against 0.
  • The page request reads 143 label translations; the computer dom block is rendered server side (no plugin AJAX call), so there is no session lock effect.
  • Full scans stay cheap on 2 000 computers (0.56 ms) but follow the same pattern as on tickets.

S6, S7 · Lists with 4 plugin columns

  • Plugin overhead on S6: 1 046 queries against 732, SQL time 449.0 ms against 252.0 ms, server time 475.6 ms against 292.1 ms, fully loaded 784.8 ms against 559.2 ms.
  • Main search query: 353.5 ms and 597 250 rows examined, against 168.3 ms and 398 250 rows without the plugin.
  • EXPLAIN: glpi_tickets read through PRIMARY with temporary table and filesort; the 4 plugin LEFT JOINs (3 on glpi_plugin_fields_ticketticketextras, 1 on glpi_plugin_fields_ticketticketalphas) use ref on itemtype_item_container (const, glpi_tickets.id).
  • Repeated query shapes on the list page: 120 label translations and 80 SELECT * FROM glpi_plugin_fields_fields WHERE id = ? (4 plugin columns x 20 rows, one getFromDB per displayed cell).
  • Plugin overhead on S7: 313 queries against 98 on a single request, server time 117.5 ms against 95.5 ms, fully loaded 266.4 ms against 214.8 ms.

S8 · Ticket list filtered on a plugin field

  • 803 queries, main search query 11.5 ms (50 012 rows examined), server time 130.7 ms, 1 ticket returned.
  • No baseline.

S9 · Plugin container form, Fields tab

  • 266 queries, server time 114.7 ms, fully loaded 275.2 ms; no anomaly.

W1, W2, W3 · Writes

  • W1 overhead: 3 551 queries against 1 550, SQL time 589.4 ms against 344.4 ms, 1 608 163 rows examined against 345 217, fully loaded resulting page 734.3 ms against 502.5 ms.
  • W1 runs 25 full scans of plugin value tables (132.1 ms): SELECT id FROM glpi_plugin_fields_ticketticketextras WHERE items_id = ? 14 times, SELECT * FROM glpi_plugin_fields_ticketticketextras WHERE plugin_fields_containers_id = ? AND items_id = ? 4 times, and one SELECT id ... WHERE items_id = ? per tab table during the purge.
  • The creation POST runs 431 queries (240 on plugin tables) against 166.
  • W2 overhead: 1 560 queries against 661, SQL time 146.8 ms against 111.1 ms, fully loaded resulting page 275.5 ms against 238.5 ms.
  • W3 (tab save, no baseline): 768 queries, 6 full scans of glpi_plugin_fields_ticketticketalphas (40.0 ms).
  • Row counts of all seeded tables were checked after each pass: unchanged, no perf-write-% item left.

Fixes: expected against measured

Fix Expected Measured
P1 itemtype in value lookups S1 -2 scans (-28 ms SQL), S3 -4, W1 -25 (-132 ms SQL), W3 -6 (-40 ms) all scans gone on S1, S3, W1 and W3; W1 rows examined 1 608 163 to 360 880
P3 label translations S1 -260 queries, S4 -140, S6 and S7 -118 S1 266 to 3 (one per request), S4 to 2, S6 and S7 to 1
P4 activation state -2 queries per HTTP request -3 per HTTP request (isPluginActive('fields') and isPluginActive('datainjection') both read the boot list)
P5 field definitions in list cells S6 and S7 -76 queries 80 to 4 on S6 and S7
P6 containers once per request -3 to -4 queries per HTTP request -4 per HTTP request: init now runs 4 plugin-table queries (container list, dom blocks of the question type, field count, rights) instead of 6 plus the activation checks
  • P4 as planned (removing the check) was not possible: plugin_init_fields also runs during plugin:install and plugin:activate, before the tables exist, so the check is kept and reads Plugin::getPlugins(), filled at boot with the activated plugins.
  • P2 was not applied: rendering the dom block calls Dropdown::show(), which stores IDOR tokens in $_SESSION; closing the session before the rendering would drop these tokens and break the dropdowns of the block.
    A fix needs the rendering split from the session writes, larger than planned.
  • P7 was not applied: the plugin uses linkfield as the field name in the display conditions, the history, showSingle and the core massive update input name, so sharing one join per container means changing linkfield everywhere and checking the core search aliasing; it does not fit a bugfix branch.
  • The plugin PHPUnit suite (217 tests) passes after each fix.

Browser console

  • 195 messages over the session, 0 error, 0 warning.

Rule check

Rule Status Evidence
R1 Self-activation check Broken (verified) Plugin::isPluginActive('fields') in plugin_init_fields, setup.php:104: 2 glpi_plugins queries per HTTP request
R2 No SQL at init, memoized config Broken (verified) getUsedItemtypes() setup.php:112, hasAvailableFields() setup.php:137, getEntries('tab') setup.php:169: 6 plugin-table queries per HTTP request; getLabelFor() inc/labeltranslation.class.php:375 without cache
R3 Assets only where used, compiled CSS Broken (static) setup.php:180 falls back to css/fields.scss (no fields.min.css in the checkout) on every page; served from the browser cache during the benchmark, compilation cost not measured
R4 Session released in AJAX endpoints Broken (verified) no session_write_close() in ajax/*.php; ajax/container.php delays the concurrent core calls by about 50 ms each on S1
R5 No remote call during rendering OK no curl, Guzzle or remote file_get_contents in the plugin
R6 One request instead of one per item Broken (verified) one translation query per label (266 on S1), one getFromDB per list cell inc/abstractcontainerinstance.class.php:154 (80 on S6); one plugin AJAX call per page (OK)
R7 JS translations n/a (core) front/locale.php?domain=fields on every page (0.3 ms server); the plugin JS does not call __(), translations are done in Twig

Findings

F1 · Value rows read without itemtype: full table scans

  • Location: inc/field.class.php:1281 (dom block and tab display), inc/container.class.php:1793 and :1838 (save), :2299 (stored values), :2744 (mandatory check), :1058 (deleteByCriteria on purge).
  • What happens: the criteria hold items_id (and sometimes plugin_fields_containers_id) but not itemtype, while the only index is the unique key (itemtype, items_id, plugin_fields_containers_id); every lookup scans the whole value table.
  • Measured cost: 13 to 25 ms per lookup at 50 000 rows; 2 scans (28.1 ms) on each ticket display, 4 on S3, 25 (132.1 ms, 1.25 million rows) on a ticket write cycle, 6 (40.0 ms) on a tab save; linear with the number of items.
  • Rule: none of R1 to R7 (index usage), closest to R6 since the cost follows the data volume.

F2 · Session lock held by ajax/container.php

  • Location: ajax/container.php:32 onwards.
  • What happens: the endpoint only reads the session but keeps it locked while it renders the dom block, so the core AJAX calls started at the same time wait for it.
  • Measured cost: on S1, actorinformation.php and comments.php wait 77 to 89 ms against 26 to 38 ms without the plugin; total lock wait 366.7 ms against 160.9 ms; fully loaded +216 ms on S1, +232 ms on W1.
  • Rule: R4.

F3 · Label translations: one query per label, no cache

  • Location: inc/labeltranslation.class.php:375 (getLabelFor), called twice per field from inc/container.class.php:3026 and :3033 (getAddSearchOptions) and from getEntries() (inc/container.class.php:1638).
  • What happens: each label triggers a find() on glpi_plugin_fields_labeltranslations; the search options are built on the form, on its main tab, on every list and in the plugin AJAX call.
  • Measured cost: 266 queries on S1 (128 page, 123 main tab, 15 plugin AJAX), 143 on S4, 120 on S6 and S7; about 4 ms of SQL on S1, plus the PHP cost of each round trip.
  • Rule: R6 and R2 (no memoization).

F4 · Plugin init queries on every HTTP request

  • Location: setup.php:104 (isPluginActive('fields')), setup.php:112 (getUsedItemtypes()), setup.php:137 (plugin_fields_register_plugin_types() then hasAvailableFields()), setup.php:169 (getEntries('tab')), setup.php:205 (isPluginActive('datainjection')).
  • What happens: these run in plugin_init_fields for every request, AJAX calls and locale.php excluded, and read the same container table several times.
  • Measured cost: 11 queries per HTTP request, 6 of them on plugin tables, about 1 to 2 ms of SQL; 13 HTTP requests on the ticket form.
  • Rule: R1 and R2.

F5 · One getFromDB per displayed list cell

  • Location: inc/abstractcontainerinstance.class.php:154 (getSpecificValueToDisplay), same pattern at :106 (getSpecificValueToSelect).
  • What happens: each plugin cell of a list loads its field definition again.
  • Measured cost: 80 queries on S6 and S7 (4 columns x 20 rows), grows with the page size and the number of plugin columns.
  • Rule: R6.

F6 · One LEFT JOIN per plugin column in lists

  • Location: search options built in inc/container.class.php:3036 to :3040 (linkfield set to the field name, jointype itemtype_item).
  • What happens: GLPI builds one join alias per search option, so 3 columns of the same container produce 3 joins on the same value table, all evaluated on every ticket before the sort.
  • Measured cost: S6 server time 475.6 ms against 292.1 ms (+184 ms) with 4 plugin columns on 50 000 tickets; S7 +22 ms on 2 000 computers.
  • Rule: R6 (cost follows the data volume); the joins use the index, so the fix is structural and needs a check of the core search join aliasing.

F7 · Runtime SCSS and JS translations (information)

  • setup.php:180: fields.min.css is not present in this checkout, so css/fields.scss is compiled by front/css.php and loaded on every page; it was served from the browser cache during the runs (0 KB transferred), so its cost was not measured (R3, static).
  • front/locale.php?domain=fields is requested on every page although the plugin JS does not translate strings (R7, core-side recommendation).

Notes

  • make e2e-db-install failed once with a duplicate key on glpi_apiclients during the default data import, then succeeded on a second run; the cause was not identified.
  • Host port 8090 is used by another GLPI checkout (main); this checkout serves its e2e vhost on host port 8290 (docker-compose.override.yaml).
  • Scenario S3 neutralizes BeforeUnloadEvent in its own page, because the urgency change marks the form as modified and the leave-page dialog would stop the measurement.
  • During the session another process installed and activated GLPI Inventory (12:47 UTC) and deactivated fields, Branding and tester (12:59 UTC) in glpi_e2e; before the re-run, GLPI Inventory was deactivated and Branding and fields reactivated, so the plugin set matches the first benchmark.
  • Scenarios W1 and W2 trash and purge their item through page.request with the AJAX CSRF headers; without them GLPI answers 403 and the cycle leaves its item behind.

Value rows were looked up by items_id only, so MariaDB scanned the whole
value table on every form display, save and purge. Adding itemtype lets
the itemtype_item_container unique key be used, as search joins already do.
getLabelFor() ran one query per label, and search options call it twice
per field on every form, list and block refresh (up to 266 queries on a
ticket form). Translations of the session language are now loaded in a
single query and kept in memory, reset when a translation is saved or
purged.
Plugin::isPluginActive() queries glpi_plugins while plugins are being
initialized, so plugin_init_fields() ran extra queries on every HTTP
request. The activated plugin list is already built at boot and gives
the same answer, including during plugin install and activation.
getSpecificValueToDisplay() and getSpecificValueToSelect() loaded the
field definition with getFromDB() for every displayed cell, about 80
queries on a 20-row list with 4 plugin columns. Definitions are now
kept in memory per field id.
getUsedItemtypes() and getEntries() each queried the containers table on
every HTTP request; they now share one in-memory list, reset when a block
is added, updated or purged. hasAvailableFields() counts the fields of
all available blocks in one query instead of two queries per block.
@stonebuzz stonebuzz self-assigned this Nov 25, 2026
@stonebuzz
stonebuzz requested review from a team, Mary-Clb, MyvTsv and RomainLvr and removed request for a team November 25, 2026 13:33
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.

1 participant