Repository navigation
Perf optimization - #1371
Open
stonebuzz wants to merge 6 commits into
Open
Perf optimization#1371stonebuzz wants to merge 6 commits into
stonebuzz wants to merge 6 commits into
Conversation
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
requested review from
a team,
Mary-Clb,
MyvTsv and
RomainLvr
and removed request for
a team
November 25, 2026 13:33
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.
Performance analysis: Additional fields (fields) 1.24.7
Description
The benchmark runs GLPI 11.0.14-dev (branch
11.0/bugfixes, commit23a7f1bb61) in the e2e environment (e2e_testing, databaseglpi_e2e, served onhttp://localhost:8290), with the plugin fields 1.24.7 (branch11.0/bugfixes, commit5cc0bb2).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
domblock 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.
Scenarios, each replayed with one discarded warm-up run and 5 measured runs:
/front/preference.php)ajax/container.php)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(branchperf_optimization, 5 local commits on top of5cc0bb2).Fixes applied: P1
itemtypein 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
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
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.phpno 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
central.php), so only the page and main tab connections are counted.glpi_pluginslookups forisPluginActive('fields')andisPluginActive('datainjection'),SELECT DISTINCT itemtypes FROM glpi_plugin_fields_containers, the dom container lookup,getFromDBand field list ofPluginFieldsQuestionType::hasAvailableFields(), then the tab container list and the profile rights ofgetEntries('tab').front/locale.php?domain=fields(0.3 ms server, 5 KB body, cached).front/css.php?file=/plugins/fields/css/fields.scss(0 KB transferred, browser cache), loaded on every page.S1 · Ticket form (hot ticket)
plugins/fields/ajax/container.php?action=get_fields_html(76 queries, 80 ms server, 8.3 KB transferred, 49 KB decoded) andfront/locale.php?domain=fields.ajax/common.tabs.php): 351 queries against 187, 84.6 ms against 65.3 ms server.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_containerdisplayconditionsread by id 8 times and by container 4 times;glpi_plugin_fields_containersby name 4 times.SELECT * FROM glpi_plugin_fields_ticketticketextras WHERE plugin_fields_containers_id = 1 AND items_id = 1twice, 13.8 and 14.4 ms, 50 000 rows examined each.ALL, no key, 50 000 rows; the same query withitemtype = 'Ticket'added: typeconstonitemtype_item_container, 1 row.container.php,comments.php(x2) andactorinformation.php(x2) start within 60 ms of each other; with the plugin,actorinformation.phpwaits 88.9 ms andcomments.php76.8 ms (37.7 and 26.2 ms without), the signature of the session lock held bycontainer.php.S2, S3 · Ticket plugin tab and urgency change
ajax/common.tabs.php, 65 queries, 27 on plugin tables) and 3 full scans of value tables (52.2 ms SQL in total).ajax/container.phptwice 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).S4, S5 · Computer form and plugin tab
S6, S7 · Lists with 4 plugin columns
glpi_ticketsread throughPRIMARYwith temporary table and filesort; the 4 plugin LEFT JOINs (3 onglpi_plugin_fields_ticketticketextras, 1 onglpi_plugin_fields_ticketticketalphas) userefonitemtype_item_container(const,glpi_tickets.id).SELECT * FROM glpi_plugin_fields_fields WHERE id = ?(4 plugin columns x 20 rows, onegetFromDBper displayed cell).S8 · Ticket list filtered on a plugin field
S9 · Plugin container form, Fields tab
W1, W2, W3 · Writes
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 oneSELECT id ... WHERE items_id = ?per tab table during the purge.glpi_plugin_fields_ticketticketalphas(40.0 ms).perf-write-%item left.Fixes: expected against measured
itemtypein value lookupsisPluginActive('fields')andisPluginActive('datainjection')both read the boot list)plugin_init_fieldsalso runs duringplugin:installandplugin:activate, before the tables exist, so the check is kept and readsPlugin::getPlugins(), filled at boot with the activated plugins.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.
linkfieldas the field name in the display conditions, the history,showSingleand the core massive update input name, so sharing one join per container means changinglinkfieldeverywhere and checking the core search aliasing; it does not fit a bugfix branch.Browser console
Rule check
Plugin::isPluginActive('fields')inplugin_init_fields,setup.php:104: 2glpi_pluginsqueries per HTTP requestgetUsedItemtypes()setup.php:112,hasAvailableFields()setup.php:137,getEntries('tab')setup.php:169: 6 plugin-table queries per HTTP request;getLabelFor()inc/labeltranslation.class.php:375without cachesetup.php:180falls back tocss/fields.scss(nofields.min.cssin the checkout) on every page; served from the browser cache during the benchmark, compilation cost not measuredsession_write_close()inajax/*.php;ajax/container.phpdelays the concurrent core calls by about 50 ms each on S1curl, Guzzle or remotefile_get_contentsin the plugingetFromDBper list cellinc/abstractcontainerinstance.class.php:154(80 on S6); one plugin AJAX call per page (OK)front/locale.php?domain=fieldson every page (0.3 ms server); the plugin JS does not call__(), translations are done in TwigFindings
F1 · Value rows read without
itemtype: full table scansinc/field.class.php:1281(dom block and tab display),inc/container.class.php:1793and:1838(save),:2299(stored values),:2744(mandatory check),:1058(deleteByCriteriaon purge).items_id(and sometimesplugin_fields_containers_id) but notitemtype, while the only index is the unique key(itemtype, items_id, plugin_fields_containers_id); every lookup scans the whole value table.F2 · Session lock held by
ajax/container.phpajax/container.php:32onwards.actorinformation.phpandcomments.phpwait 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.F3 · Label translations: one query per label, no cache
inc/labeltranslation.class.php:375(getLabelFor), called twice per field frominc/container.class.php:3026and:3033(getAddSearchOptions) and fromgetEntries()(inc/container.class.php:1638).find()onglpi_plugin_fields_labeltranslations; the search options are built on the form, on its main tab, on every list and in the plugin AJAX call.F4 · Plugin init queries on every HTTP request
setup.php:104(isPluginActive('fields')),setup.php:112(getUsedItemtypes()),setup.php:137(plugin_fields_register_plugin_types()thenhasAvailableFields()),setup.php:169(getEntries('tab')),setup.php:205(isPluginActive('datainjection')).plugin_init_fieldsfor every request, AJAX calls andlocale.phpexcluded, and read the same container table several times.F5 · One
getFromDBper displayed list cellinc/abstractcontainerinstance.class.php:154(getSpecificValueToDisplay), same pattern at:106(getSpecificValueToSelect).F6 · One LEFT JOIN per plugin column in lists
inc/container.class.php:3036to:3040(linkfieldset to the field name,jointypeitemtype_item).F7 · Runtime SCSS and JS translations (information)
setup.php:180:fields.min.cssis not present in this checkout, socss/fields.scssis compiled byfront/css.phpand 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=fieldsis requested on every page although the plugin JS does not translate strings (R7, core-side recommendation).Notes
make e2e-db-installfailed once with a duplicate key onglpi_apiclientsduring the default data import, then succeeded on a second run; the cause was not identified.main); this checkout serves its e2e vhost on host port 8290 (docker-compose.override.yaml).BeforeUnloadEventin its own page, because the urgency change marks the form as modified and the leave-page dialog would stop the measurement.glpi_e2e; before the re-run, GLPI Inventory was deactivated and Branding and fields reactivated, so the plugin set matches the first benchmark.page.requestwith the AJAX CSRF headers; without them GLPI answers 403 and the cycle leaves its item behind.