Skip to content

structio 0.2.2

Choose a tag to compare

@stephenberry stephenberry released this 02 Sep 18:04
· 34 commits to main since this release

Integer reading is 38-43% faster, and a streaming block read now accepts a complex array.

[dependencies]
structio = "0.2"

Changed

  • Reading arrays of integers is 38-43% faster, and the representative mixed document 11%. The element loop was making a function call per element, which is dearer than it sounds: the parser's cursor spilled to the stack and reloaded on every return. parse_u64 now keeps a small fast path for the common short number and hands the rare cases to an out-of-line one, which is enough for the whole read to inline. Separately, JSON whitespace is answered from a table rather than a bitmask, which needed a range guard in front of it because a byte of 64 or more would shift out of the word. Against Glaze, reading uints went from 50% to 80% and ints from 53% to 86%. The measurements, the two rewrites of the digit conversion that were tried first and were both slower, and the disassembly that pointed at the call rather than the digits are in docs/performance.md. No API or output change.

Fixed

  • read_array_into and from_reader_array read a complex array. They read the typed-array tag and stopped at the extension's, so the one shape that most needs a streaming block read - a buffer of IQ samples, which a consumer can least afford to hold twice - had to go through from_reader and hold the encoded document alongside the vector. The payload was always a block: interleaved (re, im) components are the in-memory form of [Complex<T>] for the same reason a typed array's payload is the in-memory form of [T]. Only the preamble differed.

    The aligned complex form is byte-identical to the plain one, so both arrive by the same path. COMPLEX_ONE is refused as InvalidHeader, being a lone value with no count rather than an array, as are the six undefined forms of the class byte. A generic array stays ExpectedArray and a boolean or string array stays ElementTypeMismatch.

  • The big-endian conversion in the same read reverses each component rather than each element. It could not have fired before, no complex array having reached it, but a Complex<f32> is eight bytes and reversing all eight would have transposed re and im as well as swapping the bytes of each. For every other numeric type the component is the element, so one stride serves both.

No API was added, removed or changed. Nothing needs editing to move from 0.2.1.