diff options
author | Josh Gao <jmgao@google.com> | 2020-03-26 22:02:03 -0700 |
---|---|---|
committer | Josh Gao <jmgao@google.com> | 2020-04-02 17:11:07 -0700 |
commit | ec44d35fde60d20d9ab1c6fb9ac7ee844335f1eb (patch) | |
tree | 21c769725de37a031ff6ad478a6643f59511e5db /adb/daemon/file_sync_service.cpp | |
parent | 2165717875ee15aea112f63744780cae26d6b4c4 (diff) |
adb: implement LZ4 compression.
Add support for LZ4 compression, which compresses and decompresses far
more quickly than brotli, at the cost of worse compression ratio.
`adb sync -d system` speeds (in MB/s) on aosp_blueline-eng:
none brotli lz4
USB 3.0 120 110 190
USB 2.0 38 75 63
Bug: https://issuetracker.google.com/150827486
Test: python3 -m unittest test_device.FileOperationsTest{Uncompressed,Brotli,LZ4}
Change-Id: Ibef6ac15a76b4e5dcd02d7fb9433cbb1c02b8382
Diffstat (limited to 'adb/daemon/file_sync_service.cpp')
-rw-r--r-- | adb/daemon/file_sync_service.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/adb/daemon/file_sync_service.cpp b/adb/daemon/file_sync_service.cpp index 3138ab497..3436e32c0 100644 --- a/adb/daemon/file_sync_service.cpp +++ b/adb/daemon/file_sync_service.cpp @@ -272,7 +272,7 @@ static bool handle_send_file_data(borrowed_fd s, unique_fd fd, uint32_t* timesta syncmsg msg; Block buffer(SYNC_DATA_MAX); std::span<char> buffer_span(buffer.data(), buffer.size()); - std::variant<std::monostate, NullDecoder, BrotliDecoder> decoder_storage; + std::variant<std::monostate, NullDecoder, BrotliDecoder, LZ4Decoder> decoder_storage; Decoder* decoder = nullptr; switch (compression) { @@ -284,6 +284,10 @@ static bool handle_send_file_data(borrowed_fd s, unique_fd fd, uint32_t* timesta decoder = &decoder_storage.emplace<BrotliDecoder>(buffer_span); break; + case CompressionType::LZ4: + decoder = &decoder_storage.emplace<LZ4Decoder>(buffer_span); + break; + case CompressionType::Any: LOG(FATAL) << "unexpected CompressionType::Any"; } @@ -569,6 +573,15 @@ static bool do_send_v2(int s, const std::string& path, std::vector<char>& buffer } compression = CompressionType::Brotli; } + if (msg.send_v2_setup.flags & kSyncFlagLZ4) { + msg.send_v2_setup.flags &= ~kSyncFlagLZ4; + if (compression) { + SendSyncFail(s, android::base::StringPrintf("multiple compression flags received: %d", + orig_flags)); + return false; + } + compression = CompressionType::LZ4; + } if (msg.send_v2_setup.flags) { SendSyncFail(s, android::base::StringPrintf("unknown flags: %d", msg.send_v2_setup.flags)); @@ -598,7 +611,7 @@ static bool recv_impl(borrowed_fd s, const char* path, CompressionType compressi syncmsg msg; msg.data.id = ID_DATA; - std::variant<std::monostate, NullEncoder, BrotliEncoder> encoder_storage; + std::variant<std::monostate, NullEncoder, BrotliEncoder, LZ4Encoder> encoder_storage; Encoder* encoder; switch (compression) { @@ -610,6 +623,10 @@ static bool recv_impl(borrowed_fd s, const char* path, CompressionType compressi encoder = &encoder_storage.emplace<BrotliEncoder>(SYNC_DATA_MAX); break; + case CompressionType::LZ4: + encoder = &encoder_storage.emplace<LZ4Encoder>(SYNC_DATA_MAX); + break; + case CompressionType::Any: LOG(FATAL) << "unexpected CompressionType::Any"; } @@ -688,6 +705,15 @@ static bool do_recv_v2(borrowed_fd s, const char* path, std::vector<char>& buffe } compression = CompressionType::Brotli; } + if (msg.recv_v2_setup.flags & kSyncFlagLZ4) { + msg.recv_v2_setup.flags &= ~kSyncFlagLZ4; + if (compression) { + SendSyncFail(s, android::base::StringPrintf("multiple compression flags received: %d", + orig_flags)); + return false; + } + compression = CompressionType::LZ4; + } if (msg.recv_v2_setup.flags) { SendSyncFail(s, android::base::StringPrintf("unknown flags: %d", msg.recv_v2_setup.flags)); |