Repository navigation
fontfile: name staged fonts by SHA-256 - #8
Closed
xiaoyumuxi wants to merge 1 commit into
Closed
xiaoyumuxi wants to merge 1 commit into
xiaoyumuxi wants to merge 1 commit into
Conversation
Registering a font hashes its bytes to name the staged file. FNV-1a 128 runs a byte at a time, about 390 MB/s on an M-series Mac, so an application that registers a few dozen megabytes of faces before its first paint (an interface family, a code family and a patched terminal family) waited about 75 ms on the hash alone. SHA-256 uses the platform's hash instructions and runs at about 3.3 GB/s. The key keeps its shape (128 bits and the length byte); a face staged under the old name is staged once more under the new one.
32 of 61 tasks
Author
|
上游已以 vivaui#233 合入同等改动,fork main 已通过上游同步 #21(merge commit 7df24f7)包含它,这里不再单独合入。Upstream merged the same change as vivaui#233; fork main carries it through the upstream sync #21 (merge commit 7df24f7). |
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.
What this changes
fontfilenames the file it stages a registered font in by the first 128 bits of the font's SHA-256 and its length, instead of a 128-bit FNV-1a hash and the length. The key keeps its shape (17 bytes, the same file name length); a font staged under the old name is staged once more under the new one.BenchmarkKeyOfmeasures naming a 2.5 MB face.Why
RegisterFonthashes the whole font before it registers it, and an application registers its fonts before its first paint. FNV-1a runs a byte at a time, about 390 MB/s here, so an application that ships an interface family, a code family and a patched terminal family (Inter, JetBrains Mono and JetBrains Mono Nerd Font Mono: 38 faces, 25.7 MB) waited about 75 ms of its 85–120 ms registration on the hash alone. SHA-256 uses the CPU's hash instructions (ARMv8 SHA2, x86 SHA-NI) and runs at about 3.3 GB/s, so the same set hashes in about 8 ms. Seen in Lithe, which registers those 38 faces at start.How it was verified
test -z "$(gofmt -l $(git ls-files '*.go'))"go vet ./...go test ./... -count=1: everything passes except 15cmd/vivapackaging tests (TestPackage*,TestAnAdHocSignatureIsRealAndCarriesTheEntitlements, the notarization tests andTestMinGoMinorMatchesGoMod), which fail on this machine on base too (Go 1.27.3 and an Xcode SDK that builds for macOS 13.0 or later while the test manifests saymin_system = 12.0). The same 15 fail onupstream/main.BenchmarkKeyOf, 3 runs each, 6.76–6.91 ms/op (379–388 MB/s) before and 0.78–0.80 ms/op (3264–3341 MB/s) aftercrypto/sha256replaceshash/fnv; both are small andcrypto/sha256is usually linked alreadyTestARegisteredFontIsDrawnInItsFamilyregisters a font with CoreText on macOS and passesWhere the boundary sits
Framework: how
RegisterFontnames the file it stages. Nothing an application sees changes.Cost
Nothing for a program that registers no fonts.