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

Reduce checkpoint file size by using fewer bytes to encode length of encoded payload value #2165

Conversation

fxamacker
Copy link
Member

@fxamacker fxamacker commented Mar 18, 2022

Description

Encode length of encoded payload value using 4 bytes (instead of 8 bytes) because the entire payload length is encoded to only 4 bytes.

This encoding is used in checkpoint, TrieUpdate (WAL), and TrieProof. Since this change affects code outside checkpoint, it was moved from PR #1944 to this PR.

Thanks @ramtinms and @tarakby for confirming we should reduce this length.

Closes #2070
Updates #1884
Updates https://github.com/dapperlabs/flow-go/issues/6114

Changes include:

  • Add payload encoding v1 to encode length of encoded payload value to 4 bytes. In v0, length of encoded payload value is encoded in 8 bytes.

  • Support decoding both v0 and v1.

  • Support version parameter for payload encoding. This allows gradual migration of other encoding formats using payload, such as TrieUpdate and TrieProof.

Caveats

This PR optimizes checkpoint file size which should reduce memory use. This isn't expected to have a big impact on speed. Other possible optimizations are outside the scope of this PR.

In v0, length of encoded payload value is encoded in 8 bytes.
In v1, length of encoded payload value is encoded in 4 bytes.

Payload decoding handles both v0 and v1.

Payload is encoded according to version received as parameter.
This allows gradual migration of other encoding formats using
payload, such as TrieUpdate and TrieProof.
@fxamacker fxamacker self-assigned this Mar 18, 2022
@fxamacker fxamacker marked this pull request as draft March 18, 2022 03:06
@fxamacker fxamacker marked this pull request as ready for review March 18, 2022 23:37
Copy link
Contributor

@ramtinms ramtinms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me

Bump version of checkpoint file to v5.
Support reading v4 for compatibility.
Add tests and test data to read v4.
Update checkpoint file format version from v4 to v5
encMaxDepthSizeV4 = 2
encRegCountSizeV4 = 8
encHashSizeV4 = hash.HashLen
encPathSizeV4 = ledger.PathLen
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌🏼 for using the constants

@fxamacker fxamacker merged commit f8dfffd into fxamacker/move-regcount-regsize-to-trie Mar 23, 2022
@fxamacker fxamacker deleted the fxamacker/optimize-encoded-payload-value-length-in-checkpoint branch March 23, 2022 17:42
if err != nil {
log.Fatal().Err(err).Msg("invalid root checkpoint")
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I left this comment on other PR - I would check if version is below one we explicitly support

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great suggestion! 👍 Opened issue #2205 to track this and done in PR #2206.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants