aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/RTreeTest.cpp
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2014-11-18 09:27:49 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-11-18 09:27:49 -0800
commita06a9531213d2f00a0fe1dc07acd96eba57e6044 (patch)
tree76690d6306a4ed73c72bf947ffdc05b30a242996 /tests/RTreeTest.cpp
parent52b7822fa67e1d587035165258959f9600f8572d (diff)
Prune SkRTree
- Propagate a bunch of constant parameters through. - Delete code that's not used when bulk loading. - Allocate all Nodes together. - Stay in SkRect. Doing a single malloc for the nodes can't not have improved memory usage. Looks like this might improve record performance ~5%, probably mostly from staying in SkRects. This finally dethrones building the BBH as the hot spot. (Now it's mapping user bounds back to device bounds and adjusting for paints.) Recording time changes from my MBP: desk_rectangletransition.skp 11.5us -> 11.7us 1x desk_forecastio.skp 115us -> 114us 0.98x desk_booking.skp 550us -> 541us 0.98x tabl_mercurynews.skp 176us -> 173us 0.98x tabl_hsfi.skp 294us -> 287us 0.98x desk_wordpress.skp 351us -> 343us 0.98x tabl_worldjournal.skp 439us -> 426us 0.97x tabl_gmail.skp 20.3us -> 19.7us 0.97x desk_youtubetvvideo.skp 10.8us -> 10.4us 0.97x desk_googleplus.skp 1.1ms -> 1.07ms 0.97x tabl_slashdot.skp 106us -> 103us 0.97x desk_jsfiddlebigcar.skp 26.7us -> 25.7us 0.96x tabl_techmeme.skp 95.4us -> 91.7us 0.96x tabl_deviantart.skp 133us -> 127us 0.96x desk_pinterest.skp 40.6us -> 38.9us 0.96x desk_carsvg.skp 195us -> 187us 0.96x tabl_engadget.skp 376us -> 359us 0.96x tabl_sahadan.skp 60.5us -> 57.5us 0.95x tabl_culturalsolutions.skp 255us -> 242us 0.95x tabl_gspro.skp 58.3us -> 55.5us 0.95x desk_linkedin.skp 146us -> 138us 0.94x desk_ebay.skp 192us -> 181us 0.94x tabl_cnn.skp 467us -> 440us 0.94x desk_jsfiddlehumperclip.skp 29.9us -> 28.1us 0.94x desk_tigersvg.skp 43.2us -> 40.5us 0.94x desk_yahooanswers.skp 131us -> 123us 0.94x desk_googlespreadsheetdashed.skp 1.18ms -> 1.11ms 0.94x desk_blogger.skp 193us -> 181us 0.94x tabl_mozilla.skp 1.82ms -> 1.7ms 0.94x tabl_mlb.skp 145us -> 136us 0.93x mobi_wikipedia.skp 577us -> 539us 0.93x tabl_frantzen.skp 54.1us -> 50.4us 0.93x desk_baidu.skp 87.9us -> 81.9us 0.93x desk_techcrunch.skp 224us -> 209us 0.93x desk_sfgate.skp 206us -> 192us 0.93x tabl_ukwsj.skp 269us -> 250us 0.93x desk_facebook.skp 316us -> 293us 0.93x desk_gmailthread.skp 205us -> 190us 0.93x tabl_googlecalendar.skp 158us -> 147us 0.93x tabl_digg.skp 382us -> 354us 0.93x desk_amazon.skp 106us -> 98.5us 0.93x tabl_androidpolice.skp 693us -> 642us 0.93x tabl_nytimes.skp 206us -> 191us 0.92x desk_gws.skp 124us -> 114us 0.92x desk_youtube.skp 255us -> 235us 0.92x tabl_cuteoverload.skp 583us -> 537us 0.92x desk_oldinboxapp.skp 18us -> 16.6us 0.92x desk_mobilenews.skp 297us -> 273us 0.92x tabl_pravda.skp 168us -> 154us 0.92x tabl_vnexpress.skp 236us -> 217us 0.92x desk_css3gradients.skp 202us -> 185us 0.92x tabl_gamedeksiam.skp 508us -> 464us 0.91x desk_wowwiki.skp 1.02ms -> 929us 0.91x desk_espn.skp 209us -> 191us 0.91x desk_chalkboard.skp 315us -> 284us 0.9x desk_mapsvg.skp 607us -> 543us 0.89x desk_pokemonwiki.skp 5.18ms -> 4.62ms 0.89x desk_samoasvg.skp 335us -> 298us 0.89x desk_youtubetvbrowse.skp 10.1us -> 8.59us 0.85x BUG=skia:3085, skia:2834 Review URL: https://codereview.chromium.org/734723002
Diffstat (limited to 'tests/RTreeTest.cpp')
-rw-r--r--tests/RTreeTest.cpp55
1 files changed, 14 insertions, 41 deletions
diff --git a/tests/RTreeTest.cpp b/tests/RTreeTest.cpp
index 5d5c1cb873..50eaacb603 100644
--- a/tests/RTreeTest.cpp
+++ b/tests/RTreeTest.cpp
@@ -7,12 +7,8 @@
#include "SkRTree.h"
#include "SkRandom.h"
-#include "SkTSort.h"
#include "Test.h"
-static const size_t MIN_CHILDREN = 6;
-static const size_t MAX_CHILDREN = 11;
-
static const int NUM_RECTS = 200;
static const size_t NUM_ITERATIONS = 100;
static const size_t NUM_QUERIES = 50;
@@ -30,11 +26,7 @@ static SkRect random_rect(SkRandom& rand) {
}
static bool verify_query(SkRect query, SkRect rects[], SkTDArray<unsigned>& found) {
- // TODO(mtklein): no need to do this after everything's SkRects
- query.roundOut();
-
SkTDArray<unsigned> expected;
-
// manually intersect with every rectangle
for (int i = 0; i < NUM_RECTS; ++i) {
if (SkRect::Intersects(query, rects[i])) {
@@ -45,19 +37,14 @@ static bool verify_query(SkRect query, SkRect rects[], SkTDArray<unsigned>& foun
if (expected.count() != found.count()) {
return false;
}
-
if (0 == expected.count()) {
return true;
}
-
- // skia:2834. RTree doesn't always return results in order.
- SkTQSort(expected.begin(), expected.end() -1);
- SkTQSort(found.begin(), found.end() -1);
return found == expected;
}
static void run_queries(skiatest::Reporter* reporter, SkRandom& rand, SkRect rects[],
- SkRTree& tree) {
+ const SkRTree& tree) {
for (size_t i = 0; i < NUM_QUERIES; ++i) {
SkTDArray<unsigned> hits;
SkRect query = random_rect(rand);
@@ -66,53 +53,39 @@ static void run_queries(skiatest::Reporter* reporter, SkRandom& rand, SkRect rec
}
}
-static void rtree_test_main(SkRTree* rtree, skiatest::Reporter* reporter) {
- SkASSERT(rtree);
-
+DEF_TEST(RTree, reporter) {
int expectedDepthMin = -1;
- int expectedDepthMax = -1;
-
int tmp = NUM_RECTS;
while (tmp > 0) {
- tmp -= static_cast<int>(pow(static_cast<double>(MAX_CHILDREN),
- static_cast<double>(expectedDepthMin + 1)));
+ tmp -= static_cast<int>(pow(static_cast<double>(SkRTree::kMaxChildren),
+ static_cast<double>(expectedDepthMin + 1)));
++expectedDepthMin;
}
+ int expectedDepthMax = -1;
tmp = NUM_RECTS;
while (tmp > 0) {
- tmp -= static_cast<int>(pow(static_cast<double>(MIN_CHILDREN),
- static_cast<double>(expectedDepthMax + 1)));
+ tmp -= static_cast<int>(pow(static_cast<double>(SkRTree::kMinChildren),
+ static_cast<double>(expectedDepthMax + 1)));
++expectedDepthMax;
}
SkRandom rand;
SkAutoTMalloc<SkRect> rects(NUM_RECTS);
for (size_t i = 0; i < NUM_ITERATIONS; ++i) {
- rtree->clear();
- REPORTER_ASSERT(reporter, 0 == rtree->getCount());
+ SkRTree rtree;
+ REPORTER_ASSERT(reporter, 0 == rtree.getCount());
for (int j = 0; j < NUM_RECTS; j++) {
rects[j] = random_rect(rand);
}
- rtree->insert(&rects, NUM_RECTS);
+ rtree.insert(&rects, NUM_RECTS);
SkASSERT(rects); // SkRTree doesn't take ownership of rects.
- run_queries(reporter, rand, rects, *rtree);
- REPORTER_ASSERT(reporter, NUM_RECTS == rtree->getCount());
- REPORTER_ASSERT(reporter, expectedDepthMin <= rtree->getDepth() &&
- expectedDepthMax >= rtree->getDepth());
+ run_queries(reporter, rand, rects, rtree);
+ REPORTER_ASSERT(reporter, NUM_RECTS == rtree.getCount());
+ REPORTER_ASSERT(reporter, expectedDepthMin <= rtree.getDepth() &&
+ expectedDepthMax >= rtree.getDepth());
}
}
-
-DEF_TEST(RTree, reporter) {
- SkRTree* rtree = SkRTree::Create(MIN_CHILDREN, MAX_CHILDREN);
- SkAutoUnref au(rtree);
- rtree_test_main(rtree, reporter);
-
- // Rtree that orders input rectangles on deferred insert.
- SkRTree* unsortedRtree = SkRTree::Create(MIN_CHILDREN, MAX_CHILDREN, 1, false);
- SkAutoUnref auo(unsortedRtree);
- rtree_test_main(unsortedRtree, reporter);
-}