Use u64 trie iteration tokens#52
Open
MesTTo wants to merge 1 commit into
Open
Conversation
Implements the answer the iter-token note in the TrieNode trait already sketched: the token is a node-local cursor, so it never needs to encode a whole path, and 64 bits are enough. The ByteNode stops caching the remaining mask word inside the token (the source of the 128-bit requirement); it keeps only one more than the last byte returned and recomputes the next set bit from its own mask (next_iter_byte_from, four masked trailing_zeros probes, still O(1) per step). All other node types already used small counters. iter_token_for_path semantics are unchanged (resume strictly after the given byte; the 63/127/191/255 word-edge cases land identically through the word advance), pinned by a new mask-word-boundary test. Consumers treat tokens as opaque, so the swap is type-level for them; ReadZipperCore shrinks from 144 to 128 bytes (measured on both trees), and each ancestor stack entry loses 8 bytes of padding.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Answers the question the
new_iter_tokendoc comment already asks: thetoken is a node-local cursor, so it never needs to encode a whole path, and
64 bits are enough. The
ByteNodestops caching the remaining mask wordinside the token — the source of the 128-bit requirement — and keeps only
one more than the last byte returned, recomputing the next set bit from its
own mask (
next_iter_byte_from: a maskedtrailing_zerosprobe across atmost four words, still O(1) per step). Every other node type already used
small counters, so this is purely a type change for them.
iter_token_for_pathsemantics are unchanged (resume strictly after thegiven byte); the word-edge cases (63/64, 127/128, 191/192, 255) are pinned by
a new test. Consumers (the zippers, cursors, merkleization, viz) treat
tokens as opaque, so the swap is type-level there.
Result
ReadZipperCoreshrinks from 144 to 128 bytes (measured on both this branchand
master), and each ancestor-stack entry loses 8 bytes of padding.Interleaved A/B against
master(two reps each side):superdense_k_path-7..-8%,
sparse_iter-23..-47%,binary_iterup to -53%, no regressedcell in either bench. The resume-strictly-after contract is also modeled in
Alloy (
fac27_iter_tokenin a separate verification repo), UNSAT in scope.Test plan
cargo test --release --lib(661/0, matches themasterbaseline)cargo miri teston the new boundary test and the touched dense-node testscargo test --release --doc(7/0)cargo bench --bench superdense_keys / sparse_keys / binary_keys -- iter