Remove redundant per-call Lowkey lookup in untyped_methods - #47
Open
maedi wants to merge 3 commits into
Open
Conversation
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%).
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
untyped_methods's per-call body re-derivedmethod_proxyon every single call viaLowkey[class_proxy.file_path][class_proxy.namespace][__method__], even thoughmethod_proxywas already available via the surrounding closure — the samemethod_proxies.values.filter(&:expressions?).each do |method_proxy| ... endthattyped_methodsuses 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), withconfig.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
main(Ruby-version-dependent formatting differences, unrelated to this change).abbenchmarking andGC.stat-based allocation profiling — numbers above.