perf: cache framework-path checks in console.deprecate frame walk#6736
Open
Alek99 wants to merge 2 commits into
Open
perf: cache framework-path checks in console.deprecate frame walk#6736Alek99 wants to merge 2 commits into
Alek99 wants to merge 2 commits into
Conversation
console.deprecate resolved and compared every stack frame's path against ~300 excluded framework/stdlib roots on every call, even when the warning was already deduped -- 5-6ms per call. Deprecated properties on hot paths (e.g. RouterData.page) paid this on every access from an event handler. Cache the per-filename framework-root determination (module files do not move within a process), turning repeat calls into dict lookups: ~6ms -> ~0.04ms (~150x). Emission behavior is unchanged, including one warning per distinct user-code call site. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sns7EuBPYvfGCxRSRZ1bUx
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sns7EuBPYvfGCxRSRZ1bUx
Contributor
Greptile SummaryThis PR speeds up
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (1): Last reviewed commit: "chore: add news fragment for #6736" | Re-trigger Greptile |
Merging this PR will not alter performance
Comparing Footnotes
|
FarhanAliRaza
approved these changes
Jul 10, 2026
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.
All Submissions:
Type of change
Changes To Core Features:
console.deprecatewalks the call stack to locate the first non-framework frame so it can report where deprecated usage came from. For every frame on every call — even when the warning is already deduped — it calledPath(inspect.getfile(frame)).resolve()(syscalls) and compared the result against ~300 excluded framework/stdlib roots withis_relative_to. That costs multiple milliseconds per call, and deprecated properties on hot paths pay it per access: any handler readingstate.router.pageeats it on every event.memo.pyeven carries a local workaround gating its ownconsole.deprecatecall for exactly this reason.Fix: cache the per-filename "is this a framework path?" determination (
functools.cachekeyed onco_filename— module file locations don't move within a process), and readframe.f_code.co_filenamedirectly instead ofinspect.getfile(identical for frames). The frame walk itself stays, so the reported location and the per-call-site dedupe behavior are exactly as before.The dedupe key includes the call-site location, so a "dedupe-check before walking" shortcut would have changed emission behavior (a second distinct call site would no longer warn); the cache achieves the same goal without any behavior change.
Micro-benchmark (Python 3.13, deduped steady-state
deprecate()call through 25 framework-path frames, median of 200 runs):~150x faster. A side-by-side equivalence harness loads the before/after modules together and asserts byte-identical warning output for: two distinct user call sites of the same feature (both warn), repeat calls (deduped), and a second feature (warns once).
Linear: ENG-10100
🤖 Generated with Claude Code
https://claude.ai/code/session_01Sns7EuBPYvfGCxRSRZ1bUx
Generated by Claude Code