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.
Improve getting non-overlapping rectangles from RTree (flutter#42399)
Fixes flutter/flutter#116070 Fixes flutter/flutter#126202 Introduces `DlRegion` class which implements subset of `SkRegion` required to get non-overlapping rectangles from region. The implementation is different and faster than `SkRegion` for this particular use-case (`display_list_region_benchmarks`): Edit: Updated benchmark to latest revision and natively (initial run went through rosetta) ``` ---------------------------------------------------------------------------- Benchmark Time CPU Iterations ---------------------------------------------------------------------------- BM_RegionBenchmarkDlRegion/Tiny 616 us 616 us 908 BM_RegionBenchmarkSkRegion/Tiny 70559 us 70557 us 10 BM_RegionBenchmarkDlRegion/Small 1315 us 1314 us 537 BM_RegionBenchmarkSkRegion/Small 121736 us 121717 us 6 BM_RegionBenchmarkDlRegion/Medium 1079 us 1079 us 650 BM_RegionBenchmarkSkRegion/Medium 22039 us 22035 us 32 BM_RegionBenchmarkDlRegion/Large 399 us 399 us 1763 BM_RegionBenchmarkSkRegion/Large 1510 us 1510 us 466 ``` ## Pre-launch Checklist - [X] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [X] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [X] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [X] I listed at least one issue that this PR fixes in the description above. - [X] I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See [testing the engine] for instructions on writing and running engine tests. - [X] I updated/added relevant documentation (doc comments with `///`). - [X] I signed the [CLA]. - [X] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
- Loading branch information
Showing
14 changed files
with
693 additions
and
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "flutter/benchmarking/benchmarking.h" | ||
|
||
#include "flutter/display_list/geometry/dl_region.h" | ||
#include "third_party/skia/include/core/SkRegion.h" | ||
|
||
#include <random> | ||
|
||
class SkRegionAdapter { | ||
public: | ||
void addRect(const SkIRect& rect) { region_.op(rect, SkRegion::kUnion_Op); } | ||
|
||
std::vector<SkIRect> getRects() { | ||
std::vector<SkIRect> rects; | ||
SkRegion::Iterator it(region_); | ||
while (!it.done()) { | ||
rects.push_back(it.rect()); | ||
it.next(); | ||
} | ||
return rects; | ||
} | ||
|
||
private: | ||
SkRegion region_; | ||
}; | ||
|
||
class DlRegionAdapter { | ||
public: | ||
void addRect(const SkIRect& rect) { rects_.push_back(rect); } | ||
|
||
std::vector<SkIRect> getRects() { | ||
flutter::DlRegion region(std::move(rects_)); | ||
return region.getRects(false); | ||
} | ||
|
||
private: | ||
std::vector<SkIRect> rects_; | ||
}; | ||
|
||
template <typename Region> | ||
void RunRegionBenchmark(benchmark::State& state, int maxSize) { | ||
while (state.KeepRunning()) { | ||
std::random_device d; | ||
std::seed_seq seed{2, 1, 3}; | ||
std::mt19937 rng(seed); | ||
|
||
std::uniform_int_distribution pos(0, 4000); | ||
std::uniform_int_distribution size(1, maxSize); | ||
|
||
Region region; | ||
|
||
for (int i = 0; i < 2000; ++i) { | ||
SkIRect rect = | ||
SkIRect::MakeXYWH(pos(rng), pos(rng), size(rng), size(rng)); | ||
region.addRect(rect); | ||
} | ||
|
||
auto vec2 = region.getRects(); | ||
} | ||
} | ||
|
||
namespace flutter { | ||
|
||
static void BM_RegionBenchmarkSkRegion(benchmark::State& state, int maxSize) { | ||
RunRegionBenchmark<SkRegionAdapter>(state, maxSize); | ||
} | ||
|
||
static void BM_RegionBenchmarkDlRegion(benchmark::State& state, int maxSize) { | ||
RunRegionBenchmark<DlRegionAdapter>(state, maxSize); | ||
} | ||
|
||
BENCHMARK_CAPTURE(BM_RegionBenchmarkDlRegion, Tiny, 30) | ||
->Unit(benchmark::kMicrosecond); | ||
BENCHMARK_CAPTURE(BM_RegionBenchmarkSkRegion, Tiny, 30) | ||
->Unit(benchmark::kMicrosecond); | ||
BENCHMARK_CAPTURE(BM_RegionBenchmarkDlRegion, Small, 100) | ||
->Unit(benchmark::kMicrosecond); | ||
BENCHMARK_CAPTURE(BM_RegionBenchmarkSkRegion, Small, 100) | ||
->Unit(benchmark::kMicrosecond); | ||
BENCHMARK_CAPTURE(BM_RegionBenchmarkDlRegion, Medium, 400) | ||
->Unit(benchmark::kMicrosecond); | ||
BENCHMARK_CAPTURE(BM_RegionBenchmarkSkRegion, Medium, 400) | ||
->Unit(benchmark::kMicrosecond); | ||
BENCHMARK_CAPTURE(BM_RegionBenchmarkDlRegion, Large, 1500) | ||
->Unit(benchmark::kMicrosecond); | ||
BENCHMARK_CAPTURE(BM_RegionBenchmarkSkRegion, Large, 1500) | ||
->Unit(benchmark::kMicrosecond); | ||
|
||
} // namespace flutter |
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
Oops, something went wrong.