Skip to content

[6.x] Make each taxonomy into an array once per terms listing - #15876

Merged
jasonvarga merged 1 commit into
statamic:6.xfrom
ryanmitchell:perf/listed-term-taxonomy-once
Nov 18, 2026
Merged

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

Conversation

@ryanmitchell

Copy link
Copy Markdown
Contributor

Every term in a Control Panel terms listing includes its taxonomy as 'taxonomy' => $term->taxonomy()->toArray(). That's the taxonomy's full augmented array, URLs included, and it was made again for every term on the page. All the terms in a listing share one taxonomy (or a few, in the Terms fieldtype's listing), so a page of 50 terms built the same array 50 times. That was most of the listing's time.

Terms now gives its ListedTerms a shared place to keep each taxonomy's array, keyed by handle, so each taxonomy is made into an array once per listing. A ListedTerm used on its own, without one, makes the array as before.

The response is unchanged.

Tests

  • the_taxonomy_is_only_made_into_an_array_once_per_listing lists three terms with a Taxonomy subclass that counts toArray() calls. It's called 3 times before this change and once after, and every term's taxonomy still matches Taxonomy::toArray().
  • each_term_gets_its_own_taxonomy_when_listing_terms_from_several covers a listing that mixes taxonomies, as the Terms fieldtype's can.

Benchmark

The terms listing endpoint (/cp/taxonomies/tags/terms, 50 per page) requested as a super user, alternating between 6.x (255b35f) and this branch 6 times. Each request is a fresh PHP process with a warm Stache; medians shown (Apple Silicon, PHP 8.4). The response was identical on both.

6.x This branch
50 tags, 1,000 articles 50.8ms 37.9ms −25%
200 tags, 10,000 articles 59.7ms 47.1ms −21%

The branch was faster in all 12 pairs.

🤖 Generated with Claude Code

Every term in a Control Panel terms listing included its taxonomy's
augmented array, made again for each term. Share them across the listing
so each taxonomy is made into an array once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jasonvarga
jasonvarga merged commit 54096cc into statamic:6.x Nov 18, 2026
62 checks passed
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