Skip the renamed-params lookup in declared when nothing is renamed - #2926
Closed
ericproulx wants to merge 1 commit into
Closed
Skip the renamed-params lookup in declared when nothing is renamed#2926ericproulx wants to merge 1 commit into
declared when nothing is renamed#2926ericproulx wants to merge 1 commit into
Conversation
`build_memo_key` looks every declared param up in the route's renamed params, keyed by the param's whole path. That key is built fresh each time, two Arrays and a String per declared param, on every `declared` call. Only an API using `as:` has anything in that table; everywhere else it is empty and every lookup misses. The lookup is now skipped when the table is empty: `declared` on five params went from 4.81 to 4.29 µs (6.16 to 5.59 µs with missing keys included). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ericproulx
force-pushed
the
perf/declared-skip-empty-renames
branch
from
September 10, 2026 19:18
626f1cb to
80e1f03
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
DeclaredParamsHandler#build_memo_keylooks every declared param up in the route's renamed params, keyed by the param's whole path. That key is built fresh each time (two Arrays and a String per declared param) on everydeclaredcall. Only an API usingas:has anything in that table; everywhere else it is empty and every lookup misses. The lookup is now skipped when the table is empty.Benchmarks
declaredon five params (one nested Hash), isolated:declared(params, include_missing: false)declared(params)End to end, a JSON POST returning
declared(params, include_missing: false)measured +1.4% (median of 7 interleaved subprocess rounds, Ruby 4.0.6, no JIT), which is inside that harness's noise floor: master against itself read −1.2% the same day. The saving is about 100 ns per declared param, so it is a small, fixed win that scales with how many params an endpoint declares rather than a headline number.Test plan
as:specs.🤖 Generated with Claude Code