Benchmark improvements and additions. Document n^2 benchmark findings.
Change-Id: I697acad51082151e6614abffe6bebbbe73f31a75
This commit is contained in:
@@ -232,7 +232,7 @@ BENCHMARK(BM_ParagraphStylesBigO)
|
||||
|
||||
static void BM_ParagraphMinikinDoLayout(benchmark::State& state) {
|
||||
std::vector<uint16_t> text;
|
||||
for (uint16_t i = 0; i < state.range(0) * 3; ++i) {
|
||||
for (uint16_t i = 0; i < 16000 * 2; ++i) {
|
||||
text.push_back(i % 5 == 0 ? ' ' : i);
|
||||
}
|
||||
minikin::FontStyle font;
|
||||
@@ -251,8 +251,8 @@ static void BM_ParagraphMinikinDoLayout(benchmark::State& state) {
|
||||
|
||||
while (state.KeepRunning()) {
|
||||
minikin::Layout layout;
|
||||
layout.doLayout(text.data(), 0, state.range(0), text.size(), 0, font, paint,
|
||||
collection);
|
||||
layout.doLayout(text.data(), 0, state.range(0), state.range(0), 0, font,
|
||||
paint, collection);
|
||||
}
|
||||
state.SetComplexityN(state.range(0));
|
||||
}
|
||||
@@ -261,6 +261,44 @@ BENCHMARK(BM_ParagraphMinikinDoLayout)
|
||||
->Range(1 << 7, 1 << 14)
|
||||
->Complexity(benchmark::oN);
|
||||
|
||||
static void BM_ParagraphMinikinAddStyleRun(benchmark::State& state) {
|
||||
std::vector<uint16_t> text;
|
||||
for (uint16_t i = 0; i < 16000 * 2; ++i) {
|
||||
text.push_back(i % 5 == 0 ? ' ' : i);
|
||||
}
|
||||
minikin::FontStyle font;
|
||||
txt::TextStyle text_style;
|
||||
text_style.font_family = "Roboto";
|
||||
minikin::MinikinPaint paint;
|
||||
|
||||
font = minikin::FontStyle(4, false);
|
||||
paint.size = text_style.font_size;
|
||||
paint.letterSpacing = text_style.letter_spacing;
|
||||
paint.wordSpacing = text_style.word_spacing;
|
||||
|
||||
auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir());
|
||||
|
||||
minikin::LineBreaker breaker;
|
||||
breaker.setLocale(icu::Locale(), nullptr);
|
||||
breaker.resize(text.size());
|
||||
memcpy(breaker.buffer(), text.data(), text.size() * sizeof(text[0]));
|
||||
breaker.setText();
|
||||
|
||||
while (state.KeepRunning()) {
|
||||
for (int i = 0; i < 20; ++i) {
|
||||
breaker.addStyleRun(
|
||||
&paint, font_collection.GetMinikinFontCollectionForFamily("Roboto"),
|
||||
font, state.range(0) / 20 * i, state.range(0) / 20 * (i + 1), false,
|
||||
0);
|
||||
}
|
||||
}
|
||||
state.SetComplexityN(state.range(0));
|
||||
}
|
||||
BENCHMARK(BM_ParagraphMinikinAddStyleRun)
|
||||
->RangeMultiplier(4)
|
||||
->Range(1 << 7, 1 << 14)
|
||||
->Complexity(benchmark::oN);
|
||||
|
||||
static void BM_ParagraphSkTextBlobAlloc(benchmark::State& state) {
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
|
||||
@@ -127,6 +127,11 @@ void Paragraph::SetText(std::vector<uint16_t> text, StyledRuns runs) {
|
||||
breaker_.setText();
|
||||
}
|
||||
|
||||
// NOTE: Minikin LineBreaker addStyleRun() has an O(N^2) (according to
|
||||
// benchmarks) time complexity where N is the total number of characters.
|
||||
// However, this is not significant for reasonably sized paragraphs. It is
|
||||
// currently recommended to break up very long paragraphs (10k+ characters) to
|
||||
// ensure speedy layout.
|
||||
void Paragraph::AddRunsToLineBreaker(
|
||||
std::unordered_map<std::string, std::shared_ptr<minikin::FontCollection>>&
|
||||
collection_map) {
|
||||
@@ -300,6 +305,11 @@ void Paragraph::Layout(double width, bool force) {
|
||||
const size_t layout_end = std::min(run.end, next_break);
|
||||
|
||||
bool bidiFlags = paragraph_style_.rtl;
|
||||
// NOTE: Minikin Layout doLayout() has an O(N^2) (according to
|
||||
// benchmarks) time complexity where N is the total number of characters.
|
||||
// However, this is not significant for reasonably sized paragraphs. It is
|
||||
// currently recommended to break up very long paragraphs (10k+
|
||||
// characters) to ensure speedy layout.
|
||||
layout.doLayout(text_.data() + layout_start, 0, layout_end - layout_start,
|
||||
layout_end - layout_start, bidiFlags, font, minikin_paint,
|
||||
font_collection_->GetMinikinFontCollectionForFamily(
|
||||
|
||||
@@ -43,6 +43,14 @@ class Paragraph {
|
||||
|
||||
~Paragraph();
|
||||
|
||||
// NOTE: Minikin Layout doLayout() and LineBreaker addStyleRun() has an
|
||||
// O(N^2) (according to benchmarks) time complexity where N is the total
|
||||
// number of characters. However, this is not significant for reasonably sized
|
||||
// paragraphs. It is currently recommended to break up very long paragraphs
|
||||
// (10k+ characters) to ensure speedy layout.
|
||||
//
|
||||
// Layout calculates the positioning of all the glyphs. Must call this method
|
||||
// before Painting and getting any statistics from this class.
|
||||
void Layout(double width, bool force = false);
|
||||
|
||||
// Paints the Laid out text onto the supplied SkCanvas at (x, y) offset from
|
||||
|
||||
Reference in New Issue
Block a user