⚡️ Speed up function _prompt_custom_directory by 363% in PR #1199 (omni-java)#1827
Conversation
The optimization moved the `inquirer.Path` question construction out of the while-loop and added `@lru_cache(maxsize=1)` to `_get_theme()`, eliminating repeated imports and instantiations of `CodeflashTheme` on every prompt iteration. The profiler shows `_get_theme()` was called 1247 times in the original, each time re-importing `init_config` (~2.2% overhead) and constructing a new theme object (~97.8% overhead, 323 µs per call). Moving the question object outside the loop avoids ~13 µs of reconstruction per iteration, and caching the theme cuts 1246 redundant constructions, yielding a 363% speedup with no functional trade-offs.
|
Claude finished @codeflash-ai[bot]'s task in 3m 4s —— View job PR Review SummaryTodo
Prek Checks✅ All checks pass ( MypyThree pre-existing errors in
No new type errors introduced. Code ReviewCorrectness of The Correctness of
No bugs found. Duplicate DetectionHIGH confidence duplicate: The same optimization applied here could be applied to Test CoverageNo existing unit tests for Optimization PRsThree optimization PRs are currently open against
CI is still running on all three — will not merge until checks complete. Overall: The optimization is correct and the speedup is legitimate. The only notable finding is the duplicate unoptimized code in |
⚡️ 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.📄 363% (3.63x) speedup for
_prompt_custom_directoryincodeflash/cli_cmds/init_java.py⏱️ Runtime :
374 milliseconds→80.7 milliseconds(best of34runs)📝 Explanation and details
The optimization moved the
inquirer.Pathquestion construction out of the while-loop and added@lru_cache(maxsize=1)to_get_theme(), eliminating repeated imports and instantiations ofCodeflashThemeon every prompt iteration. The profiler shows_get_theme()was called 1247 times in the original, each time re-importinginit_config(~2.2% overhead) and constructing a new theme object (~97.8% overhead, 323 µs per call). Moving the question object outside the loop avoids ~13 µs of reconstruction per iteration, and caching the theme cuts 1246 redundant constructions, yielding a 363% speedup with no functional trade-offs.✅ Correctness verification report:
🌀 Click to see Generated Regression Tests
To edit these changes
git checkout codeflash/optimize-pr1199-2026-03-13T01.44.29and push.