CBOR writer for ClojureScript.
Design follows measurements taken on node before any of this was written:
DataView, not hand-rolled shift/mask. Manual byte assembly measured 2.2x
SLOWER than DataView for a big-endian i32 (4.34 vs 1.97 ns), which is the
opposite of the usual instinct. DataView's default byte order is
big-endian, which is also CBOR's.TextEncoder costs ~56 ns per call regardless of string length, so a manual
ASCII loop wins below ~55 characters (8.7 ns for 9 chars). Keywords and map
keys are almost always shorter than that, so using TextEncoder everywhere
would cost ~6x on the hot case.setBigInt64 is 5.7x a normal write, so it is reserved for values outside
the safe-integer range.CBOR writer for ClojureScript. Design follows measurements taken on node before any of this was written: - `DataView`, not hand-rolled shift/mask. Manual byte assembly measured 2.2x SLOWER than DataView for a big-endian i32 (4.34 vs 1.97 ns), which is the opposite of the usual instinct. DataView's default byte order is big-endian, which is also CBOR's. - `TextEncoder` costs ~56 ns per call regardless of string length, so a manual ASCII loop wins below ~55 characters (8.7 ns for 9 chars). Keywords and map keys are almost always shorter than that, so using TextEncoder everywhere would cost ~6x on the hot case. - `setBigInt64` is 5.7x a normal write, so it is reserved for values outside the safe-integer range.
(head! w major val)Header byte for major carrying unsigned val, in the shortest form.
Header byte for `major` carrying unsigned `val`, in the shortest form.
(write-shortest-float! w d)RFC 8949 §4.2.2 preferred serialisation: narrowest form that round-trips.
RFC 8949 §4.2.2 preferred serialisation: narrowest form that round-trips.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |