Repository navigation
Commit e818ad6
authored
perf: index transform cache lazily
## Problem
tsx's transform cache is shared across projects and retains entries for
seven days. As users work across more projects, unrelated cache files
accumulate in the same temporary directory.
Every tsx process eagerly read that directory, even when it never needed
to transform code. Processes that did transform code then scanned the
full listing for every cache lookup. Users therefore paid a growing
startup cost based on unrelated past work: with 10,000 unrelated
entries, a 1,000-module run increased from 396ms to 717ms.
## Changes
tsx now leaves the disk cache untouched until the first transform-cache
operation. When the cache is needed, tsx indexes its entries once and
reuses that index, so unrelated files no longer make every lookup or new
write progressively slower.
Existing recovery and cleanup behavior remains protected: expired and
duplicate files are still removed, malformed files are ignored,
concurrent writers remain supported, and an older valid result is used
when the newest entry is corrupt. The benchmark uses isolated seeded
caches, leaving the user's real cache untouched.
Node 24.15, 1,000 TypeScript modules, 5 runs, minimum wall time:
| Unrelated entries | Before | After |
| ---: | ---: | ---: |
| 0 | 396ms | 378ms |
| 1,000 | 433ms | 400ms |
| 10,000 | 717ms | 486ms |1 parent cdcc623 commit e818ad6
6 files changed
Lines changed: 377 additions & 55 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| 53 | + | |
52 | 54 | | |
53 | 55 | | |
54 | 56 | | |
| |||
72 | 74 | | |
73 | 75 | | |
74 | 76 | | |
75 | | - | |
| 77 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
65 | 71 | | |
66 | 72 | | |
67 | 73 | | |
| |||
76 | 82 | | |
77 | 83 | | |
78 | 84 | | |
79 | | - | |
| 85 | + | |
80 | 86 | | |
81 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
82 | 95 | | |
83 | 96 | | |
84 | 97 | | |
| |||
100 | 113 | | |
101 | 114 | | |
102 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
103 | 155 | | |
104 | 156 | | |
105 | 157 | | |
| |||
116 | 168 | | |
117 | 169 | | |
118 | 170 | | |
119 | | - | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
120 | 182 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
126 | 186 | | |
127 | 187 | | |
128 | 188 | | |
129 | | - | |
| 189 | + | |
130 | 190 | | |
131 | 191 | | |
132 | | - | |
| 192 | + | |
133 | 193 | | |
134 | 194 | | |
135 | 195 | | |
| |||
216 | 276 | | |
217 | 277 | | |
218 | 278 | | |
| 279 | + | |
219 | 280 | | |
220 | 281 | | |
221 | 282 | | |
| |||
227 | 288 | | |
228 | 289 | | |
229 | 290 | | |
230 | | - | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
231 | 296 | | |
232 | 297 | | |
233 | 298 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| 44 | + | |
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
| |||
0 commit comments