-
Notifications
You must be signed in to change notification settings - Fork 1.7k
cache get_type_hints for heavy init subclass stuff - improve import performance #6118
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
base: main
Are you sure you want to change the base?
cache get_type_hints for heavy init subclass stuff - improve import performance #6118
Conversation
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
|
Greptile OverviewGreptile SummaryThis PR adds caching to the
The caching strategy is sound because:
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant App as Application Code
participant BS as BaseState
participant Cache as functools.cache
participant GTH as get_type_hints
participant Types as types.is_backend_base_variable
Note over App,Types: Initial State Class Import/Initialization
App->>BS: Define State subclass
BS->>BS: _check_overridden_basevars()
BS->>Cache: Call _get_type_hints()
Cache->>Cache: Check if cached for this class
alt Not Cached
Cache->>GTH: get_type_hints(cls, localns)
GTH-->>Cache: Return type hints dict
Cache->>Cache: Store in cache
end
Cache-->>BS: Return cached hints
Note over App,Types: Backend Variable Check Flow
App->>BS: Access backend_vars during init
BS->>Types: is_backend_base_variable(name, mixin_cls)
Types->>BS: Call cls._get_type_hints()
BS->>Cache: Retrieve from cache
Cache-->>BS: Return cached hints (no recomputation)
BS-->>Types: Return hints
Types-->>BS: Return bool result
Note over Cache: Performance Improvement: Subsequent calls skip get_type_hints computation
|
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.
2 files reviewed, no comments
35a2450 to
a83bdf9
Compare
For one of my apps this reduces the app import time over 50%