perf: add nearest_tsconfig cache to avoid redundant directory walks#1071
perf: add nearest_tsconfig cache to avoid redundant directory walks#1071Brooooooklyn wants to merge 1 commit intomainfrom
nearest_tsconfig cache to avoid redundant directory walks#1071Conversation
How to use the Graphite Merge QueueAdd the label merge to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1071 +/- ##
==========================================
+ Coverage 92.35% 92.37% +0.02%
==========================================
Files 21 21
Lines 4079 4092 +13
==========================================
+ Hits 3767 3780 +13
Misses 312 312 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Merging this PR will improve performance by 4.62%
Performance Changes
Comparing Footnotes
|
When `TsconfigDiscovery::Auto` is enabled, `find_tsconfig_auto` walks up the directory tree for every file. Files in the same directory repeat the identical walk. Add a `nearest_tsconfig` field to `CachedPath` that caches the walk result and propagates it to all visited directories. Future walks short-circuit at the first cached ancestor in O(1). Also move the tracing debug span inside the `resolved_tsconfig` OnceCell init closure so cache hits don't pay span creation cost. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
c888ec9 to
220da99
Compare

Problem
find_tsconfig_autowalks from a file up to/checking each directory. Withoutnearest_tsconfig, sibling files repeat the same walk:Solution
After a walk completes, propagate the result to every path visited. Future walks short-circuit when they hit a cached path.
Note
Medium Risk
Touches
find_tsconfig_autoresolution/caching behavior; while intended as a pure perf optimization, incorrect propagation or caching ofNonecould cause hard-to-debug mis-resolution across paths.Overview
Speeds up auto
tsconfig.jsondiscovery by adding a per-CachedPathnearest_tsconfigcache and propagating the final walk result (includingNone) to every visited directory, allowing sibling lookups to short-circuit instead of re-walking ancestors.Also moves the
find_tsconfigtracing span inside theresolved_tsconfigget_or_try_initclosure so tracing only runs when the value is first computed.Written by Cursor Bugbot for commit 220da99. This will update automatically on new commits. Configure here.