Skip the qualifying-params lookup for scopes other than given - #2925
Open
ericproulx wants to merge 1 commit into
Open
Skip the qualifying-params lookup for scopes other than given#2925ericproulx wants to merge 1 commit into
given#2925ericproulx wants to merge 1 commit into
Conversation
A nested scope resolves its params through `@parent.qualifying_params.presence`, which reads the request's tracker out of fiber storage and looks the parent up in its identity Hash. That runs twice per validator on a nested scope, once in `should_validate?` and once in the attributes iterator, on every request. Only `#meets_dependency?` ever stores qualifying params, and it returns before doing so unless the scope has a dependency, i.e. is a `given`. Every other scope therefore always answered empty, and now does so without the lookups: about 190 ns per resolution, and a nested validator went from 1.77 to 1.39 µs. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ericproulx
force-pushed
the
perf/qualifying-params-given-only
branch
from
September 10, 2026 19:18
271a0a6 to
0f02917
Compare
Danger ReportNo issues found. |
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.
Summary
A nested scope resolves its params through
@parent.qualifying_params.presence, which reads the request'sParamScopeTrackerout of fiber storage and looks the parent up in its identity Hash. That runs twice per validator on a nested scope (once inshould_validate?, once in the attributes iterator) on every request.Only
#meets_dependency?ever stores qualifying params, and it returns before doing so unless the scope has a dependency, i.e. is agiven. Every other scope therefore always answered empty; it now answersnilwithout the lookups. The sole caller applies.presence, soniland the previous empty Array behave the same.Benchmarks
Median of 7 interleaved subprocess rounds against master, Ruby 4.0.6, no JIT:
requires :user, type: Hash do ... end(3 attributes)Per nested validator: 1.77 → 1.39 µs; per nested scope resolution, about 190 ns saved. The gain grows with nesting depth.
Test plan
givenspecs each.🤖 Generated with Claude Code