⚡️ Speed up method JavaFunctionRanker.get_function_addressable_time by 1,245% in PR #1874 (java-tracer)#1875
Merged
misrasaurabh1 merged 1 commit intojava-tracerfrom Mar 19, 2026
Conversation
The original code performed a linear scan over `self._ranking` on every call to `get_function_addressable_time`, which `rank_functions` invokes repeatedly (once per function to filter, plus once per function to sort). The optimized version builds a hash map `_ranking_by_name` during `__init__`, replacing the O(n) loop with an O(1) dictionary lookup. Line profiler confirms the loop and comparison accounted for 94.7% of original runtime. When `rank_functions` calls `get_function_addressable_time` dozens or hundreds of times across a 1000-method ranking (as in `test_large_number_of_methods_and_repeated_queries_perf_and_correctness`), the lookup cost drops from ~293 µs to ~10 µs per call, yielding the 1244% overall speedup. The optimization also consolidates the two calls to `get_addressable_time_ns` in `get_function_stats_summary` into a single call, stored in a local variable, eliminating redundant work.
6 tasks
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.
⚡️ This pull request contains optimizations for PR #1874
If you approve this dependent PR, these changes will be merged into the original PR branch
java-tracer.📄 1,245% (12.45x) speedup for
JavaFunctionRanker.get_function_addressable_timeincodeflash/benchmarking/function_ranker.py⏱️ Runtime :
1.14 milliseconds→85.0 microseconds(best of250runs)📝 Explanation and details
The original code performed a linear scan over
self._rankingon every call toget_function_addressable_time, whichrank_functionsinvokes repeatedly (once per function to filter, plus once per function to sort). The optimized version builds a hash map_ranking_by_nameduring__init__, replacing the O(n) loop with an O(1) dictionary lookup. Line profiler confirms the loop and comparison accounted for 94.7% of original runtime. Whenrank_functionscallsget_function_addressable_timedozens or hundreds of times across a 1000-method ranking (as intest_large_number_of_methods_and_repeated_queries_perf_and_correctness), the lookup cost drops from ~293 µs to ~10 µs per call, yielding the 1244% overall speedup. The optimization also consolidates the two calls toget_addressable_time_nsinget_function_stats_summaryinto a single call, stored in a local variable, eliminating redundant work.✅ Correctness verification report:
🌀 Click to see Generated Regression Tests
To edit these changes
git checkout codeflash/optimize-pr1874-2026-03-19T06.41.55and push.