Skip to content

Skip the renamed-params lookup in declared when nothing is renamed - #2926

Closed
ericproulx wants to merge 1 commit into
masterfrom
perf/declared-skip-empty-renames
Closed

Skip the renamed-params lookup in declared when nothing is renamed#2926
ericproulx wants to merge 1 commit into
masterfrom
perf/declared-skip-empty-renames

Conversation

@ericproulx

Copy link
Copy Markdown
Contributor

Summary

DeclaredParamsHandler#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.

Benchmarks

declared on five params (one nested Hash), isolated:

call master branch
declared(params, include_missing: false) 4.81 µs 4.29 µs (−11%)
declared(params) 6.16 µs 5.59 µs (−9%)

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

  • Full RSpec suite passes locally.
  • RuboCop clean.
  • Mutation-checked through existing specs: inverting the guard fails 14 as: specs.
  • CI green.

🤖 Generated with Claude Code

`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
ericproulx force-pushed the perf/declared-skip-empty-renames branch from 626f1cb to 80e1f03 Compare September 10, 2026 19:18
@github-actions

github-actions Bot commented Sep 10, 2026

Copy link
Copy Markdown

Danger Report

No issues found.

View run

@ericproulx

Copy link
Copy Markdown
Contributor Author

Closing in favour of #2936, which combines #2922#2934 into one PR, re-benchmarked as a whole against master. The write-up here (behaviour matrix, mutation results) still describes this part of the change.

@ericproulx ericproulx closed this Sep 11, 2026
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