Skip to content

Conversation

@noib3
Copy link
Contributor

@noib3 noib3 commented Aug 4, 2025

Follow-up to #1.

TL;DR

Our custom binary encoding protocol is slightly more size efficient than serde + bincode, but both encoding and decoding are slower (benchmarks taken on a 2018 MacBook Pro).

I think it makes sense to remove the Encode and Decode traits in favor of the Tree::serialize() and Tree::deserialize() methods, which also have the added benefit of allowing users to use any serde data format they want.

Size comparison

Encode vs Serialize

Metadata = () Encode Serialize w/ bincode
unit/small_tree/with_state 1,902 B 1,767 B
unit/small_tree/without_state 1,160 B 1,057 B
unit/medium_tree/with_state 26,173 B 31,129 B
unit/medium_tree/without_state 14,931 B 16,907 B
unit/large_tree/with_state 289,100 B 363,707 B
unit/large_tree/without_state 168,341 B 197,391 B
Metadata = "x".repeat(256) Encode Serialize w/ bincode
large_string/small_tree/with_state 27,960 B 27,926 B
large_string/small_tree/without_state 27,218 B 27,216 B
large_string/medium_tree/with_state 284,431 B 290,388 B
large_string/medium_tree/without_state 273,189 B 276,166 B
large_string/large_tree/with_state 2,869,358 B 2,953,966 B
large_string/large_tree/without_state 2,748,599 B 2,787,650 B

Speed comparison

Encode vs Serialize

Metadata = () Encode Serialize w/ bincode
unit/small_tree/with_state 23.580 µs 6.5118 µs
unit/small_tree/without_state 14.385 µs 4.3177 µs
unit/medium_tree/with_state 228.70 µs 84.428 µs
unit/medium_tree/without_state 135.30 µs 41.110 µs
unit/large_tree/with_state 2.5599 ms 795.27 µs
unit/large_tree/without_state 1.4137 ms 363.39 µs
Metadata = "x".repeat(256) Encode Serialize w/ bincode
large_string/small_tree/with_state 27.216 µs 8.8061 µs
large_string/small_tree/without_state 21.076 µs 6.3444 µs
large_string/medium_tree/with_state 331.38 µs 127.20 µs
large_string/medium_tree/without_state 207.15 µs 95.048 µs
large_string/large_tree/with_state 3.5413 ms 1.8814 ms
large_string/large_tree/without_state 1.8826 ms 1.3542 ms

Decode vs Deserialize

Metadata = () Decode Deserialize w/ bincode
unit/small_tree/with_state 15.823 µs 10.497 µs
unit/small_tree/without_state 15.353 µs 15.274 µs
unit/medium_tree/with_state 172.53 µs 137.49 µs
unit/medium_tree/without_state 154.04 µs 152.02 µs
unit/large_tree/with_state 1.6321 ms 1.1954 ms
unit/large_tree/without_state 1.7363 ms 1.7076 ms
Metadata = "x".repeat(256) Decode Deserialize w/ bincode
large_string/small_tree/with_state 49.856 µs 24.086 µs
large_string/small_tree/without_state 47.795 µs 26.973 µs
large_string/medium_tree/with_state 522.56 µs 260.29 µs
large_string/medium_tree/without_state 506.42 µs 293.34 µs
large_string/large_tree/with_state 5.2648 ms 2.6326 ms
large_string/large_tree/without_state 5.1263 ms 3.1588 ms

@noib3 noib3 force-pushed the replace-encode-with-serde branch from 18b8ba7 to 1527059 Compare August 4, 2025 17:39
@noib3 noib3 force-pushed the replace-encode-with-serde branch from 1527059 to e468a3f Compare August 4, 2025 17:40
@noib3 noib3 merged commit a8b5f8f into main Aug 4, 2025
0 of 9 checks passed
@noib3 noib3 deleted the replace-encode-with-serde branch August 4, 2025 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants