⚡️ Speed up function _validate_test_filter by 27% in PR #1774 (feat/gradle-executor-from-java)#1803
Conversation
The optimized code eliminates two allocation-heavy steps in `_validate_test_filter`: building an intermediate list via `[p.strip() for p in test_filter.split(",")]` and unconditionally calling `pattern.replace("*", "A")` even when no wildcard exists. By iterating directly over `split(",")` and guarding `replace` with an `if "*" in pattern` check, the hot loop avoids ~2.5 ms of string allocations per 1000-pattern call (profiler shows the list comprehension took 11.6% of original time). Additionally, replacing `bool(_VALID_JAVA_CLASS_NAME.match(...))` with `... is not None` in both functions removes unnecessary type conversions, though the filter loop accounts for the bulk of the 26% runtime improvement across Maven test-execution paths that validate comma-separated test filters.
|
Claude finished @codeflash-ai[bot]'s task in 3m 32s —— View job PR Review Summary
Prek Checks✅ All checks passed — Mypy✅ No issues found in Code ReviewThe optimization is clean and correct. Three micro-optimizations applied:
Minor observation: No bugs, security issues, or breaking changes found. Duplicate DetectionNo duplicates detected. Test Coverage694 tests pass (all Java tests). The changed function ( Last updated: 2026-03-09 |
4e2197e
into
feat/gradle-executor-from-java
⚡️ This pull request contains optimizations for PR #1774
If you approve this dependent PR, these changes will be merged into the original PR branch
feat/gradle-executor-from-java.📄 27% (0.27x) speedup for
_validate_test_filterincodeflash/languages/java/test_runner.py⏱️ Runtime :
3.14 milliseconds→2.48 milliseconds(best of98runs)📝 Explanation and details
The optimized code eliminates two allocation-heavy steps in
_validate_test_filter: building an intermediate list via[p.strip() for p in test_filter.split(",")]and unconditionally callingpattern.replace("*", "A")even when no wildcard exists. By iterating directly oversplit(",")and guardingreplacewith anif "*" in patterncheck, the hot loop avoids ~2.5 ms of string allocations per 1000-pattern call (profiler shows the list comprehension took 11.6% of original time). Additionally, replacingbool(_VALID_JAVA_CLASS_NAME.match(...))with... is not Nonein both functions removes unnecessary type conversions, though the filter loop accounts for the bulk of the 26% runtime improvement across Maven test-execution paths that validate comma-separated test filters.✅ Correctness verification report:
⚙️ Click to see Existing Unit Tests
test_languages/test_java/test_security.py::TestErrorHandling.test_test_filter_empty_after_splittest_languages/test_java/test_security.py::TestErrorHandling.test_test_filter_with_spacestest_languages/test_java/test_security.py::TestInputValidation.test_validate_test_filter_multiple_classestest_languages/test_java/test_security.py::TestInputValidation.test_validate_test_filter_rejects_invalidtest_languages/test_java/test_security.py::TestInputValidation.test_validate_test_filter_single_classtest_languages/test_java/test_security.py::TestInputValidation.test_validate_test_filter_wildcards🌀 Click to see Generated Regression Tests
To edit these changes
git checkout codeflash/optimize-pr1774-2026-03-09T22.52.33and push.