Skip to content

Conversation

@Snezhkko
Copy link

@Snezhkko Snezhkko commented Nov 6, 2025

Previously, BigUint::serialized_size in serialize/src/impls/int_like.rs computed the size by calling to_bytes_le() and delegating to Vec’s size calculation. This performed a temporary Vec allocation solely to obtain the byte length, which is unnecessary and introduces avoidable overhead. The change replaces this with an allocation-free calculation based on BigUint::bits(), preserving the exact on-wire format including the zero edge case. For zero values, to_bytes_le() returns a single byte [0], so we return 8 + 1 for the length-prefixed encoding. For non-zero values, the payload length equals ceil(bits/8), so we compute 8 + ((bits + 7) / 8) directly. The behavior of serialization remains unchanged; only the size computation path is optimized to avoid allocation.

@Snezhkko Snezhkko requested review from a team as code owners November 6, 2025 20:56
@Snezhkko Snezhkko requested review from mmagician, weikengchen and z-tech and removed request for a team November 6, 2025 20:56
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.

1 participant