turbofish-org / merk

πŸ”₯🌲 High-performance Merkle key/value store

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Suggested change for TreeOp::Put

davebryson opened this issue Β· comments

Not a big deal, but one suggestion I have is to changeTreeOp::Put(&'a[u8]) to TreeOp::Put(Vec<u8>). Why?

  1. The consumer Node.value is already a Vec<u8>
  2. It simplifies TreeOp a bit (lifetime is not needed)
  3. It's easier to use Put(Vec<u8>) from external calls - (again simplifies lifetime stuff)

That was chosen for performance - I hate unneccessary clones. Would switching to AsRef([u8]) solve this?

Ah but you're right that it's getting cloned into the node - maybe you're right and we can just change this πŸ‘Œ

Made the change to try it out and see the perf difference. It's in my treeop branch

Bench results (just showing Put related ones):
test bench_put_insert_random: 186,201,818 (&[u8]) --- 168,084,786 (Vec<u8>) ns/iter
test bench_put_insert_sequential: 23,737,681 (&[u8]) --- 24,472,033 (Vec<u8>) ns/iter
test bench_put_update_random: 206,077,496 (&[u8]) --- 194,155,280 (Vec<u8>) ns/iter
test bench_put_update_sequential 25,539,183 (&[u8]) --- 24,806,745 (Vec<u8>) ns/iter

Performance wise they're pretty close. I'll settle for 23,809 random inserts per/sec πŸ˜„

Minimal touchpoints to make the change - πŸ‘ to the designer of this thing!

Closing this because #15 now uses Vec<u8>'s where we would have used &[u8]'s. In the future there might be a few places where we can optimize by using slices, but with a AsRef<[u8]> bound so that we can still accept Vec<u8>.