From 31f983e035d0a63ac7147fb3a6acafcae89b01f6 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 4 Dec 2026 10:02:10 -0800 Subject: [PATCH] compiler: resolve repeat imports inline in filesParser.start MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Large projects import the same resolved files tens of thousands of times, and filesParser.start previously allocated task data and queued a goroutine for every repeat import. When a path already has fully loaded task data at equal or lower depth with an uncontended mutex, record the existing task inline and skip queuing a job. benchstat (-pgo=off, parent vs commit, n=6): goos: linux goarch: amd64 │ old │ new │ │ sec/op │ sec/op vs base │ Tsc/vscode 6.434 ± 2% 6.515 ± 1% ~ (p=0.065 n=6) Tsc/mui-docs 3.923 ± 1% 3.917 ± 3% ~ (p=0.589 n=6) geomean 5.024 5.052 +0.55% │ old │ new │ │ B-rss │ B-rss vs base │ Tsc/vscode 4.850Gi ± 4% 4.651Gi ± 0% -4.10% (p=0.004 n=6) Tsc/mui-docs 2.205Gi ± 6% 2.215Gi ± 8% ~ (p=0.818 n=6) geomean 3.270Gi 3.210Gi -1.85% --- tsc/internal/compiler/filesparser.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tsc/internal/compiler/filesparser.go b/tsc/internal/compiler/filesparser.go index dcf9843de84bb..6d2a2e704908f 100644 --- a/tsc/internal/compiler/filesparser.go +++ b/tsc/internal/compiler/filesparser.go @@ -308,6 +308,28 @@ func (w *filesParser) start(ctx context.Context, loader *fileLoader, tasks []*pa if task.path == "" { panic("parse task must have a path key: " + task.normalizedFilePath.AsString()) } + if existing, ok := w.taskDataByPath.Load(task.path); ok { + if existing.mu.TryLock() { + if existingTask, ok := existing.tasks[task.normalizedFilePath]; ok && existingTask.loaded { + currentDepth := core.IfElse(task.increaseDepth, depth+1, depth) + if currentDepth >= existing.lowestDepth && (existing.packageId.Name != "" || task.packageId == nil) { + allLoaded := true + for _, t := range existing.tasks { + if !t.loaded { + allLoaded = false + break + } + } + if allLoaded { + tasks[i].loadedTask = existingTask + existing.mu.Unlock() + continue + } + } + } + existing.mu.Unlock() + } + } candidate := getParseTaskData(task) data, loaded := w.taskDataByPath.LoadOrStore(task.path, candidate) if loaded {