EGL Multifile Blobcache: Make use of crc32_z algorithm instead of crc32c
To improve the performance in generating crc. Using crc32_z would reduce
the function duration by 98 ~ 99 % as follows.
Test: Genshin Impact Loading
Algorithm Num calls Total Duration (millisec)
crc32_z 3678 9909.88
crc32c 3596 1260876.81
Bug: b/373718861
Change-Id: I0b67265c4bcf199d4433b953a5a399629c9508f9
Signed-off-by: Jisun Lee <jisunnie.lee@samsung.com>
diff --git a/opengl/libs/EGL/FileBlobCache.cpp b/opengl/libs/EGL/FileBlobCache.cpp
index 4a0fac4..573ca54 100644
--- a/opengl/libs/EGL/FileBlobCache.cpp
+++ b/opengl/libs/EGL/FileBlobCache.cpp
@@ -27,6 +27,7 @@
#include <log/log.h>
#include <utils/Trace.h>
+#include <zlib.h>
// Cache file header
static const char* cacheFileMagic = "EGL$";
@@ -34,20 +35,10 @@
namespace android {
-uint32_t crc32c(const uint8_t* buf, size_t len) {
- const uint32_t polyBits = 0x82F63B78;
- uint32_t r = 0;
- for (size_t i = 0; i < len; i++) {
- r ^= buf[i];
- for (int j = 0; j < 8; j++) {
- if (r & 1) {
- r = (r >> 1) ^ polyBits;
- } else {
- r >>= 1;
- }
- }
- }
- return r;
+uint32_t GenerateCRC32(const uint8_t *data, size_t size)
+{
+ const unsigned long initialValue = crc32_z(0u, nullptr, 0u);
+ return static_cast<uint32_t>(crc32_z(initialValue, data, size));
}
FileBlobCache::FileBlobCache(size_t maxKeySize, size_t maxValueSize, size_t maxTotalSize,
@@ -101,7 +92,7 @@
return;
}
uint32_t* crc = reinterpret_cast<uint32_t*>(buf + 4);
- if (crc32c(buf + headerSize, cacheSize) != *crc) {
+ if (GenerateCRC32(buf + headerSize, cacheSize) != *crc) {
ALOGE("cache file failed CRC check");
close(fd);
return;
@@ -175,7 +166,7 @@
// Write the file magic and CRC
memcpy(buf, cacheFileMagic, 4);
uint32_t* crc = reinterpret_cast<uint32_t*>(buf + 4);
- *crc = crc32c(buf + headerSize, cacheSize);
+ *crc = GenerateCRC32(buf + headerSize, cacheSize);
if (write(fd, buf, fileSize) == -1) {
ALOGE("error writing cache file: %s (%d)", strerror(errno),