Skip to content

[impeller] a lot of compute is used to allocate/deallocate Font classes in impeller::TextRenderContextSkia::CreateGlyphAtlas #124996

@gaaclarke

Description

@gaaclarke

I profiled the wonderous app with impeller on c5cbb03b5e17d9f7fb91806f9072bd518ff48b6f and just scrolled through the main page.

The highest usage of cpu on the main thread was in the impeller::TextRendererContextSkia::CreateGlyphAtlas with respect to creating and destroying impeller::Font objects:

Screenshot 2023-04-17 at 1 49 45 PM

I propose the following changes to the data structure of the GlyphAtlas in order to eliminate all of this extra work:

proposal

We make FontGlyphPair's have a pointer to a Font so that copying and manipulating them does not require allocating new fonts. The old way of storing the data could have the same font copied thousands of times and each one has a shared_ptr.

before

namespace impeller {

struct FontGlyphPair {
  Font font;
  Glyph glyph;
};

class GlyphAtlas {
  const Type type_;
  std::shared_ptr<Texture> texture_;

  std::unordered_map<FontGlyphPair,
                     Rect,
                     FontGlyphPair::Hash,
                     FontGlyphPair::Equal>
      positions_;
};

static std::vector<FontGlyphPair> CollectUniqueFontGlyphPairs(
    GlyphAtlas::Type type,
    const TextRenderContext::FrameIterator& frame_iterator);

}  //namespace impeller

after

namespace impeller {

struct FontGlyphPair {
  const Font& font;
  Glyph glyph;
};

struct FontGlyphPairs {
  std::vector<Font> fonts;
  std::vector<FontGlyphPairs> pairs;
}

class GlyphAtlas {
  const Type type_;
  std::shared_ptr<Texture> texture_;
  std::vector<Font> fonts;

  std::unordered_map<FontGlyphPair,
                     Rect,
                     FontGlyphPair::Hash,
                     FontGlyphPair::Equal>
      positions_;
};

static FontGlyphPairs CollectUniqueFontGlyphPairs(
    GlyphAtlas::Type type,
    const TextRenderContext::FrameIterator& frame_iterator);

}  //namespace impeller

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: performanceRelates to speed or footprint issues (see "perf:" labels)e: impellerImpeller rendering backend issues and features requests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions