⚡️ Speed up function install_github_app by 6,107,867% in PR #817 (lsp/init-flow)
#839
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 #817
If you approve this dependent PR, these changes will be merged into the original PR branch
lsp/init-flow.📄 6,107,867% (61,078.67x) speedup for
install_github_appincodeflash/cli_cmds/cmd_init.py⏱️ Runtime :
11.5 seconds→188 microseconds(best of24runs)📝 Explanation and details
The major performance bottleneck is repeated API calls to
is_github_app_installed_on_repo, especially in the retry loop withininstall_github_app. These calls are redundant because theownerandrepoarguments remain unchanged during each installation session. Caching the results of these checks using an LRU cache avoids unnecessary network calls, thus greatly improving performance without altering the function's behavior.Optimizations Applied:
@lru_cache(maxsize=16)tois_github_app_installed_on_repoincodeflash/api/cfapi.pyto automatically cache API responses for each unique(owner, repo, suppress_errors)tuple.Performance Impact:
This drastically reduces the number of network round-trips in
install_github_app, especially when prompting the user multiple times for the same repository.✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-pr817-2025-10-21T00.42.22and push.