Repository navigation
perf: Cache frame context lookups to reduce ic() overhead in loops - #247
Closed
AhmadAL-Quraan wants to merge 1 commit into
Closed
AhmadAL-Quraan wants to merge 1 commit into
AhmadAL-Quraan wants to merge 1 commit into
Conversation
…d inspect/stat calls
Collaborator
|
Thank you for your work! I have a couple of questions.
|
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.
PR Description
Description
Resolves #246 && #36
Repeated calls to
ic()(such as inside tight loops or frequently called functions) spend significant CPU time re-resolving frame context viainspect.getsourcefile()andrealpath()/basename().This PR introduces an LRU cache ($O(1)$ time rather than repeating disk/path inspections.
@functools.lru_cache(maxsize=8192)) for frame context lookups (_cached_frame_context). For static call sites where the code object, line number, and path settings remain identical, subsequent calls retrieve the context inChanges
_cached_frame_context(code, lineNumber, contextAbsPath).@functools.lru_cache(maxsize=8192)to memoize context lookups based on frame code object and line number.IceCreamDebugger._getContext()to use the cached helper.Performance Verification
Benchmark Results (20,000 iterations via
test.py)1.1946s(16,741.34 calls/sec)0.7468s(26,781.97 calls/sec)Profiling with
py-spyover a workload executingic()8,000 times shows a substantial reduction in frame inspection overhead:_formatContext/inspectoccupied a large portion of execution time across the call stack.before:


after:
Checklist
contextAbsPathand line number resolutionBTW
I tried making the tests provided with the repo:
There were 2 errors already being there before me making the changes, so hope this won't affect :)