Closed evgenykuzyakov closed 4 years ago
Is it possible that https://doc.rust-lang.org/std/io/struct.BufReader.html implements this very functionality?
I think we can use BufReader with raw fill_buf() functionality for a lot of what I did manually with read_exact
Cost of Borsh input of (s: String) where s="" is 9,080,640,736
Average diff 131,604,521
Cost of Borsh input of (v: Vec
Full results: https://github.com/nearprotocol/nearcore/issues/1829#issuecomment-596137624
TODO: Add Vec<_> tests
Could you rerun https://github.com/nearprotocol/borsh/tree/master/borsh-rs/benchmarks and re-generate the graphs?
Could you also bump the versions?
Trying switch to fn deserialize(buf: &mut [u8]) -> Result<Self, Error>;
.
Will let you know
See https://github.com/nearprotocol/borsh/pull/62 for slice reader version. Need to fix benchmarks, but overall looks clean.
Also once we switch serialize to &mut Vec<u8>
, we can kill std:io::Error
Going to regenerate benchmarks with the slice run
Merged buf slice branch, so it's ready to go (once the new benchmarks are added)
Optimizing strings/vec reads using custom implementation for
Vec<u8>
with a bit of unsafe code, but without UB. Switching deserialization to use&mut &[u8]
instead ofBufRead
. It allows us to switch toBorshError
instead ofstd::io::Error
in the future to go withno_std
.Test plan
String
andVec<T>