Repository navigation
perf: faster cold renders - #79
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
$assets.renderwas 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
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 inread,open, andstatinside the resvg constructor. bongo never needs those fonts: Satori draws text as paths, and resvg-js gives nested SVG images no fonts. Soraster()now setsloadSystemFonts: false.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.0peer range.Numbers
lukeed.com, 293 cards, cold render cache,
bongo build --minify --fresh, 3 alternating runs on an M1 Max:mainloadSystemFonts: falserenderAsyncOne card alone: 156 ms before, 25 ms without system fonts, 9.2 ms with
renderAsynctoo.Not changed
bench/results.mdhas 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 buildrastertest fails whenloadSystemFonts: falseis removedrender(); a timing test would be flaky