Skip to content

Comments

docs: add docs on state vars docs re packing in structs#20747

Open
nventuro wants to merge 2 commits intomerge-train/fairiesfrom
nico/f-341-add-note-on-state_vars-docs-re-packing-in-structs
Open

docs: add docs on state vars docs re packing in structs#20747
nventuro wants to merge 2 commits intomerge-train/fairiesfrom
nico/f-341-add-note-on-state_vars-docs-re-packing-in-structs

Conversation

@nventuro
Copy link
Contributor

I added docs to state_vars telling people to consider putting values in the same struct for cost reductions, and added lots of docs to Packable explaining what it does, benefits, when to derive and when to do it manually, along with an example (and tests for the example).

I also reorganized protocol-types/traits a little bit by putting each trait into their own mod, so that it's less messy. The mods are private and we re-export via pub::use, so from the outside everything looks the same.

For some reason the docsite does not build a page for protocol::traits and we instead get links to protocol_types. I'll need to ask @asterite about this.

nventuro and others added 2 commits February 21, 2026 17:06
Move each trait (Empty, FromField, Hash, Packable, ToField) into its own
file under traits/, with private submodules and pub re-exports. Move the
bounded_vec_serialization test to the serde crate where it belongs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@nventuro nventuro requested a review from LeilaWang as a code owner February 21, 2026 18:31
@nventuro nventuro removed the request for review from LeilaWang February 21, 2026 18:31
Copy link
Contributor

@benesjan benesjan left a comment

Choose a reason for hiding this comment

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

Nice

Comment on lines +64 to +65
//! therefore
//! a single read.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
//! therefore
//! a single read.
//! therefore a single read.

broken formatting

//! [`PublicImmutable`](crate::state_vars::PublicImmutable) and
//! [`DelayedPublicMutable`](crate::state_vars::DelayedPublicMutable)) benefit from packing multiple values in the same
//! `struct` even if there is no need for tight packing (e.g. if all values are `Field`s), since they often work by
//! reading the _hash_ of the entire value. Many values in the same `struct` will result in a single hash, and
Copy link
Contributor

Choose a reason for hiding this comment

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

Think people would be curious to learn why this optimization only works in private so would link here to the WithThash struct where I assume it's already explained.

@@ -0,0 +1,175 @@
// Trait: is_empty
//
// The general is_empty trait checks if a data type is is empty,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// The general is_empty trait checks if a data type is is empty,
// The general is_empty trait checks if a data type is empty,

I am aware it's unrelated to the PR but I couldn't help. These old docs are pretty ugly

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