⚡️ Speed up method JavaAssertTransformer._infer_return_type by 44% in PR #1655 (feat/add/void/func)#1757
Merged
claude[bot] merged 1 commit intofeat/add/void/funcfrom Mar 4, 2026
Conversation
The optimization adds a fast-path check in `_infer_type_from_assertion_args` that looks for the first comma and extracts the substring before it directly when no special delimiter characters (quotes, parentheses, braces) precede that comma, bypassing the expensive full `_extract_first_arg` parser for simple literals like `42`, `100L`, or `true`. Line profiler shows the original `_extract_first_arg` call consumed 49% of method runtime (~11.1 ms); the optimized version reduces this to 6.7% (~0.98 ms) by handling 1518 of 1632 cases via the cheap substring path, cutting per-call overhead from ~6808 ns to ~140–280 ns for common assertions. Runtime improves 43% (4.73 ms → 3.30 ms) with no correctness regressions; the fallback preserves exact behavior for nested or quoted arguments.
5 tasks
Merged
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 #1655
If you approve this dependent PR, these changes will be merged into the original PR branch
feat/add/void/func.📄 44% (0.44x) speedup for
JavaAssertTransformer._infer_return_typeincodeflash/languages/java/remove_asserts.py⏱️ Runtime :
4.73 milliseconds→3.30 milliseconds(best of151runs)📝 Explanation and details
The optimization adds a fast-path check in
_infer_type_from_assertion_argsthat looks for the first comma and extracts the substring before it directly when no special delimiter characters (quotes, parentheses, braces) precede that comma, bypassing the expensive full_extract_first_argparser for simple literals like42,100L, ortrue. Line profiler shows the original_extract_first_argcall consumed 49% of method runtime (~11.1 ms); the optimized version reduces this to 6.7% (~0.98 ms) by handling 1518 of 1632 cases via the cheap substring path, cutting per-call overhead from ~6808 ns to ~140–280 ns for common assertions. Runtime improves 43% (4.73 ms → 3.30 ms) with no correctness regressions; the fallback preserves exact behavior for nested or quoted arguments.✅ Correctness verification report:
🌀 Click to see Generated Regression Tests
To edit these changes
git checkout codeflash/optimize-pr1655-2026-03-04T03.21.59and push.