Cache rustybuzz
shape plans for vastly improved performance.
#207
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.
I added support to
rustybuzz
to cache shape plans (harfbuzz/rustybuzz#88), which has been released inrustybuzz
v0.12.0.This PR updates
cosmic-text
to make use of the newrustybuzz
functionality by adding aShapePlanCache
, storing shape plans (with an appropriate cache key), and passing the cached shape plan torustybuzz::shape_with_plan
(instead ofrustybuzz::shape
) to avoid re-paying the cost of computing the shape plan.A couple notes:
cache.rs
toglyph_cache.rs
now that there's ashape_plan_cache.rs
, but kept the names of symbols within it generic (e.g.:Cache
) as they're public outside of the crate.ShapePlanCache
viaFontFallbackIter
is nasty, but there isn't a great alternative given the fact thatShapePlanCache
is held byFontSystem
andFontFallbackIter
holds a&mut FontSystem
and we need a&mut ShapePlanCache
inshape_fallback
. That said, this nastiness is narrowly scoped and entirely internal to this crate.All tests in
cosmic-text
still pass with this change.For some anecdotal evidence on performance improvements - all font shaping/layout performance issues we were seeing in our app (https://github.com/warpdotdev/Warp) have disappeared with this patch.