forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Impeller] faster glyph atlas generation by removing data copies (flu…
…tter#41290) fixes flutter/flutter#124996 This is the best I could come up with easily. It doesn't give as good of a result as I'd hoped. I measured it with a simple microbenchmark derived from one of the unit tests and it gave a 6% decrease in time ( 241.314us vs 257.626us) on macos release builds (run with rosetta). Improvements: 1) Removed the copying of the std::set to an std::vector 1) Uses references instead of copying FontGlyphPairs out of collections in a few places 1) Holds new glyphs as a vector of references to the set instead of copying all the FontGlyphPairs 1) Deletes more lines of code than it adds ## the benchmark ```diff diff --git a/impeller/typographer/typographer_unittests.cc b/impeller/typographer/typographer_unittests.cc index 01a11d494c..1b99afa699 100644 --- a/impeller/typographer/typographer_unittests.cc +++ b/impeller/typographer/typographer_unittests.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <chrono> #include "flutter/testing/testing.h" #include "impeller/playground/playground_test.h" #include "impeller/typographer/backends/skia/text_frame_skia.h" @@ -149,23 +150,29 @@ TEST_P(TypographerTest, GlyphAtlasWithLotsOfdUniqueGlyphSize) { sk_font); ASSERT_TRUE(blob); - TextFrame frame; - size_t count = 0; - TextRenderContext::FrameIterator iterator = [&]() -> const TextFrame* { - if (count < 8) { - count++; - frame = TextFrameFromTextBlob(blob, 0.6 * count); - return &frame; - } - return nullptr; - }; - auto atlas = context->CreateGlyphAtlas(GlyphAtlas::Type::kAlphaBitmap, - atlas_context, iterator); - ASSERT_NE(atlas, nullptr); - ASSERT_NE(atlas->GetTexture(), nullptr); - - ASSERT_EQ(atlas->GetTexture()->GetSize().width * 2, - atlas->GetTexture()->GetSize().height); + auto beg = std::chrono::high_resolution_clock::now(); + int count = 10000; + for (int i = 0; i < count; ++i) { + TextFrame frame; + size_t count = 0; + TextRenderContext::FrameIterator iterator = [&]() -> const TextFrame* { + if (count < 8) { + count++; + frame = TextFrameFromTextBlob(blob, 0.6 * count); + return &frame; + } + return nullptr; + }; + auto atlas = context->CreateGlyphAtlas(GlyphAtlas::Type::kAlphaBitmap, + atlas_context, iterator); + ASSERT_NE(atlas, nullptr); + ASSERT_NE(atlas->GetTexture(), nullptr); + ASSERT_EQ(atlas->GetTexture()->GetSize().width * 2, + atlas->GetTexture()->GetSize().height); + } + auto end = std::chrono::high_resolution_clock::now(); + auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - beg); + FML_LOG(ERROR) << "Elapsed Time: " << static_cast<double>(duration.count())/count << "us"; } ``` [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
- Loading branch information
Showing
5 changed files
with
54 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters