near / borsh

Binary Object Representation Serializer for Hashing
https://borsh.io/
491 stars 41 forks source link

Single byte copies slowing things down #26

Closed jackcmay closed 4 years ago

jackcmay commented 4 years ago

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.

MaksymZavershynskyi commented 4 years ago

Good point. That change was not smart, we should revert it for arrays.

MaksymZavershynskyi commented 4 years ago

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