-
Couldn't load subscription status.
- Fork 22
[LSP] validating python and git environment #670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
…codeflash into vsc/environment-validation
| Tuple of (filtered_functions_dict, remaining_count) | ||
| """ | ||
| if is_LSP_enabled(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: could this raise questions on underterministic nature of optimizations if the function has is same.
codeflash/code_utils/git_utils.py
Outdated
| uni_diff_text = repository.git.diff(None, "HEAD", ignore_blank_lines=True, ignore_space_at_eol=True) | ||
|
|
||
| # HACK: remove binary files from the diff, find a better way # noqa: FIX004 | ||
| uni_diff_text = re.sub( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: rather than regex we can us git diff exclude and list all the exclude file types. or we can alter the .gitignore or gitattributes file too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or we can also go with --diff-filter=AMT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I am thinking either we can just change the file type to text rather than excluding them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah exclude sounds like a good option
Also I am thinking either we can just change the file type to text rather than excluding them?
actually this shouldn't happen in the first place, git can't apply patches with binary diffs, so this would be the user mistake if he forgot to ignore them
…c/environment-validation`) The optimization applies **LRU caching to API calls** that were being repeatedly executed in loops, eliminating redundant network requests. **Key Changes:** - **Wrapped `is_github_app_installed_on_repo` with LRU cache**: Added `@lru_cache(maxsize=128)` to a new `_cached_is_github_app_installed_on_repo` function that handles the actual API request - **Cache key includes all parameters**: Caches based on `(owner, repo, suppress_errors)` tuple to ensure correct behavior across different call contexts **Why This Provides Massive Speedup:** - **Eliminates redundant API calls**: The original code made multiple identical API requests in the retry loop within `install_github_app` - each network request took ~100ms based on profiling data - **Network I/O is the bottleneck**: Line profiler shows 99%+ of execution time was spent in `make_cfapi_request` calls (10+ seconds total) - **Cache hits are microsecond-fast**: Subsequent calls with same parameters return cached results instead of making new HTTP requests **Test Case Performance:** - **Scenarios with repeated checks benefit most**: Tests involving retry loops see 8000000%+ speedups (from ~900ms to ~10μs) - **Single API call scenarios**: Still see significant gains (6-7% faster) due to reduced function call overhead - **Large-scale scenarios**: Tests with many remotes see dramatic improvements when the same repo is checked multiple times This optimization is particularly effective for CLI workflows where the same repository's app installation status is checked multiple times during user interaction flows.
⚡️ Codeflash found optimizations for this PR📄 235,820% (2,358.20x) speedup for
|
…ent-validation`) The optimization replaces the expensive repeated `import` statement with a cached import pattern using a global variable and helper function. **Key optimization:** - **Cached Import Pattern**: The original code executes `from codeflash.optimization.optimizer import Optimizer` on every function call (line showing 4.6% of total time in profiler). The optimized version introduces `_get_optimizer()` which imports and caches the `Optimizer` class only once in the global `_cached_optimizer` variable. **Why this works:** Python imports are not free - they involve module lookup, loading, and namespace operations. While Python's import system caches modules internally, the `from ... import ...` statement still has overhead for symbol resolution on each execution. By caching the imported class reference, we eliminate this repeated work. **Performance impact:** The line profiler shows the import line went from 4.6% of execution time (12.3ms) to 3.8% (11.0ms) in the optimized version, contributing to the overall 40% speedup. This optimization is particularly effective for: - **High-frequency calls**: The test results show consistent 36-43% improvements across all test cases - **Large-scale operations**: The 1000-iteration tests maintain the same 40% improvement, demonstrating the optimization scales well - **Any scenario where `check_api_key` is called repeatedly**: Since LSP servers typically handle many requests, this caching prevents redundant import overhead The optimization maintains identical functionality while reducing per-call overhead through one-time import caching.
⚡️ Codeflash found optimizations for this PR📄 40% (0.40x) speedup for
|
PR Type
Enhancement, Bug fix
Description
Introduce LSP project validation feature
Extract is_valid_pyproject_toml for pyproject checks
Enhance git utils: staging, whitespace ignore, remote validation
Bypass function optimization under LSP context
Diagram Walkthrough
File Walkthrough
cli.py
Skip optimize-all under LSPcodeflash/cli_cmds/cli.py
is_LSP_enabledhelpercmd_init.py
Validate pyproject and check git remotecodeflash/cli_cmds/cmd_init.py
is_valid_pyproject_tomlconfig validatorshould_modify_pyproject_tomlto use validatorfunctions_to_optimize.py
Disable optimization check under LSPcodeflash/discovery/functions_to_optimize.py
is_LSP_enabledhelperbeta.py
Add validateProject and refactor optimizer initcodeflash/lsp/beta.py
validateProjectLSP feature for project checksserver.py
Remove config processing in server initcodeflash/lsp/server.py
process_pyproject_configfrom server initgit_utils.py
Fix worktree commit and whitespace applycodeflash/code_utils/git_utils.py
--whitespace=nowarn