⚡️ Speed up function _contains_jsx by 457% in PR #1567 (codeflash/optimize-pr1563-2026-02-20T03.27.20)#1570
Merged
claude[bot] merged 1 commit intocodeflash/optimize-pr1563-2026-02-20T03.27.20from Feb 20, 2026
Conversation
Refined the optimization to focus on the core performance improvement while maximizing code simplicity: 1. **Removed module-level `_JSX_NODE_TYPES` constant**: This micro-optimization added complexity (module-level state) without meaningful performance benefit. The original tuple is small and Python handles small tuple membership checks efficiently. 2. **Removed `reversed(children)` and associated comment**: For a boolean "contains" check, the traversal order is irrelevant. Removing this simplifies the code and eliminates the overhead of reversing children lists. 3. **Kept original variable name `node`**: Reusing `node` in the loop maintains consistency with the original code and reduces diff size. 4. **Removed unnecessary comment**: The simplified iterative approach is self-explanatory and doesn't require additional documentation. The refined code preserves the key optimization (iterative DFS avoiding recursion and generator overhead) while being more readable and closer to the original structure. The performance benefit remains intact as the core algorithmic improvement is preserved.
Contributor
PR Review SummaryPrek Checks✅ All checks passed (ruff check, ruff format). No issues found. Mypy✅ No type errors found in the changed file. Code Review✅ No critical issues found. The change converts Test Coverage
Notes:
Last updated: 2026-02-20 |
f18fa5c
into
codeflash/optimize-pr1563-2026-02-20T03.27.20
25 of 27 checks passed
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 #1567
If you approve this dependent PR, these changes will be merged into the original PR branch
codeflash/optimize-pr1563-2026-02-20T03.27.20.📄 457% (4.57x) speedup for
_contains_jsxincodeflash/languages/javascript/frameworks/react/profiler.py⏱️ Runtime :
621 microseconds→111 microseconds(best of31runs)📝 Explanation and details
Refined the optimization to focus on the core performance improvement while maximizing code simplicity:
Removed module-level
_JSX_NODE_TYPESconstant: This micro-optimization added complexity (module-level state) without meaningful performance benefit. The original tuple is small and Python handles small tuple membership checks efficiently.Removed
reversed(children)and associated comment: For a boolean "contains" check, the traversal order is irrelevant. Removing this simplifies the code and eliminates the overhead of reversing children lists.Kept original variable name
node: Reusingnodein the loop maintains consistency with the original code and reduces diff size.Removed unnecessary comment: The simplified iterative approach is self-explanatory and doesn't require additional documentation.
The refined code preserves the key optimization (iterative DFS avoiding recursion and generator overhead) while being more readable and closer to the original structure. The performance benefit remains intact as the core algorithmic improvement is preserved.
✅ Correctness verification report:
🌀 Click to see Generated Regression Tests
To edit these changes
git checkout codeflash/optimize-pr1567-2026-02-20T03.38.42and push.