Skip to content

[6.x] Fix blueprint fields being rebuilt for every entry - #15639

Merged
jasonvarga merged 2 commits into
statamic:6.xfrom
daun:perf/blueprint
Oct 15, 2026
Merged

jasonvarga merged 2 commits into
statamic:6.xfrom
daun:perf/blueprint

Conversation

@daun

@daun daun commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR

Cause

Collection::entryBlueprint() calls setParent($entry) on one shared blueprint for every entry. For dated collections, Entry::hasTime() triggers this for each entry. resetFieldsCache() keeps the fields when the new parent has the same blueprint (#9585). But since #11116, setParent() calls resetBlueprintCache() first, which clears lastBlueprintHandle, so that check never matches.

In short, #11116 switched off the cache that #9585 added for exactly this case. This change keeps the fix from #11116.

Fix

  • setParent() only calls resetFieldsCache()
  • When the cache is kept, the new parent gets copies of the fields with their parent set to it. Copying instead of changing the cached fields means fields handed out earlier keep pointing at their own entry.
  • Content changes (setContents(), ensureField(), …) still clear the cache.

Benchmarks

Stache

Same blueprint and 200 entries on the Stache. 5 runs. The fields are rebuilt when each entry is augmented.

Before This PR
Query only 7 ms 7 ms
Query + toAugmentedArray() 525 ms 27 ms

Eloquent

200 entries, dated collection, blueprint with 19 fieldset references and 2 imports. 5 runs.

Before This PR
Default entry class 547 ms 69 ms
Custom entry_class 768 ms 363 ms

Tests

Test Before After
Switching parents with the same blueprint doesn't rebuild fields ❌ ✅
Fields handed out earlier keep their parent ✅ ✅
Hydrating several dated entries resolves fields once ❌ ✅

The test from #10061 still passes, as do tests/Fields, tests/Data/Entries and tests/Revisions. #9585, #11116 and #13430 added no tests.

…ng copy

Guards the behavior from statamic#11116 now that setParent() can keep the cached fields.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@jasonvarga
jasonvarga merged commit db5ff54 into statamic:6.x Oct 15, 2026
61 checks passed
@daun
daun deleted the perf/blueprint branch October 16, 2026 09:17
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