⚡️ Speed up function _get_git_remote_for_setup by 1,032% in PR #1199 (omni-java)#1831
⚡️ Speed up function _get_git_remote_for_setup by 1,032% in PR #1199 (omni-java)#1831codeflash-ai[bot] wants to merge 2 commits intomainfrom
_get_git_remote_for_setup by 1,032% in PR #1199 (omni-java)#1831Conversation
The optimization introduced two `@lru_cache` wrappers around the expensive `Repo` instantiation and `get_git_remotes` calls, keyed by the stringified current working directory. Line profiler showed that `Repo(Path.cwd(), search_parent_directories=True)` consumed 60.5% of original runtime (403 ms) and `get_git_remotes(repo)` another 33.3% (222 ms). By caching these operations, repeated calls in the same directory bypass GitPython's repository discovery and remote enumeration entirely, reducing per-call overhead from ~570 µs to ~35 µs—a 10x improvement. The annotated tests confirm correctness is preserved across all scenarios, and the large-scale repeated-call test demonstrates the cache hit benefit (230 ms → 4.62 ms for 1000 invocations).
|
Claude finished @codeflash-ai[bot]'s task in 7s —— View job PR Review Summary
Prek Checks
Pre-existing mypy errors (not introduced by this PR, in unrelated functions):
Code ReviewCritical Bug Found and Fixed 🔴 The optimization PR introduced both Fix applied: Removed the duplicate block. Committed as Other observations:
Duplicate DetectionMEDIUM confidence: The git-remote prompt logic is duplicated across three init modules:
These are pre-existing duplicates, not introduced by this PR. Not a blocker. Test CoverageNo existing unit tests for Fixed commit pushed: |
|
⚡️ This pull request contains optimizations for PR #1199
If you approve this dependent PR, these changes will be merged into the original PR branch
omni-java.📄 1,032% (10.32x) speedup for
_get_git_remote_for_setupincodeflash/cli_cmds/init_java.py⏱️ Runtime :
287 milliseconds→25.4 milliseconds(best of27runs)📝 Explanation and details
The optimization introduced two
@lru_cachewrappers around the expensiveRepoinstantiation andget_git_remotescalls, keyed by the stringified current working directory. Line profiler showed thatRepo(Path.cwd(), search_parent_directories=True)consumed 60.5% of original runtime (403 ms) andget_git_remotes(repo)another 33.3% (222 ms). By caching these operations, repeated calls in the same directory bypass GitPython's repository discovery and remote enumeration entirely, reducing per-call overhead from ~570 µs to ~35 µs—a 10x improvement. The annotated tests confirm correctness is preserved across all scenarios, and the large-scale repeated-call test demonstrates the cache hit benefit (230 ms → 4.62 ms for 1000 invocations).✅ Correctness verification report:
🌀 Click to see Generated Regression Tests
To edit these changes
git checkout codeflash/optimize-pr1199-2026-03-13T03.44.01and push.