Skip to main content

Module stream_sizing

Module stream_sizing 

Source
Expand description

What a read of a BEEF through the streaming reader will hold, estimated from the frame’s LENGTHS AND COUNTS before anything is allocated (bsv-low #585, the doors lens E585-D12-L3).

bsv-rs 0.4.0’s BeefStream hands out one element at a time, and an element is not its wire bytes: a BUMP leaf of 2 to 38 bytes is a 56 byte Leaf and, while the root is computed, an entry in four tables; a raw transaction is its bytes and a record per input and per output. A reader that keeps a table per element adds an entry per element. So the memory of a read follows the element COUNT and a BUMP’s LEAVES, not the body’s bytes: measured by the lens, natively, 77 MB for a 9.9 MB body of 900,000 minimal transactions and 108 MB for a 9.8 MB body holding one BUMP of 2^18 leaves, each beside the body in a 128 MB isolate.

estimate walks the frame with no allocation and no hash (it reads the varints and steps over everything else), adds what the caller says each thing costs (StreamCharges), and stops at the first element that takes the estimate past the caller’s limit. The caller then does not open the stream. It is a BUDGET, never a refusal: what a caller does with a breach is its own (the script door answers “the network judges”).

The estimate is an UPPER bound by construction, not a measurement: every growing buffer is charged three times its contents (a Vec that doubles holds the old and the new buffer while it moves), every hash table three times its buckets at the fullest load (7/8), and the sizes are the native ones (a usize is 8 bytes; wasm32’s are smaller). The pins hold the measured peak under it for each shape.

Structs§

StreamCharges
What a reader holds per thing of the stream, in bytes.
StreamEstimate
The estimate of one read.

Enums§

Admission
What a reader of the stream does with the estimate, before it opens the stream. ONE rule for every reader (the script door and the census; the delta lens E585-D12-DELTA-N1, Rule 10).

Functions§

estimate
Estimates what a read of body holds under charges, stopping at the first element that takes it past limit.