Closed jackcmay closed 4 years ago
Good point. That change was not smart, we should revert it for arrays.
Performance still slightly worse than 0.2.5 because we have replaced some allocation methods for safety reasons. Researching performance optimization is now a part of #29
Disclaimer: The following performance tests were done using Rust on BPF which is under development.
I noticed that upgrading Borsh from 2.4 to 2.5 is causing a large increase in the number of BPF instructions it takes to serialize and deserialize byte arrays. From a few thousand instructions to 20k+ for a 32 byte array. The performance went from beating to being far worse than bincode.
It looks like the single-byte copies introduced in this PR is the culprit: https://github.com/nearprotocol/borsh/pull/20
Instead of copying the entire array with an
exend_from_slice
,extend_from_slice
is performed for each byte. It's possible that other rustc targets are optimizing this better then the BPF backend is.