Description
Hello Everyone!
My team is currently writing a very traffic-heavy server, so our main goals are performance and security (which are Rust's lead perks). I was extremely happy with Rust's actix-web framework performance, before introducing Bson objects.
I've started reading about this issue and found those benchmarks, and also an alternative for document operations.
https://github.com/only-cliches/NoProto
I'm wondering if it's possible to replace BSON with NoProto Documents? They seem to have the same functionality, but noProto is around 160x faster for decodes, and 85x faster for updates of a single document.
I understand that Document functionality is one of the core MongoDB features, but using BSON for it is a major performance hit for the Rust driver. Changing it might raise the performance several times!
Thanks for your time and attention!
My bench results:
========= SIZE BENCHMARK =========
NoProto: size: 308b, zlib: 198b
Flatbuffers: size: 264b, zlib: 181b
Bincode: size: 163b, zlib: 129b
Postcard: size: 128b, zlib: 119b
Protobuf: size: 154b, zlib: 141b
MessagePack: size: 311b, zlib: 193b
JSON: size: 439b, zlib: 184b
BSON: size: 414b, zlib: 216b
Prost: size: 154b, zlib: 142b
Avro: size: 702b, zlib: 333b
Flexbuffers: size: 490b, zlib: 309b
Abomonation: size: 261b, zlib: 165b
Rkyv: size: 180b, zlib: 152b
Raw BSON: size: 414b, zlib: 216b
MessagePack: size: 296b, zlib: 187b
Serde JSON: size: 446b, zlib: 198b
======== ENCODE BENCHMARK ========
NoProto: 739 ops/ms 1.00
Flatbuffers: 2710 ops/ms 3.66
Bincode: 9615 ops/ms 13.03
Postcard: 4505 ops/ms 6.10
Protobuf: 1484 ops/ms 2.01
MessagePack: 760 ops/ms 1.03
JSON: 700 ops/ms 0.95
BSON: 196 ops/ms 0.27
Prost: 1773 ops/ms 2.40
Avro: 235 ops/ms 0.32
Flexbuffers: 483 ops/ms 0.65
Abomonation: 5405 ops/ms 7.30
Rkyv: 3690 ops/ms 4.99
Raw BSON: 203 ops/ms 0.28
MessagePack: 284 ops/ms 0.39
Serde JSON: 1167 ops/ms 1.58
======== DECODE BENCHMARK ========
NoProto: 1085 ops/ms 1.00
Flatbuffers: 12821 ops/ms 11.81
Bincode: 6944 ops/ms 6.40
Postcard: 5682 ops/ms 5.22
Protobuf: 1727 ops/ms 1.59
MessagePack: 561 ops/ms 0.52
JSON: 564 ops/ms 0.52
BSON: 164 ops/ms 0.15
Prost: 2625 ops/ms 2.41
Avro: 72 ops/ms 0.07
Flexbuffers: 562 ops/ms 0.52
Abomonation: 83333 ops/ms 73.77
Rkyv: 58824 ops/ms 52.62
Raw BSON: 925 ops/ms 0.85
MessagePack: 376 ops/ms 0.35
Serde JSON: 377 ops/ms 0.35
====== DECODE ONE BENCHMARK ======
NoProto: 30303 ops/ms 1.00
Flatbuffers: 142857 ops/ms 4.24
Bincode: 7407 ops/ms 0.24
Postcard: 6289 ops/ms 0.21
Protobuf: 1751 ops/ms 0.06
MessagePack: 721 ops/ms 0.02
JSON: 714 ops/ms 0.02
BSON: 186 ops/ms 0.01
Prost: 2710 ops/ms 0.09
Avro: 83 ops/ms 0.00
Flexbuffers: 15385 ops/ms 0.50
Abomonation: 333333 ops/ms 10.65
Rkyv: 250000 ops/ms 7.14
Raw BSON: 15625 ops/ms 0.51
MessagePack: 404 ops/ms 0.01
Serde JSON: 375 ops/ms 0.01
====== UPDATE ONE BENCHMARK ======
NoProto: 11494 ops/ms 1.00
Flatbuffers: 2336 ops/ms 0.20
Bincode: 4367 ops/ms 0.38
Postcard: 2674 ops/ms 0.23
Protobuf: 706 ops/ms 0.06
MessagePack: 312 ops/ms 0.03
JSON: 525 ops/ms 0.05
BSON: 136 ops/ms 0.01
Prost: 1121 ops/ms 0.10
Avro: 54 ops/ms 0.00
Flexbuffers: 251 ops/ms 0.02
Abomonation: 5495 ops/ms 0.48
Rkyv: 3247 ops/ms 0.28
Raw BSON: 140 ops/ms 0.01
MessagePack: 215 ops/ms 0.02
Serde JSON: 289 ops/ms 0.03
//! | Format / Lib | Encode | Decode All | Decode 1 | Update 1 | Size (bytes) | Size (Zlib) |
//! |------------------------------------------------------------|---------|------------|----------|----------|--------------|-------------|
//! | **Runtime Libs** | | | | | | |
//! | *NoProto* | | | | | | |
//! | [no_proto](https://crates.io/crates/no_proto) | 739 | 1085 | 30303 | 11494 | 308 | 198 |
//! | Apache Avro | | | | | | |
//! | [avro-rs](https://crates.io/crates/avro-rs) | 235 | 72 | 83 | 54 | 702 | 333 |
//! | FlexBuffers | | | | | | |
//! | [flexbuffers](https://crates.io/crates/flexbuffers) | 483 | 562 | 15385 | 251 | 490 | 309 |
//! | JSON | | | | | | |
//! | [json](https://crates.io/crates/json) | 700 | 564 | 714 | 525 | 439 | 184 |
//! | [serde_json](https://crates.io/crates/serde_json) | 1167 | 377 | 375 | 289 | 446 | 198 |
//! | BSON | | | | | | |
//! | [bson](https://crates.io/crates/bson) | 196 | 164 | 186 | 136 | 414 | 216 |
//! | [rawbson](https://crates.io/crates/rawbson) | 203 | 925 | 15625 | 140 | 414 | 216 |
//! | MessagePack | | | | | | |
//! | [rmp](https://crates.io/crates/rmp) | 760 | 561 | 721 | 312 | 311 | 193 |
//! | [messagepack-rs](https://crates.io/crates/messagepack-rs) | 284 | 376 | 404 | 215 | 296 | 187 |
//! | **Compiled Libs** | | | | | | |
//! | Flatbuffers | | | | | | |
//! | [flatbuffers](https://crates.io/crates/flatbuffers) | 2710 | 12821 | 142857 | 2336 | 264 | 181 |
//! | Bincode | | | | | | |
//! | [bincode](https://crates.io/crates/bincode) | 9615 | 6944 | 7407 | 4367 | 163 | 129 |
//! | Postcard | | | | | | |
//! | [postcard](https://crates.io/crates/postcard) | 4505 | 5682 | 6289 | 2674 | 128 | 119 |
//! | Protocol Buffers | | | | | | |
//! | [protobuf](https://crates.io/crates/protobuf) | 1484 | 1727 | 1751 | 706 | 154 | 141 |
//! | [prost](https://crates.io/crates/prost) | 1773 | 2625 | 2710 | 1121 | 154 | 142 |
//! | Abomonation | | | | | | |
//! | [abomonation](https://crates.io/crates/abomonation) | 5405 | 83333 | 333333 | 5495 | 261 | 165 |
//! | Rkyv | | | | | | |
//! | [rkyv](https://crates.io/crates/rkyv) | 3690 | 58824 | 250000 | 3247 | 180 | 152 |