Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Remove redundant per-call Lowkey lookup in untyped_methods - #47

Open
maedi wants to merge 3 commits into
mainfrom
perf/untyped-methods-remove-redundant-lowkey-lookup
Open

Remove redundant per-call Lowkey lookup in untyped_methods#47
maedi wants to merge 3 commits into
mainfrom
perf/untyped-methods-remove-redundant-lowkey-lookup

Conversation

@maedi

@maedi maedi commented Sep 1, 2026

Copy link
Copy Markdown
Member

Summary

untyped_methods's per-call body re-derived method_proxy on every single call via Lowkey[class_proxy.file_path][class_proxy.namespace][__method__], even though method_proxy was already available via the surrounding closure — the same method_proxies.values.filter(&:expressions?).each do |method_proxy| ... end that typed_methods uses without re-deriving it anywhere. The re-fetch wasn't needed for anything; just removing it and using the closed-over value works identically.

Why this matters (not just a style nit)

This wasn't just wasted CPU — it was actively working against the purpose of disabling type checking. Measured with a clean sequential GC.stat-based methodology against Raindeer (an app built on this gem), with config.type_checking = false: mean allocations/request had gone from 268 (type checking enabled) to 292 (type checking disabled) — disabling type checking made allocations measurably worse, not better, because of this redundant lookup. Removing it dropped allocations to 260/request (now below even the type-checked baseline), and throughput went 14,632 → 15,673 req/s (+7.1%).

Verification

  • Full suite: 141 examples, same 10 pre-existing failures as main (Ruby-version-dependent formatting differences, unrelated to this change).
  • Confirmed against a real downstream app (Raindeer) via ab benchmarking and GC.stat-based allocation profiling — numbers above.

maedi and others added 3 commits August 17, 2026 11:09
untyped_methods's per-call body re-derived method_proxy on every
single call via Lowkey[class_proxy.file_path][class_proxy.namespace][__method__],
even though method_proxy was already available via the surrounding
closure -- the same method_proxies.values.filter(&:expressions?).each
do |method_proxy| ... end that typed_methods uses without re-deriving
it. The re-fetch was simply redundant, not needed for anything.

This wasn't just wasted CPU: measured with a clean sequential GC.stat
methodology (Raindeer, an app built on this gem, with type_checking
disabled), mean allocations/request had gone from 268 (type checking
enabled) to 292 (type checking disabled) because of this redundant
lookup -- disabling type checking made allocations *worse*, not
better. Removing the lookup dropped it to 260/request (now below even
the type-checked baseline) and req/s went 14,632 -> 15,673 (+7.1%).
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