-
-
Notifications
You must be signed in to change notification settings - Fork 533
perf: cache Frame objects in StacktraceBuilder by Line identity #2906
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: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,8 +78,16 @@ def build(backtrace:, &frame_callback) | |
| private | ||
|
|
||
| def convert_parsed_line_into_frame(line) | ||
| # Cache frames by Line object identity — same Line produces same Frame | ||
| cache_key = line.object_id | ||
| cached_frame = @frame_cache&.[](cache_key) | ||
| return cached_frame if cached_frame | ||
|
Comment on lines
+83
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Cached Suggested FixClone the Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
|
|
||
| frame = StacktraceInterface::Frame.new(project_root, line, strip_backtrace_load_path) | ||
| frame.set_context(linecache, context_lines) if context_lines | ||
|
|
||
| @frame_cache ||= {} | ||
| @frame_cache[cache_key] = frame if @frame_cache.size < 2048 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cached frames mutated after caching cause data leakageHigh Severity
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cache keyed by
|
||
| frame | ||
| end | ||
|
|
||
|
|
||


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.
Bug: The frame cache uses
line.object_idas a key, which is unsafe asobject_ids can be reused after garbage collection, leading to incorrect cache hits.Severity: HIGH
Suggested Fix
Use a cache key that uniquely and reliably identifies the source line, such as a string combining
file,lineno, andmethod. This avoids the problem ofobject_idreuse. Additionally, consider cloningFrameobjects when returning them from the cache to prevent mutations in callbacks from affecting the cached instance.Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.