Skip to content

perf: write over public/ - #67

Merged
lukeed merged 5 commits into
mainfrom
inplace
Oct 15, 2026
Merged

lukeed merged 5 commits into
mainfrom
inplace

Conversation

@lukeed

@lukeed lukeed commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

Closes #60. Stacked on #65.

bongo build emptied public/, then made every file again. On the 10,000-page bench, emptying took about 1.6 s. Making 10k pages takes about 1.3 s, but writing over the same files takes about 0.15 s. A streamed build now keeps the files of the last build, writes over them, then deletes each file that it did not write. A failed build still empties public/. This is also the base for #66, which renders only what changed.

  • fs.reuse checks the folder as fs.empty does, and refuses with the same message. It deletes each symlink in the folder, never its target, and indexes the rest.
  • Before each write, the disk sink calls fit(file). It deletes a kept path that no write claimed and that is in the way: a file where a folder must go, a folder where a file must go, or a path that differs in case only. Without the last check, renaming About.md to about.md on a case-insensitive disk (the macOS default) would write into the old About/ folder, and the sweep would then delete the new page. Writes that need the same path wait for that delete.
  • At the end, sweep() deletes each kept file that no write claimed, and the folders that this leaves empty.
  • Writing faster made the build outrun the GC, which raised peak RSS by about 110 MB. A streamed build now runs one full collection under Bun as it starts writing the pages again. Bun.gc(false) did not help. Dev and Node do not run it.
  • The docs say that bongo build writes over public/, and deletes what it did not write.

Benchmark

bun run bench site, interleaved A/B against #63 on an M1 Max with Bun 1.4.3: two rounds each, median of 5 runs per round. Each run builds over the output of the run before it, as a repeat build does.

10k-page site #63 this PR change
wall 5.14 s, 5.19 s 3.56 s, 3.60 s −31%
sys 15.2 s, 15.9 s 3.5 s, 3.6 s −77%
user 3.88 s, 3.88 s 3.84 s, 3.89 s same
peak RSS 606 MB, 613 MB 568 MB, 572 MB −6%
start stage 1.71 s, 1.64 s 0.27 s, 0.14 s

The output is the same, byte for byte. A first build into an empty public/ gains nothing from this change.

Flaky tests

Three tests failed now and then before this branch, in main too. Each fix has its own commit:

  • site-css-modules: about 3 in 1,000 temporary paths give lightningcss a hash that starts with "-" and a digit. CSS escapes it, as in .-\31 kqhq_red, and the test's regex did not allow escapes.
  • dev moves to the next free port: another process can hold the port after the test's port. Dev then takes the next free port, up to 10 ports higher, as documented. The test now accepts that.
  • turns a burst of changes into one rebuild: dev can update the page before it logs the rebuild for that change, so the late log line counted as part of the burst. The test now waits for the line. Under CPU load, it failed by the 4th run before, and passed 20 of 20 runs after.

Tests: 7 new tests, for fs.reuse (kept files, symlinks, file and folder swaps, case, concurrent writes, refusal), writing over a last build, and the one collection. All 813 pass, tsc -p . and tsc -p build are clean, and bun run build passes.

@lukeed
lukeed changed the base branch from stream to dates October 15, 2026 18:31
@lukeed lukeed mentioned this pull request Oct 15, 2026
About 3 in 1,000 temporary paths give lightningcss a hash that starts
with "-" and a digit, which CSS escapes, as in `.-\31 kqhq_red`. The
selector regex did not allow escapes, so the test failed now and then.
The test took a free port and expected dev to use the next one, but
another process can hold that one too; dev then takes the next free
port, up to 10 higher, as documented. The test now accepts that.
The test counted rebuild lines once the page showed the edit made
during the first build, but dev can update the page before it logs
that rebuild. The late line then counted as part of the burst, and
the test saw 3 rebuilds. It now waits for that line first. Under CPU
load it failed by the 4th run before, and passes 20 of 20 now.
`bongo build` emptied public/, then made every file again. On the 10k-
page bench, emptying took ~1.6 s, and making 10k pages takes ~1.3 s
where writing over them takes ~0.15 s. A streamed build now keeps the
files of the last build and writes over them, then sweeps each file
that it did not write. A failed build still empties public/.

`fs.reuse` deletes each symlink, never its target, and indexes the
rest. Before each write, it deletes a kept path that no write claimed
and that is in the way: a file where a folder must go, a folder where
a file must go, or a path that differs in case only, which a case-
insensitive disk would write into. Writes that need the same path
wait for that delete.

10k-page bench, repeat builds, interleaved, 2 rounds of 5 runs: wall
5.33 / 5.25 s -> 3.59 / 3.62 s, sys 16.0 / 15.8 s -> 3.6 / 3.7 s,
same output bytes. Peak RSS 584 / 590 MB -> 704 / 690 MB: the build
is faster than the GC, so more garbage is left when it peaks.

Closes #60
Writing over public/ made the build faster than the GC, so rendering
left more garbage, and peak RSS rose by ~110 MB. A streamed build now
runs one full collection under Bun as it starts writing the pages
again: on the 10k-page bench, peak RSS 713 MB -> 573-598 MB, wall time
the same within 50 ms. `Bun.gc(false)` did not lower it. Dev and Node
do not run it.

Refs #60
@lukeed
lukeed changed the base branch from dates to main October 15, 2026 18:43
@lukeed
lukeed merged commit 097602c into main Oct 15, 2026
1 of 3 checks passed
@lukeed
lukeed deleted the inplace branch October 15, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build: emptying public/ takes 1–2 s on a large site

1 participant