Hash :
b55f0f78
Author :
Date :
2020-06-02T18:01:24
Compress Program binaries saved in blob cache The Android blob cache has a limit of 2MB, so ANGLE should compress the Program binaries that are saved into it to maximize its effectiveness. ANGLE will gzip the program binaries before being stored in the blob cache and then uncompress them when retrieved. Using gzip, the binaries are compressed to ~25% of their size when running the T-Rex benchmark. Some examples (in bytes): Uncompressed: 20193, Compressed: 4455 Uncompressed: 8767, Compressed: 2369 Uncompressed: 11144, Compressed: 2927 This doesn't appear to affect the T-Rex benchmark since all of the programs are loaded/decompressed as part of the benchmark initialization, and the programs are small enough to all fit in the blob cache without compression. Bug: b/155184635 Test: T-Rex, CQ Change-Id: Ie6a101c32ab5fd49baae1cb7aecdd26a934e15af Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2227529 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Tim Van Patten <timvp@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
//
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// BlobCache_unittest.h: Unit tests for the blob cache.
#include <gtest/gtest.h>
#include "libANGLE/BlobCache.h"
namespace egl
{
// Note: this is fairly similar to SizedMRUCache_unittest, and makes sure the
// BlobCache usage of SizedMRUCache is not broken.
using BlobPut = angle::MemoryBuffer;
using Blob = BlobCache::Value;
using Key = BlobCache::Key;
template <typename T>
void MakeSequence(T &seq, uint8_t start)
{
for (uint8_t i = 0; i < seq.size(); ++i)
{
seq[i] = i + start;
}
}
BlobPut MakeBlob(size_t size, uint8_t start = 0)
{
BlobPut blob;
EXPECT_TRUE(blob.resize(size));
MakeSequence(blob, start);
return blob;
}
Key MakeKey(uint8_t start = 0)
{
Key key;
MakeSequence(key, start);
return key;
}
// Test a cache with a value that takes up maximum size.
TEST(BlobCacheTest, MaxSizedValue)
{
constexpr size_t kSize = 32;
BlobCache blobCache(kSize);
blobCache.populate(MakeKey(0), MakeBlob(kSize));
EXPECT_EQ(32u, blobCache.size());
EXPECT_FALSE(blobCache.empty());
blobCache.populate(MakeKey(1), MakeBlob(kSize));
EXPECT_EQ(32u, blobCache.size());
EXPECT_FALSE(blobCache.empty());
Blob blob;
size_t blobSize;
EXPECT_FALSE(blobCache.get(nullptr, MakeKey(0), &blob, &blobSize));
blobCache.clear();
EXPECT_TRUE(blobCache.empty());
}
// Test a cache with many small values, that it can handle unlimited inserts.
TEST(BlobCacheTest, ManySmallValues)
{
constexpr size_t kSize = 32;
BlobCache blobCache(kSize);
for (size_t value = 0; value < kSize; ++value)
{
blobCache.populate(MakeKey(value), MakeBlob(1, value));
Blob qvalue;
size_t blobSize;
EXPECT_TRUE(blobCache.get(nullptr, MakeKey(value), &qvalue, &blobSize));
if (qvalue.size() > 0)
{
EXPECT_EQ(value, qvalue[0]);
}
}
EXPECT_EQ(32u, blobCache.size());
EXPECT_FALSE(blobCache.empty());
// Putting one element evicts the first element.
blobCache.populate(MakeKey(kSize), MakeBlob(1, kSize));
Blob qvalue;
size_t blobSize;
EXPECT_FALSE(blobCache.get(nullptr, MakeKey(0), &qvalue, &blobSize));
// Putting one large element cleans out the whole stack.
blobCache.populate(MakeKey(kSize + 1), MakeBlob(kSize, kSize + 1));
EXPECT_EQ(32u, blobCache.size());
EXPECT_FALSE(blobCache.empty());
for (size_t value = 0; value <= kSize; ++value)
{
EXPECT_FALSE(blobCache.get(nullptr, MakeKey(value), &qvalue, &blobSize));
}
EXPECT_TRUE(blobCache.get(nullptr, MakeKey(kSize + 1), &qvalue, &blobSize));
if (qvalue.size() > 0)
{
EXPECT_EQ(kSize + 1, qvalue[0]);
}
// Put a bunch of items in the cache sequentially.
for (size_t value = 0; value < kSize * 10; ++value)
{
blobCache.populate(MakeKey(value), MakeBlob(1, value));
}
EXPECT_EQ(32u, blobCache.size());
}
// Tests putting an oversize element.
TEST(BlobCacheTest, OversizeValue)
{
constexpr size_t kSize = 32;
BlobCache blobCache(kSize);
blobCache.populate(MakeKey(5), MakeBlob(100));
Blob qvalue;
size_t blobSize;
EXPECT_FALSE(blobCache.get(nullptr, MakeKey(5), &qvalue, &blobSize));
}
} // namespace egl