Settle the attributes iterator's per-scope state once per pass - #2928
Closed
ericproulx wants to merge 1 commit into
Closed
ericproulx wants to merge 1 commit into
ericproulx wants to merge 1 commit into
Conversation
For every element of an array scope, and for every validator on it, `AttributesIterator#do_each` re-derived things that depend only on the scope and the request: whether the scope iterates elements, whether its params are an Array, which scope an element's index is recorded against, and the request's `ParamScopeTracker`, a fiber-storage read. They are now settled once per `#each` and handed down, and the top-level call no longer allocates its empty `parent_indices`. An element-iterating scope whose params are not an Array returns before iterating, since it yielded and recorded nothing anyway. On a ten-element array, one validator's iteration overhead went from 5.46 to 4.64 µs. The branch where a lateral scope, such as a `with` group inside an array, records each element's index against its nearest array ancestor had no spec: removing it passed the suite while naming the wrong element in errors. It now has one, which passes before and after this change. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ericproulx
force-pushed
the
perf/attributes-iterator-per-pass-state
branch
from
September 10, 2026 19:53
65851db to
840b2cf
Compare
Danger ReportNo issues found. |
5 tasks
Contributor
Author
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
For every element of an array scope, and for every validator on it,
AttributesIterator#do_eachre-derived things that depend only on the scope and the request: whether the scope iterates elements, whether its params are an Array, which scope an element's index is recorded against, and the request'sParamScopeTracker(a fiber-storage read). They are now settled once per#eachand handed down, and the top-level call no longer allocates its emptyparent_indices. An element-iterating scope whose params are not an Array returns before iterating, since it yielded and recorded nothing anyway.One validator's iteration overhead on a ten-element array: 5.46 → 4.64 µs.
Missing spec, added
The branch where a lateral scope (a
withgroup inside an array) records each element's index against its nearest array ancestor had no coverage: removing it passed the whole suite, while errors then named the wrong element (array[2][b]for the first element, and two errors collapsed into one). The new spec fails a first and a last element; it passes before and after this change, and fails with that branch removed.Benchmarks
Median of 9 interleaved subprocess rounds against master, Ruby 4.0.6, no JIT:
Test plan
🤖 Generated with Claude Code