Skip to content

Boot sweep spawns 166 parallel du walks over 96 GB on every launch, then discards the result #563

Closed

Description

@currentbits

15 seconds after every launch, the boot sweep does a full disk walk of every worktree the app has ever kept — and then throws the result away.

The path

electron/main.js:380-405: boot sweep → sweepOrphanWorktrees → enforceRetention.

enforceRetention (worktrees.js:4009) starts with a full gcScan, and gcScan sizes every directory up front:

// worktrees.js:3772
const sizes = await Promise.all(dirs.map((d) => duBytes(d)));

duBytes spawns du -sk <dir> (worktrees.js:3609). On this machine that is 166 concurrent du processes walking 96 GB (median worktree 709 MB, each with a full node_modules) — on every single launch, cold page cache, right when the app is also parsing the 143 MB store (#225) and painting first frames.

And the sizes are never used. Retention selection keeps the newest N by threadActivityAt (worktrees.js:3791) — activity time, not size. The bytes field exists for the GC dialog's UI. With worktreeRetention unset on every project (the #559 finding), the entire scan output is discarded:

// worktrees.js:3789-3790
const n = Math.floor(Number(project && project.worktreeRetention));
if (!(n > 0)) continue;   // ← every project, today

So the steady state is: 166 process spawns + a 96 GB I/O walk per boot, for a no-op.

Fix (two lines of shape, no new machinery)

  1. gcScan takes skipSizes (or enforceRetention passes a flag through): the enforce path never needs du. Candidates and classification are stat + git only.
  2. Short-circuit enforceRetention before scanning when no project has worktreeRetention > 0 — with the setting unset there is nothing to enforce, so don't scan at all.

The GC dialog keeps sizing directories — that scan is user-initiated and the bytes are the point there. If #559 lands a retention default, fix 1 alone still removes the du storm from every boot; the scan the enforce path actually needs (readdir + git status per candidate) is cheap.

Tests

  • enforceRetention on a store where no project sets retention resolves without calling the du spawner (assert via the existing setExecFile seam).
  • With retention set, enforcement still removes past-limit worktrees without du having run.
  • gcScan without skipSizes (dialog path) still reports bytes and totalBytes.

Related

#559 (retention default — makes the enforce-path scan do real work), #316 (the engine), #418 (startup wins), #359 (same class: spawn cost on hot paths).

Activity

  1. added
    plan:todo
    plan:doing
    plan:done
    and removed
    plan:todo
    plan:doing
    on Aug 19, 2026
  2. currentbits commented on Aug 19, 2026

    @currentbits
    OwnerAuthor

    Fixed in 8516d61. enforceRetention short-circuits before any disk scan when no project sets worktreeRetention (all five today), and threads skipSizes through gcScan/gcClean when a limit IS set, since retention picks by threadActivityAt, never bytes. Removes the 166-process du storm over 96 GB on every cold boot; the GC dialog still sizes on demand. Tests: electron/test/worktree-gc.test.js (16/16) with a du-spawn spy asserting zero spawns on both enforce paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    plan:done

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions