Skip to content

perf: add nearest_tsconfig cache to avoid redundant directory walks#1071

Open
Brooooooklyn wants to merge 1 commit intomainfrom
perf/reduce-tsconfig-lookup
Open

perf: add nearest_tsconfig cache to avoid redundant directory walks#1071
Brooooooklyn wants to merge 1 commit intomainfrom
perf/reduce-tsconfig-lookup

Conversation

@Brooooooklyn
Copy link
Copy Markdown
Member

@Brooooooklyn Brooooooklyn commented Mar 16, 2026

Problem

find_tsconfig_auto walks from a file up to / checking each directory. Without nearest_tsconfig, sibling files repeat the same walk:

src/d0/f0.jsx  →  walk d0/ → src/ → project/ → /  →  None   (12 hops)
src/d0/f1.jsx  →  walk d0/ → src/ → project/ → /  →  None   (12 hops, identical)
src/d0/f2.jsx  →  walk d0/ → src/ → project/ → /  →  None   (12 hops, identical)

Solution

After a walk completes, propagate the result to every path visited. Future walks short-circuit when they hit a cached path.

Call 1: find_tsconfig("src/d0/f0.jsx")

  Visit f0.jsx → d0/ → src/ → project/ → ... → /   (full walk, 12 hops)
  Result: None
  Propagate: set nearest_tsconfig = None on f0.jsx, d0/, src/, project/, ...

Call 2: find_tsconfig("src/d0/f1.jsx")

  Visit f1.jsx → d0/ has nearest_tsconfig = None → STOP   (2 hops)

Call 3: find_tsconfig("src/d1/f0.jsx")

  Visit f0.jsx → d1/ → src/ has nearest_tsconfig = None → STOP   (3 hops)

Note

Medium Risk
Touches find_tsconfig_auto resolution/caching behavior; while intended as a pure perf optimization, incorrect propagation or caching of None could cause hard-to-debug mis-resolution across paths.

Overview
Speeds up auto tsconfig.json discovery by adding a per-CachedPath nearest_tsconfig cache and propagating the final walk result (including None) to every visited directory, allowing sibling lookups to short-circuit instead of re-walking ancestors.

Also moves the find_tsconfig tracing span inside the resolved_tsconfig get_or_try_init closure 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.

Copy link
Copy Markdown
Member Author


How to use the Graphite Merge Queue

Add 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
Copy link
Copy Markdown

codecov Bot commented Mar 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.37%. Comparing base (c8ea103) to head (220da99).
⚠️ Report is 27 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 16, 2026

Merging this PR will improve performance by 4.62%

⚡ 1 improved benchmark
✅ 12 untouched benchmarks
⏩ 5 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
resolver_real[multi-thread] 462.3 µs 441.8 µs +4.62%

Comparing perf/reduce-tsconfig-lookup (220da99) with main (ccd85ea)

Open in CodSpeed

Footnotes

  1. 5 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Brooooooklyn Brooooooklyn requested a review from Boshen March 16, 2026 13:42
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>
@Brooooooklyn Brooooooklyn force-pushed the perf/reduce-tsconfig-lookup branch from c888ec9 to 220da99 Compare March 16, 2026 13:47
@Boshen Boshen self-assigned this Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants