⚡️ Speed up function _extract_modules_from_settings_gradle by 23% in PR #2015 (fix/gradle-maven-central-dependency) - #2017
Conversation
The optimization pre-compiles three regex patterns at module load time (`_INCLUDE_PATTERN`, `_LISTOF_PATTERN`, `_QUOTED_PATTERN`) instead of recompiling them on every function call, eliminating the ~1 ms pattern-compilation overhead that line profiler shows dominated the original version (44.3% of total time in the first `re.findall` alone). The second major change replaces the O(n) `if stripped not in modules` list scan with a set-based `if stripped not in seen` check, which cuts the deduplication cost from ~288 ns to ~72 ns per check when the fallback listOf branch executes. Runtime improves from 2.35 ms to 1.91 ms (23% faster) with no behavioral regressions.
|
Claude finished @codeflash-ai[bot]'s task in 1m 56s —— View job PR Review SummaryPrek ChecksAll checks passed (ruff format, ruff lint). mypy: no issues found. Code ReviewSMALL PR — 1 file changed, 18 lines. This is a codeflash-ai[bot] optimization PR. The changes are correct and the speedup is credible:
Both changes are correct and the 23% speedup claim (2.35ms → 1.91ms) is credible: line profiler showed 44% of the original runtime was in regex compilation. No bugs, security issues, or breaking changes found. Duplicate DetectionNo duplicates detected — the module-level constants are placed appropriately near the function they serve. Other open optimization PRsPR #2016 ( Last updated: 2026-04-07 |
2a2125b
into
fix/gradle-maven-central-dependency
⚡️ This pull request contains optimizations for PR #2015
If you approve this dependent PR, these changes will be merged into the original PR branch
fix/gradle-maven-central-dependency.📄 23% (0.23x) speedup for
_extract_modules_from_settings_gradleincodeflash/languages/java/test_runner.py⏱️ Runtime :
2.35 milliseconds→1.91 milliseconds(best of52runs)📝 Explanation and details
The optimization pre-compiles three regex patterns at module load time (
_INCLUDE_PATTERN,_LISTOF_PATTERN,_QUOTED_PATTERN) instead of recompiling them on every function call, eliminating the ~1 ms pattern-compilation overhead that line profiler shows dominated the original version (44.3% of total time in the firstre.findallalone). The second major change replaces the O(n)if stripped not in moduleslist scan with a set-basedif stripped not in seencheck, which cuts the deduplication cost from ~288 ns to ~72 ns per check when the fallback listOf branch executes. Runtime improves from 2.35 ms to 1.91 ms (23% faster) with no behavioral regressions.✅ Correctness verification report:
⚙️ Click to see Existing Unit Tests
test_languages/test_java/test_java_test_paths.py::TestExtractModulesFromSettingsGradle.test_leading_colon_strippedtest_languages/test_java/test_java_test_paths.py::TestExtractModulesFromSettingsGradle.test_nested_gradle_modulestest_languages/test_java/test_java_test_paths.py::TestExtractModulesFromSettingsGradle.test_simple_top_level_modules🌀 Click to see Generated Regression Tests
To edit these changes
git checkout codeflash/optimize-pr2015-2026-04-07T11.40.43and push.