Skip to content

[6.x] Memoize preprocessed fields in Validator#14605

Merged
jasonvarga merged 1 commit into
6.xfrom
memoize-validator-preprocess
May 5, 2026
Merged

[6.x] Memoize preprocessed fields in Validator#14605
jasonvarga merged 1 commit into
6.xfrom
memoize-validator-preprocess

Conversation

@jasonvarga

@jasonvarga jasonvarga commented May 5, 2026

Copy link
Copy Markdown
Member

When saving an entry, preProcessValidatable was being called on every field 3 times. The Validator::validator() method calls $this->fields->preProcessValidatables() from three places — directly to build the data array, and indirectly through rules() and attributes() — each of which iterates every field and invokes its fieldtype's preProcessValidatable().

This memoizes the result on the Validator instance so the work happens once per validation. The cache is reset in fields() so re-setting fields invalidates it.

Closes #14604

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jasonvarga jasonvarga merged commit 2430355 into 6.x May 5, 2026
19 checks passed
@jasonvarga jasonvarga deleted the memoize-validator-preprocess branch May 5, 2026 13:50
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.

preProcessValidatable called too often

1 participant