summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2018-02-20 15:21:20 -0800
committerTianjie Xu <xunchang@google.com>2018-03-03 05:13:49 +0000
commitde1685fd76c0742df848985bf448388583e1299e (patch)
treedf47b54adb613dca7d68dda33472bfd7692ba709
parent26d89772808907b3d4e6c47fa7d3d172942ca52b (diff)
Enable brotli_bsdiff in update package generation
Brotli_bsdiff uses brotli to compress the bsdiff patches; and almost always yields a smaller result than the old bsdiff with bz2. So there is little point to try both methods in update_engine. Example: walleye 4504078 -> 4585723 with bsdiff cache enabled. time size bz2 only: ~8min 494M brotli only: ~12min 455M bz2 & bro: ~16min 454M In this example, trying bz2 merely saves ~1M at the cost of 4 minutes generation time. So in this CL, we only use brotli_bsdiff if the operation is allowed; and later we can optionally implement a new mode in bsdiff to pick the compressor who generates the smallest patches. Bug: 34220646 Test: Generate and verify a walleye package Change-Id: Ideae1acea95ff204c2ba5b7637945307743f0a51
-rw-r--r--payload_generator/delta_diff_utils.cc25
1 files changed, 20 insertions, 5 deletions
diff --git a/payload_generator/delta_diff_utils.cc b/payload_generator/delta_diff_utils.cc
index bcbc3a54..877e13fd 100644
--- a/payload_generator/delta_diff_utils.cc
+++ b/payload_generator/delta_diff_utils.cc
@@ -40,6 +40,7 @@
#include <base/threading/simple_thread.h>
#include <brillo/data_encoding.h>
#include <bsdiff/bsdiff.h>
+#include <bsdiff/patch_writer_factory.h>
#include "update_engine/common/hash_calculator.h"
#include "update_engine/common/subprocess.h"
@@ -73,6 +74,8 @@ const uint64_t kMaxBsdiffDestinationSize = 200 * 1024 * 1024; // bytes
// memory intensive, so we limit these operations to 150 MiB.
const uint64_t kMaxPuffdiffDestinationSize = 150 * 1024 * 1024; // bytes
+const int kBrotliCompressionQuality = 11;
+
// Process a range of blocks from |range_start| to |range_end| in the extent at
// position |*idx_p| of |extents|. If |do_remove| is true, this range will be
// removed, which may cause the extent to be trimmed, split or removed entirely.
@@ -740,21 +743,33 @@ bool ReadExtentsToDiff(const string& old_part,
TEST_AND_RETURN_FALSE(base::CreateTemporaryFile(&patch));
ScopedPathUnlinker unlinker(patch.value());
+ std::unique_ptr<bsdiff::PatchWriterInterface> bsdiff_patch_writer;
+ InstallOperation_Type operation_type = InstallOperation::BSDIFF;
+ if (version.OperationAllowed(InstallOperation::BROTLI_BSDIFF)) {
+ bsdiff_patch_writer =
+ bsdiff::CreateBSDF2PatchWriter(patch.value(),
+ bsdiff::CompressorType::kBrotli,
+ kBrotliCompressionQuality);
+ operation_type = InstallOperation::BROTLI_BSDIFF;
+ } else {
+ bsdiff_patch_writer = bsdiff::CreateBsdiffPatchWriter(patch.value());
+ if (version.OperationAllowed(InstallOperation::SOURCE_BSDIFF)) {
+ operation_type = InstallOperation::SOURCE_BSDIFF;
+ }
+ }
+
brillo::Blob bsdiff_delta;
TEST_AND_RETURN_FALSE(0 == bsdiff::bsdiff(old_data.data(),
old_data.size(),
new_data.data(),
new_data.size(),
- patch.value().c_str(),
+ bsdiff_patch_writer.get(),
nullptr));
TEST_AND_RETURN_FALSE(utils::ReadFile(patch.value(), &bsdiff_delta));
CHECK_GT(bsdiff_delta.size(), static_cast<brillo::Blob::size_type>(0));
if (bsdiff_delta.size() < data_blob.size()) {
- operation.set_type(
- version.OperationAllowed(InstallOperation::SOURCE_BSDIFF)
- ? InstallOperation::SOURCE_BSDIFF
- : InstallOperation::BSDIFF);
+ operation.set_type(operation_type);
data_blob = std::move(bsdiff_delta);
}
}