Fix font.glyph lifetimes allow proxy glyphs in cache #65
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.
One thing I noticed about
Cache::queue_glyph
was that it calledglyph.standalone()
for each queued glyph to convert it to a'static
lifetime. I wondered why this was necessary, and when it wasn't if the performance would be improved.Allowing the cache's queue to take glyphs with a generic lifetime is fairly simple, but I had to stare at the error messages for a while to work out why it wasn't working. There was a signature error in
Font::glyph
:Before
After
Spot the difference? Before the signature means the
Glyph
takes the lifetime of the reference to the font, rather than the lifetime of the font data. This was compounded by the fact a reference to the font was used in theGlyphInner
struct. This isn't necessary, asFont
is a cheap-clone type anyway (a reference, or an Arc).With this change we can see another small improvement to cache performance, in addition to the optimisation earlier today:
Moreover, this has a larger affect downstream. In my crate
gfx_glyph
I'm seeing 15-24% reduction in cache interaction latency after allstandalone()
calls are removed (allowed by this patch).The change from
Cache
->Cache<'font>
means this isn't totally backward compatible though, so should be part of the next version, ie0.3
.