Skip to content

perf: faster cold renders - #79

Merged
lukeed merged 2 commits into
mainfrom
perf/render-cold
Oct 22, 2026
Merged

lukeed merged 2 commits into
mainfrom
perf/render-cold

Conversation

@lukeed

@lukeed lukeed commented Oct 22, 2026

Copy link
Copy Markdown
Owner

$assets.render was about 9× slower than a plain Satori + resvg script on a cold cache. On lukeed.com, a cold build of 293 Open Graph cards took 48 s, and 36 s of it was system time. With this change it takes 4.1 s, and every card is byte-identical.

Causes

  1. resvg-js loads every system font by default, on each new Resvg(). bongo makes one for each image, so a build read all system fonts once per card. A sample of the cold build had 1,105 of 1,507 frames in read, open, and stat inside the resvg constructor. bongo never needs those fonts: Satori draws text as paths, and resvg-js gives nested SVG images no fonts. So raster() now sets loadSystemFonts: false.
  2. render() blocks the main thread, so the job pool drew one image at a time. renderAsync() runs on the resvg-js thread pool. It exists in the whole ^2.6.0 peer range.

Numbers

lukeed.com, 293 cards, cold render cache, bongo build --minify --fresh, 3 alternating runs on an M1 Max:

wall user sys
main 48.0–49.0 s 12.8–13.1 s 36.3–36.9 s
loadSystemFonts: false 11.7–11.9 s 12.3–12.4 s 0.7–0.8 s
and renderAsync 4.1–4.2 s 12.4–12.6 s 0.7 s

One card alone: 156 ms before, 25 ms without system fonts, 9.2 ms with renderAsync too.

Not changed

  • The cache key stays the same. The images are byte-identical, so existing caches stay valid.
  • bench/results.md has no new row. The bench site does not call $assets.render, so its numbers do not move.

Test plan

  • bun test (852 pass), bunx tsc -p ., bunx tsc -p build, bun run build
  • The new raster test fails when loadSystemFonts: false is removed
  • lukeed.com: 293 cards before and after are the same bytes
  • Nothing catches a return to the blocking render(); a timing test would be flaky

resvg-js reads every font of the system for each new Resvg, by
default. Satori draws text as paths, so resvg never uses a font,
not even in nested SVG images. On lukeed.com, a cold build of 293
cards went from 48.0 s (36.3 s sys) to 11.8 s (0.7 s sys).
new Resvg().render() blocks the main thread, so images.slot ran
one render at a time. renderAsync runs on the libuv thread pool.
On lukeed.com, a cold build of 293 cards went from 11.8 s to 4.1 s,
and every card has the same bytes.
@lukeed
lukeed merged commit fc181d0 into main Oct 22, 2026
3 checks passed
@lukeed
lukeed deleted the perf/render-cold branch October 22, 2026 15:05
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.

1 participant