Skip to content

[6.x] Memoize the Replicator flattened sets config Blink key - #15259

Merged
jasonvarga merged 1 commit into
6.xfrom
cp-replicator-blink-memo
Aug 24, 2026
Merged

[6.x] Memoize the Replicator flattened sets config Blink key#15259
jasonvarga merged 1 commit into
6.xfrom
cp-replicator-blink-memo

Conversation

@jasonvarga

@jasonvarga jasonvarga commented Aug 24, 2026

Copy link
Copy Markdown
Member

Replicator::flattenedSetsConfig() rebuilt its Blink key on every call by json_encode-ing the entire 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. 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 a clone of 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 through Field::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

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>
@jasonvarga
jasonvarga merged commit 4720484 into 6.x Aug 24, 2026
67 checks passed
@jasonvarga
jasonvarga deleted the cp-replicator-blink-memo branch August 24, 2026 22:39
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.

1 participant