Merged
Conversation
CodSpeed Performance ReportMerging #5948 will not alter performanceComparing Summary
|
Contributor
There was a problem hiding this comment.
Greptile Overview
Greptile Summary
Optimized get_app() function by caching the current working directory path.
- Created new
_cwd()helper function decorated with@onceto cache the result ofPath.cwd()on first call - Replaced direct
str(Path.cwd())call with_cwd()inget_app()to avoid repeated filesystem calls - This is a targeted performance improvement for a frequently-called function where the working directory doesn't change during execution
Confidence Score: 5/5
- This PR is safe to merge with minimal risk
- Simple, focused performance optimization using an existing proven pattern (
@oncedecorator). The change only caches an immutable value (cwd) that doesn't change during process execution, making it safe and correct. - No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| reflex/utils/prerequisites.py | 5/5 | Added _cwd() helper with @once decorator to cache Path.cwd() result, replacing direct call in get_app() for performance optimization |
Sequence Diagram
sequenceDiagram
participant Client
participant get_app
participant _cwd
participant Path
participant once_decorator
Client->>get_app: get_app(reload=False)
get_app->>_cwd: Call _cwd()
alt First call
_cwd->>once_decorator: Check cache (unset)
once_decorator->>Path: Path.cwd()
Path-->>once_decorator: Current directory
once_decorator->>once_decorator: Cache result
once_decorator-->>_cwd: Return cached value
else Subsequent calls
_cwd->>once_decorator: Check cache (set)
once_decorator-->>_cwd: Return cached value
end
_cwd-->>get_app: Return cwd string
get_app->>get_app: sys.path.insert(0, cwd)
get_app-->>Client: Return app module
1 file reviewed, no comments
masenf
approved these changes
Nov 5, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
apparently this is somewhat slow