Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more compact v2 encodings #138

Merged
merged 2 commits into from Jan 30, 2024
Merged

Add more compact v2 encodings #138

merged 2 commits into from Jan 30, 2024

Conversation

lukechampine
Copy link
Member

The current encoding of Currency uses an 8-byte length prefix followed by a variable-length big-endian encoding of the integer. This is inherently wasteful, as currency values never require more than a 1-byte prefix. Variable-length encodings can also hurt performance in certain use cases, and make it harder to predict the real-world size of various encoded payloads.

This PR adds an alternative fixed-width (16-byte) little-endian encoding for Currency. This matches the actual struct definition of Currency in core: two uint64s. Surprisingly, this is not quite as efficient as simply reducing the 8-byte prefix to a 1-byte prefix; the currency values currently present in the blockchain would encode to between 11-15 bytes on average. Still, the advantages of fixed width outweigh the slightly larger size imo.

As a side effect, I also ended up changing the encoding of SiafundOutput to be more compact in v2.

@lukechampine lukechampine merged commit 8067f34 into master Jan 30, 2024
6 checks passed
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.

None yet

1 participant