tikv / raft-engine

A persistent storage engine for Multi-Raft log
Apache License 2.0
565 stars 88 forks source link

reduce allocation of log batch compression #98

Closed tabokie closed 3 years ago

tabokie commented 3 years ago

Signed-off-by: tabokie xy.tao@outlook.com

  1. Reuse log batch buffer for storing compressed content, instead of replacing the buffer
  2. Avoid allocate twice when creating protobuf::Message from decompressed slice
  3. Use entry reference for log batch append

Bench results:

Patched:
test log_batch::tests::bench_log_batch_add_entry_and_encode ... bench:     136,299 ns/iter (+/- 44,912)
test log_batch::tests::bench_log_batch_add_entry_and_encode ... bench:     131,405 ns/iter (+/- 82,630)

Master:
test log_batch::tests::bench_log_batch_add_entry_and_encode ... bench:     199,314 ns/iter (+/- 95,954)
test log_batch::tests::bench_log_batch_add_entry_and_encode ... bench:     197,948 ns/iter (+/- 16,842)

Without streaming encoding(#91):
test log_batch::tests::bench_log_batch_add_entry_and_encode ... bench:     407,738 ns/iter (+/- 142,417)
test log_batch::tests::bench_log_batch_add_entry_and_encode ... bench:     411,079 ns/iter (+/- 111,409)