Skip to main content

Module throughput

Module throughput 

Source
Expand description

The throughput API: the core’s, and the calls that use other cores.

Structs§

Batch
Messages of one length in Blocks, the batch calls’ input: each message starts a block, and every byte past each message’s end is zero, since a Batch lets the program write only the messages’ own bytes (so the bytes the batch kernels read in place, past a message, can never be wrong). It owns its blocks (Batch::new), or borrows blocks already in place whose messages fill them, with no bytes past their ends (Batch::from_blocks: a Merkle layer’s 64-byte nodes, a mapped file’s records).
Block
64 bytes on a 64-byte boundary: the unit the calls read, so every message starts on a cache line. A Batch holds its messages in blocks, each message starting a block and taking whole blocks (one for an empty message).
Cv
The chaining value of a whole subtree, with its place: 2^level chunks (1024 bytes each), the index-th subtree of that size in the message. It is the only kind a left child can be.
LastCv
The chaining value of a message’s last subtree, with its place and length: the right child at some level of the tree’s right edge. It may be shorter than its left sibling, and is never a left child: no call takes one on the left, so a tree with a short subtree inside it does not compile.
Lent
Guard for a message hashed in place on loan (Pipeline::lent).
Limits
Fixed memory bounds for a Pipeline.
Message
An open message on a Pipeline.
Packed
count messages of N bytes each, packed end to end with nothing between them, on a 128-byte boundary: a compact layout for many short messages of one length (a Merkle layer’s leaves or digests) without per-message block padding in caller memory (N is 16, 32, or 48; backing storage is N bytes per message rounded up once to a 128-byte line). It reads and writes as a [[u8; N]] (leaves[i] = digest), and the batch calls take it as they take a Batch. For Packed<32> with an even count, the digests can also be borrowed directly as 64-byte parent pairs via Packed::as_blocks (carry or pad an odd last digest according to your tree).
Part
Some of a batch’s messages, in place: Prepared::part makes it.
Pipeline
Streaming multithreaded hasher with bounded memory and pull-based Event delivery.
Room
Reusable ROOM_LEN-byte buffer for arriving message bytes.
TreeHasher
A Mode prepared for a program that builds or verifies a BLAKE3 tree itself (verified streaming, an outboard, a tree hashed in parts on other machines): the subtrees’ chaining values, their parents, and the root. The mode’s key is derived once, here; each call then costs its hashing alone.

Enums§

Event
Completion of a message submitted to a Pipeline.

Constants§

ROOM_LEN
Bytes in each Room: sixty-four chunks (64 KiB), a whole BLAKE3 subtree on a 64-byte boundary. Chosen by empirical measurement across x86-64 (AVX2 and AVX-512) and ARM64 (NEON and SME2), where 64 KiB reaches both the 32-lane AVX-512 chunk kernel and SME2’s flat subtree walk with one mechanism (1 whole Room == 1 worker piece).

Traits§

Prepared
The batch calls’ input: messages of one length, prepared so that a call reads them as they are. Batch holds them in blocks, any length; Packed, owned Vec<[u8; N]> / Box<[[u8; N]]> and borrowed &[[u8; N]] slices (N = 16, 32, or 48) hold fixed-width messages end to end. Sealed: the crate’s types and fixed-width byte-array collections/slices alone.

Functions§

block_on
Drive future to completion on the current thread, parking between polls.
context_key
Hash a key-derivation context string and return a ContextKey.
finalize_each
The hash of each message which names: out[k] is what hashers[which[k]].finalize() would give, and that hasher is then reset for its next message (no length hint). Requires out.len() == which.len(), each index < hashers.len(), and distinct indices: it panics on an index named twice, in every build. A call that is refused hashes nothing and leaves every hasher as it was. Messages that finish in one call hash side by side where the CPU has the lanes (with at least two eligible hashers in a 128-hasher window): on x86-64, staged plain 1 KiB chunks via hash_many_rounded (ceiling 32 lanes on Zen 5 / 16 on AVX-512 / 8 on AVX2 / 4 on SSE4.1), staged plain multi-block 65..=1023 B messages on AVX2/AVX-512 via hash_by_blocks (equal-prefix-length blocks batched in SIMD, and on Linux x86-64 AVX-512/AVX2 their final blocks compressed in output16/output8 SIMD lanes for chunks of four or more; SSE4.1 finishes staged < 1 KiB messages individually), and output16/output8 for every 4+ eligible counter-zero final blocks packed from remaining hashers on Linux AVX-512/AVX2; on AArch64, staged plain messages of up to 1024 bytes via hash_by_blocks and counter-zero final blocks via NEON output8.
find_counter_range
Search count consecutive single-block messages derived from template (4..=64 bytes) in mode, replacing the 4-byte little-endian word at byte offset counter_word * 4 with start.wrapping_add(off as u32) for off in 0..count, for digests whose first little-endian 32-bit word word0 = u32::from_le_bytes(digest[..4]) satisfies (word0 & mask) == target.
hash
The hash in mode of the message of len bytes that starts input: a batch of one. The message starts a block, so on a cache line; the bytes past its end, in its last block and any after, are ignored. Tuned for call after call: for a hash now and then amid other work, convenience::hash is the faster call.
hash_chains_32_trunc16
Evaluate init.len() independent 32-byte iterated hash chains in mode, advancing each chain by steps iterations and writing its final 16-byte state to out[i] (#584).
hash_chains_varlen_32_trunc16
Variable-step counterpart to hash_chains_32_trunc16 that advances chain i by steps[i] iterations in mode and writes its final 16-byte state to out[i] (uses stack storage up to 128 nonzero chains; allocates a call-local Vec<usize> above 128; #584).
hash_counter_range
Hash out.len() single-block messages derived from template (4..=64 bytes) in mode, replacing the 4-byte little-endian word at byte offset counter_word * 4 with start.wrapping_add(i) (modulo 2^32) for i in 0..out.len().
hash_counter_range_trunc16
Hash out.len() single-block messages derived from template (4..=64 bytes) in mode, replacing the 4-byte little-endian word at byte offset counter_word * 4 with start.wrapping_add(i) (modulo 2^32) for i in 0..out.len(), writing the first 16 bytes of each BLAKE3 digest.
hash_each
The hash of each message, of any lengths, on the calling thread: out[i] is hash(mode, items[i].0, items[i].1), each item a message of items[i].1 bytes starting its blocks (the bytes past its end ignored). Short messages hash together, so a collection of small items (a directory’s files, a repository’s objects) takes less time than one call each. Requires out.len() == items.len().
hash_each_multithreaded
hash_each, using other CPU cores for collections whose small items total 512 KiB or more (and for individual items of 512 KiB or more, as hash_multithreaded does), returning the same digests. Requires out.len() == items.len().
hash_many
The hashes of a Batch’s messages, in mode, on the calling thread: out[i] becomes the hash of message i, one digest a message. This is the shape of a Merkle tree’s layer: leaves of one size, or nodes of two 32-byte children, which the layer below writes straight into the next layer’s batch (Batch::digests_mut).
hash_many_multithreaded
hash_many, eligible to use other CPU cores above the split threshold: always the same digests as single-threaded hash_many.
hash_multithreaded
hash, eligible to use other CPU cores above the split threshold: always the same Hash as single-threaded hash. For a message whose bytes are not in blocks (a mapped file, say), update_multithreaded into a Hasher takes any slice, at the same speed on the i7-12700K from 512 KiB to 1 GiB (about 1% slower at 1 MiB).
left_len
The bytes of the left subtree of a message, or of a subtree, of len bytes: the largest power of two of chunks below its chunk count. The right subtree holds the rest.
level_of
The level of whole subtrees of len bytes: len is 1024 << level.
update_each
Feed each piece to its hasher: (i, bytes) does hashers[i].update(bytes), each hasher’s pieces in their order in pieces. Call it once with all the pieces your program has in hand (one turn of its event loop): never slower than one update each: many messages arriving at once, such as a server’s uploads, each with its own Hasher. Requires each i < hashers.len(): a turn that panics on one that is not leaves its hashers as after a panic. Finish the messages with finalize_each: plain messages of up to 1024 bytes wait whole in their stage (on both x86-64 and AArch64), so those that finish together hash side by side there. Because a staged plain first chunk has not yet compressed into ChunkState, calling a non-consuming Hasher::finalize() mid-chunk rehashes that staged prefix afresh; callers that finish each message once via finalize_each avoid that cost.
update_multithreaded
Hasher::update, eligible to use other CPU cores above the split threshold (512 KiB per eligible aligned subtree, an implementation heuristic): always the same digest as single-threaded update. Shorter updates hash on the calling thread. One Hasher may take both calls. The program calls initialize_multithreaded first.