skia/skia/ee27aa24cfd4631ee0a5e62ee284252046e9e552
[skparagraph] Share unresolved codepoints with ParagraphCache entries
Problem and per-call cost: since f2f4ac0e78 a ParagraphCache hit copies
std::unordered_set<SkUnichar> fUnresolvedCodepoints into the paragraph
(ParagraphCache::updateTo). The set allocates one node per codepoint, so
every markDirty() + layout() that hits the cache pays one allocation per
codepoint that no font resolves.
Now the cache entry and the paragraphs restored from it share one set
through std::shared_ptr; a hit copies the pointer (null when all
codepoints resolve). Shaping fills only a set that it owns: it releases
the previous set with reset() instead of clear(), so a set that a cache
entry shares never changes. addUnresolvedCodepoints asserts this.
Equivalence: unresolvedCodepoints() returns the same set by value as
before; the cache stores and restores the same codepoints, only without
the copy. SkParagraph_CachePreservesUnresolvedGlyphs now also shapes a
paragraph again after a cache hit with the cache off and checks both
paragraphs and a new one; with clear() instead of reset() the test hits
the new SkASSERT.
The paragraph_cache_hit_unresolved bench measures the hit path with 1024
Private Use Area code units (font fallback off).
Behavior notes:
- Thread safety: ParagraphCache guards its entries with its mutex; a
shared set is immutable once a cache entry holds it, and the shared_ptr
count is atomic.
- Memory: a cache entry no longer holds its own copy of the set.
Numbers (paired, interleaved, pinned to one core):
Flutter txt_benchmarks host_release (Clang, LTO), Skia 942afe3464,
20 rounds, median [95% CI]:
| Bench | unresolved | Before -> After |
| TextBigO/1024 | 410 | -13.1% [-15.0, -10.9] |
| TextBigO/4096 | 2617 | -15.7% [-17.6, -10.3] |
| TextBigO/64 | 0 | +11.1% [+9.3, +12.6] |
TextBigO/64 has an empty set, where the new code does less work. Padding
ParagraphImpl back to the old member size gives +2.6% there and leaves
TextBigO/1024 at -12.1%; an untouched control (SimpleBuilder) moves by
+3.9% from the padding alone, so this is object layout, not the change.
Skia nanobench Release (gcc, paragraph_bench_enabled=true), 4 clean
interleaved rounds:
| paragraph_cache_hit_unresolved | 3.69-3.91us -> 1.68-1.73us |
Not tested: Mac, Windows, Android, ASAN locally.
Assisted-by: Claude Opus 5.5 (Medium)
Change-Id: I61658e6b270d996c6d876f21110c0781e3910281
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1414977
Reviewed-by: Florin Malita <fmalita@google.com>
Commit-Queue: Julia Lavrova <jlavrova@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
5 files changed