Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@jason-simmons
Copy link
Member

The atlas will now store a separate map of glyph positions for each font/scale pair. This avoids the cost of repeated hashing and copying of font objects for each glyph in a text run.

See flutter/flutter#133201

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

Hey @jason-simmons, were you able to get positive improvement in the macro benchmarks?

@jonahwilliams
Copy link
Contributor

Building this now to take a look.

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

Logic looks good. In most places I think we can clearly see this is faster. I called out 2 places where it might not be (one of them I think we can actually remove). It would be nice to have a measurement for this =)

struct std::equal_to<impeller::ScaledFont> {
constexpr bool operator()(const impeller::ScaledFont& lhs,
const impeller::ScaledFont& rhs) const {
return lhs.font.IsEqual(rhs.font) && lhs.scale == rhs.scale;
Copy link
Member

Choose a reason for hiding this comment

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

No need to change this, but I'm just realizing that hashing on a floating value might finicky.

Copy link
Contributor

Choose a reason for hiding this comment

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

We round the scale to two decimal places elsewhere so it should be okay. This definitely caused a problem before if there was animated text

Comment on lines 66 to +73
std::optional<Rect> GlyphAtlas::FindFontGlyphBounds(
const FontGlyphPair& pair) const {
const auto& found = positions_.find(pair);
if (found == positions_.end()) {
const auto& found = font_atlas_map_.find(pair.scaled_font);
if (found == font_atlas_map_.end()) {
return std::nullopt;
}
return found->second;
return found->second.FindGlyphBounds(pair.glyph);
}
Copy link
Member

Choose a reason for hiding this comment

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

This is one place where we are replacing one lookup with 2, so FindFontGlyphBounds may be slower. This is where having some benchmark improvement would be nice. Are we even using this anymore?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is called when adding new glyphs to the atlas.

The overall intent of the PR is to make rendering faster when no new glyphs are needed in the atlas. The additional overhead when new glyphs are added should not be significant.

}

void TextFrame::CollectUniqueFontGlyphPairs(FontGlyphPair::Set& set,
void TextFrame::CollectUniqueFontGlyphPairs(FontGlyphMap& glyph_map,
Copy link
Member

Choose a reason for hiding this comment

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

It's hard to know if this is going to be faster. There are multiple inserts happening now.

@jason-simmons
Copy link
Member Author

The main goal here is minimizing the cost of the common case where no new glyphs need to be added to the atlas.

I tested this by scrolling repeatedly through one of the license texts in the Gallery license viewer screen on a Pixel 3.

Without this patch the Android profiler reported that GlyphAtlas::FindFontGlyphBounds and its descendants consumed 11.06% of raster thread time.

With this patch FindGlyphBounds is reduced to 0.83%.

…ing up runs of glyphs in the same font

The atlas will now store a separate map of glyph positions for each
font/scale pair.  This avoids the cost of repeated hashing and copying
of font objects for each glyph in a text run.

See flutter/flutter#133201
Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

lgtm!

Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM!

@jason-simmons jason-simmons added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 30, 2023
@auto-submit auto-submit bot merged commit b63eee2 into flutter:main Aug 30, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 30, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Aug 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

autosubmit Merge PR when tree becomes green via auto submit App e: impeller

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants