Repository navigation
perf(core): download each font file once per compile - #9048
Conversation
A variable font names one file for every weight it covers, and the cached copy was stored per weight, so the same file was downloaded once per weight. Store it per address so later weights read the first download. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
jerry-heygen
left a comment
There was a problem hiding this comment.
Approved at e0c4c339. Weights and styles that name the same WOFF2 URL now reuse that file within the family’s cache; each face still emits its own descriptors. The regression checks two distinct downloads and four embedded faces. This does not deduplicate in-flight downloads across compiles, and old cache names are not reused.
The hosted core suite was still running when checked. The Comments check is red because the new cache-key comment raises the file’s comment share; that is a separate merge check, not a runtime defect. I did not run a live render or independently benchmark the download savings.
— Jerrai (pr-review)
Edit accuracy: accurate 275 (base branch 273), smooth 65 of thoseThe gate passes. Newly passing (2)
Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)
Quarantined, measured but not gated (0) |
What
A compile now downloads each font file once. Before, a file that serves several weights was downloaded once per weight. On a cold page using 18 families this drops downloads from 143 to 54 and bytes from 2.39 MB to 0.61 MB.
Why
A variable font names the same file address for every weight it covers. The cached copy was stored per weight and style, so each weight missed the cache and fetched the same bytes again. Cold compiles are the common case on render workers, so this is time and network on every render.
Related work
None.
How
The cached copy is stored under a name made from the file address alone. Faces are resolved one after another, so the second weight finds the first weight's file on disk. What is embedded in the page does not change.
Test plan
Run: the new test and the whole
packages/coresuite (364 files, 7,578 tests) pass locally. Not run: the producer and CLI suites, and no real render.No visible change
The compiled page is the same; only the number of downloads changes.
Claude Fable 5.2
Measurement
One page using 18 families, empty cache, three runs each on the same machine, real network. The result is the download and byte counts. The seconds are n=3 on one devbox and noisy: no speed claim.
The 4.03 s run was the first run of the whole series. One of the three "before" runs received a slightly different answer from the font service and produced a page 2,624 bytes smaller.
Two weights asking for the same address at once
Within one stylesheet this cannot happen: faces are resolved one after another (
const dataUri = await ensureWoff2DataUri(...)inside theforloop indeterministicFonts.ts), so the second weight runs after the first has written the file, and there is one download. The new test covers this case. Two separate lookups for the same family running at the same moment can still each download the file: the write is exclusive (flag: "wx"), and the one that loses reads the winner's copy (theEEXISTbranch inensureWoff2DataUri). That is two downloads, one file, and was already the behaviour for two compiles sharing a cache. No test in this PR covers that second case.Things to know
Self-review
cachedWoff2Pathhas one caller, the loop that resolves a stylesheet's faces. The stylesheet lookup cache uses its own key and is untouched.🤖 Generated with Claude Code