summaryrefslogtreecommitdiffstats
path: root/compiler/image_writer.cc
diff options
context:
space:
mode:
authorMathieu Chartier <mathieuc@google.com>2016-02-25 13:52:10 -0800
committerMathieu Chartier <mathieuc@google.com>2016-02-25 14:55:55 -0800
commita6e81ed4c185b7362cd5199ebe5507d00883a9b0 (patch)
tree851f18eeb8b6401793051d5f52dfad1f7e69f965 /compiler/image_writer.cc
parenteea36cb923b078b86c7b5033ce75fe1b8ea4e522 (diff)
downloadandroid_art-a6e81ed4c185b7362cd5199ebe5507d00883a9b0.tar.gz
android_art-a6e81ed4c185b7362cd5199ebe5507d00883a9b0.tar.bz2
android_art-a6e81ed4c185b7362cd5199ebe5507d00883a9b0.zip
Add lz4hc image compression format
Smaller than lz4 and decompresses at the same speed. Compression is a bit slower. Example saves on old FB APK: Uncompressed: 44748800 bytes LZ4: 12443648 bytes LZ4HC: 11055104 bytes Generating the image slows down by ~1s per 20MB of image due to slower compression. Decompression is about the same speed but there should be a slight speedup since less data needs to be read from flash. Added test. Bug: 22858531 Change-Id: Ib2704305b9bec5b0ba3b1e871f59f4eedff330b7
Diffstat (limited to 'compiler/image_writer.cc')
-rw-r--r--compiler/image_writer.cc23
1 files changed, 20 insertions, 3 deletions
diff --git a/compiler/image_writer.cc b/compiler/image_writer.cc
index 5eff8f37ec..871435b85f 100644
--- a/compiler/image_writer.cc
+++ b/compiler/image_writer.cc
@@ -18,6 +18,7 @@
#include <sys/stat.h>
#include <lz4.h>
+#include <lz4hc.h>
#include <memory>
#include <numeric>
@@ -224,18 +225,28 @@ bool ImageWriter::Write(int image_fd,
char* image_data = reinterpret_cast<char*>(image_info.image_->Begin()) + sizeof(ImageHeader);
size_t data_size;
const char* image_data_to_write;
+ const uint64_t compress_start_time = NanoTime();
CHECK_EQ(image_header->storage_mode_, image_storage_mode_);
switch (image_storage_mode_) {
case ImageHeader::kStorageModeLZ4: {
- size_t compressed_max_size = LZ4_compressBound(image_data_size);
+ const size_t compressed_max_size = LZ4_compressBound(image_data_size);
compressed_data.reset(new char[compressed_max_size]);
data_size = LZ4_compress(
reinterpret_cast<char*>(image_info.image_->Begin()) + sizeof(ImageHeader),
&compressed_data[0],
image_data_size);
- image_data_to_write = &compressed_data[0];
- VLOG(compiler) << "Compressed from " << image_data_size << " to " << data_size;
+
+ break;
+ }
+ case ImageHeader::kStorageModeLZ4HC: {
+ // Bound is same as non HC.
+ const size_t compressed_max_size = LZ4_compressBound(image_data_size);
+ compressed_data.reset(new char[compressed_max_size]);
+ data_size = LZ4_compressHC(
+ reinterpret_cast<char*>(image_info.image_->Begin()) + sizeof(ImageHeader),
+ &compressed_data[0],
+ image_data_size);
break;
}
case ImageHeader::kStorageModeUncompressed: {
@@ -249,6 +260,12 @@ bool ImageWriter::Write(int image_fd,
}
}
+ if (compressed_data != nullptr) {
+ image_data_to_write = &compressed_data[0];
+ VLOG(compiler) << "Compressed from " << image_data_size << " to " << data_size << " in "
+ << PrettyDuration(NanoTime() - compress_start_time);
+ }
+
// Write header first, as uncompressed.
image_header->data_size_ = data_size;
if (!image_file->WriteFully(image_info.image_->Begin(), sizeof(ImageHeader))) {