⚡️ Speed up method JfrProfile._parse_json by 42% in PR #1874 (java-tracer)#1876
Merged
claude[bot] merged 1 commit intojava-tracerfrom Mar 19, 2026
Merged
Conversation
The optimization precomputes all frame-to-key conversions for a stack trace once (into a `keys` list) instead of calling `_frame_to_key` repeatedly inside the caller-callee loop, cutting per-frame extraction from ~3.3 µs to ~0.19 µs (83% reduction) and lifting `_frame_to_key` from 20.8% of total time to 43.2% (the loop cost is now dominated by the upfront list comprehension rather than repeated calls). A local `matches_packages_cached` closure memoizes package-filter results to avoid re-checking the same method keys across caller relationships, reducing `_matches_packages` overhead from 12.6% to 0.8% of total time; profiler data shows `_matches_packages` hits dropped from 18,364 to 1,500. The timestamp-duration calculation switched from accumulating a list then calling `max()`/`min()` to inline min/max tracking, removing intermediate allocations; combined, these changes yield a 42% overall speedup (46.4 ms → 32.6 ms).
6 tasks
Contributor
|
CI failures are pre-existing on the base branch (not caused by this PR): unit-tests (all platforms) fail due to test_git_utils tests that test old language-filtering behavior — these will be fixed once PR #1878 merges. Leaving open for merge once base branch CI is fixed. |
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.📄 42% (0.42x) speedup for
JfrProfile._parse_jsonincodeflash/languages/java/jfr_parser.py⏱️ Runtime :
46.4 milliseconds→32.6 milliseconds(best of32runs)📝 Explanation and details
The optimization precomputes all frame-to-key conversions for a stack trace once (into a
keyslist) instead of calling_frame_to_keyrepeatedly inside the caller-callee loop, cutting per-frame extraction from ~3.3 µs to ~0.19 µs (83% reduction) and lifting_frame_to_keyfrom 20.8% of total time to 43.2% (the loop cost is now dominated by the upfront list comprehension rather than repeated calls). A localmatches_packages_cachedclosure memoizes package-filter results to avoid re-checking the same method keys across caller relationships, reducing_matches_packagesoverhead from 12.6% to 0.8% of total time; profiler data shows_matches_packageshits dropped from 18,364 to 1,500. The timestamp-duration calculation switched from accumulating a list then callingmax()/min()to inline min/max tracking, removing intermediate allocations; combined, these changes yield a 42% overall speedup (46.4 ms → 32.6 ms).✅ Correctness verification report:
🌀 Click to see Generated Regression Tests
To edit these changes
git checkout codeflash/optimize-pr1874-2026-03-19T08.11.52and push.