Commit 06f4956
fix(git): cap and stream untracked-file line counting
`countFileLines` previously read each untracked file's full content into
memory as UTF-8 via `fs.readFile(filePath, "utf-8")`. The caller in
`getChangedFilesDetailed` runs this 16-way concurrent against every
untracked path returned by `streamGitStatus` (up to 50k entries). On a
monorepo with multi-MB build artifacts or lockfiles, peak heap was
`16 * file_bytes * 2` (V8's UTF-16 cost), easily several GB. That OOM'd
the main process and froze the renderer waiting on a tRPC call that
would never return — the symptom was the app appearing to freeze a
few seconds after the sidebar painted, with no `[ipc-rate]` warnings,
just a silent V8 `Scavenger: semi-space copy Allocation failed`.
Fix: bail out on files larger than 1 MB, and stream the rest with
`createReadStream`, counting `\n` bytes byte-by-byte. Per-stream memory
stays at ~64 KB regardless of file size, so peak across 16 concurrent
reads is ~1 MB total. Preserves the original return semantics
(trailing-newline-aware line count) for files within the cap.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 180b915 commit 06f4956
2 files changed
Lines changed: 70 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
242 | 243 | | |
243 | 244 | | |
244 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
413 | 414 | | |
414 | 415 | | |
415 | 416 | | |
| 417 | + | |
| 418 | + | |
416 | 419 | | |
417 | 420 | | |
418 | | - | |
419 | | - | |
420 | | - | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
421 | 444 | | |
422 | 445 | | |
423 | 446 | | |
| |||
0 commit comments