Skip to content

build: 94% of build time is directory churn (wipe dist, mkdir per entry); 32 s here, minutes on slow disks #80

Closed

Description

@TMHSDigital

Why it matters
The CI comment says "the whole run takes seconds", and the JS does: rendering, checks and escaping total under half a second. On a Windows drive the build takes 32 s, and on a slow or network drive several minutes, because dist/ is deleted and recreated every run and every one of the 420 pages gets its own mkdirSync({recursive: true}). The local edit-preview loop is the contributor's main tool, and at 2,000 entries this becomes about two minutes per build.

Evidence

  • --cpu-prof of a 25.7 s build on 2026-10-21: mkdir 18.4 s, rmSync 3.5 s, writeFile 1.9 s, all JavaScript < 0.5 s.
  • site/build.mjs:563-564 wipes dist/; :472-473 (entries) and :417-418 (stacks) call mkdirSync per page (about 44 ms each on this drive).
  • Measured: node site/build.mjs 32.5 s; checks.test.mjs 170 ms; lib.test.mjs 190 ms; validate.mjs 420 ms.

Suggested approach

  1. Stop wiping dist/. Create dist/entry and dist/stack once, mkdirSync a page directory only if it is missing, write a file only when its content differs (compare bytes), and remove only entry/stack directories whose id is no longer in the catalog.
  2. Add --only <id> (build one entry page plus data) and --no-clean flags for the local loop.
  3. Also exit on entry errors before loading stacks (build.mjs:501-514), so a broken entry does not hide stack errors until a second run.
  4. Record the before/after timing in the PR.

Done when
A no-change rebuild completes in under 3 s on the same machine, output is byte-identical to a clean build, and --only works.

Activity

  1. added
    priority: medium
    performance
    dx
    on Oct 22, 2026
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

    dxperformancepriority: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions