Skip to content

[6.x] Make each term once when building term indexes - #15871

Merged
jasonvarga merged 1 commit into
statamic:6.xfrom
ryanmitchell:perf/term-indexes-once-per-term
Nov 12, 2026
Merged

jasonvarga merged 1 commit into
statamic:6.xfrom
ryanmitchell:perf/term-indexes-once-per-term

Conversation

@ryanmitchell

@ryanmitchell ryanmitchell commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

A taxonomy's associations index has a row for every term each entry uses, so 10,000 entries with three tags each is about 30,000 rows for a couple of hundred tags.

When Terms\Value built a term index (id, path, slug, site, title, and any other value index on a terms store), it made a Term for every row and then kept one per site::slug with mapWithKeys(). Building the same term again and again added up: on a cold warm, the term value indexes were the single biggest cost, ahead of loading the entries themselves.

The associations are now grouped by site and slug first, and each term is made once.

Same result

A term made from an association depends only on its site and slug (the title is set to the slug as well), so every duplicate produced the same value. The index items, their keys and their order are unchanged, and term files still win over terms made from associations. TermValueIndexTest checks the indexes against the old one-term-per-association result, including multisite and a term with a file.

Benchmark

stache:warm from a cleared cache and stache:refresh, alternating between 6.x (7097691) and this branch 4 times so both see the same machine conditions. Each run is a fresh PHP process; medians shown (Apple Silicon, PHP 8.4). The site is generated: dated articles with 1–5 tags (skewed usage) and a category each, plus a structured pages collection. Tags are N/50 (min 50), and there are 12 categories.

6.x This branch
1,000 articles: warm 1.20s 0.85s −29%
1,000 articles: refresh 1.18s 0.84s −29%
10,000 articles: warm 11.77s 8.26s −30%
10,000 articles: refresh 12.27s 8.22s −33%

The branch was faster in all 16 pairs. Peak memory is unchanged.

🤖 Generated with Claude Code

Every entry that uses a term adds an association, and the value indexes
made a term for every association before keeping one per site and slug.
Group the associations first so each term is made once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jasonvarga
jasonvarga merged commit 5bc945a into statamic:6.x Nov 12, 2026
63 checks passed
@ryanmitchell
ryanmitchell deleted the perf/term-indexes-once-per-term branch November 12, 2026 21:47
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.

2 participants