Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't copy Glyph on GlyphCache hit #6954

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kchibisov
Copy link
Member

The Glyph is being passed around by reference, so doing the copy is not desired.

--

It might look ugly a bit given that missing glyph handling must be moved, but it's actually
don't try to copy lots of glyph data around on each renderer call.

@kchibisov kchibisov requested a review from chrisduerr May 25, 2023 13:46
The Glyph is being passed around by reference, so doing the copy is
not desired.
@@ -192,72 +200,92 @@ impl GlyphCache {
&mut self,
glyph_key: GlyphKey,
loader: &mut L,
show_missing: bool,
) -> Glyph
) -> Result<&Glyph, Box<RasterizerError>>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error happens once per glyph key, so to not enlarge the return value we simply box the value.

Copy link
Member

@chrisduerr chrisduerr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What inspired this change? Saying this is a bit ugly compared to the current code is an understatement, so there should be some good justification.

@kchibisov
Copy link
Member Author

The glyph is ~32 bytes and we copy it for each cell, so if we assume 77 * 180 cells we copy 400 KB of data for no reason for each frame, given that we only use a reference, and not the copy.

And with my code we copy 4x less, so it's simply faster?

@kchibisov kchibisov marked this pull request as draft May 26, 2023 17:00
@kchibisov
Copy link
Member Author

kchibisov commented May 26, 2023

I'm pretty sure our GlyphCache can do better, so I'll convert it to draft.

@chrisduerr
Copy link
Member

And with my code we copy 4x less, so it's simply faster?

Says who? Unless you've benchmarked it, it's not faster. Making the code more complicated if there's no real world benefit to it isn't useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants