Skip to content

Conversation

@adhami3310
Copy link
Member

apparently this is somewhat slow

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 4, 2025

CodSpeed Performance Report

Merging #5948 will not alter performance

Comparing cache-path-cwd (d240cb3) with main (982d2fa)

Summary

✅ 8 untouched

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Overview

Greptile Summary

Optimized get_app() function by caching the current working directory path.

  • Created new _cwd() helper function decorated with @once to cache the result of Path.cwd() on first call
  • Replaced direct str(Path.cwd()) call with _cwd() in get_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 (@once decorator). 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
Loading

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@adhami3310 adhami3310 merged commit e5d3552 into main Nov 5, 2025
47 checks passed
@adhami3310 adhami3310 deleted the cache-path-cwd branch November 5, 2025 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants