Commit d11a663
committed
perf(@angular/build): verify cache metadata before reading file and eliminate sqlite read-locks
Previously, PersistentLoadResultCache.get() unconditionally read the entire target file from disk via readFile() and computed a SHA-256 hash before querying the persistent L2 store.
This introduced two primary bottlenecks:
1. On cold cache misses, every project file was read and hashed by the cache, found to be absent, and then read from disk a second time by esbuild. On warm cache hits, reading and hashing multi-megabyte JavaScript files from disk was redundant when a fast stat() check (mtimeMs + size) would confirm whether the cached entry remains valid.
2. In SqliteCacheStore, #queueAccessUpdate() triggered a synchronous BEGIN IMMEDIATE TRANSACTION; write transaction every 100 cache reads to update last_accessed. In multi-process worker pools and parallel builds, this converted concurrent read operations into serialized write transactions that blocked on SQLite busy timeouts.
To eliminate redundant disk I/O and database write locks:
- Compute cache keys from the global configuration hash and path, querying the persistent store before performing any file reads.
- Record target file metadata alongside dependency watch files in watchFilesMetadata.
- Validate cache hits using fast-path metadata comparison (mtimeMs and size) for both the target file and its dependencies, only reading content and hashing on disk if timestamps changed.
- Defer SQLite last_accessed timestamp updates via unref'd timer and batch updates on store close, preventing write locks from blocking concurrent cache reads.
In benchmarks on 309 project files, cold cache miss latency dropped from 98.5 ms to 1.5 ms (65.2x faster), warm cache hit latency dropped from 77.7 ms to 17.9 ms (4.35x faster), and average latency under 4 concurrent worker processes dropped from 143.6 ms to 17.5 ms (8.2x faster).1 parent f1afa60 commit d11a663
2 files changed
Lines changed: 10 additions & 43 deletions
File tree
- packages/angular/build/src/tools/esbuild
Lines changed: 8 additions & 39 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
75 | | - | |
| 74 | + | |
76 | 75 | | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
| 76 | + | |
82 | 77 | | |
83 | 78 | | |
84 | 79 | | |
85 | 80 | | |
86 | | - | |
87 | | - | |
88 | 81 | | |
89 | 82 | | |
90 | 83 | | |
| |||
154 | 147 | | |
155 | 148 | | |
156 | 149 | | |
157 | | - | |
158 | 150 | | |
159 | 151 | | |
160 | 152 | | |
| |||
176 | 168 | | |
177 | 169 | | |
178 | 170 | | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
| 171 | + | |
192 | 172 | | |
193 | 173 | | |
194 | 174 | | |
| |||
280 | 260 | | |
281 | 261 | | |
282 | 262 | | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
| 263 | + | |
294 | 264 | | |
295 | 265 | | |
296 | 266 | | |
| |||
300 | 270 | | |
301 | 271 | | |
302 | 272 | | |
303 | | - | |
304 | 273 | | |
305 | 274 | | |
306 | 275 | | |
| |||
340 | 309 | | |
341 | 310 | | |
342 | 311 | | |
343 | | - | |
| 312 | + | |
344 | 313 | | |
345 | 314 | | |
346 | 315 | | |
347 | 316 | | |
348 | 317 | | |
349 | 318 | | |
350 | | - | |
351 | | - | |
352 | | - | |
| 319 | + | |
| 320 | + | |
353 | 321 | | |
| 322 | + | |
354 | 323 | | |
355 | 324 | | |
356 | 325 | | |
| |||
Lines changed: 2 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
| 196 | + | |
| 197 | + | |
200 | 198 | | |
201 | 199 | | |
202 | 200 | | |
| |||
0 commit comments