[6.x] Memoize the Replicator flattened sets config Blink key - #15259
Merged
Conversation
flattenedSetsConfig() rebuilt its Blink key on every call by json_encoding the whole field config. It's called repeatedly from fields(), preload() and augment(), so on a field with a lot of sets that serialization runs many times per request for a config that hasn't changed. Build the key once and reset it in setField(), which is the only thing that replaces the field it's derived from. Tests cover a field being replaced without the config being read in between, which is where an spl_object_id-keyed memo would serve the previous field's config, and the same via Bard since it inherits this. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Replicator::flattenedSetsConfig()rebuilt its Blink key on every call byjson_encode-ing the entire field config. It's called repeatedly fromfields(),preload()andaugment(), so on a field with a lot of sets that serialization runs many times per request for a config that hasn't changed. Bard inherits it too.The key is now built once and cached on the fieldtype, and reset in
setField()— the only thing that replaces the field it's derived from. That keeps the key's lifetime tied to the field it was built for.Caching it against
spl_object_id($this->field)instead wouldn't be safe.setField()stores acloneof the field, so the fieldtype is its sole owner and the field is freed as soon as it's replaced, and PHP reuses object ids — 300 fields throughField::fieldtype()reused just 4. Replace the field twice without reading the config in between and the third can land on the first's id, and you'd get the wrong set config back. There's a test covering that, for both Replicator and Bard.Extracted from #15158