Skip to content

perf(utils): check linecache before loader.get_source for frame context - #8419

Closed
M-Colley wants to merge 1 commit into
getsentry:masterfrom
M-Colley:fix/issue-8089-linecache-source-context
Closed

M-Colley wants to merge 1 commit into
getsentry:masterfrom
M-Colley:fix/issue-8089-linecache-source-context

Conversation

@M-Colley

Copy link
Copy Markdown

Description

get_lines_from_file() previously called loader.get_source(module) before linecache.getlines(filename), re-reading and decoding the entire source file from disk on every stack frame of every captured event for file-backed modules. This change queries linecache.getlines(filename) first so subsequent frames reuse the in-memory linecache entry. When linecache returns no lines, get_lines_from_file() falls back to loader.get_source(module) to preserve source context for zipimport and custom non-filesystem module loaders. Additionally, test_get_lines_from_file_prefers_linecache_over_loader in tests/test_utils.py verifies linecache reuse across multi-frame exceptions and loader fallback for non-filesystem modules.

Issues

Fixes getsentry#8089

Signed-off-by: Mark Colley <39366189+M-Colley@users.noreply.github.com>
@M-Colley
M-Colley requested a review from a team as a code owner November 28, 2026 10:48
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit 5674a0c.

Main concerns: reach, data sent to Sentry, host performance.

This label is a hint for reviewers, not an approval.

@sentrivana sentrivana closed this Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: Source context re-reads the whole file via loader.get_source() for every frame

2 participants