⚡️ Speed up method JavaAssertTransformer._infer_type_from_assertion_args by 32% in PR #1655 (feat/add/void/func)#1765
Closed
codeflash-ai[bot] wants to merge 1 commit intofeat/add/void/funcfrom
Conversation
The optimization replaced character-by-character list accumulation in `_extract_first_arg` with direct substring slicing (tracking `start` and `end` indices instead of building a list via `cur.append()`), eliminating repeated list operations and the final `"".join(cur)` call. For the JUnit4 message-string case (where `assertEquals("msg", expected, actual)` requires extracting the second argument), it introduced `_second_arg_if_message`, a lightweight two-comma scanner that stops as soon as it confirms three top-level arguments exist and extracts only the second one, avoiding the original `_split_top_level_args` which built a complete list of all arguments. Line profiler confirms `_split_top_level_args` accounted for 36.6% of original runtime and `_extract_first_arg`'s list operations added 10.1%; the new index-based approach cuts total runtime by 32% with no behavioral changes.
5 tasks
Contributor
|
Closing stale optimization PR. |
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.📄 32% (0.32x) speedup for
JavaAssertTransformer._infer_type_from_assertion_argsincodeflash/languages/java/remove_asserts.py⏱️ Runtime :
6.32 milliseconds→4.78 milliseconds(best of140runs)📝 Explanation and details
The optimization replaced character-by-character list accumulation in
_extract_first_argwith direct substring slicing (trackingstartandendindices instead of building a list viacur.append()), eliminating repeated list operations and the final"".join(cur)call. For the JUnit4 message-string case (whereassertEquals("msg", expected, actual)requires extracting the second argument), it introduced_second_arg_if_message, a lightweight two-comma scanner that stops as soon as it confirms three top-level arguments exist and extracts only the second one, avoiding the original_split_top_level_argswhich built a complete list of all arguments. Line profiler confirms_split_top_level_argsaccounted for 36.6% of original runtime and_extract_first_arg's list operations added 10.1%; the new index-based approach cuts total runtime by 32% with no behavioral changes.✅ Correctness verification report:
🌀 Click to see Generated Regression Tests
To edit these changes
git checkout codeflash/optimize-pr1655-2026-03-04T05.37.57and push.