⚡️ Speed up method JavaScriptSupport._build_runtime_map by 87% in PR #1561 (add/support_react)#1612
Merged
claude[bot] merged 2 commits intoadd/support_reactfrom Feb 20, 2026
Conversation
The optimized code achieves an **87% speedup** (from 85.3ms to 45.6ms) through two primary performance improvements in the `_build_runtime_map` method:
## Key Optimizations
**1. Path Resolution Caching (Primary Improvement)**
The original code called `resolve_js_test_module_path()` and `abs_path.resolve().with_suffix("")` for every invocation, even when multiple invocations shared the same `test_module_path`. The optimized version introduces `_resolved_path_cache` to store computed path strings per module path, eliminating redundant filesystem operations.
Line profiler data confirms the dramatic impact:
- `resolve_js_test_module_path` calls: 3,481 → 1,480 (57% reduction)
- Time in path resolution: 84.7ms → 38.6ms (54% faster)
- Time in `abs_path.resolve()`: 186.9ms → 89.2ms (52% faster)
**2. Optimized String Parsing**
The original code parsed `iteration_id` inefficiently:
```python
parts = iteration_id.split("_").__len__() # Creates list, calls __len__()
cur_invid = iteration_id.split("_")[0] if parts < 3 else "_".join(iteration_id.split("_")[:-1]) # Splits again!
```
The optimized version splits once and reuses the result:
```python
parts = iteration_id.split("_")
parts_len = len(parts)
cur_invid = parts[0] if parts_len < 3 else "_".join(parts[:-1])
```
Additionally, dictionary access was optimized from:
```python
if match_key not in unique_inv_ids:
unique_inv_ids[match_key] = 0
unique_inv_ids[match_key] += min(runtimes)
```
to:
```python
unique_inv_ids[match_key] = unique_inv_ids.get(match_key, 0) + min(runtimes)
```
## Performance Benefits by Test Type
The optimization particularly excels with workloads featuring:
1. **Many invocations with shared module paths** (e.g., `test_large_number_of_invocations`: 1567% faster, `test_many_different_iteration_ids`: 3037% faster) - the cache eliminates redundant path resolutions
2. **Repeated path resolution** (e.g., `test_multiple_invocations_same_module`: 52.4% faster) - cache hits avoid expensive filesystem operations
3. **Complex iteration IDs** (e.g., `test_complex_iteration_id_patterns`: 2472% faster) - optimized string parsing reduces per-item overhead
The optimization maintains correctness across all test cases while delivering substantial performance improvements, especially in realistic scenarios where test suites contain multiple tests in the same modules.
Contributor
PR Review SummaryPrek Checks✅ Passed — 1 auto-fixed issue (unsorted imports in Mypy: 2 pre-existing Code Review✅ No critical issues found The optimization in
Other changes (React framework support, type annotations, Test Coverage
Overall: 79% → 76% (-3%)
Note: The 8 test failures in Last updated: 2026-02-20 |
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 #1561
If you approve this dependent PR, these changes will be merged into the original PR branch
add/support_react.📄 87% (0.87x) speedup for
JavaScriptSupport._build_runtime_mapincodeflash/languages/javascript/support.py⏱️ Runtime :
85.3 milliseconds→45.6 milliseconds(best of17runs)📝 Explanation and details
The optimized code achieves an 87% speedup (from 85.3ms to 45.6ms) through two primary performance improvements in the
_build_runtime_mapmethod:Key Optimizations
1. Path Resolution Caching (Primary Improvement)
The original code called
resolve_js_test_module_path()andabs_path.resolve().with_suffix("")for every invocation, even when multiple invocations shared the sametest_module_path. The optimized version introduces_resolved_path_cacheto store computed path strings per module path, eliminating redundant filesystem operations.Line profiler data confirms the dramatic impact:
resolve_js_test_module_pathcalls: 3,481 → 1,480 (57% reduction)abs_path.resolve(): 186.9ms → 89.2ms (52% faster)2. Optimized String Parsing
The original code parsed
iteration_idinefficiently:The optimized version splits once and reuses the result:
Additionally, dictionary access was optimized from:
to:
Performance Benefits by Test Type
The optimization particularly excels with workloads featuring:
test_large_number_of_invocations: 1567% faster,test_many_different_iteration_ids: 3037% faster) - the cache eliminates redundant path resolutionstest_multiple_invocations_same_module: 52.4% faster) - cache hits avoid expensive filesystem operationstest_complex_iteration_id_patterns: 2472% faster) - optimized string parsing reduces per-item overheadThe optimization maintains correctness across all test cases while delivering substantial performance improvements, especially in realistic scenarios where test suites contain multiple tests in the same modules.
✅ Correctness verification report:
🌀 Click to see Generated Regression Tests
To edit these changes
git checkout codeflash/optimize-pr1561-2026-02-20T14.24.41and push.