diff options
| author | eunhhu <[email protected]> | 2026-09-24 17:14:54 +0100 |
|---|---|---|
| committer | eunhhu <[email protected]> | 2026-09-24 17:14:54 +0100 |
| commit | b1ce1927022d374198441afafeb27199fc8a052a (patch) | |
| tree | 6021f175f4c67ed03b44240eaa2f90d846f12f6f /research/experiments | |
| parent | d34f9426d5317a1948f12f229439946728bc342a (diff) | |
| download | pure-b1ce1927022d374198441afafeb27199fc8a052a.tar.gz pure-b1ce1927022d374198441afafeb27199fc8a052a.zip | |
Establish native micro runtime checkpoint
Diffstat (limited to 'research/experiments')
92 files changed, 88792 insertions, 0 deletions
diff --git a/research/experiments/001-checkpoint-granularity/README.md b/research/experiments/001-checkpoint-granularity/README.md new file mode 100644 index 0000000..4c04950 --- /dev/null +++ b/research/experiments/001-checkpoint-granularity/README.md @@ -0,0 +1,110 @@ +# Experiment 001: checkpoint granularity + +This is a native measurement apparatus for one known space/time tradeoff. It is +not a new algorithm, a general dependency-graph runtime, or the product's language +choice. The apparatus uses C17 and Python's standard library so it can be run +with the tools present on the initial Linux host and with a C compiler on macOS. + +## Question and pre-measurement expectations + +How much does storing intermediate results at different intervals save, once the +editable program and scheduling state are included? How much extra work does it +cause when a rule changes? + +Expected, not measured at the time of writing this section: + +- Uniformly spaced checkpoints shrink the result cache at the cost of starting + recomputation before the changed instruction. +- Root input changes offer no prefix to reuse. Fine checkpoints may only add + cache writes and comparisons in this workload. +- Edits near the end favor fine checkpoints. This deliberately favorable case + must not stand in for all edits. +- The editable model stays resident, so shrinking the cache 16-fold will not + shrink total core storage 16-fold. + +## Semantics and comparison + +The model consists of independent, statically connected chains. Each instruction +is an 8-byte record with a scalar operator and parameter. Values are uint64_t; +overflow wraps. Supported operators are add, XOR, multiply, and rotate/XOR. +Only the final result of each chain is observed. + +One update applies a batch of changes, then computes all affected observed +outputs. Changes alter roots, operators, and parameters, not graph topology. +There is no renderer, effectful I/O, concurrent execution, or state migration. + +- Block 1 stores every intermediate result (fine incremental baseline). +- Blocks 4, 16, and 64 store results at block ends. +- A block equal to chain length recomputes the whole affected chain, retaining + only its final output (full recomputation baseline). + +All variants share program representation, input handling and per-chain dirty +ranges. Unaffected chains are skipped by every variant. Fine and full variants +use dedicated loops. Fine/block variants stop at an unchanged cached boundary +only after passing the last changed instruction in the batch. + +The chain structure makes dependency information implicit. No general graph +edge storage or graph partitioning is needed. This is an optimistic case for +compact checkpoints; it cannot establish results for arbitrary graphs. + +For G chains of length L and checkpoint spacing B, the requested persistent +storage in this implementation is: + +```text +sizeof(Engine) + 8*G*L + 16*G + 8*G*ceil(L/B) + model inputs+ cached values, + dirty including outputs +``` + +This includes all live core arrays and the engine descriptor, but not allocator +bookkeeping, stack, executable code, trace storage or OS pages. Trace size is +recorded separately. It is not RSS, physical footprint, or total application RAM. +There are no allocations in the timed update path. + +## Workloads + +The fixed initial matrix uses 16 chains, lengths 256 and 1024, and 256 updates per +trace. Workload seed: 20260922. + +- `roots`: every chain's input changes on every update. +- `uniform`: one uniformly selected instruction changes per update. +- `tail`: one instruction in the last eight positions changes per update. +- `dense`: eight instruction edits per chain per update, with replacement. + +Changes are XOR deltas so repeated traces continue changing the model. Two +warm-up passes precede timing. Even measured replay counts leave identical final +models across strategies; the runner checks their output checksums. Differential +tests additionally compare every output after every update against independent +from-scratch evaluation across multiple seeds, odd sizes and edge cases. + +## Reproduce + +From this directory, with Python 3 and a C compiler with ASan/UBSan support: + +```sh +python3 run.py --check-only +python3 run.py --output results/local-run +``` + +The runner refuses to overwrite an existing result directory. `CC` can select a +compiler, such as `CC=clang`. It builds into a temporary directory. On Linux it +pins itself and child processes to one available CPU and records that choice. + +Default measurements use seven trials with randomized strategy order within +each trial. Pilot timings choose an even replay count per case, targeting 20 ms +per measurement. All raw samples, memory counts, instruction counts, compiler +flags, source hashes and host metadata are retained. Timing excludes program +creation, trace creation, warm-up, and output verification. It includes change +application, scheduling and recomputation. + +`median_ns_per_tick` is the median of batch-average processing times. It is not a +P50/P99 input-to-display latency measurement. A shared host without controlled +power or temperature permits preliminary comparisons, not hardware guarantees. + +The reported storage reduction is largely predicted by the formula. The useful +observations are the whole-core reduction, processing cost and losing workloads. +This experiment cannot establish automatic policy quality, novel research, +editor usability, M3 performance, or universal memory savings. + +The first run and its interpretation are available in the +[Korean research report](../../../docs/research/002-checkpoint-results.md). diff --git a/research/experiments/001-checkpoint-granularity/benchmark.c b/research/experiments/001-checkpoint-granularity/benchmark.c new file mode 100644 index 0000000..1c3f98b --- /dev/null +++ b/research/experiments/001-checkpoint-granularity/benchmark.c @@ -0,0 +1,276 @@ +#define _POSIX_C_SOURCE 200809L +#include <errno.h> +#include <inttypes.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> + +/* Experimental apparatus, not the Pure runtime. All arithmetic is modulo 2^64. */ +typedef struct { uint32_t salt, control; } Op; +typedef struct { + uint32_t chain, index; + uint64_t mask; +} Change; +typedef struct { + uint32_t chains, length, block, slots; + Op *ops; + uint64_t *inputs, *cache; + uint32_t *first, *last; +} Engine; +typedef struct { + uint32_t ticks, per_tick; + Change *changes; +} Trace; + +static void die(const char *s) { fprintf(stderr, "%s\n", s); exit(1); } +static void require(int condition, const char *s) { if (!condition) die(s); } +static void *allocate(size_t count, size_t size) { + if (size && count > SIZE_MAX / size) die("allocation size overflow"); + void *p = calloc(count, size); + if (!p) die("allocation failed"); + return p; +} +static uint64_t random64(uint64_t *s) { + uint64_t z = (*s += UINT64_C(0x9e3779b97f4a7c15)); + z = (z ^ (z >> 30)) * UINT64_C(0xbf58476d1ce4e5b9); + z = (z ^ (z >> 27)) * UINT64_C(0x94d049bb133111eb); + return z ^ (z >> 31); +} +static uint64_t rotate(uint64_t x, uint32_t n) { + return (x << n) | (x >> (64 - n)); +} +static uint64_t evaluate(Op op, uint64_t x) { + switch (op.control & 3u) { + case 0: return x + op.salt; + case 1: return x ^ ((uint64_t)op.salt << 17); + case 2: return x * ((uint64_t)op.salt | 1u); + default: return rotate(x, 1u + ((op.control >> 2) % 63u)) ^ op.salt; + } +} +static uint64_t now_ns(void) { + struct timespec t; + if (clock_gettime(CLOCK_MONOTONIC, &t)) die("clock_gettime failed"); + return (uint64_t)t.tv_sec * UINT64_C(1000000000) + (uint64_t)t.tv_nsec; +} +static uint64_t output(const Engine *e, uint32_t c) { + return e->cache[(size_t)c * e->slots + e->slots - 1]; +} +static uint64_t reference_output(const Engine *e, uint32_t c) { + uint64_t x = e->inputs[c]; + for (uint32_t n = 0; n < e->length; ++n) + x = evaluate(e->ops[(size_t)c * e->length + n], x); + return x; +} +static Engine create_engine(uint32_t chains, uint32_t length, + uint32_t block, uint64_t seed) { + Engine e = { .chains = chains, .length = length, .block = block, + .slots = (length + block - 1) / block }; + e.ops = allocate((size_t)chains * length, sizeof(*e.ops)); + e.inputs = allocate(chains, sizeof(*e.inputs)); + e.cache = allocate((size_t)chains * e.slots, sizeof(*e.cache)); + e.first = allocate(chains, sizeof(*e.first)); + e.last = allocate(chains, sizeof(*e.last)); + for (uint32_t c = 0; c < chains; ++c) { + e.inputs[c] = random64(&seed); + uint64_t x = e.inputs[c]; + for (uint32_t n = 0; n < length; ++n) { + Op *op = &e.ops[(size_t)c * length + n]; + op->salt = (uint32_t)random64(&seed); + op->control = (uint32_t)random64(&seed); + x = evaluate(*op, x); + if ((n + 1) % block == 0 || n + 1 == length) + e.cache[(size_t)c * e.slots + n / block] = x; + } + e.first[c] = length; + } + return e; +} +static void destroy_engine(Engine *e) { + free(e->ops); free(e->inputs); free(e->cache); + free(e->first); free(e->last); +} +static void apply(Engine *e, Change change) { + uint32_t c = change.chain, n = change.index; + require(c < e->chains && n <= e->length, "invalid change"); + if (!change.mask) return; + if (n == e->length) { + e->inputs[c] ^= change.mask; + n = 0; + } else { + Op *op = &e->ops[(size_t)c * e->length + n]; + op->salt ^= (uint32_t)change.mask; + op->control ^= (uint32_t)(change.mask >> 32); + } + if (n < e->first[c]) e->first[c] = n; + if (n > e->last[c]) e->last[c] = n; +} +static uint64_t update(Engine *e) { + uint64_t work = 0; + for (uint32_t c = 0; c < e->chains; ++c) { + uint32_t first = e->first[c], last = e->last[c]; + if (first == e->length) continue; + const Op *ops = e->ops + (size_t)c * e->length; + uint64_t *cache = e->cache + (size_t)c * e->slots; + /* Full and fine have dedicated loops: no block-loop penalty for B=1. */ + if (e->block == e->length) { + uint64_t x = e->inputs[c]; + for (uint32_t n = 0; n < e->length; ++n) x = evaluate(ops[n], x); + cache[0] = x; + work += e->length; + } else if (e->block == 1) { + uint64_t x = first ? cache[first - 1] : e->inputs[c]; + uint32_t n = first; + while (n < e->length) { + uint64_t old = cache[n]; + cache[n] = x = evaluate(ops[n], x); + ++n; + /* Do not skip a later edit in the same batch. */ + if (n > last && x == old) break; + } + work += n - first; + } else { + uint32_t start = first / e->block; + uint64_t x = start ? cache[start - 1] : e->inputs[c]; + for (uint32_t b = start; b < e->slots; ++b) { + uint32_t begin = b * e->block, end = begin + e->block; + if (end > e->length) end = e->length; + for (uint32_t n = begin; n < end; ++n) x = evaluate(ops[n], x); + uint64_t old = cache[b]; + cache[b] = x; + work += end - begin; + if (end > last && x == old) break; + } + } + e->first[c] = e->length; + e->last[c] = 0; + } + return work; +} +static uint64_t checksum(const Engine *e) { + uint64_t h = UINT64_C(0xcbf29ce484222325); + for (uint32_t c = 0; c < e->chains; ++c) + h = (h ^ output(e, c)) * UINT64_C(0x100000001b3); + return h; +} +static Trace create_trace(const char *kind, uint32_t chains, uint32_t length, + uint32_t ticks, uint64_t seed) { + uint32_t per_tick = 1; + int roots = !strcmp(kind, "roots"); + int dense = !strcmp(kind, "dense"); + int uniform = !strcmp(kind, "uniform"); + int tail = !strcmp(kind, "tail"); + require(roots || dense || uniform || tail, "unknown workload"); + if (roots) per_tick = chains; + if (dense) per_tick = chains * 8; + Trace t = { .ticks = ticks, .per_tick = per_tick }; + t.changes = allocate((size_t)ticks * per_tick, sizeof(*t.changes)); + for (uint32_t i = 0; i < ticks; ++i) { + for (uint32_t k = 0; k < per_tick; ++k) { + Change *p = &t.changes[(size_t)i * per_tick + k]; + p->chain = roots ? k : dense ? k / 8 : (uint32_t)(random64(&seed) % chains); + p->index = roots ? length : (uint32_t)(random64(&seed) % length); + if (tail) { + uint32_t width = length < 8 ? length : 8; + p->index = length - width + p->index % width; + } + /* XOR changes keep every replay active; fixed assignments would not. */ + p->mask = random64(&seed) | 1u; + } + } + return t; +} +static uint64_t replay(Engine *e, const Trace *t) { + uint64_t work = 0; + for (uint32_t i = 0; i < t->ticks; ++i) { + for (uint32_t k = 0; k < t->per_tick; ++k) + apply(e, t->changes[(size_t)i * t->per_tick + k]); + work += update(e); + } + return work; +} +static size_t owned_bytes(const Engine *e) { + return sizeof(*e) + (size_t)e->chains * e->length * sizeof(*e->ops) + + (size_t)e->chains * (sizeof(*e->inputs) + sizeof(*e->first) + sizeof(*e->last)) + + (size_t)e->chains * e->slots * sizeof(*e->cache); +} +static void check_outputs(const Engine *e) { + for (uint32_t c = 0; c < e->chains; ++c) + require(output(e, c) == reference_output(e, c), "output disagrees with full reference"); +} +static void self_test(void) { + const uint32_t lengths[] = {1, 2, 7, 17, 65, 257}; + const uint32_t blocks[] = {1, 2, 4, 16, 64, 256}; + uint64_t checked_ticks = 0; + for (uint64_t seed = 1; seed <= 8; ++seed) { + for (size_t l = 0; l < sizeof(lengths) / sizeof(*lengths); ++l) { + uint32_t length = lengths[l]; + for (size_t b = 0; b <= sizeof(blocks) / sizeof(*blocks); ++b) { + uint32_t block = b == sizeof(blocks) / sizeof(*blocks) ? length : blocks[b]; + if (block > length) continue; + Engine e = create_engine(3, length, block, seed); + check_outputs(&e); + uint64_t rng = seed; + for (uint32_t tick = 0; tick < 500; ++tick) { + uint32_t count = (uint32_t)(random64(&rng) % 9); + for (uint32_t k = 0; k < count; ++k) { + Change change = { + .chain = (uint32_t)(random64(&rng) % e.chains), + .index = (uint32_t)(random64(&rng) % (length + 1)), + .mask = random64(&rng) + }; + if (tick % 11 == 0) change.mask = 0; + apply(&e, change); + if (tick % 13 == 0) apply(&e, change); /* cancelling edits */ + } + (void)update(&e); + check_outputs(&e); + require(update(&e) == 0, "clean update performed work"); + ++checked_ticks; + } + destroy_engine(&e); + } + } + } + /* An unchanged early checkpoint must not suppress a later dirty operation. */ + for (uint32_t block = 1; block <= 4; block *= 2) { + Engine e = create_engine(1, 8, block, 77); + Change cancel = {0, 0, 123}, later = {0, 7, 987}; + apply(&e, cancel); apply(&e, cancel); apply(&e, later); + (void)update(&e); check_outputs(&e); destroy_engine(&e); + } + printf("{\"checked_ticks\":%" PRIu64 ",\"status\":\"passed\"}\n", checked_ticks); +} +static uint32_t number(const char *s, uint32_t max) { + char *end; + errno = 0; + unsigned long n = strtoul(s, &end, 10); + if (errno || end == s || *end || !n || n > max) die("invalid positive integer"); + return (uint32_t)n; +} +int main(int argc, char **argv) { + if (argc == 2 && !strcmp(argv[1], "--check")) { self_test(); return 0; } + if (argc != 8) die("usage: benchmark CHAINS LENGTH BLOCK WORKLOAD TICKS REPLAYS SEED | --check"); + uint32_t chains = number(argv[1], 1024), length = number(argv[2], 65536); + uint32_t block = number(argv[3], length), ticks = number(argv[5], 4096); + uint32_t replays = number(argv[6], 4096), seed = number(argv[7], UINT32_MAX); + require((uint64_t)chains * length <= UINT64_C(1048576), "model too large for this lab"); + Engine e = create_engine(chains, length, block, seed); + Trace t = create_trace(argv[4], chains, length, ticks, seed + UINT64_C(1234567)); + (void)replay(&e, &t); (void)replay(&e, &t); /* two warm-up replays */ + uint64_t work = 0, start = now_ns(); + for (uint32_t r = 0; r < replays; ++r) work += replay(&e, &t); + uint64_t elapsed = now_ns() - start; + check_outputs(&e); /* correctness check is outside the measured interval */ + printf("{\"elapsed_ns\":%" PRIu64 ",\"ticks\":%" PRIu64 + ",\"node_evaluations\":%" PRIu64 ",\"core_owned_bytes\":%zu" + ",\"model_bytes\":%zu,\"cache_bytes\":%zu,\"engine_bytes\":%zu" + ",\"trace_bytes\":%zu,\"checksum\":\"%016" PRIx64 "\"}\n", + elapsed, (uint64_t)ticks * replays, work, owned_bytes(&e), + (size_t)chains * length * sizeof(Op), + (size_t)chains * e.slots * sizeof(uint64_t), sizeof(Engine), + sizeof(t) + (size_t)t.ticks * t.per_tick * sizeof(Change), checksum(&e)); + free(t.changes); destroy_engine(&e); + return 0; +} diff --git a/research/experiments/001-checkpoint-granularity/results/2026-09-22-linux-aarch64/environment.json b/research/experiments/001-checkpoint-granularity/results/2026-09-22-linux-aarch64/environment.json new file mode 100644 index 0000000..1e967ad --- /dev/null +++ b/research/experiments/001-checkpoint-granularity/results/2026-09-22-linux-aarch64/environment.json @@ -0,0 +1,330 @@ +{ + "started_utc": "2026-09-22T09:32:06.820074+00:00", + "platform": "Linux-6.18.39+rpt-rpi-2712-aarch64-with-glibc2.41", + "machine": "aarch64", + "compiler": "cc (Debian 14.2.0-19) 14.2.0\nCopyright (C) 2024 Free Software Foundation, Inc.\nThis is free software; see the source for copying conditions. There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.", + "flags": [ + "-std=c17", + "-O3", + "-Wall", + "-Wextra", + "-Wpedantic", + "-Werror" + ], + "python": "3.14.7", + "source_sha256": "9e1b1108f58a8725458531207bd1edf06d9af43ae3255c3b97d4388c2b58c707", + "runner_sha256": "4c3e8ae899eb5068813df9529a8c7953d63730ee3ca507a0a7dbe58963b1db01", + "trials": 7, + "target_ms": 20.0, + "seed": 20260922, + "timing": "batch elapsed time / update ticks; not input latency", + "memory": "sizeof engine + requested live array bytes; excludes allocator, harness, code, OS", + "power_control": "not controlled; shared host; preliminary measurements", + "original_affinity": [ + 0, + 1, + 2, + 3 + ], + "measurement_affinity": [ + 0 + ], + "cpu_description": [ + "CPU architecture: 8", + "CPU implementer\t: 0x41", + "CPU part\t: 0xd0b", + "Model\t\t: Raspberry Pi 5 Model B Rev 1.1" + ], + "release_check": { + "checked_ticks": 108000, + "status": "passed" + }, + "sanitizer_check": { + "checked_ticks": 108000, + "status": "passed" + }, + "calibration_replays": [ + { + "chains": 16, + "length": 256, + "workload": "roots", + "block": 1, + "replays": 6 + }, + { + "chains": 16, + "length": 256, + "workload": "roots", + "block": 4, + "replays": 4 + }, + { + "chains": 16, + "length": 256, + "workload": "roots", + "block": 16, + "replays": 6 + }, + { + "chains": 16, + "length": 256, + "workload": "roots", + "block": 64, + "replays": 6 + }, + { + "chains": 16, + "length": 256, + "workload": "roots", + "block": 256, + "replays": 6 + }, + { + "chains": 16, + "length": 256, + "workload": "uniform", + "block": 1, + "replays": 130 + }, + { + "chains": 16, + "length": 256, + "workload": "uniform", + "block": 4, + "replays": 110 + }, + { + "chains": 16, + "length": 256, + "workload": "uniform", + "block": 16, + "replays": 130 + }, + { + "chains": 16, + "length": 256, + "workload": "uniform", + "block": 64, + "replays": 124 + }, + { + "chains": 16, + "length": 256, + "workload": "uniform", + "block": 256, + "replays": 74 + }, + { + "chains": 16, + "length": 256, + "workload": "tail", + "block": 1, + "replays": 968 + }, + { + "chains": 16, + "length": 256, + "workload": "tail", + "block": 4, + "replays": 870 + }, + { + "chains": 16, + "length": 256, + "workload": "tail", + "block": 16, + "replays": 730 + }, + { + "chains": 16, + "length": 256, + "workload": "tail", + "block": 64, + "replays": 384 + }, + { + "chains": 16, + "length": 256, + "workload": "tail", + "block": 256, + "replays": 86 + }, + { + "chains": 16, + "length": 256, + "workload": "dense", + "block": 1, + "replays": 4 + }, + { + "chains": 16, + "length": 256, + "workload": "dense", + "block": 4, + "replays": 4 + }, + { + "chains": 16, + "length": 256, + "workload": "dense", + "block": 16, + "replays": 4 + }, + { + "chains": 16, + "length": 256, + "workload": "dense", + "block": 64, + "replays": 4 + }, + { + "chains": 16, + "length": 256, + "workload": "dense", + "block": 256, + "replays": 4 + }, + { + "chains": 16, + "length": 1024, + "workload": "roots", + "block": 1, + "replays": 2 + }, + { + "chains": 16, + "length": 1024, + "workload": "roots", + "block": 4, + "replays": 2 + }, + { + "chains": 16, + "length": 1024, + "workload": "roots", + "block": 16, + "replays": 2 + }, + { + "chains": 16, + "length": 1024, + "workload": "roots", + "block": 64, + "replays": 2 + }, + { + "chains": 16, + "length": 1024, + "workload": "roots", + "block": 1024, + "replays": 2 + }, + { + "chains": 16, + "length": 1024, + "workload": "uniform", + "block": 1, + "replays": 24 + }, + { + "chains": 16, + "length": 1024, + "workload": "uniform", + "block": 4, + "replays": 22 + }, + { + "chains": 16, + "length": 1024, + "workload": "uniform", + "block": 16, + "replays": 24 + }, + { + "chains": 16, + "length": 1024, + "workload": "uniform", + "block": 64, + "replays": 24 + }, + { + "chains": 16, + "length": 1024, + "workload": "uniform", + "block": 1024, + "replays": 14 + }, + { + "chains": 16, + "length": 1024, + "workload": "tail", + "block": 1, + "replays": 912 + }, + { + "chains": 16, + "length": 1024, + "workload": "tail", + "block": 4, + "replays": 834 + }, + { + "chains": 16, + "length": 1024, + "workload": "tail", + "block": 16, + "replays": 708 + }, + { + "chains": 16, + "length": 1024, + "workload": "tail", + "block": 64, + "replays": 384 + }, + { + "chains": 16, + "length": 1024, + "workload": "tail", + "block": 1024, + "replays": 14 + }, + { + "chains": 16, + "length": 1024, + "workload": "dense", + "block": 1, + "replays": 2 + }, + { + "chains": 16, + "length": 1024, + "workload": "dense", + "block": 4, + "replays": 2 + }, + { + "chains": 16, + "length": 1024, + "workload": "dense", + "block": 16, + "replays": 2 + }, + { + "chains": 16, + "length": 1024, + "workload": "dense", + "block": 64, + "replays": 2 + }, + { + "chains": 16, + "length": 1024, + "workload": "dense", + "block": 1024, + "replays": 2 + } + ], + "completed_utc": "2026-09-22T09:32:24.887753+00:00", + "binary_bytes": 71208 +} diff --git a/research/experiments/001-checkpoint-granularity/results/2026-09-22-linux-aarch64/raw.csv b/research/experiments/001-checkpoint-granularity/results/2026-09-22-linux-aarch64/raw.csv new file mode 100644 index 0000000..1ed88ef --- /dev/null +++ b/research/experiments/001-checkpoint-granularity/results/2026-09-22-linux-aarch64/raw.csv @@ -0,0 +1,281 @@ +trial,chains,length,workload,block,replays,elapsed_ns,ticks,node_evaluations,core_owned_bytes,model_bytes,cache_bytes,engine_bytes,trace_bytes,checksum,ns_per_tick,evaluations_per_tick
+0,16,256,uniform,256,74,19423930,18944,4849664,33208,32768,128,56,4112,07e316e8e83163f0,1025.3341427364865,256.0
+0,16,256,dense,256,4,27889701,1024,4194304,33208,32768,128,56,524304,07e316e8e83163f0,27236.0361328125,4096.0
+0,16,256,dense,64,4,27252683,1024,4080128,33592,32768,512,56,524304,07e316e8e83163f0,26613.9482421875,3984.5
+0,16,256,tail,16,730,16031339,186880,2990080,35128,32768,2048,56,4112,07e316e8e83163f0,85.78413420376712,16.0
+0,16,1024,roots,1,2,58533196,512,8388608,262456,131072,131072,56,65552,cc440e349b9b5a57,114322.6484375,16384.0
+0,16,1024,uniform,1,24,20859539,6144,3279504,262456,131072,131072,56,4112,cc440e349b9b5a57,3395.1072591145835,533.7734375
+0,16,256,roots,256,6,23781630,1536,6291456,33208,32768,128,56,65552,07e316e8e83163f0,15482.83203125,4096.0
+0,16,1024,dense,4,2,63661600,512,7458720,164152,131072,32768,56,524304,cc440e349b9b5a57,124339.0625,14567.8125
+0,16,1024,uniform,1024,14,22677705,3584,3670016,131512,131072,128,56,4112,cc440e349b9b5a57,6327.484654017857,1024.0
+0,16,256,tail,1,968,15760618,247808,1128688,65848,32768,32768,56,4112,07e316e8e83163f0,63.60011783316116,4.5546875
+0,16,1024,tail,4,834,14631637,213504,1277688,164152,131072,32768,56,4112,cc440e349b9b5a57,68.53097365857315,5.984375
+0,16,1024,tail,1,912,15252766,233472,1063392,262456,131072,131072,56,4112,cc440e349b9b5a57,65.33017235471492,4.5546875
+0,16,256,dense,4,4,28737719,1024,3753408,41272,32768,8192,56,524304,07e316e8e83163f0,28064.1787109375,3665.4375
+0,16,1024,roots,64,2,54914217,512,8388608,133432,131072,2048,56,65552,cc440e349b9b5a57,107254.330078125,16384.0
+0,16,256,roots,1,6,30769606,1536,6291456,65848,32768,32768,56,65552,07e316e8e83163f0,20032.295572916668,4096.0
+0,16,1024,roots,16,2,57387697,512,8388608,139576,131072,8192,56,65552,cc440e349b9b5a57,112085.345703125,16384.0
+0,16,1024,roots,1024,2,55510329,512,8388608,131512,131072,128,56,65552,cc440e349b9b5a57,108418.611328125,16384.0
+0,16,1024,uniform,64,24,20219114,6144,3472896,133432,131072,2048,56,4112,cc440e349b9b5a57,3290.8714192708335,565.25
+0,16,1024,roots,4,2,69964336,512,8388608,164152,131072,32768,56,65552,cc440e349b9b5a57,136649.09375,16384.0
+0,16,1024,uniform,16,24,20636818,6144,3323520,139576,131072,8192,56,4112,cc440e349b9b5a57,3358.8570963541665,540.9375
+0,16,256,roots,4,4,21918928,1024,4194304,41272,32768,8192,56,65552,07e316e8e83163f0,21405.203125,4096.0
+0,16,1024,uniform,4,22,21167687,5632,3014264,164152,131072,32768,56,4112,cc440e349b9b5a57,3758.4671519886365,535.203125
+0,16,256,uniform,4,110,17970005,28160,3722840,41272,32768,8192,56,4112,07e316e8e83163f0,638.1393821022727,132.203125
+0,16,1024,tail,16,708,15733117,181248,2899968,139576,131072,8192,56,4112,cc440e349b9b5a57,86.80436197916667,16.0
+0,16,256,roots,16,6,25329389,1536,6291456,35128,32768,2048,56,65552,07e316e8e83163f0,16490.487630208332,4096.0
+0,16,1024,dense,64,2,55407347,512,7682176,133432,131072,2048,56,524304,cc440e349b9b5a57,108217.474609375,15004.25
+0,16,1024,tail,64,384,18079579,98304,6291456,133432,131072,2048,56,4112,cc440e349b9b5a57,183.91498819986978,64.0
+0,16,1024,dense,16,2,57109105,512,7506624,139576,131072,8192,56,524304,cc440e349b9b5a57,111541.220703125,14661.375
+0,16,256,uniform,1,130,19115671,33280,4352140,65848,32768,32768,56,4112,07e316e8e83163f0,574.3891526442308,130.7734375
+0,16,256,uniform,16,130,18864226,33280,4590560,35128,32768,2048,56,4112,07e316e8e83163f0,566.8337139423077,137.9375
+0,16,256,dense,1,4,26646406,1024,3729584,65848,32768,32768,56,524304,07e316e8e83163f0,26021.880859375,3642.171875
+0,16,1024,dense,1024,2,60125695,512,8388608,131512,131072,128,56,524304,cc440e349b9b5a57,117432.998046875,16384.0
+0,16,256,tail,4,870,15279896,222720,1332840,41272,32768,8192,56,4112,07e316e8e83163f0,68.60585488505747,5.984375
+0,16,256,tail,64,384,18427282,98304,6291456,33592,32768,512,56,4112,07e316e8e83163f0,187.4520060221354,64.0
+0,16,256,tail,256,86,19077985,22016,5636096,33208,32768,128,56,4112,07e316e8e83163f0,866.5509175145348,256.0
+0,16,256,uniform,64,124,19114097,31744,5150464,33592,32768,512,56,4112,07e316e8e83163f0,602.1325919858871,162.25
+0,16,256,dense,16,4,27271257,1024,3842048,35128,32768,2048,56,524304,07e316e8e83163f0,26632.0869140625,3752.0
+0,16,1024,dense,1,2,56247180,512,7446690,262456,131072,131072,56,524304,cc440e349b9b5a57,109857.7734375,14544.31640625
+0,16,1024,tail,1024,14,22547316,3584,3670016,131512,131072,128,56,4112,cc440e349b9b5a57,6291.103794642857,1024.0
+0,16,256,roots,64,6,24836741,1536,6291456,33592,32768,512,56,65552,07e316e8e83163f0,16169.753255208334,4096.0
+1,16,256,tail,16,730,15723896,186880,2990080,35128,32768,2048,56,4112,07e316e8e83163f0,84.13899828767123,16.0
+1,16,1024,roots,64,2,53830403,512,8388608,133432,131072,2048,56,65552,cc440e349b9b5a57,105137.505859375,16384.0
+1,16,256,uniform,64,124,19164986,31744,5150464,33592,32768,512,56,4112,07e316e8e83163f0,603.7356980846774,162.25
+1,16,1024,roots,16,2,57857808,512,8388608,139576,131072,8192,56,65552,cc440e349b9b5a57,113003.53125,16384.0
+1,16,256,tail,256,86,18910930,22016,5636096,33208,32768,128,56,4112,07e316e8e83163f0,858.9630268895348,256.0
+1,16,256,uniform,1,130,19119244,33280,4352140,65848,32768,32768,56,4112,07e316e8e83163f0,574.496514423077,130.7734375
+1,16,256,uniform,256,74,19320449,18944,4849664,33208,32768,128,56,4112,07e316e8e83163f0,1019.8716744087837,256.0
+1,16,256,dense,64,4,27044701,1024,4080128,33592,32768,512,56,524304,07e316e8e83163f0,26410.8408203125,3984.5
+1,16,1024,tail,4,834,14780378,213504,1277688,164152,131072,32768,56,4112,cc440e349b9b5a57,69.22763976318944,5.984375
+1,16,1024,tail,1,912,15955191,233472,1063392,262456,131072,131072,56,4112,cc440e349b9b5a57,68.33877724095395,4.5546875
+1,16,256,dense,256,4,27838608,1024,4194304,33208,32768,128,56,524304,07e316e8e83163f0,27186.140625,4096.0
+1,16,256,uniform,4,110,18108468,28160,3722840,41272,32768,8192,56,4112,07e316e8e83163f0,643.0563920454546,132.203125
+1,16,1024,uniform,64,24,20199430,6144,3472896,133432,131072,2048,56,4112,cc440e349b9b5a57,3287.6676432291665,565.25
+1,16,256,tail,4,870,15577488,222720,1332840,41272,32768,8192,56,4112,07e316e8e83163f0,69.94202586206896,5.984375
+1,16,1024,dense,4,2,63503118,512,7458720,164152,131072,32768,56,524304,cc440e349b9b5a57,124029.52734375,14567.8125
+1,16,1024,roots,1,2,60590399,512,8388608,262456,131072,131072,56,65552,cc440e349b9b5a57,118340.623046875,16384.0
+1,16,1024,dense,16,2,58815196,512,7506624,139576,131072,8192,56,524304,cc440e349b9b5a57,114873.4296875,14661.375
+1,16,1024,uniform,1,24,20999687,6144,3279504,262456,131072,131072,56,4112,cc440e349b9b5a57,3417.9178059895835,533.7734375
+1,16,1024,dense,64,2,55368532,512,7682176,133432,131072,2048,56,524304,cc440e349b9b5a57,108141.6640625,15004.25
+1,16,256,roots,64,6,25027166,1536,6291456,33592,32768,512,56,65552,07e316e8e83163f0,16293.727864583334,4096.0
+1,16,256,dense,4,4,28726459,1024,3753408,41272,32768,8192,56,524304,07e316e8e83163f0,28053.1826171875,3665.4375
+1,16,1024,dense,1024,2,59377529,512,8388608,131512,131072,128,56,524304,cc440e349b9b5a57,115971.736328125,16384.0
+1,16,1024,uniform,1024,14,22664872,3584,3670016,131512,131072,128,56,4112,cc440e349b9b5a57,6323.904017857143,1024.0
+1,16,1024,tail,16,708,16137451,181248,2899968,139576,131072,8192,56,4112,cc440e349b9b5a57,89.03519487111582,16.0
+1,16,1024,dense,1,2,59209844,512,7446690,262456,131072,131072,56,524304,cc440e349b9b5a57,115644.2265625,14544.31640625
+1,16,1024,tail,1024,14,28440553,3584,3670016,131512,131072,128,56,4112,cc440e349b9b5a57,7935.422154017857,1024.0
+1,16,1024,uniform,16,24,22939408,6144,3323520,139576,131072,8192,56,4112,cc440e349b9b5a57,3733.6276041666665,540.9375
+1,16,1024,roots,4,2,68243319,512,8388608,164152,131072,32768,56,65552,cc440e349b9b5a57,133287.732421875,16384.0
+1,16,1024,uniform,4,22,22284502,5632,3014264,164152,131072,32768,56,4112,cc440e349b9b5a57,3956.7652698863635,535.203125
+1,16,1024,tail,64,384,19017726,98304,6291456,133432,131072,2048,56,4112,cc440e349b9b5a57,193.45831298828125,64.0
+1,16,1024,roots,1024,2,54456218,512,8388608,131512,131072,128,56,65552,cc440e349b9b5a57,106359.80078125,16384.0
+1,16,256,roots,1,6,29430274,1536,6291456,65848,32768,32768,56,65552,07e316e8e83163f0,19160.334635416668,4096.0
+1,16,256,tail,1,968,16229803,247808,1128688,65848,32768,32768,56,4112,07e316e8e83163f0,65.4934586454029,4.5546875
+1,16,256,uniform,16,130,18842745,33280,4590560,35128,32768,2048,56,4112,07e316e8e83163f0,566.1882512019231,137.9375
+1,16,256,roots,256,6,25712943,1536,6291456,33208,32768,128,56,65552,07e316e8e83163f0,16740.197265625,4096.0
+1,16,256,roots,16,6,24999092,1536,6291456,35128,32768,2048,56,65552,07e316e8e83163f0,16275.450520833334,4096.0
+1,16,256,tail,64,384,18145560,98304,6291456,33592,32768,512,56,4112,07e316e8e83163f0,184.586181640625,64.0
+1,16,256,roots,4,4,21467262,1024,4194304,41272,32768,8192,56,65552,07e316e8e83163f0,20964.123046875,4096.0
+1,16,256,dense,1,4,26614572,1024,3729584,65848,32768,32768,56,524304,07e316e8e83163f0,25990.79296875,3642.171875
+1,16,256,dense,16,4,27211406,1024,3842048,35128,32768,2048,56,524304,07e316e8e83163f0,26573.638671875,3752.0
+2,16,1024,dense,64,2,55177792,512,7682176,133432,131072,2048,56,524304,cc440e349b9b5a57,107769.125,15004.25
+2,16,1024,roots,1024,2,56337550,512,8388608,131512,131072,128,56,65552,cc440e349b9b5a57,110034.27734375,16384.0
+2,16,256,uniform,256,74,19340633,18944,4849664,33208,32768,128,56,4112,07e316e8e83163f0,1020.9371304898649,256.0
+2,16,1024,roots,4,2,70127632,512,8388608,164152,131072,32768,56,65552,cc440e349b9b5a57,136968.03125,16384.0
+2,16,256,uniform,16,130,18852485,33280,4590560,35128,32768,2048,56,4112,07e316e8e83163f0,566.4809194711538,137.9375
+2,16,256,uniform,64,124,19214726,31744,5150464,33592,32768,512,56,4112,07e316e8e83163f0,605.3026083669355,162.25
+2,16,256,dense,4,4,29007978,1024,3753408,41272,32768,8192,56,524304,07e316e8e83163f0,28328.103515625,3665.4375
+2,16,1024,roots,64,2,55147181,512,8388608,133432,131072,2048,56,65552,cc440e349b9b5a57,107709.337890625,16384.0
+2,16,1024,uniform,16,24,20757910,6144,3323520,139576,131072,8192,56,4112,cc440e349b9b5a57,3378.5660807291665,540.9375
+2,16,256,roots,16,6,24347186,1536,6291456,35128,32768,2048,56,65552,07e316e8e83163f0,15851.032552083334,4096.0
+2,16,1024,uniform,1024,14,23230334,3584,3670016,131512,131072,128,56,4112,cc440e349b9b5a57,6481.678013392857,1024.0
+2,16,1024,dense,1024,2,59534306,512,8388608,131512,131072,128,56,524304,cc440e349b9b5a57,116277.94140625,16384.0
+2,16,1024,uniform,1,24,20842391,6144,3279504,262456,131072,131072,56,4112,cc440e349b9b5a57,3392.3162434895835,533.7734375
+2,16,256,uniform,1,130,19198967,33280,4352140,65848,32768,32768,56,4112,07e316e8e83163f0,576.8920372596153,130.7734375
+2,16,256,uniform,4,110,17994653,28160,3722840,41272,32768,8192,56,4112,07e316e8e83163f0,639.0146661931818,132.203125
+2,16,256,dense,64,4,27086276,1024,4080128,33592,32768,512,56,524304,07e316e8e83163f0,26451.44140625,3984.5
+2,16,256,roots,4,4,21994113,1024,4194304,41272,32768,8192,56,65552,07e316e8e83163f0,21478.6259765625,4096.0
+2,16,1024,roots,16,2,57820049,512,8388608,139576,131072,8192,56,65552,cc440e349b9b5a57,112929.783203125,16384.0
+2,16,256,dense,256,4,27941793,1024,4194304,33208,32768,128,56,524304,07e316e8e83163f0,27286.9072265625,4096.0
+2,16,1024,tail,16,708,16133895,181248,2899968,139576,131072,8192,56,4112,cc440e349b9b5a57,89.01557534427967,16.0
+2,16,1024,tail,64,384,18182820,98304,6291456,133432,131072,2048,56,4112,cc440e349b9b5a57,184.9652099609375,64.0
+2,16,256,tail,256,86,18779634,22016,5636096,33208,32768,128,56,4112,07e316e8e83163f0,852.9993640988372,256.0
+2,16,256,roots,256,6,22007890,1536,6291456,33208,32768,128,56,65552,07e316e8e83163f0,14328.053385416666,4096.0
+2,16,1024,tail,1024,14,22562372,3584,3670016,131512,131072,128,56,4112,cc440e349b9b5a57,6295.3046875,1024.0
+2,16,1024,tail,1,912,15219507,233472,1063392,262456,131072,131072,56,4112,cc440e349b9b5a57,65.18771844161184,4.5546875
+2,16,256,tail,1,968,16217302,247808,1128688,65848,32768,32768,56,4112,07e316e8e83163f0,65.4430123321281,4.5546875
+2,16,256,tail,16,730,15889117,186880,2990080,35128,32768,2048,56,4112,07e316e8e83163f0,85.02310038527398,16.0
+2,16,256,roots,64,6,24043260,1536,6291456,33592,32768,512,56,65552,07e316e8e83163f0,15653.1640625,4096.0
+2,16,256,tail,64,384,18128542,98304,6291456,33592,32768,512,56,4112,07e316e8e83163f0,184.4130655924479,64.0
+2,16,256,roots,1,6,28856219,1536,6291456,65848,32768,32768,56,65552,07e316e8e83163f0,18786.600911458332,4096.0
+2,16,256,dense,1,4,26688073,1024,3729584,65848,32768,32768,56,524304,07e316e8e83163f0,26062.5712890625,3642.171875
+2,16,1024,roots,1,2,59012937,512,8388608,262456,131072,131072,56,65552,cc440e349b9b5a57,115259.642578125,16384.0
+2,16,1024,tail,4,834,15146304,213504,1277688,164152,131072,32768,56,4112,cc440e349b9b5a57,70.94154676258992,5.984375
+2,16,1024,uniform,4,22,21112966,5632,3014264,164152,131072,32768,56,4112,cc440e349b9b5a57,3748.751065340909,535.203125
+2,16,1024,uniform,64,24,20180244,6144,3472896,133432,131072,2048,56,4112,cc440e349b9b5a57,3284.544921875,565.25
+2,16,256,dense,16,4,27251979,1024,3842048,35128,32768,2048,56,524304,07e316e8e83163f0,26613.2607421875,3752.0
+2,16,1024,dense,1,2,56115124,512,7446690,262456,131072,131072,56,524304,cc440e349b9b5a57,109599.8515625,14544.31640625
+2,16,256,tail,4,870,15574118,222720,1332840,41272,32768,8192,56,4112,07e316e8e83163f0,69.92689475574713,5.984375
+2,16,1024,dense,4,2,63355452,512,7458720,164152,131072,32768,56,524304,cc440e349b9b5a57,123741.1171875,14567.8125
+2,16,1024,dense,16,2,59015622,512,7506624,139576,131072,8192,56,524304,cc440e349b9b5a57,115264.88671875,14661.375
+3,16,1024,dense,1024,2,59351733,512,8388608,131512,131072,128,56,524304,cc440e349b9b5a57,115921.353515625,16384.0
+3,16,256,tail,64,384,18358098,98304,6291456,33592,32768,512,56,4112,07e316e8e83163f0,186.74822998046875,64.0
+3,16,256,tail,256,86,18854430,22016,5636096,33208,32768,128,56,4112,07e316e8e83163f0,856.3967114825581,256.0
+3,16,1024,tail,4,834,14976119,213504,1277688,164152,131072,32768,56,4112,cc440e349b9b5a57,70.14444225869305,5.984375
+3,16,1024,uniform,1024,14,22676798,3584,3670016,131512,131072,128,56,4112,cc440e349b9b5a57,6327.231584821428,1024.0
+3,16,1024,tail,1024,14,22703465,3584,3670016,131512,131072,128,56,4112,cc440e349b9b5a57,6334.672154017857,1024.0
+3,16,256,dense,64,4,27086110,1024,4080128,33592,32768,512,56,524304,07e316e8e83163f0,26451.279296875,3984.5
+3,16,256,roots,256,6,25762944,1536,6291456,33208,32768,128,56,65552,07e316e8e83163f0,16772.75,4096.0
+3,16,256,uniform,1,130,19111541,33280,4352140,65848,32768,32768,56,4112,07e316e8e83163f0,574.2650540865385,130.7734375
+3,16,1024,roots,4,2,70026373,512,8388608,164152,131072,32768,56,65552,cc440e349b9b5a57,136770.259765625,16384.0
+3,16,1024,tail,1,912,16096766,233472,1063392,262456,131072,131072,56,4112,cc440e349b9b5a57,68.94516687225877,4.5546875
+3,16,256,dense,16,4,27379350,1024,3842048,35128,32768,2048,56,524304,07e316e8e83163f0,26737.646484375,3752.0
+3,16,256,roots,16,6,24957185,1536,6291456,35128,32768,2048,56,65552,07e316e8e83163f0,16248.167317708334,4096.0
+3,16,256,tail,16,730,15562896,186880,2990080,35128,32768,2048,56,4112,07e316e8e83163f0,83.27748287671233,16.0
+3,16,256,roots,1,6,28879071,1536,6291456,65848,32768,32768,56,65552,07e316e8e83163f0,18801.478515625,4096.0
+3,16,256,dense,256,4,27899146,1024,4194304,33208,32768,128,56,524304,07e316e8e83163f0,27245.259765625,4096.0
+3,16,1024,uniform,16,24,20733021,6144,3323520,139576,131072,8192,56,4112,cc440e349b9b5a57,3374.51513671875,540.9375
+3,16,1024,roots,16,2,58642974,512,8388608,139576,131072,8192,56,65552,cc440e349b9b5a57,114537.05859375,16384.0
+3,16,256,roots,4,4,21769853,1024,4194304,41272,32768,8192,56,65552,07e316e8e83163f0,21259.6220703125,4096.0
+3,16,1024,dense,4,2,63265711,512,7458720,164152,131072,32768,56,524304,cc440e349b9b5a57,123565.841796875,14567.8125
+3,16,256,uniform,4,110,17831783,28160,3722840,41272,32768,8192,56,4112,07e316e8e83163f0,633.2309303977273,132.203125
+3,16,1024,roots,1,2,59387770,512,8388608,262456,131072,131072,56,65552,cc440e349b9b5a57,115991.73828125,16384.0
+3,16,256,dense,1,4,26625294,1024,3729584,65848,32768,32768,56,524304,07e316e8e83163f0,26001.263671875,3642.171875
+3,16,256,uniform,64,124,19081356,31744,5150464,33592,32768,512,56,4112,07e316e8e83163f0,601.1011844758065,162.25
+3,16,1024,roots,64,2,54379514,512,8388608,133432,131072,2048,56,65552,cc440e349b9b5a57,106209.98828125,16384.0
+3,16,256,roots,64,6,23421927,1536,6291456,33592,32768,512,56,65552,07e316e8e83163f0,15248.650390625,4096.0
+3,16,1024,tail,64,384,18163616,98304,6291456,133432,131072,2048,56,4112,cc440e349b9b5a57,184.76985677083334,64.0
+3,16,256,uniform,256,74,19326707,18944,4849664,33208,32768,128,56,4112,07e316e8e83163f0,1020.2020164695946,256.0
+3,16,256,tail,1,968,16443302,247808,1128688,65848,32768,32768,56,4112,07e316e8e83163f0,66.35500871642562,4.5546875
+3,16,256,uniform,16,130,18945597,33280,4590560,35128,32768,2048,56,4112,07e316e8e83163f0,569.2787560096153,137.9375
+3,16,256,tail,4,870,15606951,222720,1332840,41272,32768,8192,56,4112,07e316e8e83163f0,70.07431303879311,5.984375
+3,16,1024,uniform,4,22,21160558,5632,3014264,164152,131072,32768,56,4112,cc440e349b9b5a57,3757.201349431818,535.203125
+3,16,1024,tail,16,708,16127914,181248,2899968,139576,131072,8192,56,4112,cc440e349b9b5a57,88.98257635946328,16.0
+3,16,1024,dense,1,2,56464457,512,7446690,262456,131072,131072,56,524304,cc440e349b9b5a57,110282.142578125,14544.31640625
+3,16,1024,dense,16,2,58168790,512,7506624,139576,131072,8192,56,524304,cc440e349b9b5a57,113610.91796875,14661.375
+3,16,1024,uniform,1,24,21266872,6144,3279504,262456,131072,131072,56,4112,cc440e349b9b5a57,3461.4049479166665,533.7734375
+3,16,1024,uniform,64,24,20355706,6144,3472896,133432,131072,2048,56,4112,cc440e349b9b5a57,3313.1031901041665,565.25
+3,16,1024,roots,1024,2,55149236,512,8388608,131512,131072,128,56,65552,cc440e349b9b5a57,107713.3515625,16384.0
+3,16,256,dense,4,4,28735811,1024,3753408,41272,32768,8192,56,524304,07e316e8e83163f0,28062.3154296875,3665.4375
+3,16,1024,dense,64,2,55532161,512,7682176,133432,131072,2048,56,524304,cc440e349b9b5a57,108461.251953125,15004.25
+4,16,1024,roots,16,2,58275974,512,8388608,139576,131072,8192,56,65552,cc440e349b9b5a57,113820.26171875,16384.0
+4,16,1024,uniform,1,24,20898336,6144,3279504,262456,131072,131072,56,4112,cc440e349b9b5a57,3401.421875,533.7734375
+4,16,1024,tail,4,834,14866877,213504,1277688,164152,131072,32768,56,4112,cc440e349b9b5a57,69.63277971372902,5.984375
+4,16,1024,tail,16,708,16058932,181248,2899968,139576,131072,8192,56,4112,cc440e349b9b5a57,88.60198181497175,16.0
+4,16,1024,roots,64,2,54187366,512,8388608,133432,131072,2048,56,65552,cc440e349b9b5a57,105834.69921875,16384.0
+4,16,256,uniform,4,110,18060098,28160,3722840,41272,32768,8192,56,4112,07e316e8e83163f0,641.3387073863636,132.203125
+4,16,1024,uniform,4,22,21147503,5632,3014264,164152,131072,32768,56,4112,cc440e349b9b5a57,3754.8833451704545,535.203125
+4,16,256,roots,64,6,24374259,1536,6291456,33592,32768,512,56,65552,07e316e8e83163f0,15868.658203125,4096.0
+4,16,1024,dense,4,2,63382933,512,7458720,164152,131072,32768,56,524304,cc440e349b9b5a57,123794.791015625,14567.8125
+4,16,256,dense,64,4,27028257,1024,4080128,33592,32768,512,56,524304,07e316e8e83163f0,26394.7822265625,3984.5
+4,16,1024,tail,64,384,18112820,98304,6291456,133432,131072,2048,56,4112,cc440e349b9b5a57,184.25313313802084,64.0
+4,16,1024,uniform,1024,14,22717760,3584,3670016,131512,131072,128,56,4112,cc440e349b9b5a57,6338.660714285715,1024.0
+4,16,1024,dense,1,2,56368123,512,7446690,262456,131072,131072,56,524304,cc440e349b9b5a57,110093.990234375,14544.31640625
+4,16,256,dense,16,4,27298090,1024,3842048,35128,32768,2048,56,524304,07e316e8e83163f0,26658.291015625,3752.0
+4,16,256,tail,256,86,18729560,22016,5636096,33208,32768,128,56,4112,07e316e8e83163f0,850.7249273255813,256.0
+4,16,256,tail,4,870,15490173,222720,1332840,41272,32768,8192,56,4112,07e316e8e83163f0,69.54998653017242,5.984375
+4,16,1024,dense,1024,2,59373955,512,8388608,131512,131072,128,56,524304,cc440e349b9b5a57,115964.755859375,16384.0
+4,16,256,uniform,64,124,19073782,31744,5150464,33592,32768,512,56,4112,07e316e8e83163f0,600.8625882056451,162.25
+4,16,256,roots,16,6,25373629,1536,6291456,35128,32768,2048,56,65552,07e316e8e83163f0,16519.289713541668,4096.0
+4,16,1024,uniform,64,24,20210356,6144,3472896,133432,131072,2048,56,4112,cc440e349b9b5a57,3289.4459635416665,565.25
+4,16,256,uniform,256,74,19265226,18944,4849664,33208,32768,128,56,4112,07e316e8e83163f0,1016.9566089527027,256.0
+4,16,1024,uniform,16,24,20671781,6144,3323520,139576,131072,8192,56,4112,cc440e349b9b5a57,3364.5476888020835,540.9375
+4,16,1024,roots,1024,2,54991477,512,8388608,131512,131072,128,56,65552,cc440e349b9b5a57,107405.228515625,16384.0
+4,16,256,dense,1,4,26646128,1024,3729584,65848,32768,32768,56,524304,07e316e8e83163f0,26021.609375,3642.171875
+4,16,256,roots,1,6,27778090,1536,6291456,65848,32768,32768,56,65552,07e316e8e83163f0,18084.694010416668,4096.0
+4,16,256,tail,16,730,15578766,186880,2990080,35128,32768,2048,56,4112,07e316e8e83163f0,83.36240368150685,16.0
+4,16,1024,tail,1024,14,22511631,3584,3670016,131512,131072,128,56,4112,cc440e349b9b5a57,6281.147042410715,1024.0
+4,16,256,dense,256,4,27817794,1024,4194304,33208,32768,128,56,524304,07e316e8e83163f0,27165.814453125,4096.0
+4,16,256,roots,256,6,23618612,1536,6291456,33208,32768,128,56,65552,07e316e8e83163f0,15376.700520833334,4096.0
+4,16,1024,tail,1,912,15076693,233472,1063392,262456,131072,131072,56,4112,cc440e349b9b5a57,64.57602196408992,4.5546875
+4,16,256,dense,4,4,28763201,1024,3753408,41272,32768,8192,56,524304,07e316e8e83163f0,28089.0634765625,3665.4375
+4,16,256,uniform,16,130,18825430,33280,4590560,35128,32768,2048,56,4112,07e316e8e83163f0,565.66796875,137.9375
+4,16,256,uniform,1,130,19054708,33280,4352140,65848,32768,32768,56,4112,07e316e8e83163f0,572.5573317307692,130.7734375
+4,16,256,tail,1,968,16474654,247808,1128688,65848,32768,32768,56,4112,07e316e8e83163f0,66.48152602014463,4.5546875
+4,16,256,roots,4,4,21753002,1024,4194304,41272,32768,8192,56,65552,07e316e8e83163f0,21243.166015625,4096.0
+4,16,1024,roots,4,2,65107229,512,8388608,164152,131072,32768,56,65552,cc440e349b9b5a57,127162.556640625,16384.0
+4,16,1024,roots,1,2,59380214,512,8388608,262456,131072,131072,56,65552,cc440e349b9b5a57,115976.98046875,16384.0
+4,16,1024,dense,64,2,55434866,512,7682176,133432,131072,2048,56,524304,cc440e349b9b5a57,108271.22265625,15004.25
+4,16,1024,dense,16,2,58074048,512,7506624,139576,131072,8192,56,524304,cc440e349b9b5a57,113425.875,14661.375
+4,16,256,tail,64,384,18460486,98304,6291456,33592,32768,512,56,4112,07e316e8e83163f0,187.7897745768229,64.0
+5,16,256,uniform,64,124,19329263,31744,5150464,33592,32768,512,56,4112,07e316e8e83163f0,608.9107547883065,162.25
+5,16,1024,roots,16,2,57375679,512,8388608,139576,131072,8192,56,65552,cc440e349b9b5a57,112061.873046875,16384.0
+5,16,1024,tail,1024,14,22579761,3584,3670016,131512,131072,128,56,4112,cc440e349b9b5a57,6300.156529017857,1024.0
+5,16,1024,tail,4,834,14960082,213504,1277688,164152,131072,32768,56,4112,cc440e349b9b5a57,70.0693289118705,5.984375
+5,16,256,tail,1,968,16278580,247808,1128688,65848,32768,32768,56,4112,07e316e8e83163f0,65.69029248450413,4.5546875
+5,16,1024,dense,16,2,57445975,512,7506624,139576,131072,8192,56,524304,cc440e349b9b5a57,112199.169921875,14661.375
+5,16,1024,tail,64,384,18213134,98304,6291456,133432,131072,2048,56,4112,cc440e349b9b5a57,185.2735799153646,64.0
+5,16,256,roots,1,6,27856293,1536,6291456,65848,32768,32768,56,65552,07e316e8e83163f0,18135.607421875,4096.0
+5,16,256,dense,64,4,27057813,1024,4080128,33592,32768,512,56,524304,07e316e8e83163f0,26423.6455078125,3984.5
+5,16,256,dense,1,4,26671387,1024,3729584,65848,32768,32768,56,524304,07e316e8e83163f0,26046.2763671875,3642.171875
+5,16,256,uniform,16,130,18836911,33280,4590560,35128,32768,2048,56,4112,07e316e8e83163f0,566.0129507211539,137.9375
+5,16,1024,uniform,1,24,20823781,6144,3279504,262456,131072,131072,56,4112,cc440e349b9b5a57,3389.2872721354165,533.7734375
+5,16,256,tail,4,870,15190562,222720,1332840,41272,32768,8192,56,4112,07e316e8e83163f0,68.2047503591954,5.984375
+5,16,1024,tail,1,912,15649600,233472,1063392,262456,131072,131072,56,4112,cc440e349b9b5a57,67.02987938596492,4.5546875
+5,16,256,roots,256,6,24620815,1536,6291456,33208,32768,128,56,65552,07e316e8e83163f0,16029.176432291666,4096.0
+5,16,1024,dense,4,2,63311137,512,7458720,164152,131072,32768,56,524304,cc440e349b9b5a57,123654.564453125,14567.8125
+5,16,1024,uniform,4,22,21326706,5632,3014264,164152,131072,32768,56,4112,cc440e349b9b5a57,3786.702059659091,535.203125
+5,16,256,tail,256,86,19151578,22016,5636096,33208,32768,128,56,4112,07e316e8e83163f0,869.8936228197674,256.0
+5,16,256,roots,4,4,22301428,1024,4194304,41272,32768,8192,56,65552,07e316e8e83163f0,21778.73828125,4096.0
+5,16,256,dense,4,4,29056293,1024,3753408,41272,32768,8192,56,524304,07e316e8e83163f0,28375.2861328125,3665.4375
+5,16,256,uniform,256,74,19565633,18944,4849664,33208,32768,128,56,4112,07e316e8e83163f0,1032.8142419763512,256.0
+5,16,256,uniform,4,110,18057894,28160,3722840,41272,32768,8192,56,4112,07e316e8e83163f0,641.2604403409091,132.203125
+5,16,1024,dense,1024,2,60140195,512,8388608,131512,131072,128,56,524304,cc440e349b9b5a57,117461.318359375,16384.0
+5,16,1024,tail,16,708,16254099,181248,2899968,139576,131072,8192,56,4112,cc440e349b9b5a57,89.67877714512711,16.0
+5,16,1024,dense,1,2,56663290,512,7446690,262456,131072,131072,56,524304,cc440e349b9b5a57,110670.48828125,14544.31640625
+5,16,256,dense,256,4,27836682,1024,4194304,33208,32768,128,56,524304,07e316e8e83163f0,27184.259765625,4096.0
+5,16,256,uniform,1,130,19151874,33280,4352140,65848,32768,32768,56,4112,07e316e8e83163f0,575.476983173077,130.7734375
+5,16,256,dense,16,4,27268739,1024,3842048,35128,32768,2048,56,524304,07e316e8e83163f0,26629.6279296875,3752.0
+5,16,1024,roots,1024,2,55194940,512,8388608,131512,131072,128,56,65552,cc440e349b9b5a57,107802.6171875,16384.0
+5,16,256,roots,64,6,24760574,1536,6291456,33592,32768,512,56,65552,07e316e8e83163f0,16120.165364583334,4096.0
+5,16,1024,uniform,16,24,20702411,6144,3323520,139576,131072,8192,56,4112,cc440e349b9b5a57,3369.5330403645835,540.9375
+5,16,256,tail,16,730,15642655,186880,2990080,35128,32768,2048,56,4112,07e316e8e83163f0,83.70427547089041,16.0
+5,16,1024,roots,1,2,58483900,512,8388608,262456,131072,131072,56,65552,cc440e349b9b5a57,114226.3671875,16384.0
+5,16,1024,roots,64,2,54285033,512,8388608,133432,131072,2048,56,65552,cc440e349b9b5a57,106025.455078125,16384.0
+5,16,256,tail,64,384,18131930,98304,6291456,33592,32768,512,56,4112,07e316e8e83163f0,184.4475301106771,64.0
+5,16,1024,uniform,1024,14,22782001,3584,3670016,131512,131072,128,56,4112,cc440e349b9b5a57,6356.585100446428,1024.0
+5,16,1024,roots,4,2,70559817,512,8388608,164152,131072,32768,56,65552,cc440e349b9b5a57,137812.142578125,16384.0
+5,16,1024,uniform,64,24,20210762,6144,3472896,133432,131072,2048,56,4112,cc440e349b9b5a57,3289.5120442708335,565.25
+5,16,256,roots,16,6,25681295,1536,6291456,35128,32768,2048,56,65552,07e316e8e83163f0,16719.593098958332,4096.0
+5,16,1024,dense,64,2,55456236,512,7682176,133432,131072,2048,56,524304,cc440e349b9b5a57,108312.9609375,15004.25
+6,16,1024,roots,1024,2,54870791,512,8388608,131512,131072,128,56,65552,cc440e349b9b5a57,107169.513671875,16384.0
+6,16,1024,uniform,16,24,20742114,6144,3323520,139576,131072,8192,56,4112,cc440e349b9b5a57,3375.9951171875,540.9375
+6,16,256,tail,16,730,15687340,186880,2990080,35128,32768,2048,56,4112,07e316e8e83163f0,83.94338613013699,16.0
+6,16,1024,dense,1024,2,59332807,512,8388608,131512,131072,128,56,524304,cc440e349b9b5a57,115884.388671875,16384.0
+6,16,1024,uniform,64,24,20222374,6144,3472896,133432,131072,2048,56,4112,cc440e349b9b5a57,3291.4020182291665,565.25
+6,16,1024,roots,1,2,58901437,512,8388608,262456,131072,131072,56,65552,cc440e349b9b5a57,115041.869140625,16384.0
+6,16,1024,tail,64,384,18025357,98304,6291456,133432,131072,2048,56,4112,cc440e349b9b5a57,183.36341349283853,64.0
+6,16,256,roots,256,6,25008240,1536,6291456,33208,32768,128,56,65552,07e316e8e83163f0,16281.40625,4096.0
+6,16,1024,dense,4,2,63551748,512,7458720,164152,131072,32768,56,524304,cc440e349b9b5a57,124124.5078125,14567.8125
+6,16,1024,roots,64,2,56267698,512,8388608,133432,131072,2048,56,65552,cc440e349b9b5a57,109897.84765625,16384.0
+6,16,256,tail,256,86,18806949,22016,5636096,33208,32768,128,56,4112,07e316e8e83163f0,854.2400526889535,256.0
+6,16,1024,roots,4,2,68814522,512,8388608,164152,131072,32768,56,65552,cc440e349b9b5a57,134403.36328125,16384.0
+6,16,256,dense,256,4,27934608,1024,4194304,33208,32768,128,56,524304,07e316e8e83163f0,27279.890625,4096.0
+6,16,256,tail,4,870,15578303,222720,1332840,41272,32768,8192,56,4112,07e316e8e83163f0,69.94568516522989,5.984375
+6,16,256,dense,4,4,28803219,1024,3753408,41272,32768,8192,56,524304,07e316e8e83163f0,28128.1435546875,3665.4375
+6,16,1024,uniform,4,22,21089521,5632,3014264,164152,131072,32768,56,4112,cc440e349b9b5a57,3744.5882457386365,535.203125
+6,16,1024,tail,4,834,14739063,213504,1277688,164152,131072,32768,56,4112,cc440e349b9b5a57,69.03413050809353,5.984375
+6,16,1024,uniform,1,24,20910965,6144,3279504,262456,131072,131072,56,4112,cc440e349b9b5a57,3403.4773763020835,533.7734375
+6,16,256,roots,4,4,22458464,1024,4194304,41272,32768,8192,56,65552,07e316e8e83163f0,21932.09375,4096.0
+6,16,1024,dense,1,2,56255976,512,7446690,262456,131072,131072,56,524304,cc440e349b9b5a57,109874.953125,14544.31640625
+6,16,256,tail,64,384,18071820,98304,6291456,33592,32768,512,56,4112,07e316e8e83163f0,183.8360595703125,64.0
+6,16,256,tail,1,968,15814117,247808,1128688,65848,32768,32768,56,4112,07e316e8e83163f0,63.81600674715909,4.5546875
+6,16,1024,roots,16,2,57245493,512,8388608,139576,131072,8192,56,65552,cc440e349b9b5a57,111807.603515625,16384.0
+6,16,1024,dense,16,2,57808882,512,7506624,139576,131072,8192,56,524304,cc440e349b9b5a57,112907.97265625,14661.375
+6,16,256,roots,64,6,25547351,1536,6291456,33592,32768,512,56,65552,07e316e8e83163f0,16632.389973958332,4096.0
+6,16,1024,tail,16,708,15922932,181248,2899968,139576,131072,8192,56,4112,cc440e349b9b5a57,87.85162870762711,16.0
+6,16,256,dense,64,4,27213979,1024,4080128,33592,32768,512,56,524304,07e316e8e83163f0,26576.1513671875,3984.5
+6,16,256,uniform,256,74,19487226,18944,4849664,33208,32768,128,56,4112,07e316e8e83163f0,1028.6753589527027,256.0
+6,16,1024,tail,1,912,16061655,233472,1063392,262456,131072,131072,56,4112,cc440e349b9b5a57,68.79478053042763,4.5546875
+6,16,1024,dense,64,2,55728624,512,7682176,133432,131072,2048,56,524304,cc440e349b9b5a57,108844.96875,15004.25
+6,16,256,uniform,4,110,17905042,28160,3722840,41272,32768,8192,56,4112,07e316e8e83163f0,635.8324573863637,132.203125
+6,16,256,dense,16,4,27274238,1024,3842048,35128,32768,2048,56,524304,07e316e8e83163f0,26634.998046875,3752.0
+6,16,256,uniform,1,130,18982300,33280,4352140,65848,32768,32768,56,4112,07e316e8e83163f0,570.3816105769231,130.7734375
+6,16,256,uniform,64,124,19114171,31744,5150464,33592,32768,512,56,4112,07e316e8e83163f0,602.1349231350806,162.25
+6,16,256,roots,1,6,29285699,1536,6291456,65848,32768,32768,56,65552,07e316e8e83163f0,19066.210286458332,4096.0
+6,16,256,dense,1,4,26745535,1024,3729584,65848,32768,32768,56,524304,07e316e8e83163f0,26118.6865234375,3642.171875
+6,16,256,uniform,16,130,18815023,33280,4590560,35128,32768,2048,56,4112,07e316e8e83163f0,565.3552584134616,137.9375
+6,16,256,roots,16,6,24256649,1536,6291456,35128,32768,2048,56,65552,07e316e8e83163f0,15792.089192708334,4096.0
+6,16,1024,uniform,1024,14,22782186,3584,3670016,131512,131072,128,56,4112,cc440e349b9b5a57,6356.63671875,1024.0
+6,16,1024,tail,1024,14,22543335,3584,3670016,131512,131072,128,56,4112,cc440e349b9b5a57,6289.993024553572,1024.0
diff --git a/research/experiments/001-checkpoint-granularity/results/2026-09-22-linux-aarch64/summary.csv b/research/experiments/001-checkpoint-granularity/results/2026-09-22-linux-aarch64/summary.csv new file mode 100644 index 0000000..861c9d1 --- /dev/null +++ b/research/experiments/001-checkpoint-granularity/results/2026-09-22-linux-aarch64/summary.csv @@ -0,0 +1,41 @@ +chains,length,workload,block,median_ns_per_tick,min_ns_per_tick,max_ns_per_tick,core_owned_bytes,cache_bytes,evaluations_per_tick
+16,256,roots,1,18801.478515625,18084.694010416668,20032.295572916668,65848,32768,4096.0
+16,256,roots,4,21405.203125,20964.123046875,21932.09375,41272,8192,4096.0
+16,256,roots,16,16275.450520833334,15792.089192708334,16719.593098958332,35128,2048,4096.0
+16,256,roots,64,16120.165364583334,15248.650390625,16632.389973958332,33592,512,4096.0
+16,256,roots,256,16029.176432291666,14328.053385416666,16772.75,33208,128,4096.0
+16,256,uniform,1,574.3891526442308,570.3816105769231,576.8920372596153,65848,32768,130.7734375
+16,256,uniform,4,639.0146661931818,633.2309303977273,643.0563920454546,41272,8192,132.203125
+16,256,uniform,16,566.1882512019231,565.3552584134616,569.2787560096153,35128,2048,137.9375
+16,256,uniform,64,602.1349231350806,600.8625882056451,608.9107547883065,33592,512,162.25
+16,256,uniform,256,1020.9371304898649,1016.9566089527027,1032.8142419763512,33208,128,256.0
+16,256,tail,1,65.4934586454029,63.60011783316116,66.48152602014463,65848,32768,4.5546875
+16,256,tail,4,69.92689475574713,68.2047503591954,70.07431303879311,41272,8192,5.984375
+16,256,tail,16,83.94338613013699,83.27748287671233,85.78413420376712,35128,2048,16.0
+16,256,tail,64,184.586181640625,183.8360595703125,187.7897745768229,33592,512,64.0
+16,256,tail,256,856.3967114825581,850.7249273255813,869.8936228197674,33208,128,256.0
+16,256,dense,1,26021.880859375,25990.79296875,26118.6865234375,65848,32768,3642.171875
+16,256,dense,4,28089.0634765625,28053.1826171875,28375.2861328125,41272,8192,3665.4375
+16,256,dense,16,26632.0869140625,26573.638671875,26737.646484375,35128,2048,3752.0
+16,256,dense,64,26451.279296875,26394.7822265625,26613.9482421875,33592,512,3984.5
+16,256,dense,256,27236.0361328125,27165.814453125,27286.9072265625,33208,128,4096.0
+16,1024,roots,1,115259.642578125,114226.3671875,118340.623046875,262456,131072,16384.0
+16,1024,roots,4,136649.09375,127162.556640625,137812.142578125,164152,32768,16384.0
+16,1024,roots,16,112929.783203125,111807.603515625,114537.05859375,139576,8192,16384.0
+16,1024,roots,64,106209.98828125,105137.505859375,109897.84765625,133432,2048,16384.0
+16,1024,roots,1024,107713.3515625,106359.80078125,110034.27734375,131512,128,16384.0
+16,1024,uniform,1,3401.421875,3389.2872721354165,3461.4049479166665,262456,131072,533.7734375
+16,1024,uniform,4,3757.201349431818,3744.5882457386365,3956.7652698863635,164152,32768,535.203125
+16,1024,uniform,16,3374.51513671875,3358.8570963541665,3733.6276041666665,139576,8192,540.9375
+16,1024,uniform,64,3289.5120442708335,3284.544921875,3313.1031901041665,133432,2048,565.25
+16,1024,uniform,1024,6338.660714285715,6323.904017857143,6481.678013392857,131512,128,1024.0
+16,1024,tail,1,67.02987938596492,64.57602196408992,68.94516687225877,262456,131072,4.5546875
+16,1024,tail,4,69.63277971372902,68.53097365857315,70.94154676258992,164152,32768,5.984375
+16,1024,tail,16,88.98257635946328,86.80436197916667,89.67877714512711,139576,8192,16.0
+16,1024,tail,64,184.76985677083334,183.36341349283853,193.45831298828125,133432,2048,64.0
+16,1024,tail,1024,6295.3046875,6281.147042410715,7935.422154017857,131512,128,1024.0
+16,1024,dense,1,110093.990234375,109599.8515625,115644.2265625,262456,131072,14544.31640625
+16,1024,dense,4,123794.791015625,123565.841796875,124339.0625,164152,32768,14567.8125
+16,1024,dense,16,113425.875,111541.220703125,115264.88671875,139576,8192,14661.375
+16,1024,dense,64,108271.22265625,107769.125,108844.96875,133432,2048,15004.25
+16,1024,dense,1024,115971.736328125,115884.388671875,117461.318359375,131512,128,16384.0
diff --git a/research/experiments/001-checkpoint-granularity/run.py b/research/experiments/001-checkpoint-granularity/run.py new file mode 100644 index 0000000..b2d66f2 --- /dev/null +++ b/research/experiments/001-checkpoint-granularity/run.py @@ -0,0 +1,148 @@ +#!/usr/bin/env python3 +"""Build, check, measure, and preserve raw data using only the Python stdlib.""" +import argparse +import csv +import hashlib +import json +import math +import os +from pathlib import Path +import platform +import random +import shlex +import statistics +import subprocess +import tempfile +from datetime import datetime, timezone + + +ROOT = Path(__file__).resolve().parent +SOURCE = ROOT / "benchmark.c" +FLAGS = ["-std=c17", "-O3", "-Wall", "-Wextra", "-Wpedantic", "-Werror"] + + +def command(args): + return subprocess.check_output(args, text=True).strip() + + +def write_csv(path, rows): + with path.open("w", newline="") as f: + writer = csv.DictWriter(f, fieldnames=list(rows[0])) + writer.writeheader() + writer.writerows(rows) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--output", type=Path) + parser.add_argument("--trials", type=int, default=7) + parser.add_argument("--target-ms", type=float, default=20.0) + parser.add_argument("--check-only", action="store_true") + args = parser.parse_args() + if args.trials < 3 or not 1 <= args.target_ms <= 1000: + parser.error("use at least 3 trials and a target from 1 to 1000 ms") + if not args.check_only and args.output is None: + parser.error("--output is required for measurements") + cc = shlex.split(os.environ.get("CC", "cc")) + environment = { + "started_utc": datetime.now(timezone.utc).isoformat(), + "platform": platform.platform(), "machine": platform.machine(), + "compiler": command(cc + ["--version"]), "flags": FLAGS, + "python": platform.python_version(), + "source_sha256": hashlib.sha256(SOURCE.read_bytes()).hexdigest(), + "runner_sha256": hashlib.sha256(Path(__file__).read_bytes()).hexdigest(), + "trials": args.trials, "target_ms": args.target_ms, + "seed": 20260922, "timing": "batch elapsed time / update ticks; not input latency", + "memory": "sizeof engine + requested live array bytes; excludes allocator, harness, code, OS", + "power_control": "not controlled; shared host; preliminary measurements", + } + # One CPU reduces migration noise. This is recorded, not assumed to remove noise. + if hasattr(os, "sched_getaffinity"): + affinity = sorted(os.sched_getaffinity(0)) + environment["original_affinity"] = affinity + os.sched_setaffinity(0, {affinity[0]}) + environment["measurement_affinity"] = sorted(os.sched_getaffinity(0)) + cpuinfo = Path("/proc/cpuinfo") + if cpuinfo.exists(): + allowed = ("model name", "CPU implementer", "CPU architecture", "CPU part", "Model") + environment["cpu_description"] = sorted({ + line for line in cpuinfo.read_text().splitlines() + if line.split(":", 1)[0].strip() in allowed + }) + with tempfile.TemporaryDirectory(prefix="pure-checkpoints-") as tmp: + binary = Path(tmp) / "benchmark" + subprocess.run(cc + FLAGS + [str(SOURCE), "-o", str(binary)], check=True) + environment["release_check"] = json.loads(command([str(binary), "--check"])) + checked = Path(tmp) / "benchmark-checked" + check_flags = ["-std=c17", "-O1", "-g", "-Wall", "-Wextra", "-Wpedantic", "-Werror", + "-fsanitize=address,undefined", "-fno-omit-frame-pointer"] + subprocess.run(cc + check_flags + [str(SOURCE), "-o", str(checked)], check=True) + environment["sanitizer_check"] = json.loads(command([str(checked), "--check"])) + print("Differential checks passed in release and ASan/UBSan builds.", flush=True) + if args.check_only: + print(json.dumps(environment, indent=2)) + return + # Fail before measurements if a previous run would be overwritten. + args.output.mkdir(parents=True, exist_ok=False) + + cases = [] + for chains, length in [(16, 256), (16, 1024)]: + for workload in ["roots", "uniform", "tail", "dense"]: + for block in [1, 4, 16, 64, length]: + cases.append((chains, length, workload, block)) + + def sample(case, replays): + chains, length, workload, block = case + return json.loads(command([str(binary), str(chains), str(length), str(block), + workload, "256", str(replays), str(environment["seed"])])) + + calibration = {} + for case in cases: + pilot = sample(case, 2) + wanted = math.ceil(2 * args.target_ms * 1e6 / max(1, pilot["elapsed_ns"])) + # Even replay counts leave the same final model in every strategy. + calibration[case] = min(2048, max(2, wanted + wanted % 2)) + environment["calibration_replays"] = [ + {"chains": c[0], "length": c[1], "workload": c[2], "block": c[3], "replays": r} + for c, r in calibration.items() + ] + rows = [] + checksums = {} + rng = random.Random(81173) + for trial in range(args.trials): + order = cases.copy() + rng.shuffle(order) + for case in order: + result = sample(case, calibration[case]) + chains, length, workload, block = case + key = (chains, length, workload) + if checksums.setdefault(key, result["checksum"]) != result["checksum"]: + raise RuntimeError(f"cross-strategy output mismatch: {case}") + row = {"trial": trial, "chains": chains, "length": length, + "workload": workload, "block": block, "replays": calibration[case], + **result} + row["ns_per_tick"] = result["elapsed_ns"] / result["ticks"] + row["evaluations_per_tick"] = result["node_evaluations"] / result["ticks"] + rows.append(row) + write_csv(args.output / "raw.csv", rows) + print(f"Completed trial {trial + 1}/{args.trials}.", flush=True) + summary = [] + for case in cases: + chains, length, workload, block = case + group = [r for r in rows if (r["chains"], r["length"], r["workload"], r["block"]) == case] + times = [r["ns_per_tick"] for r in group] + summary.append({"chains": chains, "length": length, "workload": workload, "block": block, + "median_ns_per_tick": statistics.median(times), + "min_ns_per_tick": min(times), "max_ns_per_tick": max(times), + "core_owned_bytes": group[0]["core_owned_bytes"], + "cache_bytes": group[0]["cache_bytes"], + "evaluations_per_tick": group[0]["evaluations_per_tick"]}) + write_csv(args.output / "summary.csv", summary) + environment["completed_utc"] = datetime.now(timezone.utc).isoformat() + environment["binary_bytes"] = binary.stat().st_size + (args.output / "environment.json").write_text(json.dumps(environment, indent=2) + "\n") + print(f"Saved raw data, summary, and environment to {args.output}") + + +if __name__ == "__main__": + main() diff --git a/research/experiments/002-buffer-retention/README.md b/research/experiments/002-buffer-retention/README.md new file mode 100644 index 0000000..d43940d --- /dev/null +++ b/research/experiments/002-buffer-retention/README.md @@ -0,0 +1,165 @@ +# Experiment 002: buffer retention under backpressure + +This is a native C17 comparison apparatus, **not an implementation of the Pure +runtime and not a Sonic, Node.js, or .NET benchmark**. It follows +[research question 006](../../../docs/research/006-problem-landscape.md). + +Question: when a producer selects part of each record and a delayed consumer +retains that selection, what costs remain after applying ordinary copy policies, +bounded queues, pooling, a shared byte budget, and early field projection? + +## Work and observable output + +The CLI reads a sequence of experimental binary frames from stdin. Each frame +has three little-endian uint32 fields: payload byte length, selection offset, +and selection byte length, followed by the complete payload. The output is a +little-endian uint32 selection length followed by the selected bytes. Input order +is preserved. A payload is 1 byte to 8 MiB; a selection is nonempty and in bounds. +The format has no magic, version negotiation, JSON syntax, or production claims. + +The Python generator materializes every byte, with deterministic seed, varying +offsets, and source-size/selection-size distributions. It independently computes +the expected output digest; tests additionally compare bytes against a Python +reference decoder. Every measured run's complete output is checked. Input data is +synthetic, not a production trace. Large temporary fixtures are reproducible from +the saved plan, generator hash, and fixture manifest; they are not checked in. + +All variants read all payload bytes. `project` can discard bytes through a fixed +64 KiB scratch area because this fixture's header supplies the selected range. +That is an intentionally strong existing optimization when a format allows it. +Its results do not establish that arbitrary JSON, compression, or a random-access +document supports the same projection. + +## Variants and allocator + +| Variant | Decision | +|---|---| +| borrow | Keep the complete source buffer until output completes. | +| copy | Copy the selected bytes to an independent buffer, then release the source. | +| threshold2/4/8 | Copy when rounded source capacity / rounded selection capacity is at least 2/4/8. | +| pressure | Copy a smaller selection when current live buffer charges exceed half the usable budget. No future lifetime information. | +| project | Read the selection directly into its output buffer; read and discard the rest through scratch. | +| copy_no_pool | Same copy policy without the reusable buffer cache. | + +`pressure` is a simple candidate online heuristic written in ordinary C. It is +not described as a novel policy or Pure advantage. All thresholds were recorded +before measurement; all results are reported, with no fitted or held-out claim. + +Blocks use power-of-two capacity classes, minimum 64 bytes. Pool-enabled variants +reuse exactly matching classes. At most 16 idle blocks can be cached, consuming +at most one quarter of the total byte budget. Idle blocks are evicted as needed +before admitting another allocation. Pool-disabled runs use the same capacity +rounding so that this comparison isolates reuse rather than size classes. +This small explicit cache is an experimental baseline, not a best-in-class allocator. + +Each record has one owner at a time and there is one FIFO consumer. There is no +fan-out, shared-owner reference counting, persistent result cache, or async device +backend. Copy temporarily needs both source and destination; this overlap is +charged. A budget too small to admit a record returns `budget_too_small` instead +of waiting forever. Existing accepted output may already have been written. + +## Scheduling and budget + +The same single-threaded scheduler serves every policy. A queued output becomes +eligible `hold_us` after enqueue. Consecutive output completions are separated by +at least `service_us`. Ready output takes priority over another input record; +otherwise the producer reads until a queue slot or byte credit is unavailable. +Backpressure then services the oldest queued output, sleeping if needed. + +This uses actual reads, writes, allocations, copies, a monotonic clock, and +`nanosleep`; it is not a simulated memory counter. The consumer delays are +synthetic. A requested 20 us service interval is not a 20 us guarantee; kernel +wakeup granularity and host scheduling affect the realized interval. + +The byte budget includes the engine, queue array, scratch, histogram, pool pointer +array, block headers, active buffers, and cached idle buffers. It bounds requested +storage owned by the apparatus, **not whole-process RSS**. It excludes allocator +bookkeeping, libc/loader, executable pages, other stack frames, kernel I/O buffers, +filesystem page cache, and the external Python verification process. + +## Metrics and measurement limits + +- `peak_reserved_bytes`: maximum fixed apparatus bytes plus active and cached + block charges. `peak_active_bytes` excludes cached idle blocks but includes the + fixed apparatus. Allocator bookkeeping is excluded from both. +- `active_byte_seconds`: sum over active block leases of charged bytes times + elapsed lifetime. Includes transient input/output overlap and block headers; + excludes fixed apparatus storage and idle cache residency. Reused leases are + measured separately, without double counting a block's cached interval. +- `copy_bytes`: only explicit selection `memcpy` bytes. Reads, writes, kernel, + allocator, and generator copies are outside this counter. Zero does not mean + no data movement in the process or system. +- `latency_*`: starts immediately before reading a record header and ends after + its selected output is written. Includes admission waits after reading that + header. It excludes time a record waits outside the process before its header + is read. There is no independent open-loop arrival source, so these are not + service request P99 measurements. P99 is a histogram upper bound (up to 12.5% + bin rounding at normal durations), not an exact percentile. +- `elapsed_ns`: file I/O, deliberate delays, scheduling, instrumentation and + buffer cleanup. Excludes build, process startup, fixtures and verification. + `cpu_ns` uses the process CPU clock; reports deliberate waiting separately. +- `rss_peak_bytes`: approximate current-image `VmHWM` from Linux + `/proc/self/status`, read after the timed region. Zero with source `unavailable` + means no current-image implementation on another OS. `rusage_maxrss_bytes` is + retained separately (Linux KiB normalized to bytes; macOS already bytes). + Linux rusage survives exec and was contaminated by launcher history in the + first run; it cannot substitute for the child's current-image memory. + Neither measurement is added to requested buffer storage. + +Instrumentation is enabled equally in all variants, including block lifetime +timestamps. Its overhead is not separately calibrated in this first experiment. +Timing results must not be presented as uninstrumented application throughput. +Output goes to a regular temporary file without `fsync`; this measures cached +file I/O rather than durable storage. Each variant gets a warm-up run followed by +five fresh-process measured runs in randomized variant order within each case. +Cases run in fixed order. Linux runs pin to one available CPU; thermal and power +conditions are uncontrolled. Medians and ranges are descriptive, not significance +tests. The original plan predates the first measurement. Plan v2 adds an explicitly +exploratory 64-slot sensitivity case after the first run exposed queue occupancy +differences. Original data and source snapshots are preserved with an audit note; +the v2 run is the current result. Neither plan is a production SLO. + +Lower peak RAM can permit a longer queue under the same byte cap and thereby +increase observed in-process latency. Compare queue occupancy and latency as +well as memory; equal byte/slot limits do not imply equal latency. No application +SLO or success threshold has been invented for these synthetic inputs. + +## Reproduction and checks + +From the repository root, using Python 3 and a C compiler with ASan/UBSan: + +```sh +python3 research/experiments/002-buffer-retention/run.py --check-only +python3 research/experiments/002-buffer-retention/run.py --output /tmp/pure-retention-results +``` + +The result directory must not already exist. `CC` selects the compiler. The +runner builds into a temporary directory, verifies normal and sanitized builds, +and saves the plan, source hashes, build flags/hash/size, environment, fixture +digests, checks, every raw sample and summaries. Build size includes debug info. +`complete.json` appears only after all measurements and output hashes pass. +LeakSanitizer needs an execution environment without ptrace tracing; its fatal +diagnostics are treated as a failed verification, never suppressed. + +For direct use: + +```sh +cc -std=c17 -O2 -Wall -Wextra -Wpedantic -Werror research/experiments/002-buffer-retention/benchmark.c -o /tmp/pure-retention +/tmp/pure-retention --policy threshold --ratio 4 --budget 8388608 --hold-us 5000 < input.frames > selected.frames 2> metrics.json +``` + +Exit 0 indicates completion; exit 2 indicates an error; exit 3 indicates +cancellation. SIGINT/SIGTERM cancel synchronous work and release outstanding +buffers. The output may contain a completed prefix or a partially written final +frame on I/O failure. This is not an atomic-output guarantee. Tests include exact +output equivalence, empty input, malformed/truncated input, budget refusal, +deterministic cancellation, real signal cancellation, and `/dev/full` where +available. These synchronous tests do not verify async cancellation races. + +The RSS correction follows the documented preservation of +[resource usage across exec](https://man7.org/linux/man-pages/man2/getrusage.2.html). +Linux documents [VmHWM as approximate](https://man7.org/linux/man-pages/man5/proc_pid_status.5.html); +requested storage counters remain the precise apparatus accounting used here. + +The first result and its interpretation are recorded in +[report 007](../../../docs/research/007-buffer-retention-results.md). diff --git a/research/experiments/002-buffer-retention/benchmark.c b/research/experiments/002-buffer-retention/benchmark.c new file mode 100644 index 0000000..c9e8120 --- /dev/null +++ b/research/experiments/002-buffer-retention/benchmark.c @@ -0,0 +1,338 @@ +#define _POSIX_C_SOURCE 200809L +#include <assert.h> +#include <errno.h> +#include <inttypes.h> +#include <limits.h> +#include <signal.h> +#include <stdbool.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/resource.h> +#include <time.h> +#include <unistd.h> + +/* A measurement apparatus, not the Pure runtime or a general document parser. */ +enum { CACHE_SLOTS = 16, SCRATCH = 65536, HIST_SIZE = 512, MAX_FRAME = 8*1024*1024 }; +typedef struct Block { size_t capacity; uint64_t since; unsigned char bytes[]; } Block; +typedef struct Item { + Block *block; + size_t offset, length; + uint64_t start, ready; +} Item; +typedef struct Engine { + Item *queue; + Block *cache[CACHE_SLOTS]; + unsigned char scratch[SCRATCH]; + uint64_t histogram[HIST_SIZE]; + size_t slots, head, count, fixed, budget, reserved, active, cached; + size_t peak_reserved, peak_active, peak_queue; + uint64_t allocations, reuses, copies, read_bytes, written_bytes; + uint64_t accepted, emitted, copied_records, borrowed_records, pressure_copies; + uint64_t budget_waits, slot_waits, sleep_ns, hold_ns, service_ns, last_emit; + uint64_t elapsed_ns, cpu_ns, latency_sum, latency_max, start, cancel_after; + long double active_byte_ns; + unsigned ratio; + bool pool; + const char *policy, *status; +} Engine; +static volatile sig_atomic_t interrupted; +static void stop(int sig) { (void)sig; interrupted = 1; } +static uint64_t ns(clockid_t clock) { + struct timespec t; + if (clock_gettime(clock, &t)) { perror("clock_gettime"); exit(2); } + return (uint64_t)t.tv_sec * UINT64_C(1000000000) + (uint64_t)t.tv_nsec; +} +static size_t charge(const Block *b) { return sizeof(*b) + b->capacity; } +static size_t rounded(size_t n) { + size_t r = 64; + while (r < n) r *= 2; + return r; +} +static void peaks(Engine *e) { + assert(e->active + e->cached == e->reserved); + assert(e->fixed + e->reserved <= e->budget); + if (e->reserved > e->peak_reserved) e->peak_reserved = e->reserved; + if (e->active > e->peak_active) e->peak_active = e->active; +} +static void evict(Engine *e, size_t i) { + Block *b = e->cache[i]; + if (!b) return; + e->cached -= charge(b); e->reserved -= charge(b); + free(b); e->cache[i] = NULL; +} +static Block *take(Engine *e, size_t n) { + size_t capacity = rounded(n), need = sizeof(Block) + capacity; + if (e->pool) { + for (size_t i = 0; i < CACHE_SLOTS; ++i) { + Block *b = e->cache[i]; + if (b && b->capacity == capacity) { + e->cache[i] = NULL; e->cached -= need; e->active += need; + ++e->reuses; b->since = ns(CLOCK_MONOTONIC); peaks(e); return b; + } + } + } + for (size_t i = 0; i < CACHE_SLOTS && need > e->budget-e->fixed-e->reserved; ++i) + evict(e, i); + if (need > e->budget-e->fixed-e->reserved) return NULL; + Block *b = malloc(need); + if (!b) { e->status = "allocation_failed"; return NULL; } + b->capacity = capacity; b->since = ns(CLOCK_MONOTONIC); + e->reserved += need; e->active += need; ++e->allocations; peaks(e); return b; +} +static void give(Engine *e, Block *b) { + if (!b) return; + size_t bytes = charge(b); + e->active_byte_ns += (long double)bytes * (ns(CLOCK_MONOTONIC)-b->since); + e->active -= bytes; + if (e->pool && bytes <= e->budget/4-e->cached) { + for (size_t i = 0; i < CACHE_SLOTS; ++i) if (!e->cache[i]) { + e->cache[i] = b; e->cached += bytes; peaks(e); return; + } + } + e->reserved -= bytes; free(b); peaks(e); +} +static bool sleep_until(Engine *e, uint64_t deadline) { + uint64_t t = ns(CLOCK_MONOTONIC), start = t; + while (t < deadline && !interrupted) { + uint64_t delta = deadline-t; + struct timespec request = {(time_t)(delta/1000000000), (long)(delta%1000000000)}; + if (nanosleep(&request, NULL) && errno != EINTR) { e->status="sleep_failed"; return false; } + t = ns(CLOCK_MONOTONIC); + } + e->sleep_ns += t-start; + return !interrupted; +} +/* floor(log2(ns)) with eight subdivisions: upper bound error <= 12.5%. */ +static unsigned bucket(uint64_t n) { + unsigned exponent = 0; + for (uint64_t x = n; x > 1; x >>= 1) ++exponent; + if (exponent < 3) return (unsigned)n; + return exponent*8 + (unsigned)((n-(UINT64_C(1)<<exponent))>>(exponent-3)); +} +static uint64_t upper(unsigned b) { + if (b < 24) return b+1; + unsigned exponent = b/8; + if (exponent >= 63) return UINT64_MAX; + return (UINT64_C(1)<<exponent) + (uint64_t)(b%8+1)*(UINT64_C(1)<<(exponent-3)); +} +static bool write_all(Engine *e, const void *src, size_t n) { + const unsigned char *p = src; + while (n && !interrupted) { + ssize_t written = write(STDOUT_FILENO, p, n); + if (written < 0 && errno == EINTR) continue; + if (written <= 0) { e->status = "output_failed"; return false; } + p += written; n -= (size_t)written; e->written_bytes += (uint64_t)written; + } + return !interrupted; +} +static bool emit(Engine *e) { + assert(e->count); + Item *item = &e->queue[e->head]; + uint64_t ready = item->ready; + if (e->last_emit + e->service_ns > ready) ready = e->last_emit + e->service_ns; + if (!sleep_until(e, ready)) return false; + uint32_t len = (uint32_t)item->length; + unsigned char header[4] = {(unsigned char)len, (unsigned char)(len>>8), + (unsigned char)(len>>16), (unsigned char)(len>>24)}; + if (!write_all(e, header, sizeof header) || + !write_all(e, item->block->bytes+item->offset, item->length)) return false; + uint64_t now = ns(CLOCK_MONOTONIC), latency = now-item->start; + ++e->histogram[bucket(latency)]; e->latency_sum += latency; + if (latency > e->latency_max) e->latency_max = latency; + e->last_emit = now; ++e->emitted; + give(e, item->block); item->block = NULL; + e->head = (e->head+1)%e->slots; --e->count; + if (e->cancel_after && e->emitted >= e->cancel_after) { + e->status = "cancelled"; return false; + } + return true; +} +static Block *acquire(Engine *e, size_t n) { + for (;;) { + Block *b = take(e, n); + if (b) return b; + if (strcmp(e->status, "ok")) return NULL; + if (!e->count) { e->status = "budget_too_small"; return NULL; } + ++e->budget_waits; + if (!emit(e)) return NULL; + } +} +/* Returns 1 on complete read, 0 on clean EOF before any byte, -1 on failure. */ +static int read_exact(Engine *e, void *dst, size_t n) { + unsigned char *p = dst; size_t done = 0; + while (done < n && !interrupted) { + ssize_t got = read(STDIN_FILENO, p+done, n-done); + if (got < 0 && errno == EINTR) continue; + if (got < 0) { e->status="input_failed"; return -1; } + if (!got) { if (!done) return 0; e->status="truncated_input"; return -1; } + done += (size_t)got; e->read_bytes += (uint64_t)got; + } + return interrupted ? -1 : 1; +} +static bool discard(Engine *e, size_t n) { + while (n) { + size_t chunk = n < SCRATCH ? n : SCRATCH; + if (read_exact(e, e->scratch, chunk) != 1) { + if (!strcmp(e->status,"ok")) e->status="truncated_input"; + return false; + } + n -= chunk; + } + return true; +} +static uint32_t le32(const unsigned char *p) { + return (uint32_t)p[0] | (uint32_t)p[1]<<8 | (uint32_t)p[2]<<16 | (uint32_t)p[3]<<24; +} +/* Linux's rusage high-water mark survives exec. Read the current mm's HWM + * separately; proc RSS accounting is approximate, not allocator accounting. */ +static uint64_t image_peak_rss(void) { +#if defined(__linux__) + FILE *status = fopen("/proc/self/status", "r"); + if (!status) return 0; + char line[256]; unsigned long long kib = 0; + while (fgets(line, sizeof line, status)) + if (sscanf(line, "VmHWM: %llu kB", &kib) == 1) break; + fclose(status); + return (uint64_t)kib * 1024; +#else + return 0; /* No current-image peak implemented for other OSes. */ +#endif +} +static void run(Engine *e) { + for (;;) { + if (interrupted) break; + if (e->count) { + Item *head = &e->queue[e->head]; + uint64_t now = ns(CLOCK_MONOTONIC); + if (now >= head->ready && now >= e->last_emit+e->service_ns) { + if (!emit(e)) break; + continue; + } + } + if (e->count == e->slots) { ++e->slot_waits; if (!emit(e)) break; } + unsigned char header[12]; + uint64_t start = ns(CLOCK_MONOTONIC); + int got = read_exact(e, header, sizeof header); + if (got != 1) { + if (!got) while (e->count && !interrupted) if (!emit(e)) break; + break; + } + size_t payload = le32(header), offset = le32(header+4), length = le32(header+8); + if (!payload || payload > MAX_FRAME || !length || offset > payload || length > payload-offset) { + e->status="invalid_frame"; break; + } + bool project = !strcmp(e->policy,"project"); + Block *source = acquire(e, project ? length : payload); + if (!source) break; + bool valid; + if (project) { + valid = discard(e, offset) && read_exact(e, source->bytes, length)==1 && + discard(e, payload-offset-length); + offset = 0; + } else valid = read_exact(e, source->bytes, payload)==1; + if (!valid) { + if (!strcmp(e->status,"ok")) e->status="truncated_input"; + give(e, source); break; + } + bool copy = !strcmp(e->policy,"copy") || + (!strcmp(e->policy,"threshold") && rounded(payload)/rounded(length) >= e->ratio); + if (!strcmp(e->policy,"pressure")) { + /* Online rule using current charged live buffers; no future lifetime. */ + copy = rounded(length) < source->capacity && + e->active > (e->budget-e->fixed)/2; + if (copy) ++e->pressure_copies; + } + if (!project && copy) { + Block *small = acquire(e, length); + if (!small) { give(e, source); break; } + memcpy(small->bytes, source->bytes+offset, length); + e->copies += length; ++e->copied_records; + give(e, source); source = small; offset = 0; + } else if (!project) ++e->borrowed_records; + size_t tail = (e->head+e->count)%e->slots; + e->queue[tail] = (Item){source, offset, length, start, ns(CLOCK_MONOTONIC)+e->hold_ns}; + ++e->count; ++e->accepted; + if (e->count > e->peak_queue) e->peak_queue=e->count; + } + if (interrupted) e->status="cancelled"; +} +static uint64_t number(const char *s, uint64_t maximum) { + char *end; errno=0; + unsigned long long n = strtoull(s, &end, 10); + if (!*s || *s=='-' || *end || errno || n>maximum) { fprintf(stderr,"invalid number\n"); exit(2); } + return n; +} +int main(int argc, char **argv) { + Engine *e = calloc(1, sizeof *e); + if (!e) return 2; + e->policy="borrow"; e->status="ok"; e->budget=8*1024*1024; e->slots=512; + e->ratio=4; e->pool=true; + for (int i=1; i<argc; i+=2) { + if (i+1==argc) { fprintf(stderr,"options require values\n"); free(e); return 2; } + const char *key=argv[i], *value=argv[i+1]; + if (!strcmp(key,"--policy")) e->policy=value; + else if (!strcmp(key,"--budget")) e->budget=(size_t)number(value,1073741824); + else if (!strcmp(key,"--slots")) e->slots=(size_t)number(value,4096); + else if (!strcmp(key,"--hold-us")) e->hold_ns=number(value,10000000)*1000; + else if (!strcmp(key,"--service-us")) e->service_ns=number(value,10000000)*1000; + else if (!strcmp(key,"--ratio")) e->ratio=(unsigned)number(value,UINT_MAX); + else if (!strcmp(key,"--pool")) e->pool=number(value,1)!=0; + else if (!strcmp(key,"--cancel-after")) e->cancel_after=number(value,UINT64_MAX); + else { fprintf(stderr,"unknown option\n"); free(e); return 2; } + } + bool known = !strcmp(e->policy,"borrow") || !strcmp(e->policy,"copy") || + !strcmp(e->policy,"threshold") || !strcmp(e->policy,"pressure") || !strcmp(e->policy,"project"); + if (!known || !e->slots || e->slots>4096 || e->ratio<2 || e->budget>UINT64_C(1073741824) || + e->hold_ns>UINT64_C(10000000000) || e->service_ns>UINT64_C(10000000000)) { + fprintf(stderr,"invalid configuration\n"); free(e); return 2; + } + e->fixed=sizeof(*e)+e->slots*sizeof(Item); + if (e->budget < e->fixed) { fprintf(stderr,"budget below fixed metadata\n"); free(e); return 2; } + e->queue=calloc(e->slots,sizeof(Item)); + if (!e->queue) { free(e); return 2; } + signal(SIGINT,stop); signal(SIGTERM,stop); signal(SIGPIPE,SIG_IGN); + e->start=ns(CLOCK_MONOTONIC); uint64_t cpu=ns(CLOCK_PROCESS_CPUTIME_ID); + run(e); + size_t live_at_stop=e->active, cached_at_stop=e->cached; + while (e->count) { + give(e,e->queue[e->head].block); e->head=(e->head+1)%e->slots; --e->count; + } + for (size_t i=0;i<CACHE_SLOTS;++i) evict(e,i); + assert(!e->active && !e->reserved && !e->cached); + e->elapsed_ns=ns(CLOCK_MONOTONIC)-e->start; e->cpu_ns=ns(CLOCK_PROCESS_CPUTIME_ID)-cpu; + uint64_t target=e->emitted-e->emitted/100, sum=0, p99=0; + for (unsigned b=0; e->emitted && b<HIST_SIZE; ++b) { + sum+=e->histogram[b]; if (sum>=target) { p99=upper(b); break; } + } + struct rusage usage; long rss=0; + if (!getrusage(RUSAGE_SELF,&usage)) rss=usage.ru_maxrss; +#if defined(__APPLE__) + uint64_t rusage_bytes=(uint64_t)rss; +#else + uint64_t rusage_bytes=(uint64_t)rss*1024; +#endif + uint64_t rss_bytes=image_peak_rss(); + fprintf(stderr,"{\"status\":\"%s\",\"policy\":\"%s\",\"pool\":%s," + "\"budget_bytes\":%zu,\"fixed_bytes\":%zu,\"peak_reserved_bytes\":%zu," + "\"peak_active_bytes\":%zu,\"peak_queue\":%zu,\"rss_peak_bytes\":%" PRIu64 "," + "\"rusage_maxrss_bytes\":%" PRIu64 ",\"rss_peak_source\":\"%s\"," + "\"elapsed_ns\":%" PRIu64 ",\"cpu_ns\":%" PRIu64 ",\"input_bytes\":%" PRIu64 "," + "\"output_bytes\":%" PRIu64 ",\"accepted\":%" PRIu64 ",\"emitted\":%" PRIu64 "," + "\"copy_bytes\":%" PRIu64 ",\"copied_records\":%" PRIu64 ",\"borrowed_records\":%" PRIu64 "," + "\"pressure_copies\":%" PRIu64 ",\"allocations\":%" PRIu64 ",\"reuses\":%" PRIu64 "," + "\"budget_waits\":%" PRIu64 ",\"slot_waits\":%" PRIu64 ",\"sleep_ns\":%" PRIu64 "," + "\"latency_mean_ns\":%.3f,\"latency_p99_upper_ns\":%" PRIu64 ",\"latency_max_ns\":%" PRIu64 "," + "\"active_byte_seconds\":%.6Lf,\"live_at_stop_bytes\":%zu,\"cached_at_stop_bytes\":%zu," + "\"unreleased_buffer_bytes\":%zu}\n", + e->status,e->policy,e->pool?"true":"false",e->budget,e->fixed,e->fixed+e->peak_reserved, + e->fixed+e->peak_active,e->peak_queue,rss_bytes,rusage_bytes, + rss_bytes?"linux_proc_vmhwm_approximate":"unavailable",e->elapsed_ns,e->cpu_ns,e->read_bytes, + e->written_bytes,e->accepted,e->emitted,e->copies,e->copied_records,e->borrowed_records, + e->pressure_copies,e->allocations,e->reuses,e->budget_waits,e->slot_waits,e->sleep_ns, + e->emitted?(double)e->latency_sum/(double)e->emitted:0,p99,e->latency_max, + e->active_byte_ns/1e9L,live_at_stop,cached_at_stop,e->reserved); + int result=!strcmp(e->status,"ok")?0:!strcmp(e->status,"cancelled")?3:2; + free(e->queue); free(e); return result; +} diff --git a/research/experiments/002-buffer-retention/plan.json b/research/experiments/002-buffer-retention/plan.json new file mode 100644 index 0000000..1737f45 --- /dev/null +++ b/research/experiments/002-buffer-retention/plan.json @@ -0,0 +1,35 @@ +{ + "version": 2, + "written_before_measurement": true, + "revision_note": "The v1 run is preserved. Before this v2 run, RSS instrumentation was corrected and a 64-slot sparse sensitivity case was added after observing different queue occupancy. This is an exploratory follow-up, not a pre-registered confirmation.", + "seed": 20260922, + "repeats": 5, + "slots": 512, + "policies": [ + {"name": "borrow", "policy": "borrow", "pool": 1}, + {"name": "copy", "policy": "copy", "pool": 1}, + {"name": "threshold2", "policy": "threshold", "ratio": 2, "pool": 1}, + {"name": "threshold4", "policy": "threshold", "ratio": 4, "pool": 1}, + {"name": "threshold8", "policy": "threshold", "ratio": 8, "pool": 1}, + {"name": "pressure", "policy": "pressure", "pool": 1}, + {"name": "project", "policy": "project", "pool": 1}, + {"name": "copy_no_pool", "policy": "copy", "pool": 0} + ], + "cases": [ + {"name": "sparse_slow", "shape": "sparse", "records": 2048, "budget": 8388608, "hold_us": 5000, "service_us": 20}, + {"name": "sparse_slots64", "shape": "sparse", "records": 2048, "budget": 8388608, "slots": 64, "hold_us": 5000, "service_us": 20}, + {"name": "dense_slow", "shape": "dense", "records": 2048, "budget": 8388608, "hold_us": 5000, "service_us": 20}, + {"name": "mixed_slow", "shape": "mixed", "records": 2048, "budget": 8388608, "hold_us": 5000, "service_us": 20}, + {"name": "mixed_tight", "shape": "mixed", "records": 2048, "budget": 2097152, "hold_us": 5000, "service_us": 20}, + {"name": "sparse_fast", "shape": "sparse", "records": 2048, "budget": 8388608, "hold_us": 0, "service_us": 0} + ], + "expectations": [ + "Borrow retains full source allocations for small selections.", + "Copy can add CPU and transient source plus destination memory for dense selections.", + "A current-pressure rule need not outperform a static size rule or early projection.", + "Pool reuse can reduce allocation calls while increasing reserved idle memory.", + "No Pure-specific advantage, application SLO, or statistical significance is presumed." + ], + "comparison_rule": "Report all presets and repetitions; no post-hoc winner is called an out-of-sample tuned policy.", + "limits": "Single FIFO local pipeline with synthetic delayed sink. No Sonic/Node/.NET benchmark, fan-out, persistent cache, generic JSON parser, external open-loop arrivals, or production SLO." +} diff --git a/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/complete.json b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/complete.json new file mode 100644 index 0000000..0aa14f4 --- /dev/null +++ b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/complete.json @@ -0,0 +1,5 @@ +{ + "samples": 240, + "all_output_hashes_match": true, + "finished_utc": "2026-09-22T12:24:32Z" +} diff --git a/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/environment.json b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/environment.json new file mode 100644 index 0000000..b2b8d87 --- /dev/null +++ b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/environment.json @@ -0,0 +1,57 @@ +{ + "platform": "Linux-6.18.39+rpt-rpi-2712-aarch64-with-glibc2.41", + "machine": "aarch64", + "python": "3.14.7", + "cpu_affinity": 0, + "compiler": "cc (Debian 14.2.0-19) 14.2.0\nCopyright (C) 2024 Free Software Foundation, Inc.\nThis is free software; see the source for copying conditions. There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n", + "builds": [ + { + "command": [ + "cc", + "-std=c17", + "-Wall", + "-Wextra", + "-Wpedantic", + "-Werror", + "-O2", + "-g", + "/home/eunhhu/work/pure/research/experiments/002-buffer-retention/benchmark.c", + "-o", + "/tmp/pure-retention-ktukd04y/bench" + ], + "stderr": "", + "sha256": "61e0dcf961714992da8d8f2846a09caeda95ce1ac183e2b82dbb80828c6ae43c", + "size_bytes": 101072 + }, + { + "command": [ + "cc", + "-std=c17", + "-Wall", + "-Wextra", + "-Wpedantic", + "-Werror", + "-O2", + "-g", + "-fsanitize=address,undefined", + "-fno-omit-frame-pointer", + "/home/eunhhu/work/pure/research/experiments/002-buffer-retention/benchmark.c", + "-o", + "/tmp/pure-retention-ktukd04y/bench-sanitized" + ], + "stderr": "", + "sha256": "a4a383b9a31ec0d3cd2ac60a1697d863f0424a303608c69ed6faff969dd5d6de", + "size_bytes": 257680 + } + ], + "source_sha256": { + "benchmark.c": "8ac37467fd01421f23924d0e92c890cc161dbd7b3d55642ce91d47e8f12a1e52", + "run.py": "f40df6109d1270afa3a3241b4d22c6842d3dbf360ccf3f563ec067df5f9b1fb3", + "plan.json": "0e07742173d3a415af1791e2d92b3ce9319152c3bca8dfbe6e3cd8de6e13a9f4" + }, + "clock": "CLOCK_MONOTONIC; CPU = CLOCK_PROCESS_CPUTIME_ID", + "timing": "includes file IO, scheduling, deliberate sleep, metrics, buffer cleanup; excludes startup/build/fixture/verification", + "limitations": "shared host; unregulated thermals; cached files; output page cache, no fsync; synthetic closed-loop arrivals", + "started_utc": "2026-09-22T12:23:38Z", + "cpuinfo": "processor\t: 0\nBogoMIPS\t: 108.00\nFeatures\t: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp\nCPU implementer\t: 0x41\nCPU architecture: 8\nCPU variant\t: 0x4\nCPU part\t: 0xd0b\nCPU revision\t: 1\n\nprocessor\t: 1\nBogoMIPS\t: 108.00\nFeatures\t: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp\nCPU implementer\t: 0x41\nCPU architecture: 8\nCPU variant\t: 0x4\nCPU part\t: 0xd0b\nCPU revision\t: 1\n\nprocessor\t: 2\nBogoMIPS\t: 108.00\nFeatures\t: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp\nCPU implementer\t: 0x41\nCPU architecture: 8\nCPU variant\t: 0x4\nCPU part\t: 0xd0b\nCPU revision\t: 1\n\nprocessor\t: 3\nBogoMIPS\t: 108.00\nFeatures\t: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp\nCPU implementer\t: 0x41\nCPU architecture: 8\nCPU variant\t: 0x4\nCPU part\t: 0xd0b\nCPU revision\t: 1\n\nRevision\t: d04171\nSerial\t\t: d3ba8e625dbe42ac\nModel\t\t: Raspberry Pi 5 Model B Rev 1.1\n" +} diff --git a/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/fixtures.json b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/fixtures.json new file mode 100644 index 0000000..2fe2bb6 --- /dev/null +++ b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/fixtures.json @@ -0,0 +1,68 @@ +[ + { + "path": "input.frames", + "shape": "sparse", + "records": 2048, + "seed": 20260922, + "input_bytes": 134242304, + "input_sha256": "161377ac76f4b7d35b13db7edf3b93bb279ddd83f6514051020e8b49e743d1c0", + "expected_output_bytes": 139264, + "expected_output_sha256": "a01c7bff45f73512f3bc0dbd02d7c3a1f4ceb09f574d7c25b926cd3d30bb1bfa", + "case": "sparse_slow" + }, + { + "path": "input.frames", + "shape": "sparse", + "records": 2048, + "seed": 20260922, + "input_bytes": 134242304, + "input_sha256": "161377ac76f4b7d35b13db7edf3b93bb279ddd83f6514051020e8b49e743d1c0", + "expected_output_bytes": 139264, + "expected_output_sha256": "a01c7bff45f73512f3bc0dbd02d7c3a1f4ceb09f574d7c25b926cd3d30bb1bfa", + "case": "sparse_slots64" + }, + { + "path": "input.frames", + "shape": "dense", + "records": 2048, + "seed": 20260922, + "input_bytes": 134242304, + "input_sha256": "fb28c2da0af227079bd6888c3f549fa5a48abd0b790c3939dc330111e80c0b7f", + "expected_output_bytes": 100671488, + "expected_output_sha256": "d96dd7f80d696895e66521630fd30f13adabf63bea3b84b0a709fbc8c4095aa5", + "case": "dense_slow" + }, + { + "path": "input.frames", + "shape": "mixed", + "records": 2048, + "seed": 20260922, + "input_bytes": 177631232, + "input_sha256": "5cfcb8e74d5f30c3a611f373ddf53fd5bc843841d83de42c763e1d931403521d", + "expected_output_bytes": 53735632, + "expected_output_sha256": "f6b4eb83e7ca9aa4b5b2e0675d34b656815c82c992700ee9cbd7e0a15594cb0b", + "case": "mixed_slow" + }, + { + "path": "input.frames", + "shape": "mixed", + "records": 2048, + "seed": 20260922, + "input_bytes": 177631232, + "input_sha256": "5cfcb8e74d5f30c3a611f373ddf53fd5bc843841d83de42c763e1d931403521d", + "expected_output_bytes": 53735632, + "expected_output_sha256": "f6b4eb83e7ca9aa4b5b2e0675d34b656815c82c992700ee9cbd7e0a15594cb0b", + "case": "mixed_tight" + }, + { + "path": "input.frames", + "shape": "sparse", + "records": 2048, + "seed": 20260922, + "input_bytes": 134242304, + "input_sha256": "161377ac76f4b7d35b13db7edf3b93bb279ddd83f6514051020e8b49e743d1c0", + "expected_output_bytes": 139264, + "expected_output_sha256": "a01c7bff45f73512f3bc0dbd02d7c3a1f4ceb09f574d7c25b926cd3d30bb1bfa", + "case": "sparse_fast" + } +] diff --git a/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/plan.json b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/plan.json new file mode 100644 index 0000000..23db315 --- /dev/null +++ b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/plan.json @@ -0,0 +1,113 @@ +{ + "version": 2, + "written_before_measurement": true, + "revision_note": "The v1 run is preserved. Before this v2 run, RSS instrumentation was corrected and a 64-slot sparse sensitivity case was added after observing different queue occupancy. This is an exploratory follow-up, not a pre-registered confirmation.", + "seed": 20260922, + "repeats": 5, + "slots": 512, + "policies": [ + { + "name": "borrow", + "policy": "borrow", + "pool": 1 + }, + { + "name": "copy", + "policy": "copy", + "pool": 1 + }, + { + "name": "threshold2", + "policy": "threshold", + "ratio": 2, + "pool": 1 + }, + { + "name": "threshold4", + "policy": "threshold", + "ratio": 4, + "pool": 1 + }, + { + "name": "threshold8", + "policy": "threshold", + "ratio": 8, + "pool": 1 + }, + { + "name": "pressure", + "policy": "pressure", + "pool": 1 + }, + { + "name": "project", + "policy": "project", + "pool": 1 + }, + { + "name": "copy_no_pool", + "policy": "copy", + "pool": 0 + } + ], + "cases": [ + { + "name": "sparse_slow", + "shape": "sparse", + "records": 2048, + "budget": 8388608, + "hold_us": 5000, + "service_us": 20 + }, + { + "name": "sparse_slots64", + "shape": "sparse", + "records": 2048, + "budget": 8388608, + "slots": 64, + "hold_us": 5000, + "service_us": 20 + }, + { + "name": "dense_slow", + "shape": "dense", + "records": 2048, + "budget": 8388608, + "hold_us": 5000, + "service_us": 20 + }, + { + "name": "mixed_slow", + "shape": "mixed", + "records": 2048, + "budget": 8388608, + "hold_us": 5000, + "service_us": 20 + }, + { + "name": "mixed_tight", + "shape": "mixed", + "records": 2048, + "budget": 2097152, + "hold_us": 5000, + "service_us": 20 + }, + { + "name": "sparse_fast", + "shape": "sparse", + "records": 2048, + "budget": 8388608, + "hold_us": 0, + "service_us": 0 + } + ], + "expectations": [ + "Borrow retains full source allocations for small selections.", + "Copy can add CPU and transient source plus destination memory for dense selections.", + "A current-pressure rule need not outperform a static size rule or early projection.", + "Pool reuse can reduce allocation calls while increasing reserved idle memory.", + "No Pure-specific advantage, application SLO, or statistical significance is presumed." + ], + "comparison_rule": "Report all presets and repetitions; no post-hoc winner is called an out-of-sample tuned policy.", + "limits": "Single FIFO local pipeline with synthetic delayed sink. No Sonic/Node/.NET benchmark, fan-out, persistent cache, generic JSON parser, external open-loop arrivals, or production SLO." +} diff --git a/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/raw.csv b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/raw.csv new file mode 100644 index 0000000..b9160ae --- /dev/null +++ b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/raw.csv @@ -0,0 +1,241 @@ +case,variant,repeat,status,policy,pool,budget_bytes,fixed_bytes,peak_reserved_bytes,peak_active_bytes,peak_queue,rss_peak_bytes,rusage_maxrss_bytes,rss_peak_source,elapsed_ns,cpu_ns,input_bytes,output_bytes,accepted,emitted,copy_bytes,copied_records,borrowed_records,pressure_copies,allocations,reuses,budget_waits,slot_waits,sleep_ns,latency_mean_ns,latency_p99_upper_ns,latency_max_ns,active_byte_seconds,live_at_stop_bytes,cached_at_stop_bytes,unreleased_buffer_bytes
+sparse_slow,copy,0,ok,copy,True,8388608,90560,197072,197072,512,1687552,27246592,linux_proc_vmhwm_approximate,160143537,26459012,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1524,137390253,34696998.27,41943040,41171715,6863.022101,0,66752,0
+sparse_slow,threshold4,0,ok,threshold,True,8388608,90560,197072,197072,512,1703936,27246592,linux_proc_vmhwm_approximate,157308101,31229598,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1480,130450222,33900498.29,41943040,39440182,6941.796558,0,66752,0
+sparse_slow,threshold2,0,ok,threshold,True,8388608,90560,197072,197072,512,1720320,27246592,linux_proc_vmhwm_approximate,155496866,24536501,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1532,134789830,33617642.818,41943040,38582611,6573.377656,0,66752,0
+sparse_slow,copy_no_pool,0,ok,copy,False,8388608,90560,197072,197072,512,1703936,27246592,linux_proc_vmhwm_approximate,155097886,24003453,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,1537,135038766,33344720.225,41943040,38228742,6474.089644,0,0,0
+sparse_slow,project,0,ok,project,True,8388608,90560,131520,131520,512,1654784,27246592,linux_proc_vmhwm_approximate,154147870,24607892,134242304,139264,2048,2048,0,0,0,0,512,1536,0,1536,133284576,33266783.578,37748736,37610633,5450.353596,0,1280,0
+sparse_slow,threshold8,0,ok,threshold,True,8388608,90560,197072,197072,512,1703936,27246592,linux_proc_vmhwm_approximate,159785538,24425471,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1534,139188295,34401146.148,41943040,40673920,6694.694537,0,66752,0
+sparse_slow,borrow,0,ok,borrow,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,107974911,48356230,134242304,139264,2048,2048,0,0,2048,0,126,1922,1100,0,61689899,6299431.416,9437184,9257676,842052.147088,0,1048832,0
+sparse_slow,pressure,0,ok,pressure,True,8388608,90560,4321888,4318208,512,5832704,27246592,linux_proc_vmhwm_approximate,153730223,27269441,134242304,139264,2048,2048,113984,1781,267,1781,514,3315,0,1480,130232809,32945208.971,41943040,38336797,525465.223488,0,590528,0
+sparse_slow,borrow,1,ok,borrow,True,8388608,90560,8350112,8350112,126,9469952,27246592,linux_proc_vmhwm_approximate,106374934,48221069,134242304,139264,2048,2048,0,0,2048,0,126,1922,1095,0,60129493,6201710.718,9437184,9283991,829040.966005,0,1048832,0
+sparse_slow,copy_no_pool,1,ok,copy,False,8388608,90560,197072,197072,512,1687552,27246592,linux_proc_vmhwm_approximate,160320037,25896167,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,1525,138363559,34524425.147,41943040,40334217,6779.619735,0,0,0
+sparse_slow,threshold2,1,ok,threshold,True,8388608,90560,197072,197072,512,1703936,27246592,linux_proc_vmhwm_approximate,160914091,25835642,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1519,138817024,34925615.31,46137344,42672599,6869.973543,0,66752,0
+sparse_slow,threshold4,1,ok,threshold,True,8388608,90560,197072,197072,512,1687552,27246592,linux_proc_vmhwm_approximate,154184073,23590708,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1537,134309537,33299901.746,37748736,37858502,6477.65682,0,66752,0
+sparse_slow,threshold8,1,ok,threshold,True,8388608,90560,197072,197072,512,1687552,27246592,linux_proc_vmhwm_approximate,154103999,23187579,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1537,134573427,33283383.04,37748736,37891279,6458.021349,0,66752,0
+sparse_slow,project,1,ok,project,True,8388608,90560,131520,131520,512,1638400,27246592,linux_proc_vmhwm_approximate,157860470,28682548,134242304,139264,2048,2048,0,0,0,0,512,1536,0,1516,133519836,34200243.611,41943040,39812385,5603.286251,0,1280,0
+sparse_slow,pressure,1,ok,pressure,True,8388608,90560,4321888,4316848,512,5849088,27246592,linux_proc_vmhwm_approximate,157264009,27287611,134242304,139264,2048,2048,113408,1772,276,1772,514,3306,0,1470,133795355,32665634.037,41943040,42380378,542285.660244,0,656000,0
+sparse_slow,copy,1,ok,copy,True,8388608,90560,197072,197072,512,1703936,27246592,linux_proc_vmhwm_approximate,159054504,24707642,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1536,138332046,34466956.647,41943040,41828861,6705.336146,0,66752,0
+sparse_slow,threshold4,2,ok,threshold,True,8388608,90560,197072,197072,512,1703936,27246592,linux_proc_vmhwm_approximate,155128904,25543272,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1516,133541383,33533790.057,41943040,38416722,6610.674553,0,66752,0
+sparse_slow,copy_no_pool,2,ok,copy,False,8388608,90560,197072,197072,512,1703936,27246592,linux_proc_vmhwm_approximate,154376239,24141589,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,1537,134070369,33348471.497,37748736,37918872,6490.973039,0,0,0
+sparse_slow,threshold2,2,ok,threshold,True,8388608,90560,197072,197072,512,1720320,27246592,linux_proc_vmhwm_approximate,154320869,23690719,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1537,134338369,33321815.102,37748736,37742483,6490.329618,0,66752,0
+sparse_slow,pressure,2,ok,pressure,True,8388608,90560,4321888,4318768,512,5832704,27246592,linux_proc_vmhwm_approximate,151916969,26295422,134242304,139264,2048,2048,114176,1784,264,1784,514,3318,0,1489,129297978,32537118.75,37748736,37291707,513114.693547,0,590528,0
+sparse_slow,copy,2,ok,copy,True,8388608,90560,197072,197072,512,1703936,27246592,linux_proc_vmhwm_approximate,154140610,23189876,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1537,134662671,33298003.958,37748736,37866187,6456.771667,0,66752,0
+sparse_slow,project,2,ok,project,True,8388608,90560,131520,131520,512,1654784,27246592,linux_proc_vmhwm_approximate,154094443,24230112,134242304,139264,2048,2048,0,0,0,0,512,1536,0,1537,133556453,33259314.794,37748736,37585114,5449.134094,0,1280,0
+sparse_slow,threshold8,2,ok,threshold,True,8388608,90560,197072,197072,512,1703936,27246592,linux_proc_vmhwm_approximate,154652646,24092189,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1534,134423307,33402890.832,37748736,37866335,6511.54798,0,66752,0
+sparse_slow,borrow,2,ok,borrow,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,129845439,45497318,134242304,139264,2048,2048,0,0,2048,0,126,1922,1501,0,87228642,7656609.5,9437184,9287806,1022546.229446,0,1048832,0
+sparse_slow,project,3,ok,project,True,8388608,90560,131520,131520,512,1638400,27246592,linux_proc_vmhwm_approximate,154249202,24700764,134242304,139264,2048,2048,0,0,0,0,512,1536,0,1537,133261937,33273652.65,37748736,37535317,5451.483102,0,1280,0
+sparse_slow,borrow,3,ok,borrow,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,137924379,44501920,134242304,139264,2048,2048,0,0,2048,0,126,1922,1704,0,96547980,8155969.084,9437184,9259085,1088953.248436,0,1048832,0
+sparse_slow,pressure,3,ok,pressure,True,8388608,90560,4321888,4318128,512,5849088,27246592,linux_proc_vmhwm_approximate,152102968,26353180,134242304,139264,2048,2048,113984,1781,267,1781,514,3315,0,1489,129366758,32586897.428,37748736,37391725,520107.889954,0,590528,0
+sparse_slow,threshold8,3,ok,threshold,True,8388608,90560,197072,197072,512,1703936,27246592,linux_proc_vmhwm_approximate,154077370,23197132,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1537,134591611,33277920.587,37748736,37816187,6453.368258,0,66752,0
+sparse_slow,threshold2,3,ok,threshold,True,8388608,90560,197072,197072,512,1703936,27246592,linux_proc_vmhwm_approximate,154022055,23087202,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1537,134592710,33270464.792,37748736,37834187,6450.425541,0,66752,0
+sparse_slow,copy,3,ok,copy,True,8388608,90560,197072,197072,512,1720320,27246592,linux_proc_vmhwm_approximate,159640187,27408125,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1444,128856855,34666958.779,46137344,43466300,7402.36243,0,66752,0
+sparse_slow,copy_no_pool,3,ok,copy,False,8388608,90560,197072,197072,512,1720320,27246592,linux_proc_vmhwm_approximate,155595440,25939365,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,1537,134098060,33573592.059,41943040,37962687,6570.059349,0,0,0
+sparse_slow,threshold4,3,ok,threshold,True,8388608,90560,197072,197072,512,1703936,27246592,linux_proc_vmhwm_approximate,156340011,29539317,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1516,131960968,33615642.627,41943040,38156538,6719.71558,0,66752,0
+sparse_slow,copy_no_pool,4,ok,copy,False,8388608,90560,197072,197072,512,1703936,27246592,linux_proc_vmhwm_approximate,162066143,36838768,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,1413,131813978,34186582.359,46137344,44277743,7046.191505,0,0,0
+sparse_slow,copy,4,ok,copy,True,8388608,90560,197072,197072,512,1720320,27246592,linux_proc_vmhwm_approximate,154776516,28160466,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1467,130788967,33183203.845,41943040,39792181,6689.95279,0,66752,0
+sparse_slow,threshold4,4,ok,threshold,True,8388608,90560,197072,197072,512,1720320,27246592,linux_proc_vmhwm_approximate,154788109,23986070,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1537,134524839,33403921.35,41943040,37878020,6520.274636,0,66752,0
+sparse_slow,threshold8,4,ok,threshold,True,8388608,90560,197072,197072,512,1720320,27246592,linux_proc_vmhwm_approximate,154198518,23692568,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1536,134186642,33304172.097,37748736,37802706,6492.439639,0,66752,0
+sparse_slow,borrow,4,ok,borrow,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,141446795,44722082,134242304,139264,2048,2048,0,0,2048,0,126,1922,1729,0,99993943,8382742.796,9437184,9272177,1119170.099864,0,1048832,0
+sparse_slow,threshold2,4,ok,threshold,True,8388608,90560,197072,197072,512,1703936,27246592,linux_proc_vmhwm_approximate,154113537,24093342,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1537,133716023,33269305.586,37748736,37632576,6504.166448,0,66752,0
+sparse_slow,pressure,4,ok,pressure,True,8388608,90560,4321888,4318688,512,5849088,27246592,linux_proc_vmhwm_approximate,154850386,27901892,134242304,139264,2048,2048,114112,1783,265,1783,514,3317,0,1468,130766867,33232147.448,41943040,39951922,524904.925261,0,590528,0
+sparse_slow,project,4,ok,project,True,8388608,90560,131520,131520,512,1638400,27246592,linux_proc_vmhwm_approximate,157284342,26489150,134242304,139264,2048,2048,0,0,0,0,512,1536,0,1510,134748166,33888730.885,41943040,39144776,5552.251467,0,1280,0
+sparse_slots64,project,0,ok,project,True,8388608,72640,77760,77760,64,1572864,27246592,linux_proc_vmhwm_approximate,167149794,26582076,134242304,139264,2048,2048,0,0,0,0,64,1984,0,1974,144371389,5130099.306,7864320,8958215,840.438441,0,1280,0
+sparse_slots64,threshold2,0,ok,threshold,True,8388608,72640,143312,143312,64,1622016,27246592,linux_proc_vmhwm_approximate,167663571,26966696,134242304,139264,2048,2048,131072,2048,0,0,65,4031,0,1961,144092606,5142490.023,7864320,9061177,2058.951339,0,66752,0
+sparse_slots64,copy_no_pool,0,ok,copy,False,8388608,72640,143312,143312,64,1654784,27246592,linux_proc_vmhwm_approximate,168181366,26871012,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,1965,145357926,5163779.497,7864320,8918178,2024.80935,0,0,0
+sparse_slots64,borrow,0,ok,borrow,True,8388608,72640,4267968,4267968,64,5292032,27246592,linux_proc_vmhwm_approximate,167216739,43926056,134242304,139264,2048,2048,0,0,2048,0,64,1984,0,1888,126773157,5126680.831,7340032,7718922,688195.924843,0,1048832,0
+sparse_slots64,pressure,0,ok,pressure,True,8388608,72640,4268048,4268048,64,5767168,27246592,linux_proc_vmhwm_approximate,167185425,45108627,134242304,139264,2048,2048,2048,32,2016,32,65,2015,0,1714,125584463,5128742.545,6291456,6639537,677659.57207,0,1048832,0
+sparse_slots64,copy,0,ok,copy,True,8388608,72640,143312,143312,64,1622016,27246592,linux_proc_vmhwm_approximate,168358292,24933808,134242304,139264,2048,2048,131072,2048,0,0,65,4031,0,1982,147266280,5168010.066,7864320,9057715,1951.688735,0,66752,0
+sparse_slots64,threshold4,0,ok,threshold,True,8388608,72640,143312,143312,64,1654784,27246592,linux_proc_vmhwm_approximate,166820573,24630999,134242304,139264,2048,2048,131072,2048,0,0,65,4031,0,1982,145973315,5129540.053,7864320,9056604,1927.278894,0,66752,0
+sparse_slots64,threshold8,0,ok,threshold,True,8388608,72640,143312,143312,64,1654784,27246592,linux_proc_vmhwm_approximate,166777389,24643191,134242304,139264,2048,2048,131072,2048,0,0,65,4031,0,1983,145938953,5126620.092,7864320,9062437,1926.54795,0,66752,0
+sparse_slots64,pressure,1,ok,pressure,True,8388608,72640,4268048,4268048,64,5783552,27246592,linux_proc_vmhwm_approximate,167023277,43214247,134242304,139264,2048,2048,2048,32,2016,32,65,2015,0,1923,127480383,5125737.978,7340032,8171940,677260.281048,0,1048832,0
+sparse_slots64,threshold2,1,ok,threshold,True,8388608,72640,143312,143312,64,1638400,27246592,linux_proc_vmhwm_approximate,167465182,25416979,134242304,139264,2048,2048,131072,2048,0,0,65,4031,0,1982,146065308,5147482.869,7864320,9043937,1953.686249,0,66752,0
+sparse_slots64,threshold4,1,ok,threshold,True,8388608,72640,143312,143312,64,1638400,27246592,linux_proc_vmhwm_approximate,168266032,25648470,134242304,139264,2048,2048,131072,2048,0,0,65,4031,0,1982,146554478,5170189.028,7864320,8853271,1979.901257,0,66752,0
+sparse_slots64,copy_no_pool,1,ok,copy,False,8388608,72640,143312,143312,64,1638400,27246592,linux_proc_vmhwm_approximate,167352998,26167797,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,1982,145161257,5140939.162,7864320,9037974,1975.871965,0,0,0
+sparse_slots64,threshold8,1,ok,threshold,True,8388608,72640,143312,143312,64,1638400,27246592,linux_proc_vmhwm_approximate,167352294,26149112,134242304,139264,2048,2048,131072,2048,0,0,65,4031,0,1982,145164575,5140639.04,7864320,9055067,1998.899707,0,66752,0
+sparse_slots64,project,1,ok,project,True,8388608,72640,77760,77760,64,1589248,27246592,linux_proc_vmhwm_approximate,167537794,26582472,134242304,139264,2048,2048,0,0,0,0,64,1984,0,1983,144932270,5144362.881,7864320,9070492,842.776507,0,1280,0
+sparse_slots64,copy,1,ok,copy,True,8388608,72640,143312,143312,64,1638400,27246592,linux_proc_vmhwm_approximate,177068451,34395657,134242304,139264,2048,2048,131072,2048,0,0,65,4031,0,1964,148816905,5443811.067,9437184,9497139,2287.854324,0,66752,0
+sparse_slots64,borrow,1,ok,borrow,True,8388608,72640,4267968,4267968,64,5292032,27246592,linux_proc_vmhwm_approximate,169327288,47272489,134242304,139264,2048,2048,0,0,2048,0,64,1984,0,1559,125366124,5174744.393,7864320,7999125,694635.953387,0,1048832,0
+sparse_slots64,threshold4,2,ok,threshold,True,8388608,72640,143312,143312,64,1638400,27246592,linux_proc_vmhwm_approximate,166910296,25474992,134242304,139264,2048,2048,131072,2048,0,0,65,4031,0,1982,145193155,5128818.551,7864320,9004900,1987.487947,0,66752,0
+sparse_slots64,copy_no_pool,2,ok,copy,False,8388608,72640,143312,143312,64,1654784,27246592,linux_proc_vmhwm_approximate,167128888,26220522,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,1980,144715144,5134877.701,7864320,9062770,2002.587942,0,0,0
+sparse_slots64,threshold2,2,ok,threshold,True,8388608,72640,143312,143312,64,1638400,27246592,linux_proc_vmhwm_approximate,167148609,25957735,134242304,139264,2048,2048,131072,2048,0,0,65,4031,0,1977,145051954,5131955.022,7864320,9073752,1998.277517,0,66752,0
+sparse_slots64,threshold8,2,ok,threshold,True,8388608,72640,143312,143312,64,1638400,27246592,linux_proc_vmhwm_approximate,169611954,32276554,134242304,139264,2048,2048,131072,2048,0,0,65,4031,0,1914,142094763,5206380.796,7864320,8901622,2300.08379,0,66752,0
+sparse_slots64,project,2,ok,project,True,8388608,72640,77760,77760,64,1589248,27246592,linux_proc_vmhwm_approximate,171072487,27568676,134242304,139264,2048,2048,0,0,0,0,64,1984,0,1973,147623196,5258257.061,7864320,9512213,861.43609,0,1280,0
+sparse_slots64,copy,2,ok,copy,True,8388608,72640,143312,143312,64,1638400,27246592,linux_proc_vmhwm_approximate,169338770,27312589,134242304,139264,2048,2048,131072,2048,0,0,65,4031,0,1973,146307420,5201400.59,7864320,9016640,2055.277015,0,66752,0
+sparse_slots64,pressure,2,ok,pressure,True,8388608,72640,4268048,4268048,64,5767168,27246592,linux_proc_vmhwm_approximate,170783358,46177893,134242304,139264,2048,2048,2048,32,2016,32,65,2015,0,1534,127950932,5236882.494,7340032,7222257,691939.11555,0,1048832,0
+sparse_slots64,borrow,2,ok,borrow,True,8388608,72640,4267968,4267968,64,5292032,27246592,linux_proc_vmhwm_approximate,167156999,43876108,134242304,139264,2048,2048,0,0,2048,0,64,1984,0,1884,127058453,5126798.896,6815744,6645517,688213.378653,0,1048832,0
+sparse_slots64,threshold4,3,ok,threshold,True,8388608,72640,143312,143312,64,1638400,27246592,linux_proc_vmhwm_approximate,166770166,25212214,134242304,139264,2048,2048,131072,2048,0,0,65,4031,0,1984,145249611,5126749.497,7864320,9015048,1964.863682,0,66752,0
+sparse_slots64,copy,3,ok,copy,True,8388608,72640,143312,143312,64,1654784,27246592,linux_proc_vmhwm_approximate,167909533,27850375,134242304,139264,2048,2048,131072,2048,0,0,65,4031,0,1956,144091763,5137672.764,7864320,9072455,2094.171152,0,66752,0
+sparse_slots64,threshold8,3,ok,threshold,True,8388608,72640,143312,143312,64,1638400,27246592,linux_proc_vmhwm_approximate,168528180,32536976,134242304,139264,2048,2048,131072,2048,0,0,65,4031,0,1897,140338194,5169990.139,7864320,8583716,2319.792062,0,66752,0
+sparse_slots64,copy_no_pool,3,ok,copy,False,8388608,72640,143312,143312,64,1654784,27246592,linux_proc_vmhwm_approximate,166715000,24659146,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,1984,145786851,5125611.619,7864320,9016234,1919.204343,0,0,0
+sparse_slots64,threshold2,3,ok,threshold,True,8388608,72640,143312,143312,64,1654784,27246592,linux_proc_vmhwm_approximate,167074462,26663004,134242304,139264,2048,2048,131072,2048,0,0,65,4031,0,1972,144308149,5134098.172,7864320,9056067,2041.253864,0,66752,0
+sparse_slots64,project,3,ok,project,True,8388608,72640,77760,77760,64,1572864,27246592,linux_proc_vmhwm_approximate,166784685,25542781,134242304,139264,2048,2048,0,0,0,0,64,1984,0,1985,144995208,5128089.141,7864320,9028215,840.114114,0,1280,0
+sparse_slots64,pressure,3,ok,pressure,True,8388608,72640,4268048,4268048,64,5750784,27246592,linux_proc_vmhwm_approximate,167121239,44137216,134242304,139264,2048,2048,2048,32,2016,32,65,2015,0,1831,126710351,5127462.262,7340032,7853292,677483.645644,0,1048832,0
+sparse_slots64,borrow,3,ok,borrow,True,8388608,72640,4267968,4267968,64,5292032,27246592,linux_proc_vmhwm_approximate,167212479,44714000,134242304,139264,2048,2048,0,0,2048,0,64,1984,0,1813,126101064,5127098.881,6291456,6795851,688253.763142,0,1048832,0
+sparse_slots64,threshold8,4,ok,threshold,True,8388608,72640,143312,143312,64,1622016,27246592,linux_proc_vmhwm_approximate,166717963,24687036,134242304,139264,2048,2048,131072,2048,0,0,65,4031,0,1983,145714382,5125971.683,7864320,8962826,1940.992711,0,66752,0
+sparse_slots64,copy,4,ok,copy,True,8388608,72640,143312,143312,64,1638400,27246592,linux_proc_vmhwm_approximate,166680851,24341624,134242304,139264,2048,2048,131072,2048,0,0,65,4031,0,1985,146024444,5125321.995,7864320,9060326,1923.416256,0,66752,0
+sparse_slots64,threshold4,4,ok,threshold,True,8388608,72640,143312,143312,64,1654784,27246592,linux_proc_vmhwm_approximate,166829203,24368638,134242304,139264,2048,2048,131072,2048,0,0,65,4031,0,1984,146127572,5127589.86,7864320,9064418,1922.285206,0,66752,0
+sparse_slots64,project,4,ok,project,True,8388608,72640,77760,77760,64,1589248,27246592,linux_proc_vmhwm_approximate,167505794,25505816,134242304,139264,2048,2048,0,0,0,0,64,1984,0,1985,145758292,5149157.839,7864320,9024826,843.565622,0,1280,0
+sparse_slots64,copy_no_pool,4,ok,copy,False,8388608,72640,143312,143312,64,1638400,27246592,linux_proc_vmhwm_approximate,167165609,25932182,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,1976,145075045,5133720.043,7864320,9029714,1986.249813,0,0,0
+sparse_slots64,borrow,4,ok,borrow,True,8388608,72640,4267968,4267968,64,5292032,27246592,linux_proc_vmhwm_approximate,167597886,45634483,134242304,139264,2048,2048,0,0,2048,0,64,1984,0,1768,125625299,5136396.266,7340032,8047606,689499.931113,0,1048832,0
+sparse_slots64,threshold2,4,ok,threshold,True,8388608,72640,143312,143312,64,1638400,27246592,linux_proc_vmhwm_approximate,166724425,24304145,134242304,139264,2048,2048,131072,2048,0,0,65,4031,0,1984,146112652,5125215.218,7864320,8987715,1915.595622,0,66752,0
+sparse_slots64,pressure,4,ok,pressure,True,8388608,72640,4268048,4268048,64,5750784,27246592,linux_proc_vmhwm_approximate,167102943,43204463,134242304,139264,2048,2048,2048,32,2016,32,65,2015,0,1902,127501222,5127130.23,7340032,7758552,677439.045656,0,1048832,0
+dense_slow,copy_no_pool,0,ok,copy,False,8388608,90560,8350112,8350112,125,9486336,27246592,linux_proc_vmhwm_approximate,181746660,79318230,134242304,100671488,2048,2048,100663296,2048,0,0,4096,0,1923,0,106431291,10743611.753,12582912,12983832,1442582.012105,0,0,0
+dense_slow,threshold4,0,ok,threshold,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,161215386,89862451,134242304,100671488,2048,2048,0,0,2048,0,126,1922,1244,0,73999062,9530310.653,11534336,11475412,1273441.862727,0,1048832,0
+dense_slow,pressure,0,ok,pressure,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,181545716,79933333,134242304,100671488,2048,2048,0,0,2048,0,126,1922,1794,0,105524896,10805826.457,12582912,13598424,1442046.73663,0,1048832,0
+dense_slow,threshold2,0,ok,threshold,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,179808887,82476393,134242304,100671488,2048,2048,0,0,2048,0,126,1922,1739,0,101034766,10695483.804,12582912,13755645,1427516.577261,0,1048832,0
+dense_slow,copy,0,ok,copy,True,8388608,90560,8350112,8350112,125,9486336,27246592,linux_proc_vmhwm_approximate,181070273,83392187,134242304,100671488,2048,2048,100663296,2048,0,0,126,3970,1923,0,101645153,10688072.436,12582912,13270480,1435135.645514,0,1048832,0
+dense_slow,borrow,0,ok,borrow,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,182712953,81359541,134242304,100671488,2048,2048,0,0,2048,0,126,1922,1784,0,105215055,10867028.691,12582912,13321591,1450265.685197,0,1048832,0
+dense_slow,project,0,ok,project,True,8388608,90560,8350112,8350112,126,9469952,27246592,linux_proc_vmhwm_approximate,187716865,74974355,134242304,100671488,2048,2048,0,0,0,0,126,1922,1885,0,116741671,11188037.068,12582912,13610887,1492582.952313,0,1048832,0
+dense_slow,threshold8,0,ok,threshold,True,8388608,90560,8350112,8350112,126,9469952,27246592,linux_proc_vmhwm_approximate,177819652,80765616,134242304,100671488,2048,2048,0,0,2048,0,126,1922,1732,0,100790270,10569593.51,12582912,12515889,1410709.704111,0,1048832,0
+dense_slow,copy_no_pool,1,ok,copy,False,8388608,90560,8350112,8350112,125,9469952,27246592,linux_proc_vmhwm_approximate,183713376,79010560,134242304,100671488,2048,2048,100663296,2048,0,0,4096,0,1923,0,108825186,10852089.214,12582912,12891240,1457141.599471,0,0,0
+dense_slow,threshold8,1,ok,threshold,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,181690178,80219667,134242304,100671488,2048,2048,0,0,2048,0,126,1922,1787,0,105238489,10811191.05,12582912,13211998,1442791.441175,0,1048832,0
+dense_slow,project,1,ok,project,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,187516958,75386397,134242304,100671488,2048,2048,0,0,0,0,126,1922,1881,0,116242907,11180449.479,12582912,13778256,1491587.457419,0,1048832,0
+dense_slow,pressure,1,ok,pressure,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,181604364,78951924,134242304,100671488,2048,2048,0,0,2048,0,126,1922,1764,0,106543831,10804561.506,12582912,13821367,1441898.713593,0,1048832,0
+dense_slow,copy,1,ok,copy,True,8388608,90560,8350112,8350112,125,9469952,27246592,linux_proc_vmhwm_approximate,162629252,88543490,134242304,100671488,2048,2048,100663296,2048,0,0,126,3970,1913,0,77289755,9526763.21,12582912,13455924,1279274.820821,0,1048832,0
+dense_slow,threshold2,1,ok,threshold,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,177629041,82100973,134242304,100671488,2048,2048,0,0,2048,0,126,1922,1640,0,98770708,10557136.903,12582912,13384591,1409274.391678,0,1048832,0
+dense_slow,borrow,1,ok,borrow,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,176146657,82398748,134242304,100671488,2048,2048,0,0,2048,0,126,1922,1605,0,97290225,10456864.841,12582912,12598464,1395956.019109,0,1048832,0
+dense_slow,threshold4,1,ok,threshold,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,177871837,82048383,134242304,100671488,2048,2048,0,0,2048,0,126,1922,1692,0,99804043,10550904.139,12582912,13302146,1408308.914356,0,1048832,0
+dense_slow,copy,2,ok,copy,True,8388608,90560,8350112,8350112,125,9486336,27246592,linux_proc_vmhwm_approximate,178298984,83177513,134242304,100671488,2048,2048,100663296,2048,0,0,126,3970,1922,0,99077474,10508907.261,12582912,13207943,1411086.299499,0,1048832,0
+dense_slow,project,2,ok,project,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,181467845,82821089,134242304,100671488,2048,2048,0,0,0,0,126,1922,1672,0,102626015,10774249.202,12582912,12846870,1438045.689091,0,1048832,0
+dense_slow,threshold2,2,ok,threshold,True,8388608,90560,8350112,8350112,126,9469952,27246592,linux_proc_vmhwm_approximate,133633132,106591389,134242304,100671488,2048,2048,0,0,2048,0,126,1922,396,0,28102711,7778565.752,11534336,12128873,1042347.024547,0,1048832,0
+dense_slow,threshold4,2,ok,threshold,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,177934893,82638851,134242304,100671488,2048,2048,0,0,2048,0,126,1922,1719,0,98938213,10577573.546,12582912,12061188,1411845.015325,0,1048832,0
+dense_slow,pressure,2,ok,pressure,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,180208516,83532190,134242304,100671488,2048,2048,0,0,2048,0,126,1922,1755,0,100354141,10704952.958,11534336,11578059,1428781.613196,0,1048832,0
+dense_slow,copy_no_pool,2,ok,copy,False,8388608,90560,8350112,8350112,125,9486336,27246592,linux_proc_vmhwm_approximate,185672333,80542923,134242304,100671488,2048,2048,100663296,2048,0,0,4096,0,1923,0,109123678,10977524.849,12582912,13368332,1473966.510893,0,0,0
+dense_slow,threshold8,2,ok,threshold,True,8388608,90560,8350112,8350112,126,9469952,27246592,linux_proc_vmhwm_approximate,184526170,78362511,134242304,100671488,2048,2048,0,0,2048,0,126,1922,1834,0,110126299,10988073.928,12582912,13728757,1466214.025114,0,1048832,0
+dense_slow,borrow,2,ok,borrow,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,186194683,78514601,134242304,100671488,2048,2048,0,0,2048,0,126,1922,1865,0,111800399,11071491.94,12582912,13571164,1477291.36261,0,1048832,0
+dense_slow,project,3,ok,project,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,181552086,80699818,134242304,100671488,2048,2048,0,0,0,0,126,1922,1690,0,104861831,10716792.58,12582912,12527594,1430323.101776,0,1048832,0
+dense_slow,threshold2,3,ok,threshold,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,176007991,84507344,134242304,100671488,2048,2048,0,0,2048,0,126,1922,1626,0,94771244,10450519.416,12582912,13672942,1395156.109095,0,1048832,0
+dense_slow,threshold4,3,ok,threshold,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,152737854,99861953,134242304,100671488,2048,2048,0,0,2048,0,126,1922,890,0,54158702,8983717.571,12582912,12746037,1201774.933886,0,1048832,0
+dense_slow,copy,3,ok,copy,True,8388608,90560,8350112,8350112,125,9486336,27246592,linux_proc_vmhwm_approximate,184530299,78669541,134242304,100671488,2048,2048,100663296,2048,0,0,126,3970,1923,0,109915619,10914646.174,12582912,13287517,1465541.553301,0,1048832,0
+dense_slow,copy_no_pool,3,ok,copy,False,8388608,90560,8350112,8350112,125,9486336,27246592,linux_proc_vmhwm_approximate,133391651,112766017,134242304,100671488,2048,2048,100663296,2048,0,0,4096,0,1523,0,20003852,7733517.169,11534336,11792151,1038602.867364,0,0,0
+dense_slow,borrow,3,ok,borrow,True,8388608,90560,8350112,8350112,126,9469952,27246592,linux_proc_vmhwm_approximate,166473036,87150086,134242304,100671488,2048,2048,0,0,2048,0,126,1922,1399,0,82606050,9857584.602,12582912,13713590,1316650.677161,0,1048832,0
+dense_slow,threshold8,3,ok,threshold,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,154311406,92958406,134242304,100671488,2048,2048,0,0,2048,0,126,1922,1082,0,62034758,9096496.741,11534336,11453763,1216142.805053,0,1048832,0
+dense_slow,pressure,3,ok,pressure,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,172422001,86572890,134242304,100671488,2048,2048,0,0,2048,0,126,1922,1520,0,89162361,10222342.367,12582912,13171721,1365000.503032,0,1048832,0
+dense_slow,copy,4,ok,copy,True,8388608,90560,8350112,8350112,125,9486336,27246592,linux_proc_vmhwm_approximate,182776175,83801034,134242304,100671488,2048,2048,100663296,2048,0,0,126,3970,1923,0,102610607,10792342.655,12582912,13409628,1449128.406768,0,1048832,0
+dense_slow,project,4,ok,project,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,172321224,93701381,134242304,100671488,2048,2048,0,0,0,0,126,1922,1317,0,81313113,10121009.211,13631488,13629442,1352204.310615,0,1048832,0
+dense_slow,threshold8,4,ok,threshold,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,161726717,90653564,134242304,100671488,2048,2048,0,0,2048,0,126,1922,1291,0,73742733,9543033.955,12582912,13496479,1275079.33543,0,1048832,0
+dense_slow,copy_no_pool,4,ok,copy,False,8388608,90560,8350112,8350112,125,9486336,27246592,linux_proc_vmhwm_approximate,168343995,87047828,134242304,100671488,2048,2048,100663296,2048,0,0,4096,0,1917,0,84775336,9903397.208,12582912,13360535,1329804.191236,0,0,0
+dense_slow,threshold4,4,ok,threshold,True,8388608,90560,8350112,8350112,126,9469952,27246592,linux_proc_vmhwm_approximate,150178547,91472405,134242304,100671488,2048,2048,0,0,2048,0,126,1922,1089,0,61163642,8764951.531,12582912,12700278,1171761.488413,0,1048832,0
+dense_slow,borrow,4,ok,borrow,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,160544406,90636057,134242304,100671488,2048,2048,0,0,2048,0,126,1922,1220,0,72541038,9456018.519,13631488,12662167,1263635.432461,0,1048832,0
+dense_slow,threshold2,4,ok,threshold,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,177206635,83537344,134242304,100671488,2048,2048,0,0,2048,0,126,1922,1659,0,97328864,10529385.897,11534336,12256668,1405563.035864,0,1048832,0
+dense_slow,pressure,4,ok,pressure,True,8388608,90560,8350112,8350112,126,9486336,27246592,linux_proc_vmhwm_approximate,169205769,93894859,134242304,100671488,2048,2048,0,0,2048,0,126,1922,1358,0,77830920,9905630.789,14680064,15320344,1323477.613603,0,1048832,0
+mixed_slow,pressure,0,ok,pressure,True,8388608,90560,8388560,8388448,351,11059200,27246592,linux_proc_vmhwm_approximate,157820358,72816171,177631232,53735632,2048,2048,27916032,1699,349,1699,2118,1629,983,0,87435519,20627967.734,27262976,27848623,1145134.388634,0,522496,0
+mixed_slow,project,0,ok,project,True,8388608,90560,8388608,8388608,359,11059200,27246592,linux_proc_vmhwm_approximate,152663243,58871841,177631232,53735632,2048,2048,0,0,0,0,1712,336,1020,0,96564951,20645944.552,29360128,28536362,1105768.632536,0,458688,0
+mixed_slow,threshold8,0,ok,threshold,True,8388608,90560,8388480,8388432,218,10928128,27246592,linux_proc_vmhwm_approximate,154865144,68111825,177631232,53735632,2048,2048,3824848,1008,1040,0,1854,1202,1088,0,89372126,12505668.119,15728640,16314249,1173514.267706,0,1250624,0
+mixed_slow,copy_no_pool,0,ok,copy,False,8388608,90560,8388544,8388544,351,11042816,27246592,linux_proc_vmhwm_approximate,147730720,59461567,177631232,53735632,2048,2048,53727440,2048,0,0,4096,0,1091,0,90844456,19373026.656,27262976,27720475,1058083.377077,0,0,0
+mixed_slow,threshold4,0,ok,threshold,True,8388608,90560,8388608,8388608,284,11042816,27246592,linux_proc_vmhwm_approximate,154278831,65116485,177631232,53735632,2048,2048,11229392,1357,691,0,1939,1466,1101,0,91754428,15979998.057,20971520,21200642,1146944.244493,0,1153216,0
+mixed_slow,copy,0,ok,copy,True,8388608,90560,8388576,8388432,351,11583488,27246592,linux_proc_vmhwm_approximate,148231627,61867221,177631232,53735632,2048,2048,53727440,2048,0,0,2282,1814,1066,0,88853774,19421431.677,27262976,27565124,1061176.084143,0,522496,0
+mixed_slow,threshold2,0,ok,threshold,True,8388608,90560,8388560,8388432,351,11583488,27246592,linux_proc_vmhwm_approximate,151434543,63073539,177631232,53735632,2048,2048,28479696,1740,308,0,2181,1607,1055,0,90878850,19880247.948,27262976,27687586,1085460.729712,0,522496,0
+mixed_slow,borrow,0,ok,borrow,True,8388608,90560,8386736,8386688,112,11042816,27246592,linux_proc_vmhwm_approximate,155306143,76020257,177631232,53735632,2048,2048,0,0,2048,0,1309,739,1057,0,81695551,6922951.601,9437184,8980622,1223077.166921,0,667904,0
+mixed_slow,copy,1,ok,copy,True,8388608,90560,8388560,8388432,350,11059200,27246592,linux_proc_vmhwm_approximate,160379239,76853903,177631232,53735632,2048,2048,53727440,2048,0,0,2142,1954,945,0,86445280,20559126.612,31457280,31399761,1126649.918907,0,519424,0
+mixed_slow,threshold2,1,ok,threshold,True,8388608,90560,8388560,8388432,351,11059200,27246592,linux_proc_vmhwm_approximate,154875385,62824900,177631232,53735632,2048,2048,28479696,1740,308,0,2184,1604,1064,0,94824069,20387628.756,29360128,28330122,1114766.522227,0,522496,0
+mixed_slow,borrow,1,ok,borrow,True,8388608,90560,8386736,8386688,112,11059200,27246592,linux_proc_vmhwm_approximate,160560980,82185381,177631232,53735632,2048,2048,0,0,2048,0,1298,750,1014,0,81045212,7165375.219,9437184,9128899,1265871.620641,0,667904,0
+mixed_slow,threshold8,1,ok,threshold,True,8388608,90560,8388480,8388432,218,10895360,27246592,linux_proc_vmhwm_approximate,158376930,70010099,177631232,53735632,2048,2048,3824848,1008,1040,0,1840,1216,1069,0,91117649,12818618.589,16777216,16509452,1202455.090015,0,1250624,0
+mixed_slow,threshold4,1,ok,threshold,True,8388608,90560,8388608,8388608,284,11059200,27246592,linux_proc_vmhwm_approximate,158364004,67436217,177631232,53735632,2048,2048,11229392,1357,691,0,1915,1490,1082,0,93660619,16427087.508,23068672,21701826,1180098.881536,0,1153216,0
+mixed_slow,pressure,1,ok,pressure,True,8388608,90560,8388560,8388432,351,11059200,27246592,linux_proc_vmhwm_approximate,150598212,62794080,177631232,53735632,2048,2048,27916032,1699,349,1699,2194,1553,1045,0,90472858,19666383.09,27262976,27539921,1091553.931133,0,522496,0
+mixed_slow,copy_no_pool,1,ok,copy,False,8388608,90560,8388432,8388432,351,11042816,27246592,linux_proc_vmhwm_approximate,147750665,60136047,177631232,53735632,2048,2048,53727440,2048,0,0,4096,0,1079,0,90065234,19383039.199,27262976,27513476,1059302.637881,0,0,0
+mixed_slow,project,1,ok,project,True,8388608,90560,8388608,8388608,359,11583488,27246592,linux_proc_vmhwm_approximate,161035903,71350453,177631232,53735632,2048,2048,0,0,0,0,1684,364,940,0,92840414,21900800.478,31457280,29845877,1171929.531923,0,458688,0
+mixed_slow,copy_no_pool,2,ok,copy,False,8388608,90560,8388432,8388432,344,11059200,27246592,linux_proc_vmhwm_approximate,156784527,75333533,177631232,53735632,2048,2048,53727440,2048,0,0,4096,0,936,0,83839404,20060454.119,27262976,27533828,1101855.462406,0,0,0
+mixed_slow,project,2,ok,project,True,8388608,90560,8388608,8388608,359,11042816,27246592,linux_proc_vmhwm_approximate,155323458,61447221,177631232,53735632,2048,2048,0,0,0,0,1698,350,1001,0,96575508,21013565.399,29360128,28307510,1125180.461018,0,458688,0
+mixed_slow,copy,2,ok,copy,True,8388608,90560,8388576,8388544,351,11583488,27246592,linux_proc_vmhwm_approximate,148908587,62691660,177631232,53735632,2048,2048,53727440,2048,0,0,2295,1801,1060,0,88867276,19542842.845,27262976,27366569,1068483.42084,0,522496,0
+mixed_slow,threshold8,2,ok,threshold,True,8388608,90560,8388480,8388432,218,10895360,27246592,linux_proc_vmhwm_approximate,155250569,68193969,177631232,53735632,2048,2048,3824848,1008,1040,0,1856,1200,1091,0,89649032,12540132.329,15728640,16196379,1176609.476886,0,1250624,0
+mixed_slow,threshold4,2,ok,threshold,True,8388608,90560,8388608,8388608,284,11059200,27246592,linux_proc_vmhwm_approximate,153993443,64368954,177631232,53735632,2048,2048,11229392,1357,691,0,1951,1454,1113,0,92271541,15971202.74,20971520,20927051,1146423.83916,0,1153216,0
+mixed_slow,borrow,2,ok,borrow,True,8388608,90560,8386736,8386688,112,11059200,27246592,linux_proc_vmhwm_approximate,156530676,80398481,177631232,53735632,2048,2048,0,0,2048,0,1289,759,1012,0,78480840,6972909.934,9437184,9059956,1232378.631527,0,667904,0
+mixed_slow,threshold2,2,ok,threshold,True,8388608,90560,8388560,8388432,351,11010048,27246592,linux_proc_vmhwm_approximate,150924192,62137633,177631232,53735632,2048,2048,28479696,1740,308,0,2185,1603,1066,0,91396144,19908205.041,27262976,27188866,1087150.034862,0,522496,0
+mixed_slow,pressure,2,ok,pressure,True,8388608,90560,8388560,8388432,351,11042816,27246592,linux_proc_vmhwm_approximate,151817449,63923421,177631232,53735632,2048,2048,27916032,1699,349,1699,2188,1559,1043,0,90636475,19811286.8,27262976,27547513,1100686.98981,0,522496,0
+mixed_slow,pressure,3,ok,pressure,True,8388608,90560,8388560,8388432,351,11059200,27246592,linux_proc_vmhwm_approximate,150346490,61910200,177631232,53735632,2048,2048,27916032,1699,349,1699,2191,1556,1052,0,90957629,19620014.043,27262976,27598753,1088594.710179,0,522496,0
+mixed_slow,borrow,3,ok,borrow,True,8388608,90560,8386736,8386736,112,11059200,27246592,linux_proc_vmhwm_approximate,154664385,75260445,177631232,53735632,2048,2048,0,0,2048,0,1309,739,1060,0,81727723,6891592.543,9437184,9042474,1217311.080951,0,667904,0
+mixed_slow,copy_no_pool,3,ok,copy,False,8388608,90560,8388448,8388448,351,11583488,27246592,linux_proc_vmhwm_approximate,149074586,62457772,177631232,53735632,2048,2048,53727440,2048,0,0,4096,0,1070,0,89108781,19570212.309,27262976,27735827,1068598.834234,0,0,0
+mixed_slow,threshold2,3,ok,threshold,True,8388608,90560,8388560,8388448,351,11010048,27246592,linux_proc_vmhwm_approximate,151416673,62409227,177631232,53735632,2048,2048,28479696,1740,308,0,2196,1592,1072,0,91608903,19945957.829,27262976,27499217,1089269.648492,0,522496,0
+mixed_slow,threshold8,3,ok,threshold,True,8388608,90560,8388480,8388432,218,10928128,27246592,linux_proc_vmhwm_approximate,154832681,68708379,177631232,53735632,2048,2048,3824848,1008,1040,0,1844,1212,1080,0,88746131,12500210.727,15728640,16133805,1173410.180784,0,1250624,0
+mixed_slow,threshold4,3,ok,threshold,True,8388608,90560,8388608,8388608,284,11059200,27246592,linux_proc_vmhwm_approximate,153954221,64939588,177631232,53735632,2048,2048,11229392,1357,691,0,1938,1467,1106,0,91640646,15956645.429,20971520,20876513,1145843.306835,0,1153216,0
+mixed_slow,copy,3,ok,copy,True,8388608,90560,8388576,8388432,348,11026432,27246592,linux_proc_vmhwm_approximate,154316312,71405240,177631232,53735632,2048,2048,53727440,2048,0,0,2185,1911,984,0,85159635,20042799.471,27262976,27766253,1098260.452799,0,522496,0
+mixed_slow,project,3,ok,project,True,8388608,90560,8388608,8388608,359,11567104,27246592,linux_proc_vmhwm_approximate,153157278,59550541,177631232,53735632,2048,2048,0,0,0,0,1715,333,1025,0,96249111,20737608.082,29360128,28456288,1110823.213775,0,458688,0
+mixed_slow,copy,4,ok,copy,True,8388608,90560,8388576,8388432,351,11583488,27246592,linux_proc_vmhwm_approximate,148559421,60872675,177631232,53735632,2048,2048,53727440,2048,0,0,2291,1805,1082,0,90209021,19484771.246,27262976,27464198,1064901.546602,0,522496,0
+mixed_slow,threshold2,4,ok,threshold,True,8388608,90560,8388560,8388432,351,11042816,27246592,linux_proc_vmhwm_approximate,152463225,62941260,177631232,53735632,2048,2048,28479696,1740,308,0,2190,1598,1076,0,92180791,20063222.989,27262976,27720123,1096182.913762,0,522496,0
+mixed_slow,project,4,ok,project,True,8388608,90560,8388608,8388608,359,11567104,27246592,linux_proc_vmhwm_approximate,156226158,60922941,177631232,53735632,2048,2048,0,0,0,0,1712,336,1009,0,98129027,21028903.054,31457280,30198524,1124769.099854,0,458688,0
+mixed_slow,threshold8,4,ok,threshold,True,8388608,90560,8388480,8388432,218,10534912,27246592,linux_proc_vmhwm_approximate,159080169,72479922,177631232,53735632,2048,2048,3824848,1008,1040,0,1823,1233,1052,0,89038311,12767575.616,16777216,17017117,1198559.835478,0,1250624,0
+mixed_slow,borrow,4,ok,borrow,True,8388608,90560,8386736,8386688,112,11059200,27246592,linux_proc_vmhwm_approximate,160859182,83693169,177631232,53735632,2048,2048,0,0,2048,0,1286,762,998,0,79719697,7168367.113,9437184,9348362,1265838.726396,0,667904,0
+mixed_slow,copy_no_pool,4,ok,copy,False,8388608,90560,8388432,8388432,350,11059200,27246592,linux_proc_vmhwm_approximate,153665517,63556619,177631232,53735632,2048,2048,53727440,2048,0,0,4096,0,1061,0,92811834,20225367.343,29360128,27663216,1106709.142867,0,0,0
+mixed_slow,threshold4,4,ok,threshold,True,8388608,90560,8388608,8388608,284,11059200,27246592,linux_proc_vmhwm_approximate,154918866,67062426,177631232,53735632,2048,2048,11229392,1357,691,0,1917,1488,1084,0,90513202,16065937.041,20971520,20956347,1153471.713074,0,1153216,0
+mixed_slow,pressure,4,ok,pressure,True,8388608,90560,8388560,8388432,351,11026432,27246592,linux_proc_vmhwm_approximate,150607823,62564984,177631232,53735632,2048,2048,27916032,1699,349,1699,2185,1562,1048,0,90639036,19672453.154,27262976,27555809,1091824.795529,0,522496,0
+mixed_tight,pressure,0,ok,pressure,True,2097152,90560,2097136,2097136,113,4243456,27246592,linux_proc_vmhwm_approximate,190186189,62042049,177631232,53735632,2048,2048,28385168,1727,321,1727,2373,1402,1378,0,130967488,6127305.056,8388608,9614324,346183.559002,0,523712,0
+mixed_tight,project,0,ok,project,True,2097152,90560,2097120,2097120,118,4227072,27246592,linux_proc_vmhwm_approximate,175306603,59313331,177631232,53735632,2048,2048,0,0,0,0,1720,328,1300,0,118791611,6273925.584,8388608,8853437,326279.178906,0,406848,0
+mixed_tight,threshold4,0,ok,threshold,True,2097152,90560,2097136,2097104,88,4227072,27246592,linux_proc_vmhwm_approximate,225451606,64792167,177631232,53735632,2048,2048,11229392,1357,691,0,2134,1271,1457,0,163697658,5851904.688,7864320,10247748,413690.587373,0,435392,0
+mixed_tight,copy,0,ok,copy,True,2097152,90560,2097152,2097136,115,4227072,27246592,linux_proc_vmhwm_approximate,191774166,62795054,177631232,53735632,2048,2048,53727440,2048,0,0,2467,1629,1361,0,131825729,6045168.869,8388608,8688826,346452.547175,0,523712,0
+mixed_tight,copy_no_pool,0,ok,copy,False,2097152,90560,2097136,2097136,107,4243456,27246592,linux_proc_vmhwm_approximate,195726691,69455356,177631232,53735632,2048,2048,53727440,2048,0,0,4096,0,1284,0,128917157,6157981.172,9437184,9013123,353204.287515,0,0,0
+mixed_tight,threshold8,0,ok,threshold,True,2097152,90560,2097152,2097136,73,4227072,27246592,linux_proc_vmhwm_approximate,284917692,71405280,177631232,53735632,2048,2048,3824848,1008,1040,0,1986,1070,1377,0,216762211,5735627.926,7864320,9131844,525336.273255,0,386176,0
+mixed_tight,borrow,0,ok,borrow,True,2097152,90560,2094128,2094128,40,3702784,27246592,linux_proc_vmhwm_approximate,493631884,81275705,177631232,53735632,2048,2048,0,0,2048,0,1338,710,1381,0,416164894,5487868.994,8388608,10310562,930117.776585,0,495872,0
+mixed_tight,threshold2,0,ok,threshold,True,2097152,90560,2097136,2097136,115,4227072,27246592,linux_proc_vmhwm_approximate,188818619,63133028,177631232,53735632,2048,2048,28479696,1740,308,0,2370,1418,1385,0,128526332,6127166.122,8388608,8910974,342945.952067,0,523712,0
+mixed_tight,project,1,ok,project,True,2097152,90560,2097120,2097120,118,4243456,27246592,linux_proc_vmhwm_approximate,179280258,63072197,177631232,53735632,2048,2048,0,0,0,0,1706,342,1292,0,119263134,6405571.191,9437184,9266621,333023.673744,0,406848,0
+mixed_tight,threshold8,1,ok,threshold,True,2097152,90560,2097136,2097136,72,4358144,27246592,linux_proc_vmhwm_approximate,289852215,73110582,177631232,53735632,2048,2048,3824848,1008,1040,0,1968,1088,1366,0,216619289,5811531.61,10485760,14653198,533913.89253,0,386176,0
+mixed_tight,copy_no_pool,1,ok,copy,False,2097152,90560,2097136,2097136,117,4243456,27246592,linux_proc_vmhwm_approximate,192676756,64089681,177631232,53735632,2048,2048,53727440,2048,0,0,4096,0,1353,0,131367991,6074626.45,9437184,9595565,347823.24917,0,0,0
+mixed_tight,pressure,1,ok,pressure,True,2097152,90560,2097136,2097136,115,4456448,27246592,linux_proc_vmhwm_approximate,190841576,65297407,177631232,53735632,2048,2048,28385168,1727,321,1727,2364,1411,1367,0,128364836,6138653.731,8388608,9614713,347120.008423,0,523712,0
+mixed_tight,copy,1,ok,copy,True,2097152,90560,2097152,2097136,114,4407296,27246592,linux_proc_vmhwm_approximate,191186483,62157319,177631232,53735632,2048,2048,53727440,2048,0,0,2461,1635,1369,0,131673734,6044094.394,8388608,8856067,346056.920887,0,523712,0
+mixed_tight,threshold2,1,ok,threshold,True,2097152,90560,2097136,2097136,116,4227072,27246592,linux_proc_vmhwm_approximate,189607302,65204064,177631232,53735632,2048,2048,28479696,1740,308,0,2354,1434,1374,0,127228274,6129531.969,8388608,8917400,344084.726971,0,523712,0
+mixed_tight,threshold4,1,ok,threshold,True,2097152,90560,2097136,2097104,88,4227072,27246592,linux_proc_vmhwm_approximate,225029662,63936677,177631232,53735632,2048,2048,11229392,1357,691,0,2132,1273,1459,0,164083415,5845044.948,7864320,10255656,413025.125756,0,435392,0
+mixed_tight,borrow,1,ok,borrow,True,2097152,90560,2094128,2094128,40,3719168,27246592,linux_proc_vmhwm_approximate,493081274,77876795,177631232,53735632,2048,2048,0,0,2048,0,1342,706,1396,0,417981885,5480641.02,8388608,9914990,929020.44715,0,495872,0
+mixed_tight,borrow,2,ok,borrow,True,2097152,90560,2094128,2094128,40,4243456,27246592,linux_proc_vmhwm_approximate,491778453,73168533,177631232,53735632,2048,2048,0,0,2048,0,1352,696,1408,0,421825716,5473786.015,8388608,9925323,926994.460577,0,495872,0
+mixed_tight,threshold2,2,ok,threshold,True,2097152,90560,2097136,2097136,114,4243456,27246592,linux_proc_vmhwm_approximate,188770790,62771264,177631232,53735632,2048,2048,28479696,1740,308,0,2380,1408,1395,0,128898177,6126984.319,8388608,8906435,343018.464235,0,523712,0
+mixed_tight,copy_no_pool,2,ok,copy,False,2097152,90560,2097136,2097136,116,4227072,27246592,linux_proc_vmhwm_approximate,189986910,58086718,177631232,53735632,2048,2048,53727440,2048,0,0,4096,0,1383,0,134499200,6008153.507,8388608,8893917,343741.458999,0,0,0
+mixed_tight,project,2,ok,project,True,2097152,90560,2097120,2097120,118,4243456,27246592,linux_proc_vmhwm_approximate,174670169,55539698,177631232,53735632,2048,2048,0,0,0,0,1727,321,1312,0,121848710,6258533.417,8388608,8834323,325246.46456,0,406848,0
+mixed_tight,pressure,2,ok,pressure,True,2097152,90560,2097136,2097136,117,4227072,27246592,linux_proc_vmhwm_approximate,193714972,64286995,177631232,53735632,2048,2048,28385168,1727,321,1727,2353,1422,1371,0,132496502,6233962.195,10485760,11493286,352390.15124,0,523712,0
+mixed_tight,copy,2,ok,copy,True,2097152,90560,2097136,2097136,115,4243456,27246592,linux_proc_vmhwm_approximate,191684197,62544845,177631232,53735632,2048,2048,53727440,2048,0,0,2479,1617,1373,0,131979930,6064467.489,8388608,8905416,346663.433689,0,523712,0
+mixed_tight,threshold4,2,ok,threshold,True,2097152,90560,2097136,2097104,88,4227072,27246592,linux_proc_vmhwm_approximate,229047558,67894565,177631232,53735632,2048,2048,11229392,1357,691,0,2094,1311,1425,0,164358967,5921381.751,7864320,10252296,418976.246455,0,435392,0
+mixed_tight,threshold8,2,ok,threshold,True,2097152,90560,2097136,2097136,72,4243456,27246592,linux_proc_vmhwm_approximate,283681970,69888728,177631232,53735632,2048,2048,3824848,1008,1040,0,1987,1069,1378,0,217008850,5688342.625,7340032,9247808,522809.985389,0,386176,0
+mixed_tight,threshold2,3,ok,threshold,True,2097152,90560,2097152,2097136,102,4325376,27246592,linux_proc_vmhwm_approximate,201965490,80116546,177631232,53735632,2048,2048,28479696,1740,308,0,2291,1497,1275,0,123310392,6483685.515,10485760,11156636,364031.028759,0,493440,0
+mixed_tight,borrow,3,ok,borrow,True,2097152,90560,2094128,2094128,40,3719168,27246592,linux_proc_vmhwm_approximate,494160071,76904068,177631232,53735632,2048,2048,0,0,2048,0,1346,702,1397,0,420872435,5490372.664,8388608,9952646,930733.63783,0,495872,0
+mixed_tight,copy,3,ok,copy,True,2097152,90560,2097152,2097136,117,4243456,27246592,linux_proc_vmhwm_approximate,191245856,61096231,177631232,53735632,2048,2048,53727440,2048,0,0,2481,1615,1387,0,132860200,6056702.267,8388608,8733304,346194.049558,0,523712,0
+mixed_tight,project,3,ok,project,True,2097152,90560,2097120,2097120,118,4407296,27246592,linux_proc_vmhwm_approximate,174872810,56429902,177631232,53735632,2048,2048,0,0,0,0,1726,322,1310,0,121198578,6260365.932,8388608,8926676,325635.507331,0,406848,0
+mixed_tight,threshold4,3,ok,threshold,True,2097152,90560,2097136,2097104,88,4243456,27246592,linux_proc_vmhwm_approximate,224725167,63560757,177631232,53735632,2048,2048,11229392,1357,691,0,2132,1273,1456,0,164191839,5841515.207,7864320,10276240,412794.10328,0,435392,0
+mixed_tight,threshold8,3,ok,threshold,True,2097152,90560,2097136,2097136,73,4227072,27246592,linux_proc_vmhwm_approximate,283036048,73067755,177631232,53735632,2048,2048,3824848,1008,1040,0,1972,1084,1379,0,213650376,5678436.735,7864320,9220899,521434.266403,0,386176,0
+mixed_tight,pressure,3,ok,pressure,True,2097152,90560,2097136,2097136,113,4456448,27246592,linux_proc_vmhwm_approximate,189790379,60625611,177631232,53735632,2048,2048,28385168,1727,321,1727,2369,1406,1393,0,131820061,6110038.652,8388608,9522938,345327.900203,0,523712,0
+mixed_tight,copy_no_pool,3,ok,copy,False,2097152,90560,2097136,2097136,115,4243456,27246592,linux_proc_vmhwm_approximate,192179115,71826579,177631232,53735632,2048,2048,53727440,2048,0,0,4096,0,1293,0,123142369,6044858.508,8388608,8899841,346584.591442,0,0,0
+mixed_tight,project,4,ok,project,True,2097152,90560,2097120,2097120,118,4227072,27246592,linux_proc_vmhwm_approximate,175527737,57919540,177631232,53735632,2048,2048,0,0,0,0,1728,320,1310,0,120470904,6282412.787,9437184,8759229,326547.492623,0,406848,0
+mixed_tight,threshold2,4,ok,threshold,True,2097152,90560,2097136,2097136,113,4243456,27246592,linux_proc_vmhwm_approximate,188314755,61699247,177631232,53735632,2048,2048,28479696,1740,308,0,2377,1411,1394,0,129399417,6110229.914,8388608,8949046,342240.604823,0,523712,0
+mixed_tight,threshold8,4,ok,threshold,True,2097152,90560,2097136,2097136,72,4243456,27246592,linux_proc_vmhwm_approximate,282255055,67344177,177631232,53735632,2048,2048,3824848,1008,1040,0,1990,1066,1394,0,217945110,5670280.355,7340032,9286807,520513.491017,0,386176,0
+mixed_tight,copy,4,ok,copy,True,2097152,90560,2097136,2097136,116,4243456,27246592,linux_proc_vmhwm_approximate,191037345,60906478,177631232,53735632,2048,2048,53727440,2048,0,0,2491,1605,1378,0,132768233,6050681.287,8388608,8878730,345866.556263,0,523712,0
+mixed_tight,threshold4,4,ok,threshold,True,2097152,90560,2097136,2097104,88,4227072,27246592,linux_proc_vmhwm_approximate,226976916,67053797,177631232,53735632,2048,2048,11229392,1357,691,0,2113,1292,1429,0,163248630,5888077.344,8388608,10246777,416261.40193,0,435392,0
+mixed_tight,borrow,4,ok,borrow,True,2097152,90560,2094128,2094128,40,3719168,27246592,linux_proc_vmhwm_approximate,495149938,79564522,177631232,53735632,2048,2048,0,0,2048,0,1338,710,1391,0,419504678,5510109.537,8388608,10578039,933361.552539,0,495872,0
+mixed_tight,pressure,4,ok,pressure,True,2097152,90560,2097152,2097136,114,4243456,27246592,linux_proc_vmhwm_approximate,190688005,63157202,177631232,53735632,2048,2048,28385168,1727,321,1727,2371,1404,1387,0,130503094,6140018.745,8388608,9550771,347232.508173,0,523712,0
+mixed_tight,copy_no_pool,4,ok,copy,False,2097152,90560,2097136,2097136,115,4227072,27246592,linux_proc_vmhwm_approximate,195072389,63921931,177631232,53735632,2048,2048,53727440,2048,0,0,4096,0,1348,0,134032681,6160078.753,9437184,9678087,352079.814928,0,0,0
+sparse_fast,borrow,0,ok,borrow,True,8388608,90560,156112,156112,1,1605632,27246592,linux_proc_vmhwm_approximate,28472110,28306962,134242304,139264,2048,2048,0,0,2048,0,1,2047,0,0,0,13730.123,30720,65982,1788.400939,0,65552,0
+sparse_fast,copy_no_pool,0,ok,copy,False,8388608,90560,156192,156192,1,1605632,27246592,linux_proc_vmhwm_approximate,28620499,28277537,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,0,0,13795.514,40960,86816,1561.617327,0,0,0
+sparse_fast,threshold4,0,ok,threshold,True,8388608,90560,156192,156192,1,1605632,27246592,linux_proc_vmhwm_approximate,20774647,20729258,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,9997.106,14336,72204,1105.947559,0,65632,0
+sparse_fast,threshold2,0,ok,threshold,True,8388608,90560,156192,156192,1,1589248,27246592,linux_proc_vmhwm_approximate,20434497,20435000,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,9831.374,13312,45186,1087.202091,0,65632,0
+sparse_fast,project,0,ok,project,True,8388608,90560,90640,90640,1,1540096,27246592,linux_proc_vmhwm_approximate,22218843,22096574,134242304,139264,2048,2048,0,0,0,0,1,2047,0,0,0,10699.094,18432,59093,1.68791,0,80,0
+sparse_fast,threshold8,0,ok,threshold,True,8388608,90560,156192,156192,1,1589248,27246592,linux_proc_vmhwm_approximate,20787962,20732148,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,10004.317,14336,63834,1109.185459,0,65632,0
+sparse_fast,copy,0,ok,copy,True,8388608,90560,156192,156192,1,1605632,27246592,linux_proc_vmhwm_approximate,21540986,21477686,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,10352.839,18432,54334,1151.439237,0,65632,0
+sparse_fast,pressure,0,ok,pressure,True,8388608,90560,156112,156112,1,1589248,27246592,linux_proc_vmhwm_approximate,20305145,20305963,134242304,139264,2048,2048,0,0,2048,0,1,2047,0,0,0,9760.602,13312,58019,1256.330694,0,65552,0
+sparse_fast,borrow,1,ok,borrow,True,8388608,90560,156112,156112,1,1605632,27246592,linux_proc_vmhwm_approximate,20183773,20183889,134242304,139264,2048,2048,0,0,2048,0,1,2047,0,0,0,9700.917,13312,50334,1250.328097,0,65552,0
+sparse_fast,threshold4,1,ok,threshold,True,8388608,90560,156192,156192,1,1572864,27246592,linux_proc_vmhwm_approximate,20604128,20604259,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,9906.217,13312,47686,1090.792499,0,65632,0
+sparse_fast,copy,1,ok,copy,True,8388608,90560,156192,156192,1,1605632,27246592,linux_proc_vmhwm_approximate,20493516,20493889,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,9859.747,14336,52407,1088.217176,0,65632,0
+sparse_fast,project,1,ok,project,True,8388608,90560,90640,90640,1,1540096,27246592,linux_proc_vmhwm_approximate,21524893,21525074,134242304,139264,2048,2048,0,0,0,0,1,2047,0,0,0,10363.91,13312,54889,1.632854,0,80,0
+sparse_fast,threshold8,1,ok,threshold,True,8388608,90560,156192,156192,1,1589248,27246592,linux_proc_vmhwm_approximate,20381497,20382185,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,9805.745,12288,47353,1087.257309,0,65632,0
+sparse_fast,pressure,1,ok,pressure,True,8388608,90560,156112,156112,1,1589248,27246592,linux_proc_vmhwm_approximate,20244385,20244778,134242304,139264,2048,2048,0,0,2048,0,1,2047,0,0,0,9731.208,13312,41426,1251.232387,0,65552,0
+sparse_fast,threshold2,1,ok,threshold,True,8388608,90560,156192,156192,1,1605632,27246592,linux_proc_vmhwm_approximate,22684901,22652390,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,10925.772,22528,69779,1228.197157,0,65632,0
+sparse_fast,copy_no_pool,1,ok,copy,False,8388608,90560,156192,156192,1,1589248,27246592,linux_proc_vmhwm_approximate,22993108,22893763,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,0,0,11062.46,18432,74149,1228.067562,0,0,0
+sparse_fast,threshold4,2,ok,threshold,True,8388608,90560,156192,156192,1,1589248,27246592,linux_proc_vmhwm_approximate,20874129,20775314,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,10044.57,16384,55556,1112.362141,0,65632,0
+sparse_fast,borrow,2,ok,borrow,True,8388608,90560,156112,156112,1,1572864,27246592,linux_proc_vmhwm_approximate,20176198,20176500,134242304,139264,2048,2048,0,0,2048,0,1,2047,0,0,0,9697.062,12288,39001,1246.966591,0,65552,0
+sparse_fast,copy,2,ok,copy,True,8388608,90560,156192,156192,1,1589248,27246592,linux_proc_vmhwm_approximate,20382034,20382277,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,9806.967,12288,48779,1084.755978,0,65632,0
+sparse_fast,threshold8,2,ok,threshold,True,8388608,90560,156192,156192,1,1605632,27246592,linux_proc_vmhwm_approximate,20453663,20454074,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,9841.173,13312,53241,1090.324497,0,65632,0
+sparse_fast,copy_no_pool,2,ok,copy,False,8388608,90560,156192,156192,1,1605632,27246592,linux_proc_vmhwm_approximate,20636628,20636871,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,0,0,9920.915,13312,40464,1084.995845,0,0,0
+sparse_fast,pressure,2,ok,pressure,True,8388608,90560,156112,156112,1,1605632,27246592,linux_proc_vmhwm_approximate,20413515,20355722,134242304,139264,2048,2048,0,0,2048,0,1,2047,0,0,0,9812.253,14336,64112,1264.219091,0,65552,0
+sparse_fast,threshold2,2,ok,threshold,True,8388608,90560,156192,156192,1,1589248,27246592,linux_proc_vmhwm_approximate,20421089,20421796,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,9825.86,13312,53519,1088.001718,0,65632,0
+sparse_fast,project,2,ok,project,True,8388608,90560,90640,90640,1,1540096,27246592,linux_proc_vmhwm_approximate,21525764,21526111,134242304,139264,2048,2048,0,0,0,0,1,2047,0,0,0,10364.601,13312,65686,1.632264,0,80,0
+sparse_fast,threshold2,3,ok,threshold,True,8388608,90560,156192,156192,1,1605632,27246592,linux_proc_vmhwm_approximate,20829074,20798316,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,10025.307,15360,65907,1111.338342,0,65632,0
+sparse_fast,pressure,3,ok,pressure,True,8388608,90560,156112,156112,1,1572864,27246592,linux_proc_vmhwm_approximate,20018290,20018407,134242304,139264,2048,2048,0,0,2048,0,1,2047,0,0,0,9620.129,12288,34982,1238.904613,0,65552,0
+sparse_fast,borrow,3,ok,borrow,True,8388608,90560,156112,156112,1,1589248,27246592,linux_proc_vmhwm_approximate,19968383,19952888,134242304,139264,2048,2048,0,0,2048,0,1,2047,0,0,0,9596.16,11264,52612,1236.323437,0,65552,0
+sparse_fast,threshold4,3,ok,threshold,True,8388608,90560,156192,156192,1,1589248,27246592,linux_proc_vmhwm_approximate,21098686,21002369,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,10153.021,16384,71204,1130.040808,0,65632,0
+sparse_fast,project,3,ok,project,True,8388608,90560,90640,90640,1,1540096,27246592,linux_proc_vmhwm_approximate,21459134,21459111,134242304,139264,2048,2048,0,0,0,0,1,2047,0,0,0,10332.156,13312,41834,1.628379,0,80,0
+sparse_fast,threshold8,3,ok,threshold,True,8388608,90560,156192,156192,1,1605632,27246592,linux_proc_vmhwm_approximate,21122947,21019219,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,10159.663,16384,63556,1125.541597,0,65632,0
+sparse_fast,copy,3,ok,copy,True,8388608,90560,156192,156192,1,1572864,27246592,linux_proc_vmhwm_approximate,20421330,20421426,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,9825.919,13312,56575,1089.501083,0,65632,0
+sparse_fast,copy_no_pool,3,ok,copy,False,8388608,90560,156192,156192,1,1589248,27246592,linux_proc_vmhwm_approximate,20561183,20561592,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,0,0,9883.337,12288,45185,1085.229592,0,0,0
+sparse_fast,borrow,4,ok,borrow,True,8388608,90560,156112,156112,1,1589248,27246592,linux_proc_vmhwm_approximate,20082994,20072296,134242304,139264,2048,2048,0,0,2048,0,1,2047,0,0,0,9647.624,12288,51259,1243.235174,0,65552,0
+sparse_fast,pressure,4,ok,pressure,True,8388608,90560,156112,156112,1,1589248,27246592,linux_proc_vmhwm_approximate,23280610,23231480,134242304,139264,2048,2048,0,0,2048,0,1,2047,0,0,0,11211.571,24576,54778,1448.645185,0,65552,0
+sparse_fast,threshold2,4,ok,threshold,True,8388608,90560,156192,156192,1,1605632,27246592,linux_proc_vmhwm_approximate,21989119,21857259,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,10590.063,18432,79983,1185.989886,0,65632,0
+sparse_fast,copy_no_pool,4,ok,copy,False,8388608,90560,156192,156192,1,1605632,27246592,linux_proc_vmhwm_approximate,21265947,21072353,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,0,0,10215.53,16384,91668,1125.003597,0,0,0
+sparse_fast,project,4,ok,project,True,8388608,90560,90640,90640,1,1507328,27246592,linux_proc_vmhwm_approximate,21358726,21358833,134242304,139264,2048,2048,0,0,0,0,1,2047,0,0,0,10284.012,13312,47648,1.620534,0,80,0
+sparse_fast,threshold8,4,ok,threshold,True,8388608,90560,156192,156192,1,1572864,27246592,linux_proc_vmhwm_approximate,20441422,20426148,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,9835.821,13312,50945,1089.704272,0,65632,0
+sparse_fast,copy,4,ok,copy,True,8388608,90560,156192,156192,1,1605632,27246592,linux_proc_vmhwm_approximate,20717721,20717834,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,9969.584,13312,40148,1106.215747,0,65632,0
+sparse_fast,threshold4,4,ok,threshold,True,8388608,90560,156192,156192,1,1605632,27246592,linux_proc_vmhwm_approximate,20693813,20694148,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,9958.775,13312,66019,1106.254829,0,65632,0
diff --git a/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/raw.json b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/raw.json new file mode 100644 index 0000000..6fc0da0 --- /dev/null +++ b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/raw.json @@ -0,0 +1,9122 @@ +[ + { + "case": "sparse_slow", + "variant": "copy", + "repeat": 0, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1687552, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 160143537, + "cpu_ns": 26459012, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1524, + "sleep_ns": 137390253, + "latency_mean_ns": 34696998.27, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 41171715, + "active_byte_seconds": 6863.022101, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold4", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1703936, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 157308101, + "cpu_ns": 31229598, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1480, + "sleep_ns": 130450222, + "latency_mean_ns": 33900498.29, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 39440182, + "active_byte_seconds": 6941.796558, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold2", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1720320, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 155496866, + "cpu_ns": 24536501, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1532, + "sleep_ns": 134789830, + "latency_mean_ns": 33617642.818, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 38582611, + "active_byte_seconds": 6573.377656, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "copy_no_pool", + "repeat": 0, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1703936, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 155097886, + "cpu_ns": 24003453, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 1537, + "sleep_ns": 135038766, + "latency_mean_ns": 33344720.225, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 38228742, + "active_byte_seconds": 6474.089644, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "project", + "repeat": 0, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 131520, + "peak_active_bytes": 131520, + "peak_queue": 512, + "rss_peak_bytes": 1654784, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 154147870, + "cpu_ns": 24607892, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 512, + "reuses": 1536, + "budget_waits": 0, + "slot_waits": 1536, + "sleep_ns": 133284576, + "latency_mean_ns": 33266783.578, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37610633, + "active_byte_seconds": 5450.353596, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1280, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold8", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1703936, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 159785538, + "cpu_ns": 24425471, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1534, + "sleep_ns": 139188295, + "latency_mean_ns": 34401146.148, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 40673920, + "active_byte_seconds": 6694.694537, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "borrow", + "repeat": 0, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 107974911, + "cpu_ns": 48356230, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1100, + "slot_waits": 0, + "sleep_ns": 61689899, + "latency_mean_ns": 6299431.416, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 9257676, + "active_byte_seconds": 842052.147088, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "pressure", + "repeat": 0, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 4321888, + "peak_active_bytes": 4318208, + "peak_queue": 512, + "rss_peak_bytes": 5832704, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 153730223, + "cpu_ns": 27269441, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 113984, + "copied_records": 1781, + "borrowed_records": 267, + "pressure_copies": 1781, + "allocations": 514, + "reuses": 3315, + "budget_waits": 0, + "slot_waits": 1480, + "sleep_ns": 130232809, + "latency_mean_ns": 32945208.971, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 38336797, + "active_byte_seconds": 525465.223488, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 590528, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "borrow", + "repeat": 1, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9469952, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 106374934, + "cpu_ns": 48221069, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1095, + "slot_waits": 0, + "sleep_ns": 60129493, + "latency_mean_ns": 6201710.718, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 9283991, + "active_byte_seconds": 829040.966005, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "copy_no_pool", + "repeat": 1, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1687552, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 160320037, + "cpu_ns": 25896167, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 1525, + "sleep_ns": 138363559, + "latency_mean_ns": 34524425.147, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 40334217, + "active_byte_seconds": 6779.619735, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold2", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1703936, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 160914091, + "cpu_ns": 25835642, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1519, + "sleep_ns": 138817024, + "latency_mean_ns": 34925615.31, + "latency_p99_upper_ns": 46137344, + "latency_max_ns": 42672599, + "active_byte_seconds": 6869.973543, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold4", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1687552, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 154184073, + "cpu_ns": 23590708, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1537, + "sleep_ns": 134309537, + "latency_mean_ns": 33299901.746, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37858502, + "active_byte_seconds": 6477.65682, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold8", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1687552, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 154103999, + "cpu_ns": 23187579, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1537, + "sleep_ns": 134573427, + "latency_mean_ns": 33283383.04, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37891279, + "active_byte_seconds": 6458.021349, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "project", + "repeat": 1, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 131520, + "peak_active_bytes": 131520, + "peak_queue": 512, + "rss_peak_bytes": 1638400, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 157860470, + "cpu_ns": 28682548, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 512, + "reuses": 1536, + "budget_waits": 0, + "slot_waits": 1516, + "sleep_ns": 133519836, + "latency_mean_ns": 34200243.611, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 39812385, + "active_byte_seconds": 5603.286251, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1280, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "pressure", + "repeat": 1, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 4321888, + "peak_active_bytes": 4316848, + "peak_queue": 512, + "rss_peak_bytes": 5849088, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 157264009, + "cpu_ns": 27287611, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 113408, + "copied_records": 1772, + "borrowed_records": 276, + "pressure_copies": 1772, + "allocations": 514, + "reuses": 3306, + "budget_waits": 0, + "slot_waits": 1470, + "sleep_ns": 133795355, + "latency_mean_ns": 32665634.037, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 42380378, + "active_byte_seconds": 542285.660244, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 656000, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "copy", + "repeat": 1, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1703936, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 159054504, + "cpu_ns": 24707642, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1536, + "sleep_ns": 138332046, + "latency_mean_ns": 34466956.647, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 41828861, + "active_byte_seconds": 6705.336146, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold4", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1703936, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 155128904, + "cpu_ns": 25543272, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1516, + "sleep_ns": 133541383, + "latency_mean_ns": 33533790.057, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 38416722, + "active_byte_seconds": 6610.674553, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "copy_no_pool", + "repeat": 2, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1703936, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 154376239, + "cpu_ns": 24141589, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 1537, + "sleep_ns": 134070369, + "latency_mean_ns": 33348471.497, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37918872, + "active_byte_seconds": 6490.973039, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold2", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1720320, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 154320869, + "cpu_ns": 23690719, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1537, + "sleep_ns": 134338369, + "latency_mean_ns": 33321815.102, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37742483, + "active_byte_seconds": 6490.329618, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "pressure", + "repeat": 2, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 4321888, + "peak_active_bytes": 4318768, + "peak_queue": 512, + "rss_peak_bytes": 5832704, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 151916969, + "cpu_ns": 26295422, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 114176, + "copied_records": 1784, + "borrowed_records": 264, + "pressure_copies": 1784, + "allocations": 514, + "reuses": 3318, + "budget_waits": 0, + "slot_waits": 1489, + "sleep_ns": 129297978, + "latency_mean_ns": 32537118.75, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37291707, + "active_byte_seconds": 513114.693547, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 590528, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "copy", + "repeat": 2, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1703936, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 154140610, + "cpu_ns": 23189876, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1537, + "sleep_ns": 134662671, + "latency_mean_ns": 33298003.958, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37866187, + "active_byte_seconds": 6456.771667, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "project", + "repeat": 2, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 131520, + "peak_active_bytes": 131520, + "peak_queue": 512, + "rss_peak_bytes": 1654784, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 154094443, + "cpu_ns": 24230112, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 512, + "reuses": 1536, + "budget_waits": 0, + "slot_waits": 1537, + "sleep_ns": 133556453, + "latency_mean_ns": 33259314.794, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37585114, + "active_byte_seconds": 5449.134094, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1280, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold8", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1703936, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 154652646, + "cpu_ns": 24092189, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1534, + "sleep_ns": 134423307, + "latency_mean_ns": 33402890.832, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37866335, + "active_byte_seconds": 6511.54798, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "borrow", + "repeat": 2, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 129845439, + "cpu_ns": 45497318, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1501, + "slot_waits": 0, + "sleep_ns": 87228642, + "latency_mean_ns": 7656609.5, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 9287806, + "active_byte_seconds": 1022546.229446, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "project", + "repeat": 3, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 131520, + "peak_active_bytes": 131520, + "peak_queue": 512, + "rss_peak_bytes": 1638400, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 154249202, + "cpu_ns": 24700764, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 512, + "reuses": 1536, + "budget_waits": 0, + "slot_waits": 1537, + "sleep_ns": 133261937, + "latency_mean_ns": 33273652.65, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37535317, + "active_byte_seconds": 5451.483102, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1280, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "borrow", + "repeat": 3, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 137924379, + "cpu_ns": 44501920, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1704, + "slot_waits": 0, + "sleep_ns": 96547980, + "latency_mean_ns": 8155969.084, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 9259085, + "active_byte_seconds": 1088953.248436, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "pressure", + "repeat": 3, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 4321888, + "peak_active_bytes": 4318128, + "peak_queue": 512, + "rss_peak_bytes": 5849088, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 152102968, + "cpu_ns": 26353180, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 113984, + "copied_records": 1781, + "borrowed_records": 267, + "pressure_copies": 1781, + "allocations": 514, + "reuses": 3315, + "budget_waits": 0, + "slot_waits": 1489, + "sleep_ns": 129366758, + "latency_mean_ns": 32586897.428, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37391725, + "active_byte_seconds": 520107.889954, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 590528, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold8", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1703936, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 154077370, + "cpu_ns": 23197132, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1537, + "sleep_ns": 134591611, + "latency_mean_ns": 33277920.587, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37816187, + "active_byte_seconds": 6453.368258, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold2", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1703936, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 154022055, + "cpu_ns": 23087202, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1537, + "sleep_ns": 134592710, + "latency_mean_ns": 33270464.792, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37834187, + "active_byte_seconds": 6450.425541, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "copy", + "repeat": 3, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1720320, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 159640187, + "cpu_ns": 27408125, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1444, + "sleep_ns": 128856855, + "latency_mean_ns": 34666958.779, + "latency_p99_upper_ns": 46137344, + "latency_max_ns": 43466300, + "active_byte_seconds": 7402.36243, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "copy_no_pool", + "repeat": 3, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1720320, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 155595440, + "cpu_ns": 25939365, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 1537, + "sleep_ns": 134098060, + "latency_mean_ns": 33573592.059, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 37962687, + "active_byte_seconds": 6570.059349, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold4", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1703936, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 156340011, + "cpu_ns": 29539317, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1516, + "sleep_ns": 131960968, + "latency_mean_ns": 33615642.627, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 38156538, + "active_byte_seconds": 6719.71558, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "copy_no_pool", + "repeat": 4, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1703936, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 162066143, + "cpu_ns": 36838768, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 1413, + "sleep_ns": 131813978, + "latency_mean_ns": 34186582.359, + "latency_p99_upper_ns": 46137344, + "latency_max_ns": 44277743, + "active_byte_seconds": 7046.191505, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "copy", + "repeat": 4, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1720320, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 154776516, + "cpu_ns": 28160466, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1467, + "sleep_ns": 130788967, + "latency_mean_ns": 33183203.845, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 39792181, + "active_byte_seconds": 6689.95279, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold4", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1720320, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 154788109, + "cpu_ns": 23986070, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1537, + "sleep_ns": 134524839, + "latency_mean_ns": 33403921.35, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 37878020, + "active_byte_seconds": 6520.274636, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold8", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1720320, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 154198518, + "cpu_ns": 23692568, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1536, + "sleep_ns": 134186642, + "latency_mean_ns": 33304172.097, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37802706, + "active_byte_seconds": 6492.439639, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "borrow", + "repeat": 4, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 141446795, + "cpu_ns": 44722082, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1729, + "slot_waits": 0, + "sleep_ns": 99993943, + "latency_mean_ns": 8382742.796, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 9272177, + "active_byte_seconds": 1119170.099864, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold2", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 1703936, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 154113537, + "cpu_ns": 24093342, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1537, + "sleep_ns": 133716023, + "latency_mean_ns": 33269305.586, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37632576, + "active_byte_seconds": 6504.166448, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "pressure", + "repeat": 4, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 4321888, + "peak_active_bytes": 4318688, + "peak_queue": 512, + "rss_peak_bytes": 5849088, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 154850386, + "cpu_ns": 27901892, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 114112, + "copied_records": 1783, + "borrowed_records": 265, + "pressure_copies": 1783, + "allocations": 514, + "reuses": 3317, + "budget_waits": 0, + "slot_waits": 1468, + "sleep_ns": 130766867, + "latency_mean_ns": 33232147.448, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 39951922, + "active_byte_seconds": 524904.925261, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 590528, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "project", + "repeat": 4, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 131520, + "peak_active_bytes": 131520, + "peak_queue": 512, + "rss_peak_bytes": 1638400, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 157284342, + "cpu_ns": 26489150, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 512, + "reuses": 1536, + "budget_waits": 0, + "slot_waits": 1510, + "sleep_ns": 134748166, + "latency_mean_ns": 33888730.885, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 39144776, + "active_byte_seconds": 5552.251467, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1280, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "project", + "repeat": 0, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 77760, + "peak_active_bytes": 77760, + "peak_queue": 64, + "rss_peak_bytes": 1572864, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 167149794, + "cpu_ns": 26582076, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 64, + "reuses": 1984, + "budget_waits": 0, + "slot_waits": 1974, + "sleep_ns": 144371389, + "latency_mean_ns": 5130099.306, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 8958215, + "active_byte_seconds": 840.438441, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1280, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "threshold2", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1622016, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 167663571, + "cpu_ns": 26966696, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 65, + "reuses": 4031, + "budget_waits": 0, + "slot_waits": 1961, + "sleep_ns": 144092606, + "latency_mean_ns": 5142490.023, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 9061177, + "active_byte_seconds": 2058.951339, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "copy_no_pool", + "repeat": 0, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1654784, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 168181366, + "cpu_ns": 26871012, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 1965, + "sleep_ns": 145357926, + "latency_mean_ns": 5163779.497, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 8918178, + "active_byte_seconds": 2024.80935, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "borrow", + "repeat": 0, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 4267968, + "peak_active_bytes": 4267968, + "peak_queue": 64, + "rss_peak_bytes": 5292032, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 167216739, + "cpu_ns": 43926056, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 64, + "reuses": 1984, + "budget_waits": 0, + "slot_waits": 1888, + "sleep_ns": 126773157, + "latency_mean_ns": 5126680.831, + "latency_p99_upper_ns": 7340032, + "latency_max_ns": 7718922, + "active_byte_seconds": 688195.924843, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "pressure", + "repeat": 0, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 4268048, + "peak_active_bytes": 4268048, + "peak_queue": 64, + "rss_peak_bytes": 5767168, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 167185425, + "cpu_ns": 45108627, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 2048, + "copied_records": 32, + "borrowed_records": 2016, + "pressure_copies": 32, + "allocations": 65, + "reuses": 2015, + "budget_waits": 0, + "slot_waits": 1714, + "sleep_ns": 125584463, + "latency_mean_ns": 5128742.545, + "latency_p99_upper_ns": 6291456, + "latency_max_ns": 6639537, + "active_byte_seconds": 677659.57207, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "copy", + "repeat": 0, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1622016, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 168358292, + "cpu_ns": 24933808, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 65, + "reuses": 4031, + "budget_waits": 0, + "slot_waits": 1982, + "sleep_ns": 147266280, + "latency_mean_ns": 5168010.066, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 9057715, + "active_byte_seconds": 1951.688735, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "threshold4", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1654784, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 166820573, + "cpu_ns": 24630999, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 65, + "reuses": 4031, + "budget_waits": 0, + "slot_waits": 1982, + "sleep_ns": 145973315, + "latency_mean_ns": 5129540.053, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 9056604, + "active_byte_seconds": 1927.278894, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "threshold8", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1654784, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 166777389, + "cpu_ns": 24643191, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 65, + "reuses": 4031, + "budget_waits": 0, + "slot_waits": 1983, + "sleep_ns": 145938953, + "latency_mean_ns": 5126620.092, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 9062437, + "active_byte_seconds": 1926.54795, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "pressure", + "repeat": 1, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 4268048, + "peak_active_bytes": 4268048, + "peak_queue": 64, + "rss_peak_bytes": 5783552, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 167023277, + "cpu_ns": 43214247, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 2048, + "copied_records": 32, + "borrowed_records": 2016, + "pressure_copies": 32, + "allocations": 65, + "reuses": 2015, + "budget_waits": 0, + "slot_waits": 1923, + "sleep_ns": 127480383, + "latency_mean_ns": 5125737.978, + "latency_p99_upper_ns": 7340032, + "latency_max_ns": 8171940, + "active_byte_seconds": 677260.281048, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "threshold2", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1638400, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 167465182, + "cpu_ns": 25416979, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 65, + "reuses": 4031, + "budget_waits": 0, + "slot_waits": 1982, + "sleep_ns": 146065308, + "latency_mean_ns": 5147482.869, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 9043937, + "active_byte_seconds": 1953.686249, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "threshold4", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1638400, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 168266032, + "cpu_ns": 25648470, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 65, + "reuses": 4031, + "budget_waits": 0, + "slot_waits": 1982, + "sleep_ns": 146554478, + "latency_mean_ns": 5170189.028, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 8853271, + "active_byte_seconds": 1979.901257, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "copy_no_pool", + "repeat": 1, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1638400, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 167352998, + "cpu_ns": 26167797, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 1982, + "sleep_ns": 145161257, + "latency_mean_ns": 5140939.162, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 9037974, + "active_byte_seconds": 1975.871965, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "threshold8", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1638400, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 167352294, + "cpu_ns": 26149112, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 65, + "reuses": 4031, + "budget_waits": 0, + "slot_waits": 1982, + "sleep_ns": 145164575, + "latency_mean_ns": 5140639.04, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 9055067, + "active_byte_seconds": 1998.899707, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "project", + "repeat": 1, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 77760, + "peak_active_bytes": 77760, + "peak_queue": 64, + "rss_peak_bytes": 1589248, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 167537794, + "cpu_ns": 26582472, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 64, + "reuses": 1984, + "budget_waits": 0, + "slot_waits": 1983, + "sleep_ns": 144932270, + "latency_mean_ns": 5144362.881, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 9070492, + "active_byte_seconds": 842.776507, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1280, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "copy", + "repeat": 1, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1638400, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 177068451, + "cpu_ns": 34395657, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 65, + "reuses": 4031, + "budget_waits": 0, + "slot_waits": 1964, + "sleep_ns": 148816905, + "latency_mean_ns": 5443811.067, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 9497139, + "active_byte_seconds": 2287.854324, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "borrow", + "repeat": 1, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 4267968, + "peak_active_bytes": 4267968, + "peak_queue": 64, + "rss_peak_bytes": 5292032, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 169327288, + "cpu_ns": 47272489, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 64, + "reuses": 1984, + "budget_waits": 0, + "slot_waits": 1559, + "sleep_ns": 125366124, + "latency_mean_ns": 5174744.393, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 7999125, + "active_byte_seconds": 694635.953387, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "threshold4", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1638400, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 166910296, + "cpu_ns": 25474992, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 65, + "reuses": 4031, + "budget_waits": 0, + "slot_waits": 1982, + "sleep_ns": 145193155, + "latency_mean_ns": 5128818.551, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 9004900, + "active_byte_seconds": 1987.487947, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "copy_no_pool", + "repeat": 2, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1654784, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 167128888, + "cpu_ns": 26220522, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 1980, + "sleep_ns": 144715144, + "latency_mean_ns": 5134877.701, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 9062770, + "active_byte_seconds": 2002.587942, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "threshold2", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1638400, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 167148609, + "cpu_ns": 25957735, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 65, + "reuses": 4031, + "budget_waits": 0, + "slot_waits": 1977, + "sleep_ns": 145051954, + "latency_mean_ns": 5131955.022, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 9073752, + "active_byte_seconds": 1998.277517, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "threshold8", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1638400, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 169611954, + "cpu_ns": 32276554, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 65, + "reuses": 4031, + "budget_waits": 0, + "slot_waits": 1914, + "sleep_ns": 142094763, + "latency_mean_ns": 5206380.796, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 8901622, + "active_byte_seconds": 2300.08379, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "project", + "repeat": 2, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 77760, + "peak_active_bytes": 77760, + "peak_queue": 64, + "rss_peak_bytes": 1589248, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 171072487, + "cpu_ns": 27568676, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 64, + "reuses": 1984, + "budget_waits": 0, + "slot_waits": 1973, + "sleep_ns": 147623196, + "latency_mean_ns": 5258257.061, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 9512213, + "active_byte_seconds": 861.43609, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1280, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "copy", + "repeat": 2, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1638400, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 169338770, + "cpu_ns": 27312589, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 65, + "reuses": 4031, + "budget_waits": 0, + "slot_waits": 1973, + "sleep_ns": 146307420, + "latency_mean_ns": 5201400.59, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 9016640, + "active_byte_seconds": 2055.277015, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "pressure", + "repeat": 2, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 4268048, + "peak_active_bytes": 4268048, + "peak_queue": 64, + "rss_peak_bytes": 5767168, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 170783358, + "cpu_ns": 46177893, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 2048, + "copied_records": 32, + "borrowed_records": 2016, + "pressure_copies": 32, + "allocations": 65, + "reuses": 2015, + "budget_waits": 0, + "slot_waits": 1534, + "sleep_ns": 127950932, + "latency_mean_ns": 5236882.494, + "latency_p99_upper_ns": 7340032, + "latency_max_ns": 7222257, + "active_byte_seconds": 691939.11555, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "borrow", + "repeat": 2, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 4267968, + "peak_active_bytes": 4267968, + "peak_queue": 64, + "rss_peak_bytes": 5292032, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 167156999, + "cpu_ns": 43876108, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 64, + "reuses": 1984, + "budget_waits": 0, + "slot_waits": 1884, + "sleep_ns": 127058453, + "latency_mean_ns": 5126798.896, + "latency_p99_upper_ns": 6815744, + "latency_max_ns": 6645517, + "active_byte_seconds": 688213.378653, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "threshold4", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1638400, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 166770166, + "cpu_ns": 25212214, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 65, + "reuses": 4031, + "budget_waits": 0, + "slot_waits": 1984, + "sleep_ns": 145249611, + "latency_mean_ns": 5126749.497, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 9015048, + "active_byte_seconds": 1964.863682, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "copy", + "repeat": 3, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1654784, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 167909533, + "cpu_ns": 27850375, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 65, + "reuses": 4031, + "budget_waits": 0, + "slot_waits": 1956, + "sleep_ns": 144091763, + "latency_mean_ns": 5137672.764, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 9072455, + "active_byte_seconds": 2094.171152, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "threshold8", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1638400, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 168528180, + "cpu_ns": 32536976, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 65, + "reuses": 4031, + "budget_waits": 0, + "slot_waits": 1897, + "sleep_ns": 140338194, + "latency_mean_ns": 5169990.139, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 8583716, + "active_byte_seconds": 2319.792062, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "copy_no_pool", + "repeat": 3, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1654784, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 166715000, + "cpu_ns": 24659146, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 1984, + "sleep_ns": 145786851, + "latency_mean_ns": 5125611.619, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 9016234, + "active_byte_seconds": 1919.204343, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "threshold2", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1654784, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 167074462, + "cpu_ns": 26663004, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 65, + "reuses": 4031, + "budget_waits": 0, + "slot_waits": 1972, + "sleep_ns": 144308149, + "latency_mean_ns": 5134098.172, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 9056067, + "active_byte_seconds": 2041.253864, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "project", + "repeat": 3, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 77760, + "peak_active_bytes": 77760, + "peak_queue": 64, + "rss_peak_bytes": 1572864, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 166784685, + "cpu_ns": 25542781, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 64, + "reuses": 1984, + "budget_waits": 0, + "slot_waits": 1985, + "sleep_ns": 144995208, + "latency_mean_ns": 5128089.141, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 9028215, + "active_byte_seconds": 840.114114, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1280, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "pressure", + "repeat": 3, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 4268048, + "peak_active_bytes": 4268048, + "peak_queue": 64, + "rss_peak_bytes": 5750784, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 167121239, + "cpu_ns": 44137216, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 2048, + "copied_records": 32, + "borrowed_records": 2016, + "pressure_copies": 32, + "allocations": 65, + "reuses": 2015, + "budget_waits": 0, + "slot_waits": 1831, + "sleep_ns": 126710351, + "latency_mean_ns": 5127462.262, + "latency_p99_upper_ns": 7340032, + "latency_max_ns": 7853292, + "active_byte_seconds": 677483.645644, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "borrow", + "repeat": 3, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 4267968, + "peak_active_bytes": 4267968, + "peak_queue": 64, + "rss_peak_bytes": 5292032, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 167212479, + "cpu_ns": 44714000, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 64, + "reuses": 1984, + "budget_waits": 0, + "slot_waits": 1813, + "sleep_ns": 126101064, + "latency_mean_ns": 5127098.881, + "latency_p99_upper_ns": 6291456, + "latency_max_ns": 6795851, + "active_byte_seconds": 688253.763142, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "threshold8", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1622016, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 166717963, + "cpu_ns": 24687036, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 65, + "reuses": 4031, + "budget_waits": 0, + "slot_waits": 1983, + "sleep_ns": 145714382, + "latency_mean_ns": 5125971.683, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 8962826, + "active_byte_seconds": 1940.992711, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "copy", + "repeat": 4, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1638400, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 166680851, + "cpu_ns": 24341624, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 65, + "reuses": 4031, + "budget_waits": 0, + "slot_waits": 1985, + "sleep_ns": 146024444, + "latency_mean_ns": 5125321.995, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 9060326, + "active_byte_seconds": 1923.416256, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "threshold4", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1654784, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 166829203, + "cpu_ns": 24368638, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 65, + "reuses": 4031, + "budget_waits": 0, + "slot_waits": 1984, + "sleep_ns": 146127572, + "latency_mean_ns": 5127589.86, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 9064418, + "active_byte_seconds": 1922.285206, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "project", + "repeat": 4, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 77760, + "peak_active_bytes": 77760, + "peak_queue": 64, + "rss_peak_bytes": 1589248, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 167505794, + "cpu_ns": 25505816, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 64, + "reuses": 1984, + "budget_waits": 0, + "slot_waits": 1985, + "sleep_ns": 145758292, + "latency_mean_ns": 5149157.839, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 9024826, + "active_byte_seconds": 843.565622, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1280, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "copy_no_pool", + "repeat": 4, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1638400, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 167165609, + "cpu_ns": 25932182, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 1976, + "sleep_ns": 145075045, + "latency_mean_ns": 5133720.043, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 9029714, + "active_byte_seconds": 1986.249813, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "borrow", + "repeat": 4, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 4267968, + "peak_active_bytes": 4267968, + "peak_queue": 64, + "rss_peak_bytes": 5292032, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 167597886, + "cpu_ns": 45634483, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 64, + "reuses": 1984, + "budget_waits": 0, + "slot_waits": 1768, + "sleep_ns": 125625299, + "latency_mean_ns": 5136396.266, + "latency_p99_upper_ns": 7340032, + "latency_max_ns": 8047606, + "active_byte_seconds": 689499.931113, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "threshold2", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 143312, + "peak_active_bytes": 143312, + "peak_queue": 64, + "rss_peak_bytes": 1638400, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 166724425, + "cpu_ns": 24304145, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 65, + "reuses": 4031, + "budget_waits": 0, + "slot_waits": 1984, + "sleep_ns": 146112652, + "latency_mean_ns": 5125215.218, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 8987715, + "active_byte_seconds": 1915.595622, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slots64", + "variant": "pressure", + "repeat": 4, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 72640, + "peak_reserved_bytes": 4268048, + "peak_active_bytes": 4268048, + "peak_queue": 64, + "rss_peak_bytes": 5750784, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 167102943, + "cpu_ns": 43204463, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 2048, + "copied_records": 32, + "borrowed_records": 2016, + "pressure_copies": 32, + "allocations": 65, + "reuses": 2015, + "budget_waits": 0, + "slot_waits": 1902, + "sleep_ns": 127501222, + "latency_mean_ns": 5127130.23, + "latency_p99_upper_ns": 7340032, + "latency_max_ns": 7758552, + "active_byte_seconds": 677439.045656, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "copy_no_pool", + "repeat": 0, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 125, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 181746660, + "cpu_ns": 79318230, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 100663296, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 1923, + "slot_waits": 0, + "sleep_ns": 106431291, + "latency_mean_ns": 10743611.753, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 12983832, + "active_byte_seconds": 1442582.012105, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold4", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 161215386, + "cpu_ns": 89862451, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1244, + "slot_waits": 0, + "sleep_ns": 73999062, + "latency_mean_ns": 9530310.653, + "latency_p99_upper_ns": 11534336, + "latency_max_ns": 11475412, + "active_byte_seconds": 1273441.862727, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "pressure", + "repeat": 0, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 181545716, + "cpu_ns": 79933333, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1794, + "slot_waits": 0, + "sleep_ns": 105524896, + "latency_mean_ns": 10805826.457, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 13598424, + "active_byte_seconds": 1442046.73663, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold2", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 179808887, + "cpu_ns": 82476393, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1739, + "slot_waits": 0, + "sleep_ns": 101034766, + "latency_mean_ns": 10695483.804, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 13755645, + "active_byte_seconds": 1427516.577261, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "copy", + "repeat": 0, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 125, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 181070273, + "cpu_ns": 83392187, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 100663296, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 126, + "reuses": 3970, + "budget_waits": 1923, + "slot_waits": 0, + "sleep_ns": 101645153, + "latency_mean_ns": 10688072.436, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 13270480, + "active_byte_seconds": 1435135.645514, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "borrow", + "repeat": 0, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 182712953, + "cpu_ns": 81359541, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1784, + "slot_waits": 0, + "sleep_ns": 105215055, + "latency_mean_ns": 10867028.691, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 13321591, + "active_byte_seconds": 1450265.685197, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "project", + "repeat": 0, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9469952, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 187716865, + "cpu_ns": 74974355, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1885, + "slot_waits": 0, + "sleep_ns": 116741671, + "latency_mean_ns": 11188037.068, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 13610887, + "active_byte_seconds": 1492582.952313, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold8", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9469952, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 177819652, + "cpu_ns": 80765616, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1732, + "slot_waits": 0, + "sleep_ns": 100790270, + "latency_mean_ns": 10569593.51, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 12515889, + "active_byte_seconds": 1410709.704111, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "copy_no_pool", + "repeat": 1, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 125, + "rss_peak_bytes": 9469952, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 183713376, + "cpu_ns": 79010560, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 100663296, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 1923, + "slot_waits": 0, + "sleep_ns": 108825186, + "latency_mean_ns": 10852089.214, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 12891240, + "active_byte_seconds": 1457141.599471, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold8", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 181690178, + "cpu_ns": 80219667, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1787, + "slot_waits": 0, + "sleep_ns": 105238489, + "latency_mean_ns": 10811191.05, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 13211998, + "active_byte_seconds": 1442791.441175, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "project", + "repeat": 1, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 187516958, + "cpu_ns": 75386397, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1881, + "slot_waits": 0, + "sleep_ns": 116242907, + "latency_mean_ns": 11180449.479, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 13778256, + "active_byte_seconds": 1491587.457419, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "pressure", + "repeat": 1, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 181604364, + "cpu_ns": 78951924, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1764, + "slot_waits": 0, + "sleep_ns": 106543831, + "latency_mean_ns": 10804561.506, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 13821367, + "active_byte_seconds": 1441898.713593, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "copy", + "repeat": 1, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 125, + "rss_peak_bytes": 9469952, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 162629252, + "cpu_ns": 88543490, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 100663296, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 126, + "reuses": 3970, + "budget_waits": 1913, + "slot_waits": 0, + "sleep_ns": 77289755, + "latency_mean_ns": 9526763.21, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 13455924, + "active_byte_seconds": 1279274.820821, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold2", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 177629041, + "cpu_ns": 82100973, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1640, + "slot_waits": 0, + "sleep_ns": 98770708, + "latency_mean_ns": 10557136.903, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 13384591, + "active_byte_seconds": 1409274.391678, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "borrow", + "repeat": 1, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 176146657, + "cpu_ns": 82398748, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1605, + "slot_waits": 0, + "sleep_ns": 97290225, + "latency_mean_ns": 10456864.841, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 12598464, + "active_byte_seconds": 1395956.019109, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold4", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 177871837, + "cpu_ns": 82048383, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1692, + "slot_waits": 0, + "sleep_ns": 99804043, + "latency_mean_ns": 10550904.139, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 13302146, + "active_byte_seconds": 1408308.914356, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "copy", + "repeat": 2, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 125, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 178298984, + "cpu_ns": 83177513, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 100663296, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 126, + "reuses": 3970, + "budget_waits": 1922, + "slot_waits": 0, + "sleep_ns": 99077474, + "latency_mean_ns": 10508907.261, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 13207943, + "active_byte_seconds": 1411086.299499, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "project", + "repeat": 2, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 181467845, + "cpu_ns": 82821089, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1672, + "slot_waits": 0, + "sleep_ns": 102626015, + "latency_mean_ns": 10774249.202, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 12846870, + "active_byte_seconds": 1438045.689091, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold2", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9469952, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 133633132, + "cpu_ns": 106591389, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 396, + "slot_waits": 0, + "sleep_ns": 28102711, + "latency_mean_ns": 7778565.752, + "latency_p99_upper_ns": 11534336, + "latency_max_ns": 12128873, + "active_byte_seconds": 1042347.024547, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold4", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 177934893, + "cpu_ns": 82638851, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1719, + "slot_waits": 0, + "sleep_ns": 98938213, + "latency_mean_ns": 10577573.546, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 12061188, + "active_byte_seconds": 1411845.015325, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "pressure", + "repeat": 2, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 180208516, + "cpu_ns": 83532190, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1755, + "slot_waits": 0, + "sleep_ns": 100354141, + "latency_mean_ns": 10704952.958, + "latency_p99_upper_ns": 11534336, + "latency_max_ns": 11578059, + "active_byte_seconds": 1428781.613196, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "copy_no_pool", + "repeat": 2, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 125, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 185672333, + "cpu_ns": 80542923, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 100663296, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 1923, + "slot_waits": 0, + "sleep_ns": 109123678, + "latency_mean_ns": 10977524.849, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 13368332, + "active_byte_seconds": 1473966.510893, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold8", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9469952, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 184526170, + "cpu_ns": 78362511, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1834, + "slot_waits": 0, + "sleep_ns": 110126299, + "latency_mean_ns": 10988073.928, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 13728757, + "active_byte_seconds": 1466214.025114, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "borrow", + "repeat": 2, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 186194683, + "cpu_ns": 78514601, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1865, + "slot_waits": 0, + "sleep_ns": 111800399, + "latency_mean_ns": 11071491.94, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 13571164, + "active_byte_seconds": 1477291.36261, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "project", + "repeat": 3, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 181552086, + "cpu_ns": 80699818, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1690, + "slot_waits": 0, + "sleep_ns": 104861831, + "latency_mean_ns": 10716792.58, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 12527594, + "active_byte_seconds": 1430323.101776, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold2", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 176007991, + "cpu_ns": 84507344, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1626, + "slot_waits": 0, + "sleep_ns": 94771244, + "latency_mean_ns": 10450519.416, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 13672942, + "active_byte_seconds": 1395156.109095, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold4", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 152737854, + "cpu_ns": 99861953, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 890, + "slot_waits": 0, + "sleep_ns": 54158702, + "latency_mean_ns": 8983717.571, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 12746037, + "active_byte_seconds": 1201774.933886, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "copy", + "repeat": 3, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 125, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 184530299, + "cpu_ns": 78669541, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 100663296, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 126, + "reuses": 3970, + "budget_waits": 1923, + "slot_waits": 0, + "sleep_ns": 109915619, + "latency_mean_ns": 10914646.174, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 13287517, + "active_byte_seconds": 1465541.553301, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "copy_no_pool", + "repeat": 3, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 125, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 133391651, + "cpu_ns": 112766017, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 100663296, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 1523, + "slot_waits": 0, + "sleep_ns": 20003852, + "latency_mean_ns": 7733517.169, + "latency_p99_upper_ns": 11534336, + "latency_max_ns": 11792151, + "active_byte_seconds": 1038602.867364, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "borrow", + "repeat": 3, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9469952, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 166473036, + "cpu_ns": 87150086, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1399, + "slot_waits": 0, + "sleep_ns": 82606050, + "latency_mean_ns": 9857584.602, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 13713590, + "active_byte_seconds": 1316650.677161, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold8", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 154311406, + "cpu_ns": 92958406, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1082, + "slot_waits": 0, + "sleep_ns": 62034758, + "latency_mean_ns": 9096496.741, + "latency_p99_upper_ns": 11534336, + "latency_max_ns": 11453763, + "active_byte_seconds": 1216142.805053, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "pressure", + "repeat": 3, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 172422001, + "cpu_ns": 86572890, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1520, + "slot_waits": 0, + "sleep_ns": 89162361, + "latency_mean_ns": 10222342.367, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 13171721, + "active_byte_seconds": 1365000.503032, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "copy", + "repeat": 4, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 125, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 182776175, + "cpu_ns": 83801034, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 100663296, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 126, + "reuses": 3970, + "budget_waits": 1923, + "slot_waits": 0, + "sleep_ns": 102610607, + "latency_mean_ns": 10792342.655, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 13409628, + "active_byte_seconds": 1449128.406768, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "project", + "repeat": 4, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 172321224, + "cpu_ns": 93701381, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1317, + "slot_waits": 0, + "sleep_ns": 81313113, + "latency_mean_ns": 10121009.211, + "latency_p99_upper_ns": 13631488, + "latency_max_ns": 13629442, + "active_byte_seconds": 1352204.310615, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold8", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 161726717, + "cpu_ns": 90653564, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1291, + "slot_waits": 0, + "sleep_ns": 73742733, + "latency_mean_ns": 9543033.955, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 13496479, + "active_byte_seconds": 1275079.33543, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "copy_no_pool", + "repeat": 4, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 125, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 168343995, + "cpu_ns": 87047828, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 100663296, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 1917, + "slot_waits": 0, + "sleep_ns": 84775336, + "latency_mean_ns": 9903397.208, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 13360535, + "active_byte_seconds": 1329804.191236, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold4", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9469952, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 150178547, + "cpu_ns": 91472405, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1089, + "slot_waits": 0, + "sleep_ns": 61163642, + "latency_mean_ns": 8764951.531, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 12700278, + "active_byte_seconds": 1171761.488413, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "borrow", + "repeat": 4, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 160544406, + "cpu_ns": 90636057, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1220, + "slot_waits": 0, + "sleep_ns": 72541038, + "latency_mean_ns": 9456018.519, + "latency_p99_upper_ns": 13631488, + "latency_max_ns": 12662167, + "active_byte_seconds": 1263635.432461, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold2", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 177206635, + "cpu_ns": 83537344, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1659, + "slot_waits": 0, + "sleep_ns": 97328864, + "latency_mean_ns": 10529385.897, + "latency_p99_upper_ns": 11534336, + "latency_max_ns": 12256668, + "active_byte_seconds": 1405563.035864, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "pressure", + "repeat": 4, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 9486336, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 169205769, + "cpu_ns": 93894859, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1358, + "slot_waits": 0, + "sleep_ns": 77830920, + "latency_mean_ns": 9905630.789, + "latency_p99_upper_ns": 14680064, + "latency_max_ns": 15320344, + "active_byte_seconds": 1323477.613603, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "pressure", + "repeat": 0, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388560, + "peak_active_bytes": 8388448, + "peak_queue": 351, + "rss_peak_bytes": 11059200, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 157820358, + "cpu_ns": 72816171, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 27916032, + "copied_records": 1699, + "borrowed_records": 349, + "pressure_copies": 1699, + "allocations": 2118, + "reuses": 1629, + "budget_waits": 983, + "slot_waits": 0, + "sleep_ns": 87435519, + "latency_mean_ns": 20627967.734, + "latency_p99_upper_ns": 27262976, + "latency_max_ns": 27848623, + "active_byte_seconds": 1145134.388634, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 522496, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "project", + "repeat": 0, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388608, + "peak_active_bytes": 8388608, + "peak_queue": 359, + "rss_peak_bytes": 11059200, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 152663243, + "cpu_ns": 58871841, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1712, + "reuses": 336, + "budget_waits": 1020, + "slot_waits": 0, + "sleep_ns": 96564951, + "latency_mean_ns": 20645944.552, + "latency_p99_upper_ns": 29360128, + "latency_max_ns": 28536362, + "active_byte_seconds": 1105768.632536, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 458688, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold8", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388480, + "peak_active_bytes": 8388432, + "peak_queue": 218, + "rss_peak_bytes": 10928128, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 154865144, + "cpu_ns": 68111825, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 3824848, + "copied_records": 1008, + "borrowed_records": 1040, + "pressure_copies": 0, + "allocations": 1854, + "reuses": 1202, + "budget_waits": 1088, + "slot_waits": 0, + "sleep_ns": 89372126, + "latency_mean_ns": 12505668.119, + "latency_p99_upper_ns": 15728640, + "latency_max_ns": 16314249, + "active_byte_seconds": 1173514.267706, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1250624, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "copy_no_pool", + "repeat": 0, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388544, + "peak_active_bytes": 8388544, + "peak_queue": 351, + "rss_peak_bytes": 11042816, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 147730720, + "cpu_ns": 59461567, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 1091, + "slot_waits": 0, + "sleep_ns": 90844456, + "latency_mean_ns": 19373026.656, + "latency_p99_upper_ns": 27262976, + "latency_max_ns": 27720475, + "active_byte_seconds": 1058083.377077, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold4", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388608, + "peak_active_bytes": 8388608, + "peak_queue": 284, + "rss_peak_bytes": 11042816, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 154278831, + "cpu_ns": 65116485, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 11229392, + "copied_records": 1357, + "borrowed_records": 691, + "pressure_copies": 0, + "allocations": 1939, + "reuses": 1466, + "budget_waits": 1101, + "slot_waits": 0, + "sleep_ns": 91754428, + "latency_mean_ns": 15979998.057, + "latency_p99_upper_ns": 20971520, + "latency_max_ns": 21200642, + "active_byte_seconds": 1146944.244493, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1153216, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "copy", + "repeat": 0, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388576, + "peak_active_bytes": 8388432, + "peak_queue": 351, + "rss_peak_bytes": 11583488, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 148231627, + "cpu_ns": 61867221, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2282, + "reuses": 1814, + "budget_waits": 1066, + "slot_waits": 0, + "sleep_ns": 88853774, + "latency_mean_ns": 19421431.677, + "latency_p99_upper_ns": 27262976, + "latency_max_ns": 27565124, + "active_byte_seconds": 1061176.084143, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 522496, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold2", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388560, + "peak_active_bytes": 8388432, + "peak_queue": 351, + "rss_peak_bytes": 11583488, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 151434543, + "cpu_ns": 63073539, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28479696, + "copied_records": 1740, + "borrowed_records": 308, + "pressure_copies": 0, + "allocations": 2181, + "reuses": 1607, + "budget_waits": 1055, + "slot_waits": 0, + "sleep_ns": 90878850, + "latency_mean_ns": 19880247.948, + "latency_p99_upper_ns": 27262976, + "latency_max_ns": 27687586, + "active_byte_seconds": 1085460.729712, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 522496, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "borrow", + "repeat": 0, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8386736, + "peak_active_bytes": 8386688, + "peak_queue": 112, + "rss_peak_bytes": 11042816, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 155306143, + "cpu_ns": 76020257, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1309, + "reuses": 739, + "budget_waits": 1057, + "slot_waits": 0, + "sleep_ns": 81695551, + "latency_mean_ns": 6922951.601, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 8980622, + "active_byte_seconds": 1223077.166921, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 667904, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "copy", + "repeat": 1, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388560, + "peak_active_bytes": 8388432, + "peak_queue": 350, + "rss_peak_bytes": 11059200, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 160379239, + "cpu_ns": 76853903, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2142, + "reuses": 1954, + "budget_waits": 945, + "slot_waits": 0, + "sleep_ns": 86445280, + "latency_mean_ns": 20559126.612, + "latency_p99_upper_ns": 31457280, + "latency_max_ns": 31399761, + "active_byte_seconds": 1126649.918907, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 519424, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold2", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388560, + "peak_active_bytes": 8388432, + "peak_queue": 351, + "rss_peak_bytes": 11059200, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 154875385, + "cpu_ns": 62824900, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28479696, + "copied_records": 1740, + "borrowed_records": 308, + "pressure_copies": 0, + "allocations": 2184, + "reuses": 1604, + "budget_waits": 1064, + "slot_waits": 0, + "sleep_ns": 94824069, + "latency_mean_ns": 20387628.756, + "latency_p99_upper_ns": 29360128, + "latency_max_ns": 28330122, + "active_byte_seconds": 1114766.522227, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 522496, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "borrow", + "repeat": 1, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8386736, + "peak_active_bytes": 8386688, + "peak_queue": 112, + "rss_peak_bytes": 11059200, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 160560980, + "cpu_ns": 82185381, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1298, + "reuses": 750, + "budget_waits": 1014, + "slot_waits": 0, + "sleep_ns": 81045212, + "latency_mean_ns": 7165375.219, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 9128899, + "active_byte_seconds": 1265871.620641, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 667904, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold8", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388480, + "peak_active_bytes": 8388432, + "peak_queue": 218, + "rss_peak_bytes": 10895360, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 158376930, + "cpu_ns": 70010099, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 3824848, + "copied_records": 1008, + "borrowed_records": 1040, + "pressure_copies": 0, + "allocations": 1840, + "reuses": 1216, + "budget_waits": 1069, + "slot_waits": 0, + "sleep_ns": 91117649, + "latency_mean_ns": 12818618.589, + "latency_p99_upper_ns": 16777216, + "latency_max_ns": 16509452, + "active_byte_seconds": 1202455.090015, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1250624, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold4", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388608, + "peak_active_bytes": 8388608, + "peak_queue": 284, + "rss_peak_bytes": 11059200, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 158364004, + "cpu_ns": 67436217, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 11229392, + "copied_records": 1357, + "borrowed_records": 691, + "pressure_copies": 0, + "allocations": 1915, + "reuses": 1490, + "budget_waits": 1082, + "slot_waits": 0, + "sleep_ns": 93660619, + "latency_mean_ns": 16427087.508, + "latency_p99_upper_ns": 23068672, + "latency_max_ns": 21701826, + "active_byte_seconds": 1180098.881536, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1153216, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "pressure", + "repeat": 1, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388560, + "peak_active_bytes": 8388432, + "peak_queue": 351, + "rss_peak_bytes": 11059200, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 150598212, + "cpu_ns": 62794080, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 27916032, + "copied_records": 1699, + "borrowed_records": 349, + "pressure_copies": 1699, + "allocations": 2194, + "reuses": 1553, + "budget_waits": 1045, + "slot_waits": 0, + "sleep_ns": 90472858, + "latency_mean_ns": 19666383.09, + "latency_p99_upper_ns": 27262976, + "latency_max_ns": 27539921, + "active_byte_seconds": 1091553.931133, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 522496, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "copy_no_pool", + "repeat": 1, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388432, + "peak_active_bytes": 8388432, + "peak_queue": 351, + "rss_peak_bytes": 11042816, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 147750665, + "cpu_ns": 60136047, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 1079, + "slot_waits": 0, + "sleep_ns": 90065234, + "latency_mean_ns": 19383039.199, + "latency_p99_upper_ns": 27262976, + "latency_max_ns": 27513476, + "active_byte_seconds": 1059302.637881, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "project", + "repeat": 1, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388608, + "peak_active_bytes": 8388608, + "peak_queue": 359, + "rss_peak_bytes": 11583488, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 161035903, + "cpu_ns": 71350453, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1684, + "reuses": 364, + "budget_waits": 940, + "slot_waits": 0, + "sleep_ns": 92840414, + "latency_mean_ns": 21900800.478, + "latency_p99_upper_ns": 31457280, + "latency_max_ns": 29845877, + "active_byte_seconds": 1171929.531923, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 458688, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "copy_no_pool", + "repeat": 2, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388432, + "peak_active_bytes": 8388432, + "peak_queue": 344, + "rss_peak_bytes": 11059200, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 156784527, + "cpu_ns": 75333533, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 936, + "slot_waits": 0, + "sleep_ns": 83839404, + "latency_mean_ns": 20060454.119, + "latency_p99_upper_ns": 27262976, + "latency_max_ns": 27533828, + "active_byte_seconds": 1101855.462406, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "project", + "repeat": 2, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388608, + "peak_active_bytes": 8388608, + "peak_queue": 359, + "rss_peak_bytes": 11042816, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 155323458, + "cpu_ns": 61447221, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1698, + "reuses": 350, + "budget_waits": 1001, + "slot_waits": 0, + "sleep_ns": 96575508, + "latency_mean_ns": 21013565.399, + "latency_p99_upper_ns": 29360128, + "latency_max_ns": 28307510, + "active_byte_seconds": 1125180.461018, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 458688, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "copy", + "repeat": 2, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388576, + "peak_active_bytes": 8388544, + "peak_queue": 351, + "rss_peak_bytes": 11583488, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 148908587, + "cpu_ns": 62691660, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2295, + "reuses": 1801, + "budget_waits": 1060, + "slot_waits": 0, + "sleep_ns": 88867276, + "latency_mean_ns": 19542842.845, + "latency_p99_upper_ns": 27262976, + "latency_max_ns": 27366569, + "active_byte_seconds": 1068483.42084, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 522496, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold8", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388480, + "peak_active_bytes": 8388432, + "peak_queue": 218, + "rss_peak_bytes": 10895360, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 155250569, + "cpu_ns": 68193969, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 3824848, + "copied_records": 1008, + "borrowed_records": 1040, + "pressure_copies": 0, + "allocations": 1856, + "reuses": 1200, + "budget_waits": 1091, + "slot_waits": 0, + "sleep_ns": 89649032, + "latency_mean_ns": 12540132.329, + "latency_p99_upper_ns": 15728640, + "latency_max_ns": 16196379, + "active_byte_seconds": 1176609.476886, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1250624, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold4", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388608, + "peak_active_bytes": 8388608, + "peak_queue": 284, + "rss_peak_bytes": 11059200, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 153993443, + "cpu_ns": 64368954, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 11229392, + "copied_records": 1357, + "borrowed_records": 691, + "pressure_copies": 0, + "allocations": 1951, + "reuses": 1454, + "budget_waits": 1113, + "slot_waits": 0, + "sleep_ns": 92271541, + "latency_mean_ns": 15971202.74, + "latency_p99_upper_ns": 20971520, + "latency_max_ns": 20927051, + "active_byte_seconds": 1146423.83916, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1153216, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "borrow", + "repeat": 2, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8386736, + "peak_active_bytes": 8386688, + "peak_queue": 112, + "rss_peak_bytes": 11059200, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 156530676, + "cpu_ns": 80398481, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1289, + "reuses": 759, + "budget_waits": 1012, + "slot_waits": 0, + "sleep_ns": 78480840, + "latency_mean_ns": 6972909.934, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 9059956, + "active_byte_seconds": 1232378.631527, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 667904, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold2", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388560, + "peak_active_bytes": 8388432, + "peak_queue": 351, + "rss_peak_bytes": 11010048, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 150924192, + "cpu_ns": 62137633, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28479696, + "copied_records": 1740, + "borrowed_records": 308, + "pressure_copies": 0, + "allocations": 2185, + "reuses": 1603, + "budget_waits": 1066, + "slot_waits": 0, + "sleep_ns": 91396144, + "latency_mean_ns": 19908205.041, + "latency_p99_upper_ns": 27262976, + "latency_max_ns": 27188866, + "active_byte_seconds": 1087150.034862, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 522496, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "pressure", + "repeat": 2, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388560, + "peak_active_bytes": 8388432, + "peak_queue": 351, + "rss_peak_bytes": 11042816, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 151817449, + "cpu_ns": 63923421, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 27916032, + "copied_records": 1699, + "borrowed_records": 349, + "pressure_copies": 1699, + "allocations": 2188, + "reuses": 1559, + "budget_waits": 1043, + "slot_waits": 0, + "sleep_ns": 90636475, + "latency_mean_ns": 19811286.8, + "latency_p99_upper_ns": 27262976, + "latency_max_ns": 27547513, + "active_byte_seconds": 1100686.98981, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 522496, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "pressure", + "repeat": 3, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388560, + "peak_active_bytes": 8388432, + "peak_queue": 351, + "rss_peak_bytes": 11059200, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 150346490, + "cpu_ns": 61910200, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 27916032, + "copied_records": 1699, + "borrowed_records": 349, + "pressure_copies": 1699, + "allocations": 2191, + "reuses": 1556, + "budget_waits": 1052, + "slot_waits": 0, + "sleep_ns": 90957629, + "latency_mean_ns": 19620014.043, + "latency_p99_upper_ns": 27262976, + "latency_max_ns": 27598753, + "active_byte_seconds": 1088594.710179, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 522496, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "borrow", + "repeat": 3, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8386736, + "peak_active_bytes": 8386736, + "peak_queue": 112, + "rss_peak_bytes": 11059200, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 154664385, + "cpu_ns": 75260445, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1309, + "reuses": 739, + "budget_waits": 1060, + "slot_waits": 0, + "sleep_ns": 81727723, + "latency_mean_ns": 6891592.543, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 9042474, + "active_byte_seconds": 1217311.080951, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 667904, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "copy_no_pool", + "repeat": 3, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388448, + "peak_active_bytes": 8388448, + "peak_queue": 351, + "rss_peak_bytes": 11583488, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 149074586, + "cpu_ns": 62457772, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 1070, + "slot_waits": 0, + "sleep_ns": 89108781, + "latency_mean_ns": 19570212.309, + "latency_p99_upper_ns": 27262976, + "latency_max_ns": 27735827, + "active_byte_seconds": 1068598.834234, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold2", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388560, + "peak_active_bytes": 8388448, + "peak_queue": 351, + "rss_peak_bytes": 11010048, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 151416673, + "cpu_ns": 62409227, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28479696, + "copied_records": 1740, + "borrowed_records": 308, + "pressure_copies": 0, + "allocations": 2196, + "reuses": 1592, + "budget_waits": 1072, + "slot_waits": 0, + "sleep_ns": 91608903, + "latency_mean_ns": 19945957.829, + "latency_p99_upper_ns": 27262976, + "latency_max_ns": 27499217, + "active_byte_seconds": 1089269.648492, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 522496, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold8", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388480, + "peak_active_bytes": 8388432, + "peak_queue": 218, + "rss_peak_bytes": 10928128, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 154832681, + "cpu_ns": 68708379, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 3824848, + "copied_records": 1008, + "borrowed_records": 1040, + "pressure_copies": 0, + "allocations": 1844, + "reuses": 1212, + "budget_waits": 1080, + "slot_waits": 0, + "sleep_ns": 88746131, + "latency_mean_ns": 12500210.727, + "latency_p99_upper_ns": 15728640, + "latency_max_ns": 16133805, + "active_byte_seconds": 1173410.180784, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1250624, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold4", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388608, + "peak_active_bytes": 8388608, + "peak_queue": 284, + "rss_peak_bytes": 11059200, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 153954221, + "cpu_ns": 64939588, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 11229392, + "copied_records": 1357, + "borrowed_records": 691, + "pressure_copies": 0, + "allocations": 1938, + "reuses": 1467, + "budget_waits": 1106, + "slot_waits": 0, + "sleep_ns": 91640646, + "latency_mean_ns": 15956645.429, + "latency_p99_upper_ns": 20971520, + "latency_max_ns": 20876513, + "active_byte_seconds": 1145843.306835, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1153216, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "copy", + "repeat": 3, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388576, + "peak_active_bytes": 8388432, + "peak_queue": 348, + "rss_peak_bytes": 11026432, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 154316312, + "cpu_ns": 71405240, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2185, + "reuses": 1911, + "budget_waits": 984, + "slot_waits": 0, + "sleep_ns": 85159635, + "latency_mean_ns": 20042799.471, + "latency_p99_upper_ns": 27262976, + "latency_max_ns": 27766253, + "active_byte_seconds": 1098260.452799, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 522496, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "project", + "repeat": 3, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388608, + "peak_active_bytes": 8388608, + "peak_queue": 359, + "rss_peak_bytes": 11567104, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 153157278, + "cpu_ns": 59550541, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1715, + "reuses": 333, + "budget_waits": 1025, + "slot_waits": 0, + "sleep_ns": 96249111, + "latency_mean_ns": 20737608.082, + "latency_p99_upper_ns": 29360128, + "latency_max_ns": 28456288, + "active_byte_seconds": 1110823.213775, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 458688, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "copy", + "repeat": 4, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388576, + "peak_active_bytes": 8388432, + "peak_queue": 351, + "rss_peak_bytes": 11583488, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 148559421, + "cpu_ns": 60872675, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2291, + "reuses": 1805, + "budget_waits": 1082, + "slot_waits": 0, + "sleep_ns": 90209021, + "latency_mean_ns": 19484771.246, + "latency_p99_upper_ns": 27262976, + "latency_max_ns": 27464198, + "active_byte_seconds": 1064901.546602, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 522496, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold2", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388560, + "peak_active_bytes": 8388432, + "peak_queue": 351, + "rss_peak_bytes": 11042816, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 152463225, + "cpu_ns": 62941260, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28479696, + "copied_records": 1740, + "borrowed_records": 308, + "pressure_copies": 0, + "allocations": 2190, + "reuses": 1598, + "budget_waits": 1076, + "slot_waits": 0, + "sleep_ns": 92180791, + "latency_mean_ns": 20063222.989, + "latency_p99_upper_ns": 27262976, + "latency_max_ns": 27720123, + "active_byte_seconds": 1096182.913762, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 522496, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "project", + "repeat": 4, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388608, + "peak_active_bytes": 8388608, + "peak_queue": 359, + "rss_peak_bytes": 11567104, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 156226158, + "cpu_ns": 60922941, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1712, + "reuses": 336, + "budget_waits": 1009, + "slot_waits": 0, + "sleep_ns": 98129027, + "latency_mean_ns": 21028903.054, + "latency_p99_upper_ns": 31457280, + "latency_max_ns": 30198524, + "active_byte_seconds": 1124769.099854, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 458688, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold8", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388480, + "peak_active_bytes": 8388432, + "peak_queue": 218, + "rss_peak_bytes": 10534912, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 159080169, + "cpu_ns": 72479922, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 3824848, + "copied_records": 1008, + "borrowed_records": 1040, + "pressure_copies": 0, + "allocations": 1823, + "reuses": 1233, + "budget_waits": 1052, + "slot_waits": 0, + "sleep_ns": 89038311, + "latency_mean_ns": 12767575.616, + "latency_p99_upper_ns": 16777216, + "latency_max_ns": 17017117, + "active_byte_seconds": 1198559.835478, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1250624, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "borrow", + "repeat": 4, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8386736, + "peak_active_bytes": 8386688, + "peak_queue": 112, + "rss_peak_bytes": 11059200, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 160859182, + "cpu_ns": 83693169, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1286, + "reuses": 762, + "budget_waits": 998, + "slot_waits": 0, + "sleep_ns": 79719697, + "latency_mean_ns": 7168367.113, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 9348362, + "active_byte_seconds": 1265838.726396, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 667904, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "copy_no_pool", + "repeat": 4, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388432, + "peak_active_bytes": 8388432, + "peak_queue": 350, + "rss_peak_bytes": 11059200, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 153665517, + "cpu_ns": 63556619, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 1061, + "slot_waits": 0, + "sleep_ns": 92811834, + "latency_mean_ns": 20225367.343, + "latency_p99_upper_ns": 29360128, + "latency_max_ns": 27663216, + "active_byte_seconds": 1106709.142867, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold4", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388608, + "peak_active_bytes": 8388608, + "peak_queue": 284, + "rss_peak_bytes": 11059200, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 154918866, + "cpu_ns": 67062426, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 11229392, + "copied_records": 1357, + "borrowed_records": 691, + "pressure_copies": 0, + "allocations": 1917, + "reuses": 1488, + "budget_waits": 1084, + "slot_waits": 0, + "sleep_ns": 90513202, + "latency_mean_ns": 16065937.041, + "latency_p99_upper_ns": 20971520, + "latency_max_ns": 20956347, + "active_byte_seconds": 1153471.713074, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1153216, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "pressure", + "repeat": 4, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388560, + "peak_active_bytes": 8388432, + "peak_queue": 351, + "rss_peak_bytes": 11026432, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 150607823, + "cpu_ns": 62564984, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 27916032, + "copied_records": 1699, + "borrowed_records": 349, + "pressure_copies": 1699, + "allocations": 2185, + "reuses": 1562, + "budget_waits": 1048, + "slot_waits": 0, + "sleep_ns": 90639036, + "latency_mean_ns": 19672453.154, + "latency_p99_upper_ns": 27262976, + "latency_max_ns": 27555809, + "active_byte_seconds": 1091824.795529, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 522496, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "pressure", + "repeat": 0, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 113, + "rss_peak_bytes": 4243456, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 190186189, + "cpu_ns": 62042049, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28385168, + "copied_records": 1727, + "borrowed_records": 321, + "pressure_copies": 1727, + "allocations": 2373, + "reuses": 1402, + "budget_waits": 1378, + "slot_waits": 0, + "sleep_ns": 130967488, + "latency_mean_ns": 6127305.056, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 9614324, + "active_byte_seconds": 346183.559002, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "project", + "repeat": 0, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097120, + "peak_active_bytes": 2097120, + "peak_queue": 118, + "rss_peak_bytes": 4227072, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 175306603, + "cpu_ns": 59313331, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1720, + "reuses": 328, + "budget_waits": 1300, + "slot_waits": 0, + "sleep_ns": 118791611, + "latency_mean_ns": 6273925.584, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8853437, + "active_byte_seconds": 326279.178906, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 406848, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold4", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097104, + "peak_queue": 88, + "rss_peak_bytes": 4227072, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 225451606, + "cpu_ns": 64792167, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 11229392, + "copied_records": 1357, + "borrowed_records": 691, + "pressure_copies": 0, + "allocations": 2134, + "reuses": 1271, + "budget_waits": 1457, + "slot_waits": 0, + "sleep_ns": 163697658, + "latency_mean_ns": 5851904.688, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 10247748, + "active_byte_seconds": 413690.587373, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 435392, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "copy", + "repeat": 0, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097152, + "peak_active_bytes": 2097136, + "peak_queue": 115, + "rss_peak_bytes": 4227072, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 191774166, + "cpu_ns": 62795054, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2467, + "reuses": 1629, + "budget_waits": 1361, + "slot_waits": 0, + "sleep_ns": 131825729, + "latency_mean_ns": 6045168.869, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8688826, + "active_byte_seconds": 346452.547175, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "copy_no_pool", + "repeat": 0, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 107, + "rss_peak_bytes": 4243456, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 195726691, + "cpu_ns": 69455356, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 1284, + "slot_waits": 0, + "sleep_ns": 128917157, + "latency_mean_ns": 6157981.172, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 9013123, + "active_byte_seconds": 353204.287515, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold8", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097152, + "peak_active_bytes": 2097136, + "peak_queue": 73, + "rss_peak_bytes": 4227072, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 284917692, + "cpu_ns": 71405280, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 3824848, + "copied_records": 1008, + "borrowed_records": 1040, + "pressure_copies": 0, + "allocations": 1986, + "reuses": 1070, + "budget_waits": 1377, + "slot_waits": 0, + "sleep_ns": 216762211, + "latency_mean_ns": 5735627.926, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 9131844, + "active_byte_seconds": 525336.273255, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 386176, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "borrow", + "repeat": 0, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2094128, + "peak_active_bytes": 2094128, + "peak_queue": 40, + "rss_peak_bytes": 3702784, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 493631884, + "cpu_ns": 81275705, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1338, + "reuses": 710, + "budget_waits": 1381, + "slot_waits": 0, + "sleep_ns": 416164894, + "latency_mean_ns": 5487868.994, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 10310562, + "active_byte_seconds": 930117.776585, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 495872, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold2", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 115, + "rss_peak_bytes": 4227072, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 188818619, + "cpu_ns": 63133028, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28479696, + "copied_records": 1740, + "borrowed_records": 308, + "pressure_copies": 0, + "allocations": 2370, + "reuses": 1418, + "budget_waits": 1385, + "slot_waits": 0, + "sleep_ns": 128526332, + "latency_mean_ns": 6127166.122, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8910974, + "active_byte_seconds": 342945.952067, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "project", + "repeat": 1, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097120, + "peak_active_bytes": 2097120, + "peak_queue": 118, + "rss_peak_bytes": 4243456, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 179280258, + "cpu_ns": 63072197, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1706, + "reuses": 342, + "budget_waits": 1292, + "slot_waits": 0, + "sleep_ns": 119263134, + "latency_mean_ns": 6405571.191, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 9266621, + "active_byte_seconds": 333023.673744, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 406848, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold8", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 72, + "rss_peak_bytes": 4358144, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 289852215, + "cpu_ns": 73110582, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 3824848, + "copied_records": 1008, + "borrowed_records": 1040, + "pressure_copies": 0, + "allocations": 1968, + "reuses": 1088, + "budget_waits": 1366, + "slot_waits": 0, + "sleep_ns": 216619289, + "latency_mean_ns": 5811531.61, + "latency_p99_upper_ns": 10485760, + "latency_max_ns": 14653198, + "active_byte_seconds": 533913.89253, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 386176, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "copy_no_pool", + "repeat": 1, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 117, + "rss_peak_bytes": 4243456, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 192676756, + "cpu_ns": 64089681, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 1353, + "slot_waits": 0, + "sleep_ns": 131367991, + "latency_mean_ns": 6074626.45, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 9595565, + "active_byte_seconds": 347823.24917, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "pressure", + "repeat": 1, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 115, + "rss_peak_bytes": 4456448, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 190841576, + "cpu_ns": 65297407, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28385168, + "copied_records": 1727, + "borrowed_records": 321, + "pressure_copies": 1727, + "allocations": 2364, + "reuses": 1411, + "budget_waits": 1367, + "slot_waits": 0, + "sleep_ns": 128364836, + "latency_mean_ns": 6138653.731, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 9614713, + "active_byte_seconds": 347120.008423, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "copy", + "repeat": 1, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097152, + "peak_active_bytes": 2097136, + "peak_queue": 114, + "rss_peak_bytes": 4407296, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 191186483, + "cpu_ns": 62157319, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2461, + "reuses": 1635, + "budget_waits": 1369, + "slot_waits": 0, + "sleep_ns": 131673734, + "latency_mean_ns": 6044094.394, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8856067, + "active_byte_seconds": 346056.920887, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold2", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 116, + "rss_peak_bytes": 4227072, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 189607302, + "cpu_ns": 65204064, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28479696, + "copied_records": 1740, + "borrowed_records": 308, + "pressure_copies": 0, + "allocations": 2354, + "reuses": 1434, + "budget_waits": 1374, + "slot_waits": 0, + "sleep_ns": 127228274, + "latency_mean_ns": 6129531.969, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8917400, + "active_byte_seconds": 344084.726971, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold4", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097104, + "peak_queue": 88, + "rss_peak_bytes": 4227072, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 225029662, + "cpu_ns": 63936677, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 11229392, + "copied_records": 1357, + "borrowed_records": 691, + "pressure_copies": 0, + "allocations": 2132, + "reuses": 1273, + "budget_waits": 1459, + "slot_waits": 0, + "sleep_ns": 164083415, + "latency_mean_ns": 5845044.948, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 10255656, + "active_byte_seconds": 413025.125756, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 435392, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "borrow", + "repeat": 1, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2094128, + "peak_active_bytes": 2094128, + "peak_queue": 40, + "rss_peak_bytes": 3719168, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 493081274, + "cpu_ns": 77876795, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1342, + "reuses": 706, + "budget_waits": 1396, + "slot_waits": 0, + "sleep_ns": 417981885, + "latency_mean_ns": 5480641.02, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 9914990, + "active_byte_seconds": 929020.44715, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 495872, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "borrow", + "repeat": 2, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2094128, + "peak_active_bytes": 2094128, + "peak_queue": 40, + "rss_peak_bytes": 4243456, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 491778453, + "cpu_ns": 73168533, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1352, + "reuses": 696, + "budget_waits": 1408, + "slot_waits": 0, + "sleep_ns": 421825716, + "latency_mean_ns": 5473786.015, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 9925323, + "active_byte_seconds": 926994.460577, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 495872, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold2", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 114, + "rss_peak_bytes": 4243456, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 188770790, + "cpu_ns": 62771264, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28479696, + "copied_records": 1740, + "borrowed_records": 308, + "pressure_copies": 0, + "allocations": 2380, + "reuses": 1408, + "budget_waits": 1395, + "slot_waits": 0, + "sleep_ns": 128898177, + "latency_mean_ns": 6126984.319, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8906435, + "active_byte_seconds": 343018.464235, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "copy_no_pool", + "repeat": 2, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 116, + "rss_peak_bytes": 4227072, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 189986910, + "cpu_ns": 58086718, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 1383, + "slot_waits": 0, + "sleep_ns": 134499200, + "latency_mean_ns": 6008153.507, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8893917, + "active_byte_seconds": 343741.458999, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "project", + "repeat": 2, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097120, + "peak_active_bytes": 2097120, + "peak_queue": 118, + "rss_peak_bytes": 4243456, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 174670169, + "cpu_ns": 55539698, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1727, + "reuses": 321, + "budget_waits": 1312, + "slot_waits": 0, + "sleep_ns": 121848710, + "latency_mean_ns": 6258533.417, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8834323, + "active_byte_seconds": 325246.46456, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 406848, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "pressure", + "repeat": 2, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 117, + "rss_peak_bytes": 4227072, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 193714972, + "cpu_ns": 64286995, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28385168, + "copied_records": 1727, + "borrowed_records": 321, + "pressure_copies": 1727, + "allocations": 2353, + "reuses": 1422, + "budget_waits": 1371, + "slot_waits": 0, + "sleep_ns": 132496502, + "latency_mean_ns": 6233962.195, + "latency_p99_upper_ns": 10485760, + "latency_max_ns": 11493286, + "active_byte_seconds": 352390.15124, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "copy", + "repeat": 2, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 115, + "rss_peak_bytes": 4243456, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 191684197, + "cpu_ns": 62544845, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2479, + "reuses": 1617, + "budget_waits": 1373, + "slot_waits": 0, + "sleep_ns": 131979930, + "latency_mean_ns": 6064467.489, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8905416, + "active_byte_seconds": 346663.433689, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold4", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097104, + "peak_queue": 88, + "rss_peak_bytes": 4227072, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 229047558, + "cpu_ns": 67894565, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 11229392, + "copied_records": 1357, + "borrowed_records": 691, + "pressure_copies": 0, + "allocations": 2094, + "reuses": 1311, + "budget_waits": 1425, + "slot_waits": 0, + "sleep_ns": 164358967, + "latency_mean_ns": 5921381.751, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 10252296, + "active_byte_seconds": 418976.246455, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 435392, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold8", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 72, + "rss_peak_bytes": 4243456, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 283681970, + "cpu_ns": 69888728, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 3824848, + "copied_records": 1008, + "borrowed_records": 1040, + "pressure_copies": 0, + "allocations": 1987, + "reuses": 1069, + "budget_waits": 1378, + "slot_waits": 0, + "sleep_ns": 217008850, + "latency_mean_ns": 5688342.625, + "latency_p99_upper_ns": 7340032, + "latency_max_ns": 9247808, + "active_byte_seconds": 522809.985389, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 386176, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold2", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097152, + "peak_active_bytes": 2097136, + "peak_queue": 102, + "rss_peak_bytes": 4325376, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 201965490, + "cpu_ns": 80116546, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28479696, + "copied_records": 1740, + "borrowed_records": 308, + "pressure_copies": 0, + "allocations": 2291, + "reuses": 1497, + "budget_waits": 1275, + "slot_waits": 0, + "sleep_ns": 123310392, + "latency_mean_ns": 6483685.515, + "latency_p99_upper_ns": 10485760, + "latency_max_ns": 11156636, + "active_byte_seconds": 364031.028759, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 493440, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "borrow", + "repeat": 3, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2094128, + "peak_active_bytes": 2094128, + "peak_queue": 40, + "rss_peak_bytes": 3719168, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 494160071, + "cpu_ns": 76904068, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1346, + "reuses": 702, + "budget_waits": 1397, + "slot_waits": 0, + "sleep_ns": 420872435, + "latency_mean_ns": 5490372.664, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 9952646, + "active_byte_seconds": 930733.63783, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 495872, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "copy", + "repeat": 3, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097152, + "peak_active_bytes": 2097136, + "peak_queue": 117, + "rss_peak_bytes": 4243456, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 191245856, + "cpu_ns": 61096231, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2481, + "reuses": 1615, + "budget_waits": 1387, + "slot_waits": 0, + "sleep_ns": 132860200, + "latency_mean_ns": 6056702.267, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8733304, + "active_byte_seconds": 346194.049558, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "project", + "repeat": 3, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097120, + "peak_active_bytes": 2097120, + "peak_queue": 118, + "rss_peak_bytes": 4407296, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 174872810, + "cpu_ns": 56429902, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1726, + "reuses": 322, + "budget_waits": 1310, + "slot_waits": 0, + "sleep_ns": 121198578, + "latency_mean_ns": 6260365.932, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8926676, + "active_byte_seconds": 325635.507331, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 406848, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold4", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097104, + "peak_queue": 88, + "rss_peak_bytes": 4243456, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 224725167, + "cpu_ns": 63560757, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 11229392, + "copied_records": 1357, + "borrowed_records": 691, + "pressure_copies": 0, + "allocations": 2132, + "reuses": 1273, + "budget_waits": 1456, + "slot_waits": 0, + "sleep_ns": 164191839, + "latency_mean_ns": 5841515.207, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 10276240, + "active_byte_seconds": 412794.10328, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 435392, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold8", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 73, + "rss_peak_bytes": 4227072, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 283036048, + "cpu_ns": 73067755, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 3824848, + "copied_records": 1008, + "borrowed_records": 1040, + "pressure_copies": 0, + "allocations": 1972, + "reuses": 1084, + "budget_waits": 1379, + "slot_waits": 0, + "sleep_ns": 213650376, + "latency_mean_ns": 5678436.735, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 9220899, + "active_byte_seconds": 521434.266403, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 386176, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "pressure", + "repeat": 3, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 113, + "rss_peak_bytes": 4456448, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 189790379, + "cpu_ns": 60625611, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28385168, + "copied_records": 1727, + "borrowed_records": 321, + "pressure_copies": 1727, + "allocations": 2369, + "reuses": 1406, + "budget_waits": 1393, + "slot_waits": 0, + "sleep_ns": 131820061, + "latency_mean_ns": 6110038.652, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 9522938, + "active_byte_seconds": 345327.900203, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "copy_no_pool", + "repeat": 3, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 115, + "rss_peak_bytes": 4243456, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 192179115, + "cpu_ns": 71826579, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 1293, + "slot_waits": 0, + "sleep_ns": 123142369, + "latency_mean_ns": 6044858.508, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8899841, + "active_byte_seconds": 346584.591442, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "project", + "repeat": 4, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097120, + "peak_active_bytes": 2097120, + "peak_queue": 118, + "rss_peak_bytes": 4227072, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 175527737, + "cpu_ns": 57919540, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1728, + "reuses": 320, + "budget_waits": 1310, + "slot_waits": 0, + "sleep_ns": 120470904, + "latency_mean_ns": 6282412.787, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 8759229, + "active_byte_seconds": 326547.492623, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 406848, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold2", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 113, + "rss_peak_bytes": 4243456, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 188314755, + "cpu_ns": 61699247, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28479696, + "copied_records": 1740, + "borrowed_records": 308, + "pressure_copies": 0, + "allocations": 2377, + "reuses": 1411, + "budget_waits": 1394, + "slot_waits": 0, + "sleep_ns": 129399417, + "latency_mean_ns": 6110229.914, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8949046, + "active_byte_seconds": 342240.604823, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold8", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 72, + "rss_peak_bytes": 4243456, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 282255055, + "cpu_ns": 67344177, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 3824848, + "copied_records": 1008, + "borrowed_records": 1040, + "pressure_copies": 0, + "allocations": 1990, + "reuses": 1066, + "budget_waits": 1394, + "slot_waits": 0, + "sleep_ns": 217945110, + "latency_mean_ns": 5670280.355, + "latency_p99_upper_ns": 7340032, + "latency_max_ns": 9286807, + "active_byte_seconds": 520513.491017, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 386176, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "copy", + "repeat": 4, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 116, + "rss_peak_bytes": 4243456, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 191037345, + "cpu_ns": 60906478, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2491, + "reuses": 1605, + "budget_waits": 1378, + "slot_waits": 0, + "sleep_ns": 132768233, + "latency_mean_ns": 6050681.287, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8878730, + "active_byte_seconds": 345866.556263, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold4", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097104, + "peak_queue": 88, + "rss_peak_bytes": 4227072, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 226976916, + "cpu_ns": 67053797, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 11229392, + "copied_records": 1357, + "borrowed_records": 691, + "pressure_copies": 0, + "allocations": 2113, + "reuses": 1292, + "budget_waits": 1429, + "slot_waits": 0, + "sleep_ns": 163248630, + "latency_mean_ns": 5888077.344, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 10246777, + "active_byte_seconds": 416261.40193, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 435392, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "borrow", + "repeat": 4, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2094128, + "peak_active_bytes": 2094128, + "peak_queue": 40, + "rss_peak_bytes": 3719168, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 495149938, + "cpu_ns": 79564522, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1338, + "reuses": 710, + "budget_waits": 1391, + "slot_waits": 0, + "sleep_ns": 419504678, + "latency_mean_ns": 5510109.537, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 10578039, + "active_byte_seconds": 933361.552539, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 495872, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "pressure", + "repeat": 4, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097152, + "peak_active_bytes": 2097136, + "peak_queue": 114, + "rss_peak_bytes": 4243456, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 190688005, + "cpu_ns": 63157202, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28385168, + "copied_records": 1727, + "borrowed_records": 321, + "pressure_copies": 1727, + "allocations": 2371, + "reuses": 1404, + "budget_waits": 1387, + "slot_waits": 0, + "sleep_ns": 130503094, + "latency_mean_ns": 6140018.745, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 9550771, + "active_byte_seconds": 347232.508173, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "copy_no_pool", + "repeat": 4, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 115, + "rss_peak_bytes": 4227072, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 195072389, + "cpu_ns": 63921931, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 1348, + "slot_waits": 0, + "sleep_ns": 134032681, + "latency_mean_ns": 6160078.753, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 9678087, + "active_byte_seconds": 352079.814928, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "borrow", + "repeat": 0, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156112, + "peak_active_bytes": 156112, + "peak_queue": 1, + "rss_peak_bytes": 1605632, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 28472110, + "cpu_ns": 28306962, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 13730.123, + "latency_p99_upper_ns": 30720, + "latency_max_ns": 65982, + "active_byte_seconds": 1788.400939, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65552, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "copy_no_pool", + "repeat": 0, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1605632, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 28620499, + "cpu_ns": 28277537, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 13795.514, + "latency_p99_upper_ns": 40960, + "latency_max_ns": 86816, + "active_byte_seconds": 1561.617327, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold4", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1605632, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 20774647, + "cpu_ns": 20729258, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9997.106, + "latency_p99_upper_ns": 14336, + "latency_max_ns": 72204, + "active_byte_seconds": 1105.947559, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold2", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1589248, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 20434497, + "cpu_ns": 20435000, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9831.374, + "latency_p99_upper_ns": 13312, + "latency_max_ns": 45186, + "active_byte_seconds": 1087.202091, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "project", + "repeat": 0, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 90640, + "peak_active_bytes": 90640, + "peak_queue": 1, + "rss_peak_bytes": 1540096, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 22218843, + "cpu_ns": 22096574, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10699.094, + "latency_p99_upper_ns": 18432, + "latency_max_ns": 59093, + "active_byte_seconds": 1.68791, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 80, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold8", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1589248, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 20787962, + "cpu_ns": 20732148, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10004.317, + "latency_p99_upper_ns": 14336, + "latency_max_ns": 63834, + "active_byte_seconds": 1109.185459, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "copy", + "repeat": 0, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1605632, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 21540986, + "cpu_ns": 21477686, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10352.839, + "latency_p99_upper_ns": 18432, + "latency_max_ns": 54334, + "active_byte_seconds": 1151.439237, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "pressure", + "repeat": 0, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156112, + "peak_active_bytes": 156112, + "peak_queue": 1, + "rss_peak_bytes": 1589248, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 20305145, + "cpu_ns": 20305963, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9760.602, + "latency_p99_upper_ns": 13312, + "latency_max_ns": 58019, + "active_byte_seconds": 1256.330694, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65552, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "borrow", + "repeat": 1, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156112, + "peak_active_bytes": 156112, + "peak_queue": 1, + "rss_peak_bytes": 1605632, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 20183773, + "cpu_ns": 20183889, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9700.917, + "latency_p99_upper_ns": 13312, + "latency_max_ns": 50334, + "active_byte_seconds": 1250.328097, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65552, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold4", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1572864, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 20604128, + "cpu_ns": 20604259, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9906.217, + "latency_p99_upper_ns": 13312, + "latency_max_ns": 47686, + "active_byte_seconds": 1090.792499, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "copy", + "repeat": 1, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1605632, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 20493516, + "cpu_ns": 20493889, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9859.747, + "latency_p99_upper_ns": 14336, + "latency_max_ns": 52407, + "active_byte_seconds": 1088.217176, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "project", + "repeat": 1, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 90640, + "peak_active_bytes": 90640, + "peak_queue": 1, + "rss_peak_bytes": 1540096, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 21524893, + "cpu_ns": 21525074, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10363.91, + "latency_p99_upper_ns": 13312, + "latency_max_ns": 54889, + "active_byte_seconds": 1.632854, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 80, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold8", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1589248, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 20381497, + "cpu_ns": 20382185, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9805.745, + "latency_p99_upper_ns": 12288, + "latency_max_ns": 47353, + "active_byte_seconds": 1087.257309, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "pressure", + "repeat": 1, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156112, + "peak_active_bytes": 156112, + "peak_queue": 1, + "rss_peak_bytes": 1589248, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 20244385, + "cpu_ns": 20244778, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9731.208, + "latency_p99_upper_ns": 13312, + "latency_max_ns": 41426, + "active_byte_seconds": 1251.232387, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65552, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold2", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1605632, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 22684901, + "cpu_ns": 22652390, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10925.772, + "latency_p99_upper_ns": 22528, + "latency_max_ns": 69779, + "active_byte_seconds": 1228.197157, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "copy_no_pool", + "repeat": 1, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1589248, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 22993108, + "cpu_ns": 22893763, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 11062.46, + "latency_p99_upper_ns": 18432, + "latency_max_ns": 74149, + "active_byte_seconds": 1228.067562, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold4", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1589248, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 20874129, + "cpu_ns": 20775314, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10044.57, + "latency_p99_upper_ns": 16384, + "latency_max_ns": 55556, + "active_byte_seconds": 1112.362141, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "borrow", + "repeat": 2, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156112, + "peak_active_bytes": 156112, + "peak_queue": 1, + "rss_peak_bytes": 1572864, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 20176198, + "cpu_ns": 20176500, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9697.062, + "latency_p99_upper_ns": 12288, + "latency_max_ns": 39001, + "active_byte_seconds": 1246.966591, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65552, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "copy", + "repeat": 2, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1589248, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 20382034, + "cpu_ns": 20382277, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9806.967, + "latency_p99_upper_ns": 12288, + "latency_max_ns": 48779, + "active_byte_seconds": 1084.755978, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold8", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1605632, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 20453663, + "cpu_ns": 20454074, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9841.173, + "latency_p99_upper_ns": 13312, + "latency_max_ns": 53241, + "active_byte_seconds": 1090.324497, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "copy_no_pool", + "repeat": 2, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1605632, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 20636628, + "cpu_ns": 20636871, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9920.915, + "latency_p99_upper_ns": 13312, + "latency_max_ns": 40464, + "active_byte_seconds": 1084.995845, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "pressure", + "repeat": 2, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156112, + "peak_active_bytes": 156112, + "peak_queue": 1, + "rss_peak_bytes": 1605632, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 20413515, + "cpu_ns": 20355722, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9812.253, + "latency_p99_upper_ns": 14336, + "latency_max_ns": 64112, + "active_byte_seconds": 1264.219091, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65552, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold2", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1589248, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 20421089, + "cpu_ns": 20421796, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9825.86, + "latency_p99_upper_ns": 13312, + "latency_max_ns": 53519, + "active_byte_seconds": 1088.001718, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "project", + "repeat": 2, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 90640, + "peak_active_bytes": 90640, + "peak_queue": 1, + "rss_peak_bytes": 1540096, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 21525764, + "cpu_ns": 21526111, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10364.601, + "latency_p99_upper_ns": 13312, + "latency_max_ns": 65686, + "active_byte_seconds": 1.632264, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 80, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold2", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1605632, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 20829074, + "cpu_ns": 20798316, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10025.307, + "latency_p99_upper_ns": 15360, + "latency_max_ns": 65907, + "active_byte_seconds": 1111.338342, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "pressure", + "repeat": 3, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156112, + "peak_active_bytes": 156112, + "peak_queue": 1, + "rss_peak_bytes": 1572864, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 20018290, + "cpu_ns": 20018407, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9620.129, + "latency_p99_upper_ns": 12288, + "latency_max_ns": 34982, + "active_byte_seconds": 1238.904613, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65552, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "borrow", + "repeat": 3, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156112, + "peak_active_bytes": 156112, + "peak_queue": 1, + "rss_peak_bytes": 1589248, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 19968383, + "cpu_ns": 19952888, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9596.16, + "latency_p99_upper_ns": 11264, + "latency_max_ns": 52612, + "active_byte_seconds": 1236.323437, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65552, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold4", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1589248, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 21098686, + "cpu_ns": 21002369, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10153.021, + "latency_p99_upper_ns": 16384, + "latency_max_ns": 71204, + "active_byte_seconds": 1130.040808, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "project", + "repeat": 3, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 90640, + "peak_active_bytes": 90640, + "peak_queue": 1, + "rss_peak_bytes": 1540096, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 21459134, + "cpu_ns": 21459111, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10332.156, + "latency_p99_upper_ns": 13312, + "latency_max_ns": 41834, + "active_byte_seconds": 1.628379, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 80, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold8", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1605632, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 21122947, + "cpu_ns": 21019219, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10159.663, + "latency_p99_upper_ns": 16384, + "latency_max_ns": 63556, + "active_byte_seconds": 1125.541597, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "copy", + "repeat": 3, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1572864, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 20421330, + "cpu_ns": 20421426, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9825.919, + "latency_p99_upper_ns": 13312, + "latency_max_ns": 56575, + "active_byte_seconds": 1089.501083, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "copy_no_pool", + "repeat": 3, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1589248, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 20561183, + "cpu_ns": 20561592, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9883.337, + "latency_p99_upper_ns": 12288, + "latency_max_ns": 45185, + "active_byte_seconds": 1085.229592, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "borrow", + "repeat": 4, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156112, + "peak_active_bytes": 156112, + "peak_queue": 1, + "rss_peak_bytes": 1589248, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 20082994, + "cpu_ns": 20072296, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9647.624, + "latency_p99_upper_ns": 12288, + "latency_max_ns": 51259, + "active_byte_seconds": 1243.235174, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65552, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "pressure", + "repeat": 4, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156112, + "peak_active_bytes": 156112, + "peak_queue": 1, + "rss_peak_bytes": 1589248, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 23280610, + "cpu_ns": 23231480, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 11211.571, + "latency_p99_upper_ns": 24576, + "latency_max_ns": 54778, + "active_byte_seconds": 1448.645185, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65552, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold2", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1605632, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 21989119, + "cpu_ns": 21857259, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10590.063, + "latency_p99_upper_ns": 18432, + "latency_max_ns": 79983, + "active_byte_seconds": 1185.989886, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "copy_no_pool", + "repeat": 4, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1605632, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 21265947, + "cpu_ns": 21072353, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10215.53, + "latency_p99_upper_ns": 16384, + "latency_max_ns": 91668, + "active_byte_seconds": 1125.003597, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "project", + "repeat": 4, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 90640, + "peak_active_bytes": 90640, + "peak_queue": 1, + "rss_peak_bytes": 1507328, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 21358726, + "cpu_ns": 21358833, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10284.012, + "latency_p99_upper_ns": 13312, + "latency_max_ns": 47648, + "active_byte_seconds": 1.620534, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 80, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold8", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1572864, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 20441422, + "cpu_ns": 20426148, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9835.821, + "latency_p99_upper_ns": 13312, + "latency_max_ns": 50945, + "active_byte_seconds": 1089.704272, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "copy", + "repeat": 4, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1605632, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 20717721, + "cpu_ns": 20717834, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9969.584, + "latency_p99_upper_ns": 13312, + "latency_max_ns": 40148, + "active_byte_seconds": 1106.215747, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold4", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 1605632, + "rusage_maxrss_bytes": 27246592, + "rss_peak_source": "linux_proc_vmhwm_approximate", + "elapsed_ns": 20693813, + "cpu_ns": 20694148, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9958.775, + "latency_p99_upper_ns": 13312, + "latency_max_ns": 66019, + "active_byte_seconds": 1106.254829, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + } +] diff --git a/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/sources/benchmark.c b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/sources/benchmark.c new file mode 100644 index 0000000..c9e8120 --- /dev/null +++ b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/sources/benchmark.c @@ -0,0 +1,338 @@ +#define _POSIX_C_SOURCE 200809L +#include <assert.h> +#include <errno.h> +#include <inttypes.h> +#include <limits.h> +#include <signal.h> +#include <stdbool.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/resource.h> +#include <time.h> +#include <unistd.h> + +/* A measurement apparatus, not the Pure runtime or a general document parser. */ +enum { CACHE_SLOTS = 16, SCRATCH = 65536, HIST_SIZE = 512, MAX_FRAME = 8*1024*1024 }; +typedef struct Block { size_t capacity; uint64_t since; unsigned char bytes[]; } Block; +typedef struct Item { + Block *block; + size_t offset, length; + uint64_t start, ready; +} Item; +typedef struct Engine { + Item *queue; + Block *cache[CACHE_SLOTS]; + unsigned char scratch[SCRATCH]; + uint64_t histogram[HIST_SIZE]; + size_t slots, head, count, fixed, budget, reserved, active, cached; + size_t peak_reserved, peak_active, peak_queue; + uint64_t allocations, reuses, copies, read_bytes, written_bytes; + uint64_t accepted, emitted, copied_records, borrowed_records, pressure_copies; + uint64_t budget_waits, slot_waits, sleep_ns, hold_ns, service_ns, last_emit; + uint64_t elapsed_ns, cpu_ns, latency_sum, latency_max, start, cancel_after; + long double active_byte_ns; + unsigned ratio; + bool pool; + const char *policy, *status; +} Engine; +static volatile sig_atomic_t interrupted; +static void stop(int sig) { (void)sig; interrupted = 1; } +static uint64_t ns(clockid_t clock) { + struct timespec t; + if (clock_gettime(clock, &t)) { perror("clock_gettime"); exit(2); } + return (uint64_t)t.tv_sec * UINT64_C(1000000000) + (uint64_t)t.tv_nsec; +} +static size_t charge(const Block *b) { return sizeof(*b) + b->capacity; } +static size_t rounded(size_t n) { + size_t r = 64; + while (r < n) r *= 2; + return r; +} +static void peaks(Engine *e) { + assert(e->active + e->cached == e->reserved); + assert(e->fixed + e->reserved <= e->budget); + if (e->reserved > e->peak_reserved) e->peak_reserved = e->reserved; + if (e->active > e->peak_active) e->peak_active = e->active; +} +static void evict(Engine *e, size_t i) { + Block *b = e->cache[i]; + if (!b) return; + e->cached -= charge(b); e->reserved -= charge(b); + free(b); e->cache[i] = NULL; +} +static Block *take(Engine *e, size_t n) { + size_t capacity = rounded(n), need = sizeof(Block) + capacity; + if (e->pool) { + for (size_t i = 0; i < CACHE_SLOTS; ++i) { + Block *b = e->cache[i]; + if (b && b->capacity == capacity) { + e->cache[i] = NULL; e->cached -= need; e->active += need; + ++e->reuses; b->since = ns(CLOCK_MONOTONIC); peaks(e); return b; + } + } + } + for (size_t i = 0; i < CACHE_SLOTS && need > e->budget-e->fixed-e->reserved; ++i) + evict(e, i); + if (need > e->budget-e->fixed-e->reserved) return NULL; + Block *b = malloc(need); + if (!b) { e->status = "allocation_failed"; return NULL; } + b->capacity = capacity; b->since = ns(CLOCK_MONOTONIC); + e->reserved += need; e->active += need; ++e->allocations; peaks(e); return b; +} +static void give(Engine *e, Block *b) { + if (!b) return; + size_t bytes = charge(b); + e->active_byte_ns += (long double)bytes * (ns(CLOCK_MONOTONIC)-b->since); + e->active -= bytes; + if (e->pool && bytes <= e->budget/4-e->cached) { + for (size_t i = 0; i < CACHE_SLOTS; ++i) if (!e->cache[i]) { + e->cache[i] = b; e->cached += bytes; peaks(e); return; + } + } + e->reserved -= bytes; free(b); peaks(e); +} +static bool sleep_until(Engine *e, uint64_t deadline) { + uint64_t t = ns(CLOCK_MONOTONIC), start = t; + while (t < deadline && !interrupted) { + uint64_t delta = deadline-t; + struct timespec request = {(time_t)(delta/1000000000), (long)(delta%1000000000)}; + if (nanosleep(&request, NULL) && errno != EINTR) { e->status="sleep_failed"; return false; } + t = ns(CLOCK_MONOTONIC); + } + e->sleep_ns += t-start; + return !interrupted; +} +/* floor(log2(ns)) with eight subdivisions: upper bound error <= 12.5%. */ +static unsigned bucket(uint64_t n) { + unsigned exponent = 0; + for (uint64_t x = n; x > 1; x >>= 1) ++exponent; + if (exponent < 3) return (unsigned)n; + return exponent*8 + (unsigned)((n-(UINT64_C(1)<<exponent))>>(exponent-3)); +} +static uint64_t upper(unsigned b) { + if (b < 24) return b+1; + unsigned exponent = b/8; + if (exponent >= 63) return UINT64_MAX; + return (UINT64_C(1)<<exponent) + (uint64_t)(b%8+1)*(UINT64_C(1)<<(exponent-3)); +} +static bool write_all(Engine *e, const void *src, size_t n) { + const unsigned char *p = src; + while (n && !interrupted) { + ssize_t written = write(STDOUT_FILENO, p, n); + if (written < 0 && errno == EINTR) continue; + if (written <= 0) { e->status = "output_failed"; return false; } + p += written; n -= (size_t)written; e->written_bytes += (uint64_t)written; + } + return !interrupted; +} +static bool emit(Engine *e) { + assert(e->count); + Item *item = &e->queue[e->head]; + uint64_t ready = item->ready; + if (e->last_emit + e->service_ns > ready) ready = e->last_emit + e->service_ns; + if (!sleep_until(e, ready)) return false; + uint32_t len = (uint32_t)item->length; + unsigned char header[4] = {(unsigned char)len, (unsigned char)(len>>8), + (unsigned char)(len>>16), (unsigned char)(len>>24)}; + if (!write_all(e, header, sizeof header) || + !write_all(e, item->block->bytes+item->offset, item->length)) return false; + uint64_t now = ns(CLOCK_MONOTONIC), latency = now-item->start; + ++e->histogram[bucket(latency)]; e->latency_sum += latency; + if (latency > e->latency_max) e->latency_max = latency; + e->last_emit = now; ++e->emitted; + give(e, item->block); item->block = NULL; + e->head = (e->head+1)%e->slots; --e->count; + if (e->cancel_after && e->emitted >= e->cancel_after) { + e->status = "cancelled"; return false; + } + return true; +} +static Block *acquire(Engine *e, size_t n) { + for (;;) { + Block *b = take(e, n); + if (b) return b; + if (strcmp(e->status, "ok")) return NULL; + if (!e->count) { e->status = "budget_too_small"; return NULL; } + ++e->budget_waits; + if (!emit(e)) return NULL; + } +} +/* Returns 1 on complete read, 0 on clean EOF before any byte, -1 on failure. */ +static int read_exact(Engine *e, void *dst, size_t n) { + unsigned char *p = dst; size_t done = 0; + while (done < n && !interrupted) { + ssize_t got = read(STDIN_FILENO, p+done, n-done); + if (got < 0 && errno == EINTR) continue; + if (got < 0) { e->status="input_failed"; return -1; } + if (!got) { if (!done) return 0; e->status="truncated_input"; return -1; } + done += (size_t)got; e->read_bytes += (uint64_t)got; + } + return interrupted ? -1 : 1; +} +static bool discard(Engine *e, size_t n) { + while (n) { + size_t chunk = n < SCRATCH ? n : SCRATCH; + if (read_exact(e, e->scratch, chunk) != 1) { + if (!strcmp(e->status,"ok")) e->status="truncated_input"; + return false; + } + n -= chunk; + } + return true; +} +static uint32_t le32(const unsigned char *p) { + return (uint32_t)p[0] | (uint32_t)p[1]<<8 | (uint32_t)p[2]<<16 | (uint32_t)p[3]<<24; +} +/* Linux's rusage high-water mark survives exec. Read the current mm's HWM + * separately; proc RSS accounting is approximate, not allocator accounting. */ +static uint64_t image_peak_rss(void) { +#if defined(__linux__) + FILE *status = fopen("/proc/self/status", "r"); + if (!status) return 0; + char line[256]; unsigned long long kib = 0; + while (fgets(line, sizeof line, status)) + if (sscanf(line, "VmHWM: %llu kB", &kib) == 1) break; + fclose(status); + return (uint64_t)kib * 1024; +#else + return 0; /* No current-image peak implemented for other OSes. */ +#endif +} +static void run(Engine *e) { + for (;;) { + if (interrupted) break; + if (e->count) { + Item *head = &e->queue[e->head]; + uint64_t now = ns(CLOCK_MONOTONIC); + if (now >= head->ready && now >= e->last_emit+e->service_ns) { + if (!emit(e)) break; + continue; + } + } + if (e->count == e->slots) { ++e->slot_waits; if (!emit(e)) break; } + unsigned char header[12]; + uint64_t start = ns(CLOCK_MONOTONIC); + int got = read_exact(e, header, sizeof header); + if (got != 1) { + if (!got) while (e->count && !interrupted) if (!emit(e)) break; + break; + } + size_t payload = le32(header), offset = le32(header+4), length = le32(header+8); + if (!payload || payload > MAX_FRAME || !length || offset > payload || length > payload-offset) { + e->status="invalid_frame"; break; + } + bool project = !strcmp(e->policy,"project"); + Block *source = acquire(e, project ? length : payload); + if (!source) break; + bool valid; + if (project) { + valid = discard(e, offset) && read_exact(e, source->bytes, length)==1 && + discard(e, payload-offset-length); + offset = 0; + } else valid = read_exact(e, source->bytes, payload)==1; + if (!valid) { + if (!strcmp(e->status,"ok")) e->status="truncated_input"; + give(e, source); break; + } + bool copy = !strcmp(e->policy,"copy") || + (!strcmp(e->policy,"threshold") && rounded(payload)/rounded(length) >= e->ratio); + if (!strcmp(e->policy,"pressure")) { + /* Online rule using current charged live buffers; no future lifetime. */ + copy = rounded(length) < source->capacity && + e->active > (e->budget-e->fixed)/2; + if (copy) ++e->pressure_copies; + } + if (!project && copy) { + Block *small = acquire(e, length); + if (!small) { give(e, source); break; } + memcpy(small->bytes, source->bytes+offset, length); + e->copies += length; ++e->copied_records; + give(e, source); source = small; offset = 0; + } else if (!project) ++e->borrowed_records; + size_t tail = (e->head+e->count)%e->slots; + e->queue[tail] = (Item){source, offset, length, start, ns(CLOCK_MONOTONIC)+e->hold_ns}; + ++e->count; ++e->accepted; + if (e->count > e->peak_queue) e->peak_queue=e->count; + } + if (interrupted) e->status="cancelled"; +} +static uint64_t number(const char *s, uint64_t maximum) { + char *end; errno=0; + unsigned long long n = strtoull(s, &end, 10); + if (!*s || *s=='-' || *end || errno || n>maximum) { fprintf(stderr,"invalid number\n"); exit(2); } + return n; +} +int main(int argc, char **argv) { + Engine *e = calloc(1, sizeof *e); + if (!e) return 2; + e->policy="borrow"; e->status="ok"; e->budget=8*1024*1024; e->slots=512; + e->ratio=4; e->pool=true; + for (int i=1; i<argc; i+=2) { + if (i+1==argc) { fprintf(stderr,"options require values\n"); free(e); return 2; } + const char *key=argv[i], *value=argv[i+1]; + if (!strcmp(key,"--policy")) e->policy=value; + else if (!strcmp(key,"--budget")) e->budget=(size_t)number(value,1073741824); + else if (!strcmp(key,"--slots")) e->slots=(size_t)number(value,4096); + else if (!strcmp(key,"--hold-us")) e->hold_ns=number(value,10000000)*1000; + else if (!strcmp(key,"--service-us")) e->service_ns=number(value,10000000)*1000; + else if (!strcmp(key,"--ratio")) e->ratio=(unsigned)number(value,UINT_MAX); + else if (!strcmp(key,"--pool")) e->pool=number(value,1)!=0; + else if (!strcmp(key,"--cancel-after")) e->cancel_after=number(value,UINT64_MAX); + else { fprintf(stderr,"unknown option\n"); free(e); return 2; } + } + bool known = !strcmp(e->policy,"borrow") || !strcmp(e->policy,"copy") || + !strcmp(e->policy,"threshold") || !strcmp(e->policy,"pressure") || !strcmp(e->policy,"project"); + if (!known || !e->slots || e->slots>4096 || e->ratio<2 || e->budget>UINT64_C(1073741824) || + e->hold_ns>UINT64_C(10000000000) || e->service_ns>UINT64_C(10000000000)) { + fprintf(stderr,"invalid configuration\n"); free(e); return 2; + } + e->fixed=sizeof(*e)+e->slots*sizeof(Item); + if (e->budget < e->fixed) { fprintf(stderr,"budget below fixed metadata\n"); free(e); return 2; } + e->queue=calloc(e->slots,sizeof(Item)); + if (!e->queue) { free(e); return 2; } + signal(SIGINT,stop); signal(SIGTERM,stop); signal(SIGPIPE,SIG_IGN); + e->start=ns(CLOCK_MONOTONIC); uint64_t cpu=ns(CLOCK_PROCESS_CPUTIME_ID); + run(e); + size_t live_at_stop=e->active, cached_at_stop=e->cached; + while (e->count) { + give(e,e->queue[e->head].block); e->head=(e->head+1)%e->slots; --e->count; + } + for (size_t i=0;i<CACHE_SLOTS;++i) evict(e,i); + assert(!e->active && !e->reserved && !e->cached); + e->elapsed_ns=ns(CLOCK_MONOTONIC)-e->start; e->cpu_ns=ns(CLOCK_PROCESS_CPUTIME_ID)-cpu; + uint64_t target=e->emitted-e->emitted/100, sum=0, p99=0; + for (unsigned b=0; e->emitted && b<HIST_SIZE; ++b) { + sum+=e->histogram[b]; if (sum>=target) { p99=upper(b); break; } + } + struct rusage usage; long rss=0; + if (!getrusage(RUSAGE_SELF,&usage)) rss=usage.ru_maxrss; +#if defined(__APPLE__) + uint64_t rusage_bytes=(uint64_t)rss; +#else + uint64_t rusage_bytes=(uint64_t)rss*1024; +#endif + uint64_t rss_bytes=image_peak_rss(); + fprintf(stderr,"{\"status\":\"%s\",\"policy\":\"%s\",\"pool\":%s," + "\"budget_bytes\":%zu,\"fixed_bytes\":%zu,\"peak_reserved_bytes\":%zu," + "\"peak_active_bytes\":%zu,\"peak_queue\":%zu,\"rss_peak_bytes\":%" PRIu64 "," + "\"rusage_maxrss_bytes\":%" PRIu64 ",\"rss_peak_source\":\"%s\"," + "\"elapsed_ns\":%" PRIu64 ",\"cpu_ns\":%" PRIu64 ",\"input_bytes\":%" PRIu64 "," + "\"output_bytes\":%" PRIu64 ",\"accepted\":%" PRIu64 ",\"emitted\":%" PRIu64 "," + "\"copy_bytes\":%" PRIu64 ",\"copied_records\":%" PRIu64 ",\"borrowed_records\":%" PRIu64 "," + "\"pressure_copies\":%" PRIu64 ",\"allocations\":%" PRIu64 ",\"reuses\":%" PRIu64 "," + "\"budget_waits\":%" PRIu64 ",\"slot_waits\":%" PRIu64 ",\"sleep_ns\":%" PRIu64 "," + "\"latency_mean_ns\":%.3f,\"latency_p99_upper_ns\":%" PRIu64 ",\"latency_max_ns\":%" PRIu64 "," + "\"active_byte_seconds\":%.6Lf,\"live_at_stop_bytes\":%zu,\"cached_at_stop_bytes\":%zu," + "\"unreleased_buffer_bytes\":%zu}\n", + e->status,e->policy,e->pool?"true":"false",e->budget,e->fixed,e->fixed+e->peak_reserved, + e->fixed+e->peak_active,e->peak_queue,rss_bytes,rusage_bytes, + rss_bytes?"linux_proc_vmhwm_approximate":"unavailable",e->elapsed_ns,e->cpu_ns,e->read_bytes, + e->written_bytes,e->accepted,e->emitted,e->copies,e->copied_records,e->borrowed_records, + e->pressure_copies,e->allocations,e->reuses,e->budget_waits,e->slot_waits,e->sleep_ns, + e->emitted?(double)e->latency_sum/(double)e->emitted:0,p99,e->latency_max, + e->active_byte_ns/1e9L,live_at_stop,cached_at_stop,e->reserved); + int result=!strcmp(e->status,"ok")?0:!strcmp(e->status,"cancelled")?3:2; + free(e->queue); free(e); return result; +} diff --git a/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/sources/plan.json b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/sources/plan.json new file mode 100644 index 0000000..1737f45 --- /dev/null +++ b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/sources/plan.json @@ -0,0 +1,35 @@ +{ + "version": 2, + "written_before_measurement": true, + "revision_note": "The v1 run is preserved. Before this v2 run, RSS instrumentation was corrected and a 64-slot sparse sensitivity case was added after observing different queue occupancy. This is an exploratory follow-up, not a pre-registered confirmation.", + "seed": 20260922, + "repeats": 5, + "slots": 512, + "policies": [ + {"name": "borrow", "policy": "borrow", "pool": 1}, + {"name": "copy", "policy": "copy", "pool": 1}, + {"name": "threshold2", "policy": "threshold", "ratio": 2, "pool": 1}, + {"name": "threshold4", "policy": "threshold", "ratio": 4, "pool": 1}, + {"name": "threshold8", "policy": "threshold", "ratio": 8, "pool": 1}, + {"name": "pressure", "policy": "pressure", "pool": 1}, + {"name": "project", "policy": "project", "pool": 1}, + {"name": "copy_no_pool", "policy": "copy", "pool": 0} + ], + "cases": [ + {"name": "sparse_slow", "shape": "sparse", "records": 2048, "budget": 8388608, "hold_us": 5000, "service_us": 20}, + {"name": "sparse_slots64", "shape": "sparse", "records": 2048, "budget": 8388608, "slots": 64, "hold_us": 5000, "service_us": 20}, + {"name": "dense_slow", "shape": "dense", "records": 2048, "budget": 8388608, "hold_us": 5000, "service_us": 20}, + {"name": "mixed_slow", "shape": "mixed", "records": 2048, "budget": 8388608, "hold_us": 5000, "service_us": 20}, + {"name": "mixed_tight", "shape": "mixed", "records": 2048, "budget": 2097152, "hold_us": 5000, "service_us": 20}, + {"name": "sparse_fast", "shape": "sparse", "records": 2048, "budget": 8388608, "hold_us": 0, "service_us": 0} + ], + "expectations": [ + "Borrow retains full source allocations for small selections.", + "Copy can add CPU and transient source plus destination memory for dense selections.", + "A current-pressure rule need not outperform a static size rule or early projection.", + "Pool reuse can reduce allocation calls while increasing reserved idle memory.", + "No Pure-specific advantage, application SLO, or statistical significance is presumed." + ], + "comparison_rule": "Report all presets and repetitions; no post-hoc winner is called an out-of-sample tuned policy.", + "limits": "Single FIFO local pipeline with synthetic delayed sink. No Sonic/Node/.NET benchmark, fan-out, persistent cache, generic JSON parser, external open-loop arrivals, or production SLO." +} diff --git a/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/sources/run.py b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/sources/run.py new file mode 100644 index 0000000..49a693c --- /dev/null +++ b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/sources/run.py @@ -0,0 +1,300 @@ +#!/usr/bin/env python3 +"""Build, independently verify, and measure the retention experiment.""" +import argparse +import csv +import hashlib +import json +import os +from pathlib import Path +import platform +import random +import shlex +import signal +import statistics +import struct +import subprocess +import tempfile +import time + +ROOT = Path(__file__).resolve().parent +FLAGS = ["-std=c17", "-Wall", "-Wextra", "-Wpedantic", "-Werror", "-O2", "-g"] + + +def digest(path): + with open(path, "rb") as stream: + return hashlib.file_digest(stream, "sha256").hexdigest() + + +def dump(path, value): + path.write_text(json.dumps(value, indent=2, ensure_ascii=False) + "\n") + + +def build(cc, output, sanitizer=False): + command = [*cc, *FLAGS] + if sanitizer: + command += ["-fsanitize=address,undefined", "-fno-omit-frame-pointer"] + command += [str(ROOT / "benchmark.c"), "-o", str(output)] + result = subprocess.run(command, capture_output=True, text=True, check=True) + return {"command": command, "stderr": result.stderr, "sha256": digest(output), + "size_bytes": output.stat().st_size} + + +def shape_for(shape, rng, i): + if shape == "sparse": + return 65536, 64 + if shape == "dense": + return 65536, 49152 + if shape == "mixed": + source = rng.choice([4096, 16384, 65536, 262144]) + keep = max(16, source // rng.choice([1, 2, 4, 8, 64, 1024])) + return source, keep + if shape == "test": + return [(1, 1), (63, 17), (4097, 12), (65536, 49152), (127, 127)][i % 5] + raise ValueError(shape) + + +def fixture(path, shape, count, seed): + rng = random.Random(seed) + expected = hashlib.sha256() + total = 0 + with path.open("wb") as stream: + for i in range(count): + size, keep = shape_for(shape, rng, i) + offset = rng.randrange(size - keep + 1) + # All input bytes exist on disk; no sparse files or seeking past data. + tile = rng.randbytes(256) + payload = (tile * ((size + 255) // 256))[:size] + stream.write(struct.pack("<III", size, offset, keep)) + stream.write(payload) + out = struct.pack("<I", keep) + payload[offset:offset + keep] + expected.update(out) + total += len(out) + return {"path": path.name, "shape": shape, "records": count, "seed": seed, + "input_bytes": path.stat().st_size, "input_sha256": digest(path), + "expected_output_bytes": total, "expected_output_sha256": expected.hexdigest()} + + +def reference(data): + result = bytearray() + at = 0 + while at < len(data): + if len(data) - at < 12: + raise ValueError("short header") + size, offset, keep = struct.unpack_from("<III", data, at) + at += 12 + if not 0 < size <= 8 * 1024 * 1024 or not 0 < keep <= size or offset > size - keep: + raise ValueError("invalid frame") + if len(data) - at < size: + raise ValueError("short payload") + result.extend(struct.pack("<I", keep)) + result.extend(data[at + offset:at + offset + keep]) + at += size + return bytes(result) + + +def command(binary, case, policy, *extra): + args = [str(binary), "--policy", policy["policy"], "--pool", str(policy.get("pool", 1)), + "--ratio", str(policy.get("ratio", 4)), "--budget", str(case.get("budget", 8388608)), + "--slots", str(case.get("slots", 512)), "--hold-us", str(case.get("hold_us", 0)), + "--service-us", str(case.get("service_us", 0))] + return args + list(extra) + + +def metrics(stderr): + # Sanitizer diagnostics must not be silently ignored. + text = stderr.decode().strip() + try: + result = json.loads(text) + except json.JSONDecodeError as exc: + raise AssertionError(f"Expected metrics only; tool/runtime diagnostics:\n{text}") from exc + assert result["unreleased_buffer_bytes"] == 0, result + assert result["peak_active_bytes"] <= result["peak_reserved_bytes"] <= result["budget_bytes"], result + return result + + +def check(binary, tmp, policies): + checks = [] + test = tmp / "test.frames" + fixture(test, "test", 45, 177) + data = test.read_bytes() + expected = reference(data) + for policy in policies: + for slow in [False, True]: + case = {"slots": 7, "hold_us": 100 if slow else 0, "budget": 300000} + result = subprocess.run(command(binary, case, policy), input=data, capture_output=True, timeout=15) + m = metrics(result.stderr) + assert result.returncode == 0 and m["status"] == "ok", (policy, result.stderr) + assert result.stdout == expected and m["emitted"] == 45 + assert m["input_bytes"] == len(data) and m["output_bytes"] == len(expected) + assert m["live_at_stop_bytes"] == 0 + checks.append(f'{policy["name"]}: byte equality, accounting, cleanup, slow={slow}') + # Truncation at both header and payload boundaries, including exact missing payload. + bad_inputs = [b"x", struct.pack("<III", 12, 0, 4), + struct.pack("<III", 12, 0, 4) + b"123", + struct.pack("<III", 12, 11, 4) + b"x" * 12, + struct.pack("<III", 0, 0, 0), + struct.pack("<III", 8 * 1024 * 1024 + 1, 0, 1)] + for bad in bad_inputs: + result = subprocess.run(command(binary, {"hold_us": 1000}, policy), + input=data[:13] + bad, capture_output=True, timeout=15) + m = metrics(result.stderr) + assert result.returncode == 2 and m["status"] in {"invalid_frame", "truncated_input"} + checks.append(f'{policy["name"]}: six malformed inputs with pending buffer cleanup') + result = subprocess.run(command(binary, {"hold_us": 1000}, policy, "--cancel-after", "3"), + input=data, capture_output=True, timeout=15) + m = metrics(result.stderr) + prefix_end = 0 + for _ in range(3): + prefix_end += 4 + struct.unpack_from("<I", expected, prefix_end)[0] + assert result.returncode == 3 and m["status"] == "cancelled" and m["emitted"] == 3 + assert result.stdout == expected[:prefix_end] + checks.append(f'{policy["name"]}: cancellation preserves completed output prefix and releases pending buffers') + result = subprocess.run(command(binary, {}, policy), input=b"", capture_output=True, timeout=15) + assert result.returncode == 0 and metrics(result.stderr)["emitted"] == 0 + checks.append(f'{policy["name"]}: empty stream') + # Tight budget must refuse a whole-frame requirement, while streaming projection can work. + large = struct.pack("<III", 1048576, 17, 64) + b"a" * 1048576 + for policy in policies: + result = subprocess.run(command(binary, {"budget": 131072, "slots": 1}, policy), + input=large, capture_output=True, timeout=15) + m = metrics(result.stderr) + assert m["status"] == ("ok" if policy["policy"] == "project" else "budget_too_small") + checks.append("frame larger than buffer budget: bounded refusal versus projection") + if Path("/dev/full").exists(): + with open("/dev/full", "wb") as sink: + result = subprocess.run(command(binary, {"hold_us": 1000}, policies[0]), input=data, + stdout=sink, stderr=subprocess.PIPE, timeout=15) + assert result.returncode == 2 and metrics(result.stderr)["status"] == "output_failed" + checks.append("real output failure through /dev/full, pending buffers released") + # Real signal cancellation after allocation, while waiting for the delayed sink. + with test.open("rb") as source, open(os.devnull, "wb") as sink: + proc = subprocess.Popen(command(binary, {"hold_us": 500000}, policies[0]), + stdin=source, stdout=sink, stderr=subprocess.PIPE) + time.sleep(0.08) + proc.send_signal(signal.SIGTERM) + _, error = proc.communicate(timeout=5) + assert proc.returncode == 3 and metrics(error)["status"] == "cancelled", error + checks.append("SIGTERM interrupts delayed sink and releases buffers") + if platform.system() == "Linux": + # Regression: inherited rusage peak cannot stand in for current-image HWM. + resident = tmp / "rss.frames" + fixture(resident, "sparse", 512, 817) + values = {} + for policy in [{"policy": "borrow"}, {"policy": "project"}]: + with resident.open("rb") as source, open(os.devnull, "wb") as sink: + result = subprocess.run(command(binary, {"hold_us": 10000}, policy), + stdin=source, stdout=sink, stderr=subprocess.PIPE, timeout=15) + m = metrics(result.stderr) + assert result.returncode == 0 and m["rss_peak_source"] == "linux_proc_vmhwm_approximate" + assert m["rss_peak_bytes"] > 0 + values[policy["policy"]] = m["rss_peak_bytes"] + # Only a sanity check for this deliberately wide memory gap, not exact RSS arithmetic. + assert values["borrow"] > values["project"], values + checks.append("current-image VmHWM distinguishes large retained sources from small projections") + return checks + + +def sample(binary, source, output, case, policy): + with source.open("rb") as inp, output.open("wb") as out: + result = subprocess.run(command(binary, case, policy), stdin=inp, stdout=out, + stderr=subprocess.PIPE, timeout=30) + m = metrics(result.stderr) + assert result.returncode == 0 and m["status"] == "ok", result.stderr + return m + + +def summarize(rows): + result = [] + names = ["elapsed_ns", "cpu_ns", "peak_reserved_bytes", "peak_active_bytes", "rss_peak_bytes", + "copy_bytes", "active_byte_seconds", "latency_mean_ns", "latency_p99_upper_ns", + "budget_waits", "allocations", "reuses"] + groups = sorted({(r["case"], r["variant"]) for r in rows}) + for case, variant in groups: + group = [r for r in rows if (r["case"], r["variant"]) == (case, variant)] + value = {"case": case, "variant": variant, "samples": len(group)} + for name in names: + values = [r[name] for r in group] + value[name] = {"median": statistics.median(values), "min": min(values), "max": max(values)} + result.append(value) + return result + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--check-only", action="store_true") + parser.add_argument("--output", type=Path) + args = parser.parse_args() + if not args.check_only and args.output is None: + parser.error("provide --check-only or --output (new directory)") + if args.output: + args.output.mkdir(parents=True, exist_ok=False) + cc = shlex.split(os.environ.get("CC", "cc")) + plan = json.loads((ROOT / "plan.json").read_text()) + affinity = None + if hasattr(os, "sched_getaffinity"): + affinity = min(os.sched_getaffinity(0)) + os.sched_setaffinity(0, {affinity}) + with tempfile.TemporaryDirectory(prefix="pure-retention-") as folder: + tmp = Path(folder) + native, sanitized = tmp / "bench", tmp / "bench-sanitized" + builds = [build(cc, native), build(cc, sanitized, True)] + verification = {"native": check(native, tmp, plan["policies"]), + "asan_ubsan": check(sanitized, tmp, plan["policies"])} + print(f'Verified {sum(map(len, verification.values()))} scenario groups (native + ASan/UBSan).', flush=True) + if args.check_only: + return + sources = {name: digest(ROOT / name) for name in ["benchmark.c", "run.py", "plan.json"]} + environment = {"platform": platform.platform(), "machine": platform.machine(), + "python": platform.python_version(), "cpu_affinity": affinity, + "compiler": subprocess.check_output([*cc, "--version"], text=True), + "builds": builds, "source_sha256": sources, + "clock": "CLOCK_MONOTONIC; CPU = CLOCK_PROCESS_CPUTIME_ID", + "timing": "includes file IO, scheduling, deliberate sleep, metrics, buffer cleanup; excludes startup/build/fixture/verification", + "limitations": "shared host; unregulated thermals; cached files; output page cache, no fsync; synthetic closed-loop arrivals", + "started_utc": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())} + if Path("/proc/cpuinfo").exists(): + environment["cpuinfo"] = Path("/proc/cpuinfo").read_text() + dump(args.output / "environment.json", environment) + dump(args.output / "verification.json", verification) + dump(args.output / "plan.json", plan) + (args.output / "sources").mkdir() + for name in sources: + (args.output / "sources" / name).write_bytes((ROOT / name).read_bytes()) + fixtures, rows = [], [] + rng = random.Random(plan["seed"]) + for case in plan["cases"]: + source, output = tmp / "input.frames", tmp / "output.frames" + info = fixture(source, case["shape"], case["records"], plan["seed"]) + info["case"] = case["name"] + fixtures.append(info) + # Warm each strategy once. The following measurements use fresh processes. + for policy in plan["policies"]: + sample(native, source, output, case, policy) + assert digest(output) == info["expected_output_sha256"] + for repeat in range(plan["repeats"]): + order = list(plan["policies"]) + rng.shuffle(order) + for policy in order: + m = sample(native, source, output, case, policy) + assert m["accepted"] == m["emitted"] == case["records"] + assert m["input_bytes"] == info["input_bytes"] + assert m["output_bytes"] == info["expected_output_bytes"] + assert digest(output) == info["expected_output_sha256"] + rows.append({"case": case["name"], "variant": policy["name"], "repeat": repeat, **m}) + dump(args.output / "raw.json", rows) + dump(args.output / "fixtures.json", fixtures) + print(f'Completed {case["name"]}: {len(plan["policies"])} variants x {plan["repeats"]} trials.', flush=True) + dump(args.output / "summary.json", summarize(rows)) + with (args.output / "raw.csv").open("w") as out: + writer = csv.DictWriter(out, fieldnames=list(rows[0])) + writer.writeheader() + writer.writerows(rows) + # Detect accidental source edits during a measurement run. + assert sources == {name: digest(ROOT / name) for name in sources} + dump(args.output / "complete.json", {"samples": len(rows), "all_output_hashes_match": True, + "finished_utc": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())}) + print(args.output.resolve()) + + +if __name__ == "__main__": + main() diff --git a/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/summary.json b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/summary.json new file mode 100644 index 0000000..fceebba --- /dev/null +++ b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/summary.json @@ -0,0 +1,3122 @@ +[ + { + "case": "dense_slow", + "variant": "borrow", + "samples": 5, + "elapsed_ns": { + "median": 176146657, + "min": 160544406, + "max": 186194683 + }, + "cpu_ns": { + "median": 82398748, + "min": 78514601, + "max": 90636057 + }, + "peak_reserved_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "peak_active_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "rss_peak_bytes": { + "median": 9486336, + "min": 9469952, + "max": 9486336 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 1395956.019109, + "min": 1263635.432461, + "max": 1477291.36261 + }, + "latency_mean_ns": { + "median": 10456864.841, + "min": 9456018.519, + "max": 11071491.94 + }, + "latency_p99_upper_ns": { + "median": 12582912, + "min": 12582912, + "max": 13631488 + }, + "budget_waits": { + "median": 1605, + "min": 1220, + "max": 1865 + }, + "allocations": { + "median": 126, + "min": 126, + "max": 126 + }, + "reuses": { + "median": 1922, + "min": 1922, + "max": 1922 + } + }, + { + "case": "dense_slow", + "variant": "copy", + "samples": 5, + "elapsed_ns": { + "median": 181070273, + "min": 162629252, + "max": 184530299 + }, + "cpu_ns": { + "median": 83392187, + "min": 78669541, + "max": 88543490 + }, + "peak_reserved_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "peak_active_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "rss_peak_bytes": { + "median": 9486336, + "min": 9469952, + "max": 9486336 + }, + "copy_bytes": { + "median": 100663296, + "min": 100663296, + "max": 100663296 + }, + "active_byte_seconds": { + "median": 1435135.645514, + "min": 1279274.820821, + "max": 1465541.553301 + }, + "latency_mean_ns": { + "median": 10688072.436, + "min": 9526763.21, + "max": 10914646.174 + }, + "latency_p99_upper_ns": { + "median": 12582912, + "min": 12582912, + "max": 12582912 + }, + "budget_waits": { + "median": 1923, + "min": 1913, + "max": 1923 + }, + "allocations": { + "median": 126, + "min": 126, + "max": 126 + }, + "reuses": { + "median": 3970, + "min": 3970, + "max": 3970 + } + }, + { + "case": "dense_slow", + "variant": "copy_no_pool", + "samples": 5, + "elapsed_ns": { + "median": 181746660, + "min": 133391651, + "max": 185672333 + }, + "cpu_ns": { + "median": 80542923, + "min": 79010560, + "max": 112766017 + }, + "peak_reserved_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "peak_active_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "rss_peak_bytes": { + "median": 9486336, + "min": 9469952, + "max": 9486336 + }, + "copy_bytes": { + "median": 100663296, + "min": 100663296, + "max": 100663296 + }, + "active_byte_seconds": { + "median": 1442582.012105, + "min": 1038602.867364, + "max": 1473966.510893 + }, + "latency_mean_ns": { + "median": 10743611.753, + "min": 7733517.169, + "max": 10977524.849 + }, + "latency_p99_upper_ns": { + "median": 12582912, + "min": 11534336, + "max": 12582912 + }, + "budget_waits": { + "median": 1923, + "min": 1523, + "max": 1923 + }, + "allocations": { + "median": 4096, + "min": 4096, + "max": 4096 + }, + "reuses": { + "median": 0, + "min": 0, + "max": 0 + } + }, + { + "case": "dense_slow", + "variant": "pressure", + "samples": 5, + "elapsed_ns": { + "median": 180208516, + "min": 169205769, + "max": 181604364 + }, + "cpu_ns": { + "median": 83532190, + "min": 78951924, + "max": 93894859 + }, + "peak_reserved_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "peak_active_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "rss_peak_bytes": { + "median": 9486336, + "min": 9486336, + "max": 9486336 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 1428781.613196, + "min": 1323477.613603, + "max": 1442046.73663 + }, + "latency_mean_ns": { + "median": 10704952.958, + "min": 9905630.789, + "max": 10805826.457 + }, + "latency_p99_upper_ns": { + "median": 12582912, + "min": 11534336, + "max": 14680064 + }, + "budget_waits": { + "median": 1755, + "min": 1358, + "max": 1794 + }, + "allocations": { + "median": 126, + "min": 126, + "max": 126 + }, + "reuses": { + "median": 1922, + "min": 1922, + "max": 1922 + } + }, + { + "case": "dense_slow", + "variant": "project", + "samples": 5, + "elapsed_ns": { + "median": 181552086, + "min": 172321224, + "max": 187716865 + }, + "cpu_ns": { + "median": 80699818, + "min": 74974355, + "max": 93701381 + }, + "peak_reserved_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "peak_active_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "rss_peak_bytes": { + "median": 9486336, + "min": 9469952, + "max": 9486336 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 1438045.689091, + "min": 1352204.310615, + "max": 1492582.952313 + }, + "latency_mean_ns": { + "median": 10774249.202, + "min": 10121009.211, + "max": 11188037.068 + }, + "latency_p99_upper_ns": { + "median": 12582912, + "min": 12582912, + "max": 13631488 + }, + "budget_waits": { + "median": 1690, + "min": 1317, + "max": 1885 + }, + "allocations": { + "median": 126, + "min": 126, + "max": 126 + }, + "reuses": { + "median": 1922, + "min": 1922, + "max": 1922 + } + }, + { + "case": "dense_slow", + "variant": "threshold2", + "samples": 5, + "elapsed_ns": { + "median": 177206635, + "min": 133633132, + "max": 179808887 + }, + "cpu_ns": { + "median": 83537344, + "min": 82100973, + "max": 106591389 + }, + "peak_reserved_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "peak_active_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "rss_peak_bytes": { + "median": 9486336, + "min": 9469952, + "max": 9486336 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 1405563.035864, + "min": 1042347.024547, + "max": 1427516.577261 + }, + "latency_mean_ns": { + "median": 10529385.897, + "min": 7778565.752, + "max": 10695483.804 + }, + "latency_p99_upper_ns": { + "median": 12582912, + "min": 11534336, + "max": 12582912 + }, + "budget_waits": { + "median": 1640, + "min": 396, + "max": 1739 + }, + "allocations": { + "median": 126, + "min": 126, + "max": 126 + }, + "reuses": { + "median": 1922, + "min": 1922, + "max": 1922 + } + }, + { + "case": "dense_slow", + "variant": "threshold4", + "samples": 5, + "elapsed_ns": { + "median": 161215386, + "min": 150178547, + "max": 177934893 + }, + "cpu_ns": { + "median": 89862451, + "min": 82048383, + "max": 99861953 + }, + "peak_reserved_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "peak_active_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "rss_peak_bytes": { + "median": 9486336, + "min": 9469952, + "max": 9486336 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 1273441.862727, + "min": 1171761.488413, + "max": 1411845.015325 + }, + "latency_mean_ns": { + "median": 9530310.653, + "min": 8764951.531, + "max": 10577573.546 + }, + "latency_p99_upper_ns": { + "median": 12582912, + "min": 11534336, + "max": 12582912 + }, + "budget_waits": { + "median": 1244, + "min": 890, + "max": 1719 + }, + "allocations": { + "median": 126, + "min": 126, + "max": 126 + }, + "reuses": { + "median": 1922, + "min": 1922, + "max": 1922 + } + }, + { + "case": "dense_slow", + "variant": "threshold8", + "samples": 5, + "elapsed_ns": { + "median": 177819652, + "min": 154311406, + "max": 184526170 + }, + "cpu_ns": { + "median": 80765616, + "min": 78362511, + "max": 92958406 + }, + "peak_reserved_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "peak_active_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "rss_peak_bytes": { + "median": 9486336, + "min": 9469952, + "max": 9486336 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 1410709.704111, + "min": 1216142.805053, + "max": 1466214.025114 + }, + "latency_mean_ns": { + "median": 10569593.51, + "min": 9096496.741, + "max": 10988073.928 + }, + "latency_p99_upper_ns": { + "median": 12582912, + "min": 11534336, + "max": 12582912 + }, + "budget_waits": { + "median": 1732, + "min": 1082, + "max": 1834 + }, + "allocations": { + "median": 126, + "min": 126, + "max": 126 + }, + "reuses": { + "median": 1922, + "min": 1922, + "max": 1922 + } + }, + { + "case": "mixed_slow", + "variant": "borrow", + "samples": 5, + "elapsed_ns": { + "median": 156530676, + "min": 154664385, + "max": 160859182 + }, + "cpu_ns": { + "median": 80398481, + "min": 75260445, + "max": 83693169 + }, + "peak_reserved_bytes": { + "median": 8386736, + "min": 8386736, + "max": 8386736 + }, + "peak_active_bytes": { + "median": 8386688, + "min": 8386688, + "max": 8386736 + }, + "rss_peak_bytes": { + "median": 11059200, + "min": 11042816, + "max": 11059200 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 1232378.631527, + "min": 1217311.080951, + "max": 1265871.620641 + }, + "latency_mean_ns": { + "median": 6972909.934, + "min": 6891592.543, + "max": 7168367.113 + }, + "latency_p99_upper_ns": { + "median": 9437184, + "min": 9437184, + "max": 9437184 + }, + "budget_waits": { + "median": 1014, + "min": 998, + "max": 1060 + }, + "allocations": { + "median": 1298, + "min": 1286, + "max": 1309 + }, + "reuses": { + "median": 750, + "min": 739, + "max": 762 + } + }, + { + "case": "mixed_slow", + "variant": "copy", + "samples": 5, + "elapsed_ns": { + "median": 148908587, + "min": 148231627, + "max": 160379239 + }, + "cpu_ns": { + "median": 62691660, + "min": 60872675, + "max": 76853903 + }, + "peak_reserved_bytes": { + "median": 8388576, + "min": 8388560, + "max": 8388576 + }, + "peak_active_bytes": { + "median": 8388432, + "min": 8388432, + "max": 8388544 + }, + "rss_peak_bytes": { + "median": 11583488, + "min": 11026432, + "max": 11583488 + }, + "copy_bytes": { + "median": 53727440, + "min": 53727440, + "max": 53727440 + }, + "active_byte_seconds": { + "median": 1068483.42084, + "min": 1061176.084143, + "max": 1126649.918907 + }, + "latency_mean_ns": { + "median": 19542842.845, + "min": 19421431.677, + "max": 20559126.612 + }, + "latency_p99_upper_ns": { + "median": 27262976, + "min": 27262976, + "max": 31457280 + }, + "budget_waits": { + "median": 1060, + "min": 945, + "max": 1082 + }, + "allocations": { + "median": 2282, + "min": 2142, + "max": 2295 + }, + "reuses": { + "median": 1814, + "min": 1801, + "max": 1954 + } + }, + { + "case": "mixed_slow", + "variant": "copy_no_pool", + "samples": 5, + "elapsed_ns": { + "median": 149074586, + "min": 147730720, + "max": 156784527 + }, + "cpu_ns": { + "median": 62457772, + "min": 59461567, + "max": 75333533 + }, + "peak_reserved_bytes": { + "median": 8388432, + "min": 8388432, + "max": 8388544 + }, + "peak_active_bytes": { + "median": 8388432, + "min": 8388432, + "max": 8388544 + }, + "rss_peak_bytes": { + "median": 11059200, + "min": 11042816, + "max": 11583488 + }, + "copy_bytes": { + "median": 53727440, + "min": 53727440, + "max": 53727440 + }, + "active_byte_seconds": { + "median": 1068598.834234, + "min": 1058083.377077, + "max": 1106709.142867 + }, + "latency_mean_ns": { + "median": 19570212.309, + "min": 19373026.656, + "max": 20225367.343 + }, + "latency_p99_upper_ns": { + "median": 27262976, + "min": 27262976, + "max": 29360128 + }, + "budget_waits": { + "median": 1070, + "min": 936, + "max": 1091 + }, + "allocations": { + "median": 4096, + "min": 4096, + "max": 4096 + }, + "reuses": { + "median": 0, + "min": 0, + "max": 0 + } + }, + { + "case": "mixed_slow", + "variant": "pressure", + "samples": 5, + "elapsed_ns": { + "median": 150607823, + "min": 150346490, + "max": 157820358 + }, + "cpu_ns": { + "median": 62794080, + "min": 61910200, + "max": 72816171 + }, + "peak_reserved_bytes": { + "median": 8388560, + "min": 8388560, + "max": 8388560 + }, + "peak_active_bytes": { + "median": 8388432, + "min": 8388432, + "max": 8388448 + }, + "rss_peak_bytes": { + "median": 11059200, + "min": 11026432, + "max": 11059200 + }, + "copy_bytes": { + "median": 27916032, + "min": 27916032, + "max": 27916032 + }, + "active_byte_seconds": { + "median": 1091824.795529, + "min": 1088594.710179, + "max": 1145134.388634 + }, + "latency_mean_ns": { + "median": 19672453.154, + "min": 19620014.043, + "max": 20627967.734 + }, + "latency_p99_upper_ns": { + "median": 27262976, + "min": 27262976, + "max": 27262976 + }, + "budget_waits": { + "median": 1045, + "min": 983, + "max": 1052 + }, + "allocations": { + "median": 2188, + "min": 2118, + "max": 2194 + }, + "reuses": { + "median": 1559, + "min": 1553, + "max": 1629 + } + }, + { + "case": "mixed_slow", + "variant": "project", + "samples": 5, + "elapsed_ns": { + "median": 155323458, + "min": 152663243, + "max": 161035903 + }, + "cpu_ns": { + "median": 60922941, + "min": 58871841, + "max": 71350453 + }, + "peak_reserved_bytes": { + "median": 8388608, + "min": 8388608, + "max": 8388608 + }, + "peak_active_bytes": { + "median": 8388608, + "min": 8388608, + "max": 8388608 + }, + "rss_peak_bytes": { + "median": 11567104, + "min": 11042816, + "max": 11583488 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 1124769.099854, + "min": 1105768.632536, + "max": 1171929.531923 + }, + "latency_mean_ns": { + "median": 21013565.399, + "min": 20645944.552, + "max": 21900800.478 + }, + "latency_p99_upper_ns": { + "median": 29360128, + "min": 29360128, + "max": 31457280 + }, + "budget_waits": { + "median": 1009, + "min": 940, + "max": 1025 + }, + "allocations": { + "median": 1712, + "min": 1684, + "max": 1715 + }, + "reuses": { + "median": 336, + "min": 333, + "max": 364 + } + }, + { + "case": "mixed_slow", + "variant": "threshold2", + "samples": 5, + "elapsed_ns": { + "median": 151434543, + "min": 150924192, + "max": 154875385 + }, + "cpu_ns": { + "median": 62824900, + "min": 62137633, + "max": 63073539 + }, + "peak_reserved_bytes": { + "median": 8388560, + "min": 8388560, + "max": 8388560 + }, + "peak_active_bytes": { + "median": 8388432, + "min": 8388432, + "max": 8388448 + }, + "rss_peak_bytes": { + "median": 11042816, + "min": 11010048, + "max": 11583488 + }, + "copy_bytes": { + "median": 28479696, + "min": 28479696, + "max": 28479696 + }, + "active_byte_seconds": { + "median": 1089269.648492, + "min": 1085460.729712, + "max": 1114766.522227 + }, + "latency_mean_ns": { + "median": 19945957.829, + "min": 19880247.948, + "max": 20387628.756 + }, + "latency_p99_upper_ns": { + "median": 27262976, + "min": 27262976, + "max": 29360128 + }, + "budget_waits": { + "median": 1066, + "min": 1055, + "max": 1076 + }, + "allocations": { + "median": 2185, + "min": 2181, + "max": 2196 + }, + "reuses": { + "median": 1603, + "min": 1592, + "max": 1607 + } + }, + { + "case": "mixed_slow", + "variant": "threshold4", + "samples": 5, + "elapsed_ns": { + "median": 154278831, + "min": 153954221, + "max": 158364004 + }, + "cpu_ns": { + "median": 65116485, + "min": 64368954, + "max": 67436217 + }, + "peak_reserved_bytes": { + "median": 8388608, + "min": 8388608, + "max": 8388608 + }, + "peak_active_bytes": { + "median": 8388608, + "min": 8388608, + "max": 8388608 + }, + "rss_peak_bytes": { + "median": 11059200, + "min": 11042816, + "max": 11059200 + }, + "copy_bytes": { + "median": 11229392, + "min": 11229392, + "max": 11229392 + }, + "active_byte_seconds": { + "median": 1146944.244493, + "min": 1145843.306835, + "max": 1180098.881536 + }, + "latency_mean_ns": { + "median": 15979998.057, + "min": 15956645.429, + "max": 16427087.508 + }, + "latency_p99_upper_ns": { + "median": 20971520, + "min": 20971520, + "max": 23068672 + }, + "budget_waits": { + "median": 1101, + "min": 1082, + "max": 1113 + }, + "allocations": { + "median": 1938, + "min": 1915, + "max": 1951 + }, + "reuses": { + "median": 1467, + "min": 1454, + "max": 1490 + } + }, + { + "case": "mixed_slow", + "variant": "threshold8", + "samples": 5, + "elapsed_ns": { + "median": 155250569, + "min": 154832681, + "max": 159080169 + }, + "cpu_ns": { + "median": 68708379, + "min": 68111825, + "max": 72479922 + }, + "peak_reserved_bytes": { + "median": 8388480, + "min": 8388480, + "max": 8388480 + }, + "peak_active_bytes": { + "median": 8388432, + "min": 8388432, + "max": 8388432 + }, + "rss_peak_bytes": { + "median": 10895360, + "min": 10534912, + "max": 10928128 + }, + "copy_bytes": { + "median": 3824848, + "min": 3824848, + "max": 3824848 + }, + "active_byte_seconds": { + "median": 1176609.476886, + "min": 1173410.180784, + "max": 1202455.090015 + }, + "latency_mean_ns": { + "median": 12540132.329, + "min": 12500210.727, + "max": 12818618.589 + }, + "latency_p99_upper_ns": { + "median": 15728640, + "min": 15728640, + "max": 16777216 + }, + "budget_waits": { + "median": 1080, + "min": 1052, + "max": 1091 + }, + "allocations": { + "median": 1844, + "min": 1823, + "max": 1856 + }, + "reuses": { + "median": 1212, + "min": 1200, + "max": 1233 + } + }, + { + "case": "mixed_tight", + "variant": "borrow", + "samples": 5, + "elapsed_ns": { + "median": 493631884, + "min": 491778453, + "max": 495149938 + }, + "cpu_ns": { + "median": 77876795, + "min": 73168533, + "max": 81275705 + }, + "peak_reserved_bytes": { + "median": 2094128, + "min": 2094128, + "max": 2094128 + }, + "peak_active_bytes": { + "median": 2094128, + "min": 2094128, + "max": 2094128 + }, + "rss_peak_bytes": { + "median": 3719168, + "min": 3702784, + "max": 4243456 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 930117.776585, + "min": 926994.460577, + "max": 933361.552539 + }, + "latency_mean_ns": { + "median": 5487868.994, + "min": 5473786.015, + "max": 5510109.537 + }, + "latency_p99_upper_ns": { + "median": 8388608, + "min": 8388608, + "max": 8388608 + }, + "budget_waits": { + "median": 1396, + "min": 1381, + "max": 1408 + }, + "allocations": { + "median": 1342, + "min": 1338, + "max": 1352 + }, + "reuses": { + "median": 706, + "min": 696, + "max": 710 + } + }, + { + "case": "mixed_tight", + "variant": "copy", + "samples": 5, + "elapsed_ns": { + "median": 191245856, + "min": 191037345, + "max": 191774166 + }, + "cpu_ns": { + "median": 62157319, + "min": 60906478, + "max": 62795054 + }, + "peak_reserved_bytes": { + "median": 2097152, + "min": 2097136, + "max": 2097152 + }, + "peak_active_bytes": { + "median": 2097136, + "min": 2097136, + "max": 2097136 + }, + "rss_peak_bytes": { + "median": 4243456, + "min": 4227072, + "max": 4407296 + }, + "copy_bytes": { + "median": 53727440, + "min": 53727440, + "max": 53727440 + }, + "active_byte_seconds": { + "median": 346194.049558, + "min": 345866.556263, + "max": 346663.433689 + }, + "latency_mean_ns": { + "median": 6050681.287, + "min": 6044094.394, + "max": 6064467.489 + }, + "latency_p99_upper_ns": { + "median": 8388608, + "min": 8388608, + "max": 8388608 + }, + "budget_waits": { + "median": 1373, + "min": 1361, + "max": 1387 + }, + "allocations": { + "median": 2479, + "min": 2461, + "max": 2491 + }, + "reuses": { + "median": 1617, + "min": 1605, + "max": 1635 + } + }, + { + "case": "mixed_tight", + "variant": "copy_no_pool", + "samples": 5, + "elapsed_ns": { + "median": 192676756, + "min": 189986910, + "max": 195726691 + }, + "cpu_ns": { + "median": 64089681, + "min": 58086718, + "max": 71826579 + }, + "peak_reserved_bytes": { + "median": 2097136, + "min": 2097136, + "max": 2097136 + }, + "peak_active_bytes": { + "median": 2097136, + "min": 2097136, + "max": 2097136 + }, + "rss_peak_bytes": { + "median": 4243456, + "min": 4227072, + "max": 4243456 + }, + "copy_bytes": { + "median": 53727440, + "min": 53727440, + "max": 53727440 + }, + "active_byte_seconds": { + "median": 347823.24917, + "min": 343741.458999, + "max": 353204.287515 + }, + "latency_mean_ns": { + "median": 6074626.45, + "min": 6008153.507, + "max": 6160078.753 + }, + "latency_p99_upper_ns": { + "median": 9437184, + "min": 8388608, + "max": 9437184 + }, + "budget_waits": { + "median": 1348, + "min": 1284, + "max": 1383 + }, + "allocations": { + "median": 4096, + "min": 4096, + "max": 4096 + }, + "reuses": { + "median": 0, + "min": 0, + "max": 0 + } + }, + { + "case": "mixed_tight", + "variant": "pressure", + "samples": 5, + "elapsed_ns": { + "median": 190688005, + "min": 189790379, + "max": 193714972 + }, + "cpu_ns": { + "median": 63157202, + "min": 60625611, + "max": 65297407 + }, + "peak_reserved_bytes": { + "median": 2097136, + "min": 2097136, + "max": 2097152 + }, + "peak_active_bytes": { + "median": 2097136, + "min": 2097136, + "max": 2097136 + }, + "rss_peak_bytes": { + "median": 4243456, + "min": 4227072, + "max": 4456448 + }, + "copy_bytes": { + "median": 28385168, + "min": 28385168, + "max": 28385168 + }, + "active_byte_seconds": { + "median": 347120.008423, + "min": 345327.900203, + "max": 352390.15124 + }, + "latency_mean_ns": { + "median": 6138653.731, + "min": 6110038.652, + "max": 6233962.195 + }, + "latency_p99_upper_ns": { + "median": 8388608, + "min": 8388608, + "max": 10485760 + }, + "budget_waits": { + "median": 1378, + "min": 1367, + "max": 1393 + }, + "allocations": { + "median": 2369, + "min": 2353, + "max": 2373 + }, + "reuses": { + "median": 1406, + "min": 1402, + "max": 1422 + } + }, + { + "case": "mixed_tight", + "variant": "project", + "samples": 5, + "elapsed_ns": { + "median": 175306603, + "min": 174670169, + "max": 179280258 + }, + "cpu_ns": { + "median": 57919540, + "min": 55539698, + "max": 63072197 + }, + "peak_reserved_bytes": { + "median": 2097120, + "min": 2097120, + "max": 2097120 + }, + "peak_active_bytes": { + "median": 2097120, + "min": 2097120, + "max": 2097120 + }, + "rss_peak_bytes": { + "median": 4243456, + "min": 4227072, + "max": 4407296 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 326279.178906, + "min": 325246.46456, + "max": 333023.673744 + }, + "latency_mean_ns": { + "median": 6273925.584, + "min": 6258533.417, + "max": 6405571.191 + }, + "latency_p99_upper_ns": { + "median": 8388608, + "min": 8388608, + "max": 9437184 + }, + "budget_waits": { + "median": 1310, + "min": 1292, + "max": 1312 + }, + "allocations": { + "median": 1726, + "min": 1706, + "max": 1728 + }, + "reuses": { + "median": 322, + "min": 320, + "max": 342 + } + }, + { + "case": "mixed_tight", + "variant": "threshold2", + "samples": 5, + "elapsed_ns": { + "median": 188818619, + "min": 188314755, + "max": 201965490 + }, + "cpu_ns": { + "median": 63133028, + "min": 61699247, + "max": 80116546 + }, + "peak_reserved_bytes": { + "median": 2097136, + "min": 2097136, + "max": 2097152 + }, + "peak_active_bytes": { + "median": 2097136, + "min": 2097136, + "max": 2097136 + }, + "rss_peak_bytes": { + "median": 4243456, + "min": 4227072, + "max": 4325376 + }, + "copy_bytes": { + "median": 28479696, + "min": 28479696, + "max": 28479696 + }, + "active_byte_seconds": { + "median": 343018.464235, + "min": 342240.604823, + "max": 364031.028759 + }, + "latency_mean_ns": { + "median": 6127166.122, + "min": 6110229.914, + "max": 6483685.515 + }, + "latency_p99_upper_ns": { + "median": 8388608, + "min": 8388608, + "max": 10485760 + }, + "budget_waits": { + "median": 1385, + "min": 1275, + "max": 1395 + }, + "allocations": { + "median": 2370, + "min": 2291, + "max": 2380 + }, + "reuses": { + "median": 1418, + "min": 1408, + "max": 1497 + } + }, + { + "case": "mixed_tight", + "variant": "threshold4", + "samples": 5, + "elapsed_ns": { + "median": 225451606, + "min": 224725167, + "max": 229047558 + }, + "cpu_ns": { + "median": 64792167, + "min": 63560757, + "max": 67894565 + }, + "peak_reserved_bytes": { + "median": 2097136, + "min": 2097136, + "max": 2097136 + }, + "peak_active_bytes": { + "median": 2097104, + "min": 2097104, + "max": 2097104 + }, + "rss_peak_bytes": { + "median": 4227072, + "min": 4227072, + "max": 4243456 + }, + "copy_bytes": { + "median": 11229392, + "min": 11229392, + "max": 11229392 + }, + "active_byte_seconds": { + "median": 413690.587373, + "min": 412794.10328, + "max": 418976.246455 + }, + "latency_mean_ns": { + "median": 5851904.688, + "min": 5841515.207, + "max": 5921381.751 + }, + "latency_p99_upper_ns": { + "median": 7864320, + "min": 7864320, + "max": 8388608 + }, + "budget_waits": { + "median": 1456, + "min": 1425, + "max": 1459 + }, + "allocations": { + "median": 2132, + "min": 2094, + "max": 2134 + }, + "reuses": { + "median": 1273, + "min": 1271, + "max": 1311 + } + }, + { + "case": "mixed_tight", + "variant": "threshold8", + "samples": 5, + "elapsed_ns": { + "median": 283681970, + "min": 282255055, + "max": 289852215 + }, + "cpu_ns": { + "median": 71405280, + "min": 67344177, + "max": 73110582 + }, + "peak_reserved_bytes": { + "median": 2097136, + "min": 2097136, + "max": 2097152 + }, + "peak_active_bytes": { + "median": 2097136, + "min": 2097136, + "max": 2097136 + }, + "rss_peak_bytes": { + "median": 4243456, + "min": 4227072, + "max": 4358144 + }, + "copy_bytes": { + "median": 3824848, + "min": 3824848, + "max": 3824848 + }, + "active_byte_seconds": { + "median": 522809.985389, + "min": 520513.491017, + "max": 533913.89253 + }, + "latency_mean_ns": { + "median": 5688342.625, + "min": 5670280.355, + "max": 5811531.61 + }, + "latency_p99_upper_ns": { + "median": 7864320, + "min": 7340032, + "max": 10485760 + }, + "budget_waits": { + "median": 1378, + "min": 1366, + "max": 1394 + }, + "allocations": { + "median": 1986, + "min": 1968, + "max": 1990 + }, + "reuses": { + "median": 1070, + "min": 1066, + "max": 1088 + } + }, + { + "case": "sparse_fast", + "variant": "borrow", + "samples": 5, + "elapsed_ns": { + "median": 20176198, + "min": 19968383, + "max": 28472110 + }, + "cpu_ns": { + "median": 20176500, + "min": 19952888, + "max": 28306962 + }, + "peak_reserved_bytes": { + "median": 156112, + "min": 156112, + "max": 156112 + }, + "peak_active_bytes": { + "median": 156112, + "min": 156112, + "max": 156112 + }, + "rss_peak_bytes": { + "median": 1589248, + "min": 1572864, + "max": 1605632 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 1246.966591, + "min": 1236.323437, + "max": 1788.400939 + }, + "latency_mean_ns": { + "median": 9697.062, + "min": 9596.16, + "max": 13730.123 + }, + "latency_p99_upper_ns": { + "median": 12288, + "min": 11264, + "max": 30720 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 1, + "min": 1, + "max": 1 + }, + "reuses": { + "median": 2047, + "min": 2047, + "max": 2047 + } + }, + { + "case": "sparse_fast", + "variant": "copy", + "samples": 5, + "elapsed_ns": { + "median": 20493516, + "min": 20382034, + "max": 21540986 + }, + "cpu_ns": { + "median": 20493889, + "min": 20382277, + "max": 21477686 + }, + "peak_reserved_bytes": { + "median": 156192, + "min": 156192, + "max": 156192 + }, + "peak_active_bytes": { + "median": 156192, + "min": 156192, + "max": 156192 + }, + "rss_peak_bytes": { + "median": 1605632, + "min": 1572864, + "max": 1605632 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 1089.501083, + "min": 1084.755978, + "max": 1151.439237 + }, + "latency_mean_ns": { + "median": 9859.747, + "min": 9806.967, + "max": 10352.839 + }, + "latency_p99_upper_ns": { + "median": 13312, + "min": 12288, + "max": 18432 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 2, + "min": 2, + "max": 2 + }, + "reuses": { + "median": 4094, + "min": 4094, + "max": 4094 + } + }, + { + "case": "sparse_fast", + "variant": "copy_no_pool", + "samples": 5, + "elapsed_ns": { + "median": 21265947, + "min": 20561183, + "max": 28620499 + }, + "cpu_ns": { + "median": 21072353, + "min": 20561592, + "max": 28277537 + }, + "peak_reserved_bytes": { + "median": 156192, + "min": 156192, + "max": 156192 + }, + "peak_active_bytes": { + "median": 156192, + "min": 156192, + "max": 156192 + }, + "rss_peak_bytes": { + "median": 1605632, + "min": 1589248, + "max": 1605632 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 1125.003597, + "min": 1084.995845, + "max": 1561.617327 + }, + "latency_mean_ns": { + "median": 10215.53, + "min": 9883.337, + "max": 13795.514 + }, + "latency_p99_upper_ns": { + "median": 16384, + "min": 12288, + "max": 40960 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 4096, + "min": 4096, + "max": 4096 + }, + "reuses": { + "median": 0, + "min": 0, + "max": 0 + } + }, + { + "case": "sparse_fast", + "variant": "pressure", + "samples": 5, + "elapsed_ns": { + "median": 20305145, + "min": 20018290, + "max": 23280610 + }, + "cpu_ns": { + "median": 20305963, + "min": 20018407, + "max": 23231480 + }, + "peak_reserved_bytes": { + "median": 156112, + "min": 156112, + "max": 156112 + }, + "peak_active_bytes": { + "median": 156112, + "min": 156112, + "max": 156112 + }, + "rss_peak_bytes": { + "median": 1589248, + "min": 1572864, + "max": 1605632 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 1256.330694, + "min": 1238.904613, + "max": 1448.645185 + }, + "latency_mean_ns": { + "median": 9760.602, + "min": 9620.129, + "max": 11211.571 + }, + "latency_p99_upper_ns": { + "median": 13312, + "min": 12288, + "max": 24576 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 1, + "min": 1, + "max": 1 + }, + "reuses": { + "median": 2047, + "min": 2047, + "max": 2047 + } + }, + { + "case": "sparse_fast", + "variant": "project", + "samples": 5, + "elapsed_ns": { + "median": 21524893, + "min": 21358726, + "max": 22218843 + }, + "cpu_ns": { + "median": 21525074, + "min": 21358833, + "max": 22096574 + }, + "peak_reserved_bytes": { + "median": 90640, + "min": 90640, + "max": 90640 + }, + "peak_active_bytes": { + "median": 90640, + "min": 90640, + "max": 90640 + }, + "rss_peak_bytes": { + "median": 1540096, + "min": 1507328, + "max": 1540096 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 1.632264, + "min": 1.620534, + "max": 1.68791 + }, + "latency_mean_ns": { + "median": 10363.91, + "min": 10284.012, + "max": 10699.094 + }, + "latency_p99_upper_ns": { + "median": 13312, + "min": 13312, + "max": 18432 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 1, + "min": 1, + "max": 1 + }, + "reuses": { + "median": 2047, + "min": 2047, + "max": 2047 + } + }, + { + "case": "sparse_fast", + "variant": "threshold2", + "samples": 5, + "elapsed_ns": { + "median": 20829074, + "min": 20421089, + "max": 22684901 + }, + "cpu_ns": { + "median": 20798316, + "min": 20421796, + "max": 22652390 + }, + "peak_reserved_bytes": { + "median": 156192, + "min": 156192, + "max": 156192 + }, + "peak_active_bytes": { + "median": 156192, + "min": 156192, + "max": 156192 + }, + "rss_peak_bytes": { + "median": 1605632, + "min": 1589248, + "max": 1605632 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 1111.338342, + "min": 1087.202091, + "max": 1228.197157 + }, + "latency_mean_ns": { + "median": 10025.307, + "min": 9825.86, + "max": 10925.772 + }, + "latency_p99_upper_ns": { + "median": 15360, + "min": 13312, + "max": 22528 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 2, + "min": 2, + "max": 2 + }, + "reuses": { + "median": 4094, + "min": 4094, + "max": 4094 + } + }, + { + "case": "sparse_fast", + "variant": "threshold4", + "samples": 5, + "elapsed_ns": { + "median": 20774647, + "min": 20604128, + "max": 21098686 + }, + "cpu_ns": { + "median": 20729258, + "min": 20604259, + "max": 21002369 + }, + "peak_reserved_bytes": { + "median": 156192, + "min": 156192, + "max": 156192 + }, + "peak_active_bytes": { + "median": 156192, + "min": 156192, + "max": 156192 + }, + "rss_peak_bytes": { + "median": 1589248, + "min": 1572864, + "max": 1605632 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 1106.254829, + "min": 1090.792499, + "max": 1130.040808 + }, + "latency_mean_ns": { + "median": 9997.106, + "min": 9906.217, + "max": 10153.021 + }, + "latency_p99_upper_ns": { + "median": 14336, + "min": 13312, + "max": 16384 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 2, + "min": 2, + "max": 2 + }, + "reuses": { + "median": 4094, + "min": 4094, + "max": 4094 + } + }, + { + "case": "sparse_fast", + "variant": "threshold8", + "samples": 5, + "elapsed_ns": { + "median": 20453663, + "min": 20381497, + "max": 21122947 + }, + "cpu_ns": { + "median": 20454074, + "min": 20382185, + "max": 21019219 + }, + "peak_reserved_bytes": { + "median": 156192, + "min": 156192, + "max": 156192 + }, + "peak_active_bytes": { + "median": 156192, + "min": 156192, + "max": 156192 + }, + "rss_peak_bytes": { + "median": 1589248, + "min": 1572864, + "max": 1605632 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 1090.324497, + "min": 1087.257309, + "max": 1125.541597 + }, + "latency_mean_ns": { + "median": 9841.173, + "min": 9805.745, + "max": 10159.663 + }, + "latency_p99_upper_ns": { + "median": 13312, + "min": 12288, + "max": 16384 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 2, + "min": 2, + "max": 2 + }, + "reuses": { + "median": 4094, + "min": 4094, + "max": 4094 + } + }, + { + "case": "sparse_slots64", + "variant": "borrow", + "samples": 5, + "elapsed_ns": { + "median": 167216739, + "min": 167156999, + "max": 169327288 + }, + "cpu_ns": { + "median": 44714000, + "min": 43876108, + "max": 47272489 + }, + "peak_reserved_bytes": { + "median": 4267968, + "min": 4267968, + "max": 4267968 + }, + "peak_active_bytes": { + "median": 4267968, + "min": 4267968, + "max": 4267968 + }, + "rss_peak_bytes": { + "median": 5292032, + "min": 5292032, + "max": 5292032 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 688253.763142, + "min": 688195.924843, + "max": 694635.953387 + }, + "latency_mean_ns": { + "median": 5127098.881, + "min": 5126680.831, + "max": 5174744.393 + }, + "latency_p99_upper_ns": { + "median": 7340032, + "min": 6291456, + "max": 7864320 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 64, + "min": 64, + "max": 64 + }, + "reuses": { + "median": 1984, + "min": 1984, + "max": 1984 + } + }, + { + "case": "sparse_slots64", + "variant": "copy", + "samples": 5, + "elapsed_ns": { + "median": 168358292, + "min": 166680851, + "max": 177068451 + }, + "cpu_ns": { + "median": 27312589, + "min": 24341624, + "max": 34395657 + }, + "peak_reserved_bytes": { + "median": 143312, + "min": 143312, + "max": 143312 + }, + "peak_active_bytes": { + "median": 143312, + "min": 143312, + "max": 143312 + }, + "rss_peak_bytes": { + "median": 1638400, + "min": 1622016, + "max": 1654784 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 2055.277015, + "min": 1923.416256, + "max": 2287.854324 + }, + "latency_mean_ns": { + "median": 5168010.066, + "min": 5125321.995, + "max": 5443811.067 + }, + "latency_p99_upper_ns": { + "median": 7864320, + "min": 7864320, + "max": 9437184 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 65, + "min": 65, + "max": 65 + }, + "reuses": { + "median": 4031, + "min": 4031, + "max": 4031 + } + }, + { + "case": "sparse_slots64", + "variant": "copy_no_pool", + "samples": 5, + "elapsed_ns": { + "median": 167165609, + "min": 166715000, + "max": 168181366 + }, + "cpu_ns": { + "median": 26167797, + "min": 24659146, + "max": 26871012 + }, + "peak_reserved_bytes": { + "median": 143312, + "min": 143312, + "max": 143312 + }, + "peak_active_bytes": { + "median": 143312, + "min": 143312, + "max": 143312 + }, + "rss_peak_bytes": { + "median": 1654784, + "min": 1638400, + "max": 1654784 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 1986.249813, + "min": 1919.204343, + "max": 2024.80935 + }, + "latency_mean_ns": { + "median": 5134877.701, + "min": 5125611.619, + "max": 5163779.497 + }, + "latency_p99_upper_ns": { + "median": 7864320, + "min": 7864320, + "max": 7864320 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 4096, + "min": 4096, + "max": 4096 + }, + "reuses": { + "median": 0, + "min": 0, + "max": 0 + } + }, + { + "case": "sparse_slots64", + "variant": "pressure", + "samples": 5, + "elapsed_ns": { + "median": 167121239, + "min": 167023277, + "max": 170783358 + }, + "cpu_ns": { + "median": 44137216, + "min": 43204463, + "max": 46177893 + }, + "peak_reserved_bytes": { + "median": 4268048, + "min": 4268048, + "max": 4268048 + }, + "peak_active_bytes": { + "median": 4268048, + "min": 4268048, + "max": 4268048 + }, + "rss_peak_bytes": { + "median": 5767168, + "min": 5750784, + "max": 5783552 + }, + "copy_bytes": { + "median": 2048, + "min": 2048, + "max": 2048 + }, + "active_byte_seconds": { + "median": 677483.645644, + "min": 677260.281048, + "max": 691939.11555 + }, + "latency_mean_ns": { + "median": 5127462.262, + "min": 5125737.978, + "max": 5236882.494 + }, + "latency_p99_upper_ns": { + "median": 7340032, + "min": 6291456, + "max": 7340032 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 65, + "min": 65, + "max": 65 + }, + "reuses": { + "median": 2015, + "min": 2015, + "max": 2015 + } + }, + { + "case": "sparse_slots64", + "variant": "project", + "samples": 5, + "elapsed_ns": { + "median": 167505794, + "min": 166784685, + "max": 171072487 + }, + "cpu_ns": { + "median": 26582076, + "min": 25505816, + "max": 27568676 + }, + "peak_reserved_bytes": { + "median": 77760, + "min": 77760, + "max": 77760 + }, + "peak_active_bytes": { + "median": 77760, + "min": 77760, + "max": 77760 + }, + "rss_peak_bytes": { + "median": 1589248, + "min": 1572864, + "max": 1589248 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 842.776507, + "min": 840.114114, + "max": 861.43609 + }, + "latency_mean_ns": { + "median": 5144362.881, + "min": 5128089.141, + "max": 5258257.061 + }, + "latency_p99_upper_ns": { + "median": 7864320, + "min": 7864320, + "max": 7864320 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 64, + "min": 64, + "max": 64 + }, + "reuses": { + "median": 1984, + "min": 1984, + "max": 1984 + } + }, + { + "case": "sparse_slots64", + "variant": "threshold2", + "samples": 5, + "elapsed_ns": { + "median": 167148609, + "min": 166724425, + "max": 167663571 + }, + "cpu_ns": { + "median": 25957735, + "min": 24304145, + "max": 26966696 + }, + "peak_reserved_bytes": { + "median": 143312, + "min": 143312, + "max": 143312 + }, + "peak_active_bytes": { + "median": 143312, + "min": 143312, + "max": 143312 + }, + "rss_peak_bytes": { + "median": 1638400, + "min": 1622016, + "max": 1654784 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 1998.277517, + "min": 1915.595622, + "max": 2058.951339 + }, + "latency_mean_ns": { + "median": 5134098.172, + "min": 5125215.218, + "max": 5147482.869 + }, + "latency_p99_upper_ns": { + "median": 7864320, + "min": 7864320, + "max": 7864320 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 65, + "min": 65, + "max": 65 + }, + "reuses": { + "median": 4031, + "min": 4031, + "max": 4031 + } + }, + { + "case": "sparse_slots64", + "variant": "threshold4", + "samples": 5, + "elapsed_ns": { + "median": 166829203, + "min": 166770166, + "max": 168266032 + }, + "cpu_ns": { + "median": 25212214, + "min": 24368638, + "max": 25648470 + }, + "peak_reserved_bytes": { + "median": 143312, + "min": 143312, + "max": 143312 + }, + "peak_active_bytes": { + "median": 143312, + "min": 143312, + "max": 143312 + }, + "rss_peak_bytes": { + "median": 1638400, + "min": 1638400, + "max": 1654784 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 1964.863682, + "min": 1922.285206, + "max": 1987.487947 + }, + "latency_mean_ns": { + "median": 5128818.551, + "min": 5126749.497, + "max": 5170189.028 + }, + "latency_p99_upper_ns": { + "median": 7864320, + "min": 7864320, + "max": 7864320 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 65, + "min": 65, + "max": 65 + }, + "reuses": { + "median": 4031, + "min": 4031, + "max": 4031 + } + }, + { + "case": "sparse_slots64", + "variant": "threshold8", + "samples": 5, + "elapsed_ns": { + "median": 167352294, + "min": 166717963, + "max": 169611954 + }, + "cpu_ns": { + "median": 26149112, + "min": 24643191, + "max": 32536976 + }, + "peak_reserved_bytes": { + "median": 143312, + "min": 143312, + "max": 143312 + }, + "peak_active_bytes": { + "median": 143312, + "min": 143312, + "max": 143312 + }, + "rss_peak_bytes": { + "median": 1638400, + "min": 1622016, + "max": 1654784 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 1998.899707, + "min": 1926.54795, + "max": 2319.792062 + }, + "latency_mean_ns": { + "median": 5140639.04, + "min": 5125971.683, + "max": 5206380.796 + }, + "latency_p99_upper_ns": { + "median": 7864320, + "min": 7864320, + "max": 7864320 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 65, + "min": 65, + "max": 65 + }, + "reuses": { + "median": 4031, + "min": 4031, + "max": 4031 + } + }, + { + "case": "sparse_slow", + "variant": "borrow", + "samples": 5, + "elapsed_ns": { + "median": 129845439, + "min": 106374934, + "max": 141446795 + }, + "cpu_ns": { + "median": 45497318, + "min": 44501920, + "max": 48356230 + }, + "peak_reserved_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "peak_active_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "rss_peak_bytes": { + "median": 9486336, + "min": 9469952, + "max": 9486336 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 1022546.229446, + "min": 829040.966005, + "max": 1119170.099864 + }, + "latency_mean_ns": { + "median": 7656609.5, + "min": 6201710.718, + "max": 8382742.796 + }, + "latency_p99_upper_ns": { + "median": 9437184, + "min": 9437184, + "max": 9437184 + }, + "budget_waits": { + "median": 1501, + "min": 1095, + "max": 1729 + }, + "allocations": { + "median": 126, + "min": 126, + "max": 126 + }, + "reuses": { + "median": 1922, + "min": 1922, + "max": 1922 + } + }, + { + "case": "sparse_slow", + "variant": "copy", + "samples": 5, + "elapsed_ns": { + "median": 159054504, + "min": 154140610, + "max": 160143537 + }, + "cpu_ns": { + "median": 26459012, + "min": 23189876, + "max": 28160466 + }, + "peak_reserved_bytes": { + "median": 197072, + "min": 197072, + "max": 197072 + }, + "peak_active_bytes": { + "median": 197072, + "min": 197072, + "max": 197072 + }, + "rss_peak_bytes": { + "median": 1703936, + "min": 1687552, + "max": 1720320 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 6705.336146, + "min": 6456.771667, + "max": 7402.36243 + }, + "latency_mean_ns": { + "median": 34466956.647, + "min": 33183203.845, + "max": 34696998.27 + }, + "latency_p99_upper_ns": { + "median": 41943040, + "min": 37748736, + "max": 46137344 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 513, + "min": 513, + "max": 513 + }, + "reuses": { + "median": 3583, + "min": 3583, + "max": 3583 + } + }, + { + "case": "sparse_slow", + "variant": "copy_no_pool", + "samples": 5, + "elapsed_ns": { + "median": 155595440, + "min": 154376239, + "max": 162066143 + }, + "cpu_ns": { + "median": 25896167, + "min": 24003453, + "max": 36838768 + }, + "peak_reserved_bytes": { + "median": 197072, + "min": 197072, + "max": 197072 + }, + "peak_active_bytes": { + "median": 197072, + "min": 197072, + "max": 197072 + }, + "rss_peak_bytes": { + "median": 1703936, + "min": 1687552, + "max": 1720320 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 6570.059349, + "min": 6474.089644, + "max": 7046.191505 + }, + "latency_mean_ns": { + "median": 33573592.059, + "min": 33344720.225, + "max": 34524425.147 + }, + "latency_p99_upper_ns": { + "median": 41943040, + "min": 37748736, + "max": 46137344 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 4096, + "min": 4096, + "max": 4096 + }, + "reuses": { + "median": 0, + "min": 0, + "max": 0 + } + }, + { + "case": "sparse_slow", + "variant": "pressure", + "samples": 5, + "elapsed_ns": { + "median": 153730223, + "min": 151916969, + "max": 157264009 + }, + "cpu_ns": { + "median": 27269441, + "min": 26295422, + "max": 27901892 + }, + "peak_reserved_bytes": { + "median": 4321888, + "min": 4321888, + "max": 4321888 + }, + "peak_active_bytes": { + "median": 4318208, + "min": 4316848, + "max": 4318768 + }, + "rss_peak_bytes": { + "median": 5849088, + "min": 5832704, + "max": 5849088 + }, + "copy_bytes": { + "median": 113984, + "min": 113408, + "max": 114176 + }, + "active_byte_seconds": { + "median": 524904.925261, + "min": 513114.693547, + "max": 542285.660244 + }, + "latency_mean_ns": { + "median": 32665634.037, + "min": 32537118.75, + "max": 33232147.448 + }, + "latency_p99_upper_ns": { + "median": 41943040, + "min": 37748736, + "max": 41943040 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 514, + "min": 514, + "max": 514 + }, + "reuses": { + "median": 3315, + "min": 3306, + "max": 3318 + } + }, + { + "case": "sparse_slow", + "variant": "project", + "samples": 5, + "elapsed_ns": { + "median": 154249202, + "min": 154094443, + "max": 157860470 + }, + "cpu_ns": { + "median": 24700764, + "min": 24230112, + "max": 28682548 + }, + "peak_reserved_bytes": { + "median": 131520, + "min": 131520, + "max": 131520 + }, + "peak_active_bytes": { + "median": 131520, + "min": 131520, + "max": 131520 + }, + "rss_peak_bytes": { + "median": 1638400, + "min": 1638400, + "max": 1654784 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 5451.483102, + "min": 5449.134094, + "max": 5603.286251 + }, + "latency_mean_ns": { + "median": 33273652.65, + "min": 33259314.794, + "max": 34200243.611 + }, + "latency_p99_upper_ns": { + "median": 37748736, + "min": 37748736, + "max": 41943040 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 512, + "min": 512, + "max": 512 + }, + "reuses": { + "median": 1536, + "min": 1536, + "max": 1536 + } + }, + { + "case": "sparse_slow", + "variant": "threshold2", + "samples": 5, + "elapsed_ns": { + "median": 154320869, + "min": 154022055, + "max": 160914091 + }, + "cpu_ns": { + "median": 24093342, + "min": 23087202, + "max": 25835642 + }, + "peak_reserved_bytes": { + "median": 197072, + "min": 197072, + "max": 197072 + }, + "peak_active_bytes": { + "median": 197072, + "min": 197072, + "max": 197072 + }, + "rss_peak_bytes": { + "median": 1703936, + "min": 1703936, + "max": 1720320 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 6504.166448, + "min": 6450.425541, + "max": 6869.973543 + }, + "latency_mean_ns": { + "median": 33321815.102, + "min": 33269305.586, + "max": 34925615.31 + }, + "latency_p99_upper_ns": { + "median": 37748736, + "min": 37748736, + "max": 46137344 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 513, + "min": 513, + "max": 513 + }, + "reuses": { + "median": 3583, + "min": 3583, + "max": 3583 + } + }, + { + "case": "sparse_slow", + "variant": "threshold4", + "samples": 5, + "elapsed_ns": { + "median": 155128904, + "min": 154184073, + "max": 157308101 + }, + "cpu_ns": { + "median": 25543272, + "min": 23590708, + "max": 31229598 + }, + "peak_reserved_bytes": { + "median": 197072, + "min": 197072, + "max": 197072 + }, + "peak_active_bytes": { + "median": 197072, + "min": 197072, + "max": 197072 + }, + "rss_peak_bytes": { + "median": 1703936, + "min": 1687552, + "max": 1720320 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 6610.674553, + "min": 6477.65682, + "max": 6941.796558 + }, + "latency_mean_ns": { + "median": 33533790.057, + "min": 33299901.746, + "max": 33900498.29 + }, + "latency_p99_upper_ns": { + "median": 41943040, + "min": 37748736, + "max": 41943040 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 513, + "min": 513, + "max": 513 + }, + "reuses": { + "median": 3583, + "min": 3583, + "max": 3583 + } + }, + { + "case": "sparse_slow", + "variant": "threshold8", + "samples": 5, + "elapsed_ns": { + "median": 154198518, + "min": 154077370, + "max": 159785538 + }, + "cpu_ns": { + "median": 23692568, + "min": 23187579, + "max": 24425471 + }, + "peak_reserved_bytes": { + "median": 197072, + "min": 197072, + "max": 197072 + }, + "peak_active_bytes": { + "median": 197072, + "min": 197072, + "max": 197072 + }, + "rss_peak_bytes": { + "median": 1703936, + "min": 1687552, + "max": 1720320 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 6492.439639, + "min": 6453.368258, + "max": 6694.694537 + }, + "latency_mean_ns": { + "median": 33304172.097, + "min": 33277920.587, + "max": 34401146.148 + }, + "latency_p99_upper_ns": { + "median": 37748736, + "min": 37748736, + "max": 41943040 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 513, + "min": 513, + "max": 513 + }, + "reuses": { + "median": 3583, + "min": 3583, + "max": 3583 + } + } +] diff --git a/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/verification.json b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/verification.json new file mode 100644 index 0000000..539be67 --- /dev/null +++ b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64-v2/verification.json @@ -0,0 +1,94 @@ +{ + "native": [ + "borrow: byte equality, accounting, cleanup, slow=False", + "borrow: byte equality, accounting, cleanup, slow=True", + "borrow: six malformed inputs with pending buffer cleanup", + "borrow: cancellation preserves completed output prefix and releases pending buffers", + "borrow: empty stream", + "copy: byte equality, accounting, cleanup, slow=False", + "copy: byte equality, accounting, cleanup, slow=True", + "copy: six malformed inputs with pending buffer cleanup", + "copy: cancellation preserves completed output prefix and releases pending buffers", + "copy: empty stream", + "threshold2: byte equality, accounting, cleanup, slow=False", + "threshold2: byte equality, accounting, cleanup, slow=True", + "threshold2: six malformed inputs with pending buffer cleanup", + "threshold2: cancellation preserves completed output prefix and releases pending buffers", + "threshold2: empty stream", + "threshold4: byte equality, accounting, cleanup, slow=False", + "threshold4: byte equality, accounting, cleanup, slow=True", + "threshold4: six malformed inputs with pending buffer cleanup", + "threshold4: cancellation preserves completed output prefix and releases pending buffers", + "threshold4: empty stream", + "threshold8: byte equality, accounting, cleanup, slow=False", + "threshold8: byte equality, accounting, cleanup, slow=True", + "threshold8: six malformed inputs with pending buffer cleanup", + "threshold8: cancellation preserves completed output prefix and releases pending buffers", + "threshold8: empty stream", + "pressure: byte equality, accounting, cleanup, slow=False", + "pressure: byte equality, accounting, cleanup, slow=True", + "pressure: six malformed inputs with pending buffer cleanup", + "pressure: cancellation preserves completed output prefix and releases pending buffers", + "pressure: empty stream", + "project: byte equality, accounting, cleanup, slow=False", + "project: byte equality, accounting, cleanup, slow=True", + "project: six malformed inputs with pending buffer cleanup", + "project: cancellation preserves completed output prefix and releases pending buffers", + "project: empty stream", + "copy_no_pool: byte equality, accounting, cleanup, slow=False", + "copy_no_pool: byte equality, accounting, cleanup, slow=True", + "copy_no_pool: six malformed inputs with pending buffer cleanup", + "copy_no_pool: cancellation preserves completed output prefix and releases pending buffers", + "copy_no_pool: empty stream", + "frame larger than buffer budget: bounded refusal versus projection", + "real output failure through /dev/full, pending buffers released", + "SIGTERM interrupts delayed sink and releases buffers", + "current-image VmHWM distinguishes large retained sources from small projections" + ], + "asan_ubsan": [ + "borrow: byte equality, accounting, cleanup, slow=False", + "borrow: byte equality, accounting, cleanup, slow=True", + "borrow: six malformed inputs with pending buffer cleanup", + "borrow: cancellation preserves completed output prefix and releases pending buffers", + "borrow: empty stream", + "copy: byte equality, accounting, cleanup, slow=False", + "copy: byte equality, accounting, cleanup, slow=True", + "copy: six malformed inputs with pending buffer cleanup", + "copy: cancellation preserves completed output prefix and releases pending buffers", + "copy: empty stream", + "threshold2: byte equality, accounting, cleanup, slow=False", + "threshold2: byte equality, accounting, cleanup, slow=True", + "threshold2: six malformed inputs with pending buffer cleanup", + "threshold2: cancellation preserves completed output prefix and releases pending buffers", + "threshold2: empty stream", + "threshold4: byte equality, accounting, cleanup, slow=False", + "threshold4: byte equality, accounting, cleanup, slow=True", + "threshold4: six malformed inputs with pending buffer cleanup", + "threshold4: cancellation preserves completed output prefix and releases pending buffers", + "threshold4: empty stream", + "threshold8: byte equality, accounting, cleanup, slow=False", + "threshold8: byte equality, accounting, cleanup, slow=True", + "threshold8: six malformed inputs with pending buffer cleanup", + "threshold8: cancellation preserves completed output prefix and releases pending buffers", + "threshold8: empty stream", + "pressure: byte equality, accounting, cleanup, slow=False", + "pressure: byte equality, accounting, cleanup, slow=True", + "pressure: six malformed inputs with pending buffer cleanup", + "pressure: cancellation preserves completed output prefix and releases pending buffers", + "pressure: empty stream", + "project: byte equality, accounting, cleanup, slow=False", + "project: byte equality, accounting, cleanup, slow=True", + "project: six malformed inputs with pending buffer cleanup", + "project: cancellation preserves completed output prefix and releases pending buffers", + "project: empty stream", + "copy_no_pool: byte equality, accounting, cleanup, slow=False", + "copy_no_pool: byte equality, accounting, cleanup, slow=True", + "copy_no_pool: six malformed inputs with pending buffer cleanup", + "copy_no_pool: cancellation preserves completed output prefix and releases pending buffers", + "copy_no_pool: empty stream", + "frame larger than buffer budget: bounded refusal versus projection", + "real output failure through /dev/full, pending buffers released", + "SIGTERM interrupts delayed sink and releases buffers", + "current-image VmHWM distinguishes large retained sources from small projections" + ] +} diff --git a/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/audit.json b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/audit.json new file mode 100644 index 0000000..54a4546 --- /dev/null +++ b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/audit.json @@ -0,0 +1,6 @@ +{ + "status": "superseded_by_corrected_measurement", + "reason": "All rusage RSS samples were identical at 28753920 bytes. Linux resource usage survives exec; this measure includes pre-exec history and is unsuitable for child image RSS comparison. The corrected run records proc/self/status VmHWM as a separate approximate metric and retains raw rusage. A 64-slot sparse case is added to examine the latency/queue confound. Other first-run observations remain exploratory.", + "next_run": "2026-09-22-linux-aarch64-v2", + "sources_preserved": true +} diff --git a/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/complete.json b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/complete.json new file mode 100644 index 0000000..0980f35 --- /dev/null +++ b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/complete.json @@ -0,0 +1,5 @@ +{ + "samples": 200, + "all_output_hashes_match": true, + "finished_utc": "2026-09-22T12:20:38Z" +} diff --git a/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/environment.json b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/environment.json new file mode 100644 index 0000000..f5173ae --- /dev/null +++ b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/environment.json @@ -0,0 +1,57 @@ +{ + "platform": "Linux-6.18.39+rpt-rpi-2712-aarch64-with-glibc2.41", + "machine": "aarch64", + "python": "3.14.7", + "cpu_affinity": 0, + "compiler": "cc (Debian 14.2.0-19) 14.2.0\nCopyright (C) 2024 Free Software Foundation, Inc.\nThis is free software; see the source for copying conditions. There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n", + "builds": [ + { + "command": [ + "cc", + "-std=c17", + "-Wall", + "-Wextra", + "-Wpedantic", + "-Werror", + "-O2", + "-g", + "/home/eunhhu/work/pure/research/experiments/002-buffer-retention/benchmark.c", + "-o", + "/tmp/pure-retention-ezjbfrb1/bench" + ], + "stderr": "", + "sha256": "c38e4f6e9e09c77368c1ba188333bc43a8b8a4a1c4500fbdf218ee74545bd2d2", + "size_bytes": 99936 + }, + { + "command": [ + "cc", + "-std=c17", + "-Wall", + "-Wextra", + "-Wpedantic", + "-Werror", + "-O2", + "-g", + "-fsanitize=address,undefined", + "-fno-omit-frame-pointer", + "/home/eunhhu/work/pure/research/experiments/002-buffer-retention/benchmark.c", + "-o", + "/tmp/pure-retention-ezjbfrb1/bench-sanitized" + ], + "stderr": "", + "sha256": "4810904c7507cc9d8d5550eb6444560f3ed5658a49e7e4a6d753cde23dc32124", + "size_bytes": 256136 + } + ], + "source_sha256": { + "benchmark.c": "68256a441907d944b4f5b3f50d32bb06b349cc18db49e03f5dbd6158c79e2623", + "run.py": "d337cd069b63f50f5810875c5fa59e9771ab69333805ab450d182c19e07b814d", + "plan.json": "12daa51463df2a4a288adaf85c631f439993e50c9bf3f21fc248c92859ae5214" + }, + "clock": "CLOCK_MONOTONIC; CPU = CLOCK_PROCESS_CPUTIME_ID", + "timing": "includes file IO, scheduling, deliberate sleep, metrics, buffer cleanup; excludes startup/build/fixture/verification", + "limitations": "shared host; unregulated thermals; cached files; output page cache, no fsync; synthetic closed-loop arrivals", + "started_utc": "2026-09-22T12:19:50Z", + "cpuinfo": "processor\t: 0\nBogoMIPS\t: 108.00\nFeatures\t: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp\nCPU implementer\t: 0x41\nCPU architecture: 8\nCPU variant\t: 0x4\nCPU part\t: 0xd0b\nCPU revision\t: 1\n\nprocessor\t: 1\nBogoMIPS\t: 108.00\nFeatures\t: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp\nCPU implementer\t: 0x41\nCPU architecture: 8\nCPU variant\t: 0x4\nCPU part\t: 0xd0b\nCPU revision\t: 1\n\nprocessor\t: 2\nBogoMIPS\t: 108.00\nFeatures\t: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp\nCPU implementer\t: 0x41\nCPU architecture: 8\nCPU variant\t: 0x4\nCPU part\t: 0xd0b\nCPU revision\t: 1\n\nprocessor\t: 3\nBogoMIPS\t: 108.00\nFeatures\t: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp\nCPU implementer\t: 0x41\nCPU architecture: 8\nCPU variant\t: 0x4\nCPU part\t: 0xd0b\nCPU revision\t: 1\n\nRevision\t: d04171\nSerial\t\t: d3ba8e625dbe42ac\nModel\t\t: Raspberry Pi 5 Model B Rev 1.1\n" +} diff --git a/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/fixtures.json b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/fixtures.json new file mode 100644 index 0000000..3a68713 --- /dev/null +++ b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/fixtures.json @@ -0,0 +1,57 @@ +[ + { + "path": "input.frames", + "shape": "sparse", + "records": 2048, + "seed": 20260922, + "input_bytes": 134242304, + "input_sha256": "161377ac76f4b7d35b13db7edf3b93bb279ddd83f6514051020e8b49e743d1c0", + "expected_output_bytes": 139264, + "expected_output_sha256": "a01c7bff45f73512f3bc0dbd02d7c3a1f4ceb09f574d7c25b926cd3d30bb1bfa", + "case": "sparse_slow" + }, + { + "path": "input.frames", + "shape": "dense", + "records": 2048, + "seed": 20260922, + "input_bytes": 134242304, + "input_sha256": "fb28c2da0af227079bd6888c3f549fa5a48abd0b790c3939dc330111e80c0b7f", + "expected_output_bytes": 100671488, + "expected_output_sha256": "d96dd7f80d696895e66521630fd30f13adabf63bea3b84b0a709fbc8c4095aa5", + "case": "dense_slow" + }, + { + "path": "input.frames", + "shape": "mixed", + "records": 2048, + "seed": 20260922, + "input_bytes": 177631232, + "input_sha256": "5cfcb8e74d5f30c3a611f373ddf53fd5bc843841d83de42c763e1d931403521d", + "expected_output_bytes": 53735632, + "expected_output_sha256": "f6b4eb83e7ca9aa4b5b2e0675d34b656815c82c992700ee9cbd7e0a15594cb0b", + "case": "mixed_slow" + }, + { + "path": "input.frames", + "shape": "mixed", + "records": 2048, + "seed": 20260922, + "input_bytes": 177631232, + "input_sha256": "5cfcb8e74d5f30c3a611f373ddf53fd5bc843841d83de42c763e1d931403521d", + "expected_output_bytes": 53735632, + "expected_output_sha256": "f6b4eb83e7ca9aa4b5b2e0675d34b656815c82c992700ee9cbd7e0a15594cb0b", + "case": "mixed_tight" + }, + { + "path": "input.frames", + "shape": "sparse", + "records": 2048, + "seed": 20260922, + "input_bytes": 134242304, + "input_sha256": "161377ac76f4b7d35b13db7edf3b93bb279ddd83f6514051020e8b49e743d1c0", + "expected_output_bytes": 139264, + "expected_output_sha256": "a01c7bff45f73512f3bc0dbd02d7c3a1f4ceb09f574d7c25b926cd3d30bb1bfa", + "case": "sparse_fast" + } +] diff --git a/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/plan.json b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/plan.json new file mode 100644 index 0000000..349e5e2 --- /dev/null +++ b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/plan.json @@ -0,0 +1,103 @@ +{ + "version": 1, + "written_before_measurement": true, + "seed": 20260922, + "repeats": 5, + "slots": 512, + "policies": [ + { + "name": "borrow", + "policy": "borrow", + "pool": 1 + }, + { + "name": "copy", + "policy": "copy", + "pool": 1 + }, + { + "name": "threshold2", + "policy": "threshold", + "ratio": 2, + "pool": 1 + }, + { + "name": "threshold4", + "policy": "threshold", + "ratio": 4, + "pool": 1 + }, + { + "name": "threshold8", + "policy": "threshold", + "ratio": 8, + "pool": 1 + }, + { + "name": "pressure", + "policy": "pressure", + "pool": 1 + }, + { + "name": "project", + "policy": "project", + "pool": 1 + }, + { + "name": "copy_no_pool", + "policy": "copy", + "pool": 0 + } + ], + "cases": [ + { + "name": "sparse_slow", + "shape": "sparse", + "records": 2048, + "budget": 8388608, + "hold_us": 5000, + "service_us": 20 + }, + { + "name": "dense_slow", + "shape": "dense", + "records": 2048, + "budget": 8388608, + "hold_us": 5000, + "service_us": 20 + }, + { + "name": "mixed_slow", + "shape": "mixed", + "records": 2048, + "budget": 8388608, + "hold_us": 5000, + "service_us": 20 + }, + { + "name": "mixed_tight", + "shape": "mixed", + "records": 2048, + "budget": 2097152, + "hold_us": 5000, + "service_us": 20 + }, + { + "name": "sparse_fast", + "shape": "sparse", + "records": 2048, + "budget": 8388608, + "hold_us": 0, + "service_us": 0 + } + ], + "expectations": [ + "Borrow retains full source allocations for small selections.", + "Copy can add CPU and transient source plus destination memory for dense selections.", + "A current-pressure rule need not outperform a static size rule or early projection.", + "Pool reuse can reduce allocation calls while increasing reserved idle memory.", + "No Pure-specific advantage, application SLO, or statistical significance is presumed." + ], + "comparison_rule": "Report all presets and repetitions; no post-hoc winner is called an out-of-sample tuned policy.", + "limits": "Single FIFO local pipeline with synthetic delayed sink. No Sonic/Node/.NET benchmark, fan-out, persistent cache, generic JSON parser, external open-loop arrivals, or production SLO." +} diff --git a/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/raw.csv b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/raw.csv new file mode 100644 index 0000000..bf0f08d --- /dev/null +++ b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/raw.csv @@ -0,0 +1,201 @@ +case,variant,repeat,status,policy,pool,budget_bytes,fixed_bytes,peak_reserved_bytes,peak_active_bytes,peak_queue,rss_peak_bytes,elapsed_ns,cpu_ns,input_bytes,output_bytes,accepted,emitted,copy_bytes,copied_records,borrowed_records,pressure_copies,allocations,reuses,budget_waits,slot_waits,sleep_ns,latency_mean_ns,latency_p99_upper_ns,latency_max_ns,active_byte_seconds,live_at_stop_bytes,cached_at_stop_bytes,unreleased_buffer_bytes
+sparse_slow,copy,0,ok,copy,True,8388608,90560,197072,197072,512,28753920,156440711,48121065,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,878,109587045,32718961.288,50331648,47686700,7879.414446,0,66752,0
+sparse_slow,threshold4,0,ok,threshold,True,8388608,90560,197072,197072,512,28753920,152733814,52980104,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,718,102189918,30324683.181,54525952,52327335,7602.229051,0,66752,0
+sparse_slow,threshold2,0,ok,threshold,True,8388608,90560,197072,197072,512,28753920,155247640,47779812,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,809,108519282,31414916.006,54525952,51100228,7369.340036,0,66752,0
+sparse_slow,copy_no_pool,0,ok,copy,False,8388608,90560,197072,197072,512,28753920,164046264,46944898,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,881,113764083,35133900.267,46137344,46051556,8459.440246,0,0,0
+sparse_slow,project,0,ok,project,True,8388608,90560,131520,131520,512,28753920,157789596,25739163,134242304,139264,2048,2048,0,0,0,0,512,1536,0,1536,136058109,34150955.425,41943040,40528961,5595.217111,0,1280,0
+sparse_slow,threshold8,0,ok,threshold,True,8388608,90560,197072,197072,512,28753920,154250903,24028565,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1537,133827808,33265597.392,37748736,37531339,6504.707846,0,66752,0
+sparse_slow,borrow,0,ok,borrow,True,8388608,90560,8350112,8350112,126,28753920,101576920,50248602,134242304,139264,2048,2048,0,0,2048,0,126,1922,825,0,53200392,5868549.98,10485760,10885229,784884.708981,0,1048832,0
+sparse_slow,pressure,0,ok,pressure,True,8388608,90560,4321888,4316448,512,28753920,153086035,29353156,134242304,139264,2048,2048,113152,1768,280,1768,514,3302,0,1424,127637166,32763957.697,41943040,38592411,549197.237404,0,590528,0
+sparse_slow,borrow,1,ok,borrow,True,8388608,90560,8350112,8350112,126,28753920,132106520,45409725,134242304,139264,2048,2048,0,0,2048,0,126,1922,1532,0,89610425,7801228.044,9437184,9303567,1041796.843202,0,1048832,0
+sparse_slow,copy_no_pool,1,ok,copy,False,8388608,90560,197072,197072,512,28753920,154376717,24625261,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,1534,133550825,33304515.117,37748736,37563136,6521.304714,0,0,0
+sparse_slow,threshold2,1,ok,threshold,True,8388608,90560,197072,197072,512,28753920,154790882,24092354,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1537,134531052,33433846.048,37748736,37877431,6519.648368,0,66752,0
+sparse_slow,threshold4,1,ok,threshold,True,8388608,90560,197072,197072,512,28753920,154495679,24603184,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1536,133731727,33331969.71,37748736,37527099,6535.057316,0,66752,0
+sparse_slow,threshold8,1,ok,threshold,True,8388608,90560,197072,197072,512,28753920,154242976,24135969,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1535,133865874,33299370.61,37748736,37484173,6509.096995,0,66752,0
+sparse_slow,project,1,ok,project,True,8388608,90560,131520,131520,512,28753920,154024996,25025451,134242304,139264,2048,2048,0,0,0,0,512,1536,0,1534,132769732,33212736.419,37748736,37402803,5441.502377,0,1280,0
+sparse_slow,pressure,1,ok,pressure,True,8388608,90560,4321888,4316928,512,28753920,151466095,27009927,134242304,139264,2048,2048,113280,1770,278,1770,514,3304,0,1473,128099292,32391902.953,37748736,37408099,539531.143577,0,590528,0
+sparse_slow,copy,1,ok,copy,True,8388608,90560,197072,197072,512,28753920,155007270,24608283,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1535,134124966,33382726.714,37748736,37593062,6546.135984,0,66752,0
+sparse_slow,threshold4,2,ok,threshold,True,8388608,90560,197072,197072,512,28753920,154312902,23956224,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1535,134085359,33321820.453,37748736,37660191,6502.811837,0,66752,0
+sparse_slow,copy_no_pool,2,ok,copy,False,8388608,90560,197072,197072,512,28753920,154586382,24703970,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,1534,133705501,33392210.559,41943040,37987523,6536.248232,0,0,0
+sparse_slow,threshold2,2,ok,threshold,True,8388608,90560,197072,197072,512,28753920,154368809,24191625,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1534,133926227,33288663.865,37748736,37544080,6508.096109,0,66752,0
+sparse_slow,pressure,2,ok,pressure,True,8388608,90560,4321888,4316208,512,28753920,151522021,27174295,134242304,139264,2048,2048,113088,1767,281,1767,514,3301,0,1465,128053394,32398179.535,37748736,37585173,545315.69968,0,590528,0
+sparse_slow,copy,2,ok,copy,True,8388608,90560,197072,197072,512,28753920,154139254,24156681,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1535,133742452,33274854.653,37748736,37580636,6504.184345,0,66752,0
+sparse_slow,project,2,ok,project,True,8388608,90560,131520,131520,512,28753920,154504494,25538018,134242304,139264,2048,2048,0,0,0,0,512,1536,0,1533,132803019,33348679.346,37748736,37696024,5463.772808,0,1280,0
+sparse_slow,threshold8,2,ok,threshold,True,8388608,90560,197072,197072,512,28753920,154268606,24017037,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1537,134039266,33296530.878,37748736,37600117,6499.765006,0,66752,0
+sparse_slow,borrow,2,ok,borrow,True,8388608,90560,8350112,8350112,126,28753920,116617303,46471284,134242304,139264,2048,2048,0,0,2048,0,126,1922,1258,0,72494973,6836360.134,9437184,9280234,913414.105279,0,1048832,0
+sparse_slow,project,3,ok,project,True,8388608,90560,131520,131520,512,28753920,155002696,25290252,134242304,139264,2048,2048,0,0,0,0,512,1536,0,1537,133467827,33443160.686,41943040,38061801,5479.253547,0,1280,0
+sparse_slow,borrow,3,ok,borrow,True,8388608,90560,8350112,8350112,126,28753920,122707360,46832624,134242304,139264,2048,2048,0,0,2048,0,126,1922,1334,0,78581274,7210177.487,9437184,9450215,963195.592926,0,1048832,0
+sparse_slow,pressure,3,ok,pressure,True,8388608,90560,4321888,4316128,512,28753920,170735523,36085789,134242304,139264,2048,2048,113024,1766,282,1766,514,3300,0,1403,140741412,37128525.741,50331648,49207437,624641.105995,0,590528,0
+sparse_slow,threshold8,3,ok,threshold,True,8388608,90560,197072,197072,512,28753920,161984455,35308455,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1418,132544941,34734342.366,41943040,41927513,7196.657649,0,66752,0
+sparse_slow,threshold2,3,ok,threshold,True,8388608,90560,197072,197072,512,28753920,183186784,39562601,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1377,149944607,39799236.839,50331648,49954231,8175.636446,0,66752,0
+sparse_slow,copy,3,ok,copy,True,8388608,90560,197072,197072,512,28753920,160896124,25740442,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1519,138959714,34942676.828,41943040,40635979,6866.098036,0,66752,0
+sparse_slow,copy_no_pool,3,ok,copy,False,8388608,90560,197072,197072,512,28753920,155242417,24840078,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,1534,134375289,33387730.27,41943040,38123912,6526.934401,0,0,0
+sparse_slow,threshold4,3,ok,threshold,True,8388608,90560,197072,197072,512,28753920,153980365,24665615,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1523,133098283,33153737.672,37748736,37518117,6514.197106,0,66752,0
+sparse_slow,copy_no_pool,4,ok,copy,False,8388608,90560,197072,197072,512,28753920,154143199,24004931,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,1536,133901751,33287028.642,37748736,37626617,6483.552028,0,0,0
+sparse_slow,copy,4,ok,copy,True,8388608,90560,197072,197072,512,28753920,153170646,26299681,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1505,130663631,33019408.27,37748736,37369469,6585.869234,0,66752,0
+sparse_slow,threshold4,4,ok,threshold,True,8388608,90560,197072,197072,512,28753920,154103699,23694419,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1537,134088060,33271036.464,37748736,37623950,6485.074292,0,66752,0
+sparse_slow,threshold8,4,ok,threshold,True,8388608,90560,197072,197072,512,28753920,154585216,23936885,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1536,134389609,33393120.598,37748736,38036616,6515.371593,0,66752,0
+sparse_slow,borrow,4,ok,borrow,True,8388608,90560,8350112,8350112,126,28753920,124475504,45943956,134242304,139264,2048,2048,0,0,2048,0,126,1922,1468,0,81119761,7320646.162,9437184,9274900,977840.583339,0,1048832,0
+sparse_slow,threshold2,4,ok,threshold,True,8388608,90560,197072,197072,512,28753920,154125217,24321563,134242304,139264,2048,2048,131072,2048,0,0,513,3583,0,1536,133545099,33270620.015,37748736,37515988,6516.994726,0,66752,0
+sparse_slow,pressure,4,ok,pressure,True,8388608,90560,4321888,4317248,512,28753920,151398447,26713792,134242304,139264,2048,2048,113408,1772,276,1772,514,3306,0,1473,128307648,32397554.332,37748736,37324395,535707.02646,0,590528,0
+sparse_slow,project,4,ok,project,True,8388608,90560,131520,131520,512,28753920,154766567,24892483,134242304,139264,2048,2048,0,0,0,0,512,1536,0,1537,133703008,33388895.003,41943040,37874598,5470.365986,0,1280,0
+dense_slow,project,0,ok,project,True,8388608,90560,8350112,8350112,126,28753920,153699255,97036844,134242304,100671488,2048,2048,0,0,0,0,126,1922,890,0,59162056,8908081.106,15728640,16113048,1191532.621299,0,1048832,0
+dense_slow,threshold2,0,ok,threshold,True,8388608,90560,8350112,8350112,126,28753920,130854245,109226645,134242304,100671488,2048,2048,0,0,2048,0,126,1922,318,0,22611916,7607977.365,11534336,12586113,1019874.721927,0,1048832,0
+dense_slow,copy_no_pool,0,ok,copy,False,8388608,90560,8350112,8350112,125,28753920,130227024,112627422,134242304,100671488,2048,2048,100663296,2048,0,0,4096,0,1363,0,17672583,7496902.226,12582912,12386151,1006822.239807,0,0,0
+dense_slow,borrow,0,ok,borrow,True,8388608,90560,8350112,8350112,126,28753920,132968553,110199520,134242304,100671488,2048,2048,0,0,2048,0,126,1922,230,0,24087338,7516016.308,16777216,17649580,1007870.242312,0,1048832,0
+dense_slow,pressure,0,ok,pressure,True,8388608,90560,8350112,8350112,126,28753920,139106888,110625767,134242304,100671488,2048,2048,0,0,2048,0,126,1922,217,0,29387892,8069611.928,16777216,17083878,1081569.371059,0,1048832,0
+dense_slow,copy,0,ok,copy,True,8388608,90560,8350112,8350112,125,28753920,139677276,98850013,134242304,100671488,2048,2048,100663296,2048,0,0,126,3970,1911,0,41099434,8122260.495,11534336,11425690,1090782.263887,0,1048832,0
+dense_slow,threshold4,0,ok,threshold,True,8388608,90560,8350112,8350112,126,28753920,152388963,133280290,134242304,100671488,2048,2048,0,0,2048,0,126,1922,263,0,19097885,8858624.865,13631488,13575925,1188061.088853,0,1048832,0
+dense_slow,threshold8,0,ok,threshold,True,8388608,90560,8350112,8350112,126,28753920,158487631,104607294,134242304,100671488,2048,2048,0,0,2048,0,126,1922,881,0,55726830,9142910.493,16777216,16508139,1223330.140557,0,1048832,0
+dense_slow,pressure,1,ok,pressure,True,8388608,90560,8350112,8350112,126,28753920,148054808,118930635,134242304,100671488,2048,2048,0,0,2048,0,126,1922,243,0,23339314,8545660.143,12582912,13488795,1145837.182993,0,1048832,0
+dense_slow,threshold2,1,ok,threshold,True,8388608,90560,8350112,8350112,126,28753920,127102070,98389110,134242304,100671488,2048,2048,0,0,2048,0,126,1922,548,0,29835471,7376714.273,11534336,11721430,988062.578411,0,1048832,0
+dense_slow,threshold4,1,ok,threshold,True,8388608,90560,8350112,8350112,126,28753920,137097783,105658521,134242304,100671488,2048,2048,0,0,2048,0,126,1922,319,0,33507567,7492151.426,25165824,25521632,1004322.345588,0,1048832,0
+dense_slow,copy_no_pool,1,ok,copy,False,8388608,90560,8350112,8350112,125,28753920,129205398,106642340,134242304,100671488,2048,2048,100663296,2048,0,0,4096,0,1837,0,23366005,7161052.395,20971520,19672000,961708.896247,0,0,0
+dense_slow,threshold8,1,ok,threshold,True,8388608,90560,8350112,8350112,126,28753920,149831970,119769747,134242304,100671488,2048,2048,0,0,2048,0,126,1922,207,0,22835752,8570181.832,25165824,24456487,1149620.580849,0,1048832,0
+dense_slow,project,1,ok,project,True,8388608,90560,8350112,8350112,126,28753920,138012595,104050639,134242304,100671488,2048,2048,0,0,0,0,126,1922,573,0,35587895,8024328.08,11534336,11967226,1074555.345603,0,1048832,0
+dense_slow,copy,1,ok,copy,True,8388608,90560,8350112,8350112,125,28753920,139897423,116916607,134242304,100671488,2048,2048,100663296,2048,0,0,126,3970,1245,0,21827476,7467830.775,11534336,12057799,1002967.933698,0,1048832,0
+dense_slow,borrow,1,ok,borrow,True,8388608,90560,8350112,8350112,126,28753920,124760040,105059769,134242304,100671488,2048,2048,0,0,2048,0,126,1922,279,0,20851427,7121146.062,13631488,13454333,954812.49966,0,1048832,0
+dense_slow,threshold4,2,ok,threshold,True,8388608,90560,8350112,8350112,126,28753920,128197678,100339777,134242304,100671488,2048,2048,0,0,2048,0,126,1922,483,0,29286062,7442559.441,11534336,11489301,997040.290853,0,1048832,0
+dense_slow,copy_no_pool,2,ok,copy,False,8388608,90560,8350112,8350112,125,28753920,205943127,116032671,134242304,100671488,2048,2048,100663296,2048,0,0,4096,0,1454,0,23092169,12031760.945,20971520,20696239,1615356.534078,0,0,0
+dense_slow,threshold2,2,ok,threshold,True,8388608,90560,8350112,8350112,126,28753920,126630183,111840417,134242304,100671488,2048,2048,0,0,2048,0,126,1922,123,0,14544050,7317376.727,11534336,11766189,981675.539219,0,1048832,0
+dense_slow,threshold8,2,ok,threshold,True,8388608,90560,8350112,8350112,126,28753920,130400357,115426208,134242304,100671488,2048,2048,0,0,2048,0,126,1922,33,0,15522516,7311488.307,13631488,16432805,981225.27374,0,1048832,0
+dense_slow,project,2,ok,project,True,8388608,90560,8350112,8350112,126,28753920,158617537,105530265,134242304,100671488,2048,2048,0,0,0,0,126,1922,630,0,53505513,8986415.696,20971520,20150036,1202933.657783,0,1048832,0
+dense_slow,copy,2,ok,copy,True,8388608,90560,8350112,8350112,125,28753920,136167489,109997334,134242304,100671488,2048,2048,100663296,2048,0,0,126,3970,1562,0,27532835,7639923.617,13631488,16520028,1026043.651851,0,1048832,0
+dense_slow,pressure,2,ok,pressure,True,8388608,90560,8350112,8350112,126,28753920,124401411,111783663,134242304,100671488,2048,2048,0,0,2048,0,126,1922,108,0,12978960,7175143.561,11534336,11871096,962716.975355,0,1048832,0
+dense_slow,borrow,2,ok,borrow,True,8388608,90560,8350112,8350112,126,28753920,140192626,129302907,134242304,100671488,2048,2048,0,0,2048,0,126,1922,32,0,11304553,8151791.4,12582912,11985985,1094054.601176,0,1048832,0
+dense_slow,threshold4,3,ok,threshold,True,8388608,90560,8350112,8350112,126,28753920,127500625,109051339,134242304,100671488,2048,2048,0,0,2048,0,126,1922,86,0,15655621,7370372.812,13631488,13648518,988934.033123,0,1048832,0
+dense_slow,copy,3,ok,copy,True,8388608,90560,8350112,8350112,125,28753920,139629443,112148433,134242304,100671488,2048,2048,100663296,2048,0,0,126,3970,1923,0,28146396,7999954.838,16777216,16468658,1074362.142096,0,1048832,0
+dense_slow,threshold8,3,ok,threshold,True,8388608,90560,8350112,8350112,126,28753920,129397045,108222327,134242304,100671488,2048,2048,0,0,2048,0,126,1922,210,0,19281611,7449478.358,13631488,13544240,999089.777214,0,1048832,0
+dense_slow,copy_no_pool,3,ok,copy,False,8388608,90560,8350112,8350112,125,28753920,125060409,101408203,134242304,100671488,2048,2048,100663296,2048,0,0,4096,0,1720,0,24842157,7224036.272,11534336,11678097,970120.753206,0,0,0
+dense_slow,threshold2,3,ok,threshold,True,8388608,90560,8350112,8350112,126,28753920,121944973,98926473,134242304,100671488,2048,2048,0,0,2048,0,126,1922,410,0,24262193,7027416.376,11534336,12229040,941745.792822,0,1048832,0
+dense_slow,project,3,ok,project,True,8388608,90560,8350112,8350112,126,28753920,140664495,101124724,134242304,100671488,2048,2048,0,0,0,0,126,1922,716,0,41804911,8134234.887,12582912,13075389,1088709.015188,0,1048832,0
+dense_slow,pressure,3,ok,pressure,True,8388608,90560,8350112,8350112,126,28753920,121667696,101165480,134242304,100671488,2048,2048,0,0,2048,0,126,1922,330,0,21242064,7047783.954,11534336,11408672,944768.902586,0,1048832,0
+dense_slow,borrow,3,ok,borrow,True,8388608,90560,8350112,8350112,126,28753920,122887693,108048811,134242304,100671488,2048,2048,0,0,2048,0,126,1922,100,0,15309844,6960585.889,14680064,14962365,933965.439249,0,1048832,0
+dense_slow,threshold8,4,ok,threshold,True,8388608,90560,8350112,8350112,126,28753920,127832493,107011535,134242304,100671488,2048,2048,0,0,2048,0,126,1922,312,0,21568032,7387611.189,12582912,12693631,990437.837956,0,1048832,0
+dense_slow,copy,4,ok,copy,True,8388608,90560,8350112,8350112,125,28753920,132323981,104579167,134242304,100671488,2048,2048,100663296,2048,0,0,126,3970,1868,0,28280826,7629563.252,11534336,12006726,1024670.67878,0,1048832,0
+dense_slow,threshold4,4,ok,threshold,True,8388608,90560,8350112,8350112,126,28753920,117467153,100913544,134242304,100671488,2048,2048,0,0,2048,0,126,1922,211,0,17302742,6773721.904,11534336,11750486,908428.389283,0,1048832,0
+dense_slow,project,4,ok,project,True,8388608,90560,8350112,8350112,126,28753920,177547354,98087776,134242304,100671488,2048,2048,0,0,0,0,126,1922,1077,0,66269238,10478829.253,27262976,26359796,1401395.334755,0,1048832,0
+dense_slow,copy_no_pool,4,ok,copy,False,8388608,90560,8350112,8350112,125,28753920,127352551,95896509,134242304,100671488,2048,2048,100663296,2048,0,0,4096,0,1854,0,33140024,7371263.893,11534336,11482598,989890.745684,0,0,0
+dense_slow,borrow,4,ok,borrow,True,8388608,90560,8350112,8350112,126,28753920,156176896,135527318,134242304,100671488,2048,2048,0,0,2048,0,126,1922,8,0,19302646,8983882.317,23068672,21705495,1205798.201258,0,1048832,0
+dense_slow,threshold2,4,ok,threshold,True,8388608,90560,8350112,8350112,126,28753920,150967021,112103512,134242304,100671488,2048,2048,0,0,2048,0,126,1922,343,0,27798231,8607200.207,14680064,15553678,1153842.867633,0,1048832,0
+dense_slow,pressure,4,ok,pressure,True,8388608,90560,8350112,8350112,126,28753920,131031651,108678412,134242304,100671488,2048,2048,0,0,2048,0,126,1922,194,0,17318187,7550902.647,12582912,12787335,1012712.39438,0,1048832,0
+mixed_slow,copy_no_pool,0,ok,copy,False,8388608,90560,8388432,8388432,349,28753920,196227931,90207409,177631232,53735632,2048,2048,53727440,2048,0,0,4096,0,899,0,106212702,25497204.119,41943040,38861965,1403800.480768,0,0,0
+mixed_slow,threshold4,0,ok,threshold,True,8388608,90560,8388608,8388608,282,28753920,182099749,86444975,177631232,53735632,2048,2048,11229392,1357,691,0,1834,1571,951,0,99448742,18702737.958,27262976,26735888,1347766.35285,0,1153216,0
+mixed_slow,pressure,0,ok,pressure,True,8388608,90560,8388480,8388432,345,28753920,170729984,95177478,177631232,53735632,2048,2048,27916032,1699,349,1699,1996,1751,848,0,79228418,22318118.532,33554432,33636461,1237184.456112,0,522496,0
+mixed_slow,threshold2,0,ok,threshold,True,8388608,90560,8388560,8388432,344,28753920,248649117,108815021,177631232,53735632,2048,2048,28479696,1740,308,0,1911,1877,806,0,141754620,32835308.438,50331648,52109020,1817663.170181,0,519424,0
+mixed_slow,copy,0,ok,copy,True,8388608,90560,8388576,8388432,343,28753920,188497435,95408242,177631232,53735632,2048,2048,53727440,2048,0,0,2001,2095,825,0,93045012,24119999.997,37748736,36830878,1331578.296683,0,519424,0
+mixed_slow,borrow,0,ok,borrow,True,8388608,90560,8386736,8386640,112,28753920,202207266,112741417,177631232,53735632,2048,2048,0,0,2048,0,1260,788,922,0,93158576,9030450.097,15728640,16897915,1584952.748115,0,667904,0
+mixed_slow,project,0,ok,project,True,8388608,90560,8388608,8388544,358,28753920,196788319,85794578,177631232,53735632,2048,2048,0,0,0,0,1594,454,835,0,111694672,25911259.331,41943040,39632482,1386620.278442,0,458688,0
+mixed_slow,threshold8,0,ok,threshold,True,8388608,90560,8388608,8388432,216,28753920,177004559,88488220,177631232,53735632,2048,2048,3824848,1008,1040,0,1769,1287,956,0,91999803,13961564.399,20971520,20644424,1308343.909911,0,1250624,0
+mixed_slow,copy_no_pool,1,ok,copy,False,8388608,90560,8388432,8388432,349,28753920,209526727,99009959,177631232,53735632,2048,2048,53727440,2048,0,0,4096,0,852,0,113158134,27706362.205,50331648,49857323,1504182.816335,0,0,0
+mixed_slow,threshold8,1,ok,threshold,True,8388608,90560,8388608,8388432,216,28753920,178695721,88024506,177631232,53735632,2048,2048,3824848,1008,1040,0,1752,1304,957,0,93665641,14283495.48,25165824,25314392,1350685.597943,0,1250624,0
+mixed_slow,project,1,ok,project,True,8388608,90560,8388608,8388544,358,28753920,188062454,85805781,177631232,53735632,2048,2048,0,0,0,0,1613,435,876,0,106943146,25106963.876,41943040,40388905,1338315.607594,0,463808,0
+mixed_slow,pressure,1,ok,pressure,True,8388608,90560,8388560,8388432,349,28753920,180476475,82814346,177631232,53735632,2048,2048,27916032,1699,349,1699,2034,1713,906,0,101386971,23117968.235,37748736,34624643,1287754.655314,0,522496,0
+mixed_slow,copy,1,ok,copy,True,8388608,90560,8388576,8388432,345,28753920,179916143,88224841,177631232,53735632,2048,2048,53727440,2048,0,0,2035,2061,868,0,95038979,23134688.68,37748736,38482948,1259295.778761,0,519424,0
+mixed_slow,threshold2,1,ok,threshold,True,8388608,90560,8388560,8388432,345,28753920,172458424,95876297,177631232,53735632,2048,2048,28479696,1740,308,0,1950,1838,838,0,80637955,22201893.822,29360128,29750009,1218383.798869,0,522496,0
+mixed_slow,borrow,1,ok,borrow,True,8388608,90560,8386736,8386688,112,28753920,202718412,105879101,177631232,53735632,2048,2048,0,0,2048,0,1270,778,933,0,101496664,8968645.74,15728640,15509271,1593585.502544,0,667904,0
+mixed_slow,threshold4,1,ok,threshold,True,8388608,90560,8388608,8388608,268,28753920,178050667,95042355,177631232,53735632,2048,2048,11229392,1357,691,0,1767,1638,919,0,87305079,17737601.933,27262976,26498834,1276748.071158,0,1154176,0
+mixed_slow,copy,2,ok,copy,True,8388608,90560,8388560,8388432,343,28753920,166505070,87773371,177631232,53735632,2048,2048,53727440,2048,0,0,2029,2067,855,0,82039937,21365903.831,31457280,30499822,1169734.902412,0,522496,0
+mixed_slow,project,2,ok,project,True,8388608,90560,8388576,8388576,358,28753920,184834889,77869217,177631232,53735632,2048,2048,0,0,0,0,1654,394,900,0,108638540,24466594.426,46137344,45971408,1295645.073976,0,458688,0
+mixed_slow,threshold2,2,ok,threshold,True,8388608,90560,8388432,8388432,346,28753920,191170037,94174606,177631232,53735632,2048,2048,28479696,1740,308,0,1933,1855,839,0,99297240,24916604.797,37748736,37194081,1364006.158543,0,519424,0
+mixed_slow,threshold4,2,ok,threshold,True,8388608,90560,8388608,8388608,267,28753920,221114880,108320175,177631232,53735632,2048,2048,11229392,1357,691,0,1725,1680,867,0,112272606,22302398.136,31457280,31418968,1620151.723755,0,1153216,0
+mixed_slow,pressure,2,ok,pressure,True,8388608,90560,8388560,8388432,343,28753920,200423808,95868665,177631232,53735632,2048,2048,27916032,1699,349,1699,1950,1797,826,0,104684245,26149827.952,37748736,37286562,1462564.435239,0,519424,0
+mixed_slow,copy_no_pool,2,ok,copy,False,8388608,90560,8388432,8388432,348,28753920,185563183,99669005,177631232,53735632,2048,2048,53727440,2048,0,0,4096,0,824,0,88520259,24158310.672,37748736,37578913,1315287.672243,0,0,0
+mixed_slow,threshold8,2,ok,threshold,True,8388608,90560,8388576,8388352,216,28753920,285706068,123773735,177631232,53735632,2048,2048,3824848,1008,1040,0,1639,1417,811,0,151915315,22809999.729,41943040,39308704,2141933.275175,0,1250624,0
+mixed_slow,borrow,2,ok,borrow,True,8388608,90560,8386736,8386640,112,28753920,277725554,130508378,177631232,53735632,2048,2048,0,0,2048,0,1246,802,882,0,145190817,12364716.181,25165824,24717468,2188978.814479,0,667904,0
+mixed_slow,project,3,ok,project,True,8388608,90560,8388576,8388544,350,28753920,266408067,111663429,177631232,53735632,2048,2048,0,0,0,0,1498,550,732,0,138942208,34638344.422,54525952,52949259,1878408.17389,0,458688,0
+mixed_slow,threshold2,3,ok,threshold,True,8388608,90560,8388560,8388432,341,28753920,204623815,104506177,177631232,53735632,2048,2048,28479696,1740,308,0,1822,1966,758,0,97171540,25691162.972,41943040,40286443,1429280.943963,0,522496,0
+mixed_slow,threshold4,3,ok,threshold,True,8388608,90560,8388608,8388608,277,28753920,162195656,80564634,177631232,53735632,2048,2048,11229392,1357,691,0,1810,1595,983,0,84519072,16670151.746,23068672,21537625,1200241.584576,0,1153216,0
+mixed_slow,copy,3,ok,copy,True,8388608,90560,8388560,8388432,350,28753920,155808970,73686530,177631232,53735632,2048,2048,53727440,2048,0,0,2181,1915,970,0,84997837,20210703.898,29360128,29034418,1105823.092919,0,522496,0
+mixed_slow,copy_no_pool,3,ok,copy,False,8388608,90560,8388432,8388432,343,28753920,175012120,86574113,177631232,53735632,2048,2048,53727440,2048,0,0,4096,0,847,0,86153992,21577383.531,37748736,35170512,1189109.090661,0,0,0
+mixed_slow,borrow,3,ok,borrow,True,8388608,90560,8386736,8386640,112,28753920,192464571,109214745,177631232,53735632,2048,2048,0,0,2048,0,1270,778,921,0,85288420,8548822.691,13631488,14178942,1513389.1547,0,667904,0
+mixed_slow,threshold8,3,ok,threshold,True,8388608,90560,8388496,8388432,216,28753920,180744548,92447570,177631232,53735632,2048,2048,3824848,1008,1040,0,1772,1284,987,0,91033265,14634490.266,20971520,21334847,1375000.84592,0,1250624,0
+mixed_slow,pressure,3,ok,pressure,True,8388608,90560,8388480,8388432,347,28753920,190539057,89751173,177631232,53735632,2048,2048,27916032,1699,349,1699,1983,1764,862,0,102577548,24120880.139,46137344,43388027,1333423.649457,0,519424,0
+mixed_slow,copy,4,ok,copy,True,8388608,90560,8388432,8388432,339,28753920,221349934,109576369,177631232,53735632,2048,2048,53727440,2048,0,0,1871,2225,733,0,114046592,28163326.597,46137344,46133518,1540447.287587,0,519424,0
+mixed_slow,project,4,ok,project,True,8388608,90560,8388576,8388544,351,28753920,182031656,81559603,177631232,53735632,2048,2048,0,0,0,0,1543,505,829,0,98044537,23787174.92,33554432,33075333,1288001.912824,0,458688,0
+mixed_slow,threshold8,4,ok,threshold,True,8388608,90560,8388608,8388432,216,28753920,190119929,98659849,177631232,53735632,2048,2048,3824848,1008,1040,0,1748,1308,937,0,91519644,15332315.134,27262976,28453087,1432190.421467,0,1262912,0
+mixed_slow,copy_no_pool,4,ok,copy,False,8388608,90560,8388432,8388432,348,28753920,181246528,87821814,177631232,53735632,2048,2048,53727440,2048,0,0,4096,0,854,0,96465580,23009953.597,37748736,35350753,1263667.037898,0,0,0
+mixed_slow,threshold4,4,ok,threshold,True,8388608,90560,8388608,8388608,268,28753920,202902060,94178139,177631232,53735632,2048,2048,11229392,1357,691,0,1778,1627,948,0,111627333,20292318.825,41943040,42672491,1456891.057432,0,1153216,0
+mixed_slow,borrow,4,ok,borrow,True,8388608,90560,8386736,8386640,112,28753920,187355085,105102970,177631232,53735632,2048,2048,0,0,2048,0,1268,780,942,0,86194520,8306217.014,16777216,16560027,1467132.987688,0,667904,0
+mixed_slow,threshold2,4,ok,threshold,True,8388608,90560,8388560,8388432,349,28753920,185932830,88442274,177631232,53735632,2048,2048,28479696,1740,308,0,1998,1790,873,0,100159229,24415772.17,37748736,35463160,1333943.667435,0,519424,0
+mixed_slow,pressure,4,ok,pressure,True,8388608,90560,8388560,8388432,351,28753920,175115990,85590028,177631232,53735632,2048,2048,27916032,1699,349,1699,2029,1718,897,0,90980114,22901875.606,31457280,30636340,1271349.314418,0,519424,0
+mixed_tight,pressure,0,ok,pressure,True,2097152,90560,2097152,2097136,106,28753920,194998211,80964449,177631232,53735632,2048,2048,28385168,1727,321,1727,2265,1510,1251,0,117554960,6209271.27,9437184,9610047,352937.551048,0,523712,0
+mixed_tight,project,0,ok,project,True,2097152,90560,2097120,2097120,118,28753920,191006927,80024226,177631232,53735632,2048,2048,0,0,0,0,1659,389,1164,0,113283506,6749781.49,10485760,10754747,354343.266259,0,406848,0
+mixed_tight,threshold8,0,ok,threshold,True,2097152,90560,2097120,2097120,72,28753920,315263040,90750328,177631232,53735632,2048,2048,3824848,1008,1040,0,1890,1166,1248,0,228816753,6291155.426,13631488,13216574,579371.042178,0,386176,0
+mixed_tight,copy_no_pool,0,ok,copy,False,2097152,90560,2097136,2097136,116,28753920,215534802,92135979,177631232,53735632,2048,2048,53727440,2048,0,0,4096,0,1179,0,127073694,6714221.641,10485760,12545668,387556.898349,0,0,0
+mixed_tight,threshold4,0,ok,threshold,True,2097152,90560,2097136,2097104,91,28753920,240539157,82888986,177631232,53735632,2048,2048,11229392,1357,691,0,2037,1368,1333,0,157978818,6115847.212,9437184,11204691,437508.612236,0,435392,0
+mixed_tight,copy,0,ok,copy,True,2097152,90560,2097136,2097136,111,28753920,205803459,87522857,177631232,53735632,2048,2048,53727440,2048,0,0,2361,1735,1210,0,121961836,6356735.332,11534336,12149188,363428.263552,0,523712,0
+mixed_tight,threshold2,0,ok,threshold,True,2097152,90560,2097136,2097136,103,28753920,218109869,94383237,177631232,53735632,2048,2048,28479696,1740,308,0,2188,1600,1166,0,128480946,7013746.965,14680064,15108236,394831.364885,0,523712,0
+mixed_tight,borrow,0,ok,borrow,True,2097152,90560,2094128,2094032,40,28753920,544543692,90900399,177631232,53735632,2048,2048,0,0,2048,0,1332,716,1286,0,453134113,6077465.417,11534336,12176243,1028555.825239,0,495872,0
+mixed_tight,copy,1,ok,copy,True,2097152,90560,2097136,2097136,117,28753920,191836517,62332245,177631232,53735632,2048,2048,53727440,2048,0,0,2460,1636,1362,0,131898458,6069082.115,8388608,8770216,346911.480275,0,523712,0
+mixed_tight,threshold2,1,ok,threshold,True,2097152,90560,2097136,2097136,117,28753920,188885136,63904326,177631232,53735632,2048,2048,28479696,1740,308,0,2356,1432,1390,0,127844964,6121880.805,8388608,8708698,342822.067006,0,523712,0
+mixed_tight,borrow,1,ok,borrow,True,2097152,90560,2094128,2094128,40,28753920,492789763,76140523,177631232,53735632,2048,2048,0,0,2048,0,1347,701,1406,0,420428963,5485700.477,8388608,9955175,928718.610429,0,495872,0
+mixed_tight,threshold8,1,ok,threshold,True,2097152,90560,2097136,2097136,72,28753920,282084485,66066433,177631232,53735632,2048,2048,3824848,1008,1040,0,1992,1064,1398,0,219096863,5671193.431,7340032,9274955,520410.956771,0,386176,0
+mixed_tight,threshold4,1,ok,threshold,True,2097152,90560,2097136,2097104,88,28753920,224500368,61534673,177631232,53735632,2048,2048,11229392,1357,691,0,2145,1260,1465,0,165914339,5837746.733,7864320,10210564,412262.960044,0,435392,0
+mixed_tight,pressure,1,ok,pressure,True,2097152,90560,2097136,2097136,115,28753920,189684559,60774942,177631232,53735632,2048,2048,28385168,1727,321,1727,2383,1392,1399,0,131755127,6110993.322,8388608,9608714,345607.344111,0,523712,0
+mixed_tight,copy_no_pool,1,ok,copy,False,2097152,90560,2097136,2097136,117,28753920,190441538,59274120,177631232,53735632,2048,2048,53727440,2048,0,0,4096,0,1383,0,133844636,6031707.432,8388608,8881216,344699.365648,0,0,0
+mixed_tight,project,1,ok,project,True,2097152,90560,2097120,2097120,118,28753920,175373266,57346839,177631232,53735632,2048,2048,0,0,0,0,1727,321,1312,0,120854151,6287663.374,8388608,8829253,326669.995028,0,406848,0
+mixed_tight,copy_no_pool,2,ok,copy,False,2097152,90560,2097136,2097136,115,28753920,190230224,58883103,177631232,53735632,2048,2048,53727440,2048,0,0,4096,0,1379,0,133923360,6020977.936,8388608,8904123,344486.353015,0,0,0
+mixed_tight,project,2,ok,project,True,2097152,90560,2097120,2097120,118,28753920,176712466,57142470,177631232,53735632,2048,2048,0,0,0,0,1727,321,1308,0,122435178,6344282.023,9437184,9173733,329327.109037,0,406848,0
+mixed_tight,copy,2,ok,copy,True,2097152,90560,2097152,2097136,115,28753920,192640551,62036091,177631232,53735632,2048,2048,53727440,2048,0,0,2463,1633,1367,0,133360267,6075663.601,8388608,8830642,347845.920578,0,523712,0
+mixed_tight,threshold8,2,ok,threshold,True,2097152,90560,2097136,2097136,73,28753920,284454034,68644342,177631232,53735632,2048,2048,3824848,1008,1040,0,1983,1073,1386,0,218577789,5702048.39,7340032,9254474,523314.413618,0,386176,0
+mixed_tight,threshold4,2,ok,threshold,True,2097152,90560,2097136,2097104,88,28753920,226008956,64169718,177631232,53735632,2048,2048,11229392,1357,691,0,2125,1280,1458,0,164889565,5866464.096,8388608,10318805,414911.228869,0,435392,0
+mixed_tight,borrow,2,ok,borrow,True,2097152,90560,2094128,2094128,40,28753920,494360387,73512176,177631232,53735632,2048,2048,0,0,2048,0,1345,703,1395,0,424305645,5500812.732,8388608,9972009,932412.777581,0,495872,0
+mixed_tight,threshold2,2,ok,threshold,True,2097152,90560,2097136,2097136,115,28753920,188224878,60744558,177631232,53735632,2048,2048,28479696,1740,308,0,2384,1404,1411,0,130279846,6114092.392,8388608,8874864,342235.388035,0,523712,0
+mixed_tight,pressure,2,ok,pressure,True,2097152,90560,2097136,2097136,115,28753920,189816540,60109883,177631232,53735632,2048,2048,28385168,1727,321,1727,2377,1398,1401,0,132388467,6115537.712,8388608,9634918,345575.615482,0,523712,0
+mixed_tight,pressure,3,ok,pressure,True,2097152,90560,2097136,2097136,115,28753920,190593723,62104383,177631232,53735632,2048,2048,28385168,1727,321,1727,2377,1398,1387,0,131246281,6133228.412,8388608,9617713,346774.138471,0,523712,0
+mixed_tight,borrow,3,ok,borrow,True,2097152,90560,2094128,2094128,40,28753920,491528840,70906509,177631232,53735632,2048,2048,0,0,2048,0,1353,695,1421,0,423844868,5472000.565,8388608,9945028,926418.118409,0,495872,0
+mixed_tight,copy_no_pool,3,ok,copy,False,2097152,90560,2097136,2097136,116,28753920,190661223,60180004,177631232,53735632,2048,2048,53727440,2048,0,0,4096,0,1376,0,133160918,6036141.159,8388608,8916068,345094.680154,0,0,0
+mixed_tight,threshold2,3,ok,threshold,True,2097152,90560,2097136,2097136,116,28753920,193175809,69008296,177631232,53735632,2048,2048,28479696,1740,308,0,2336,1452,1351,0,125127054,6239198.13,9437184,9276566,350903.059901,0,523712,0
+mixed_tight,threshold8,3,ok,threshold,True,2097152,90560,2097120,2097120,73,28753920,286766304,73096130,177631232,53735632,2048,2048,3824848,1008,1040,0,1974,1082,1367,0,215532386,5744366.208,7864320,8864197,528100.049771,0,386176,0
+mixed_tight,threshold4,3,ok,threshold,True,2097152,90560,2097136,2097104,88,28753920,225938124,65488664,177631232,53735632,2048,2048,11229392,1357,691,0,2121,1284,1445,0,163452164,5856203.824,8388608,10380804,414648.202609,0,435392,0
+mixed_tight,copy,3,ok,copy,True,2097152,90560,2097152,2097136,108,28753920,191114147,63369902,177631232,53735632,2048,2048,53727440,2048,0,0,2453,1643,1341,0,130459979,6032302.559,8388608,8833531,345755.184019,0,523712,0
+mixed_tight,project,3,ok,project,True,2097152,90560,2097120,2097120,118,28753920,177942277,63483663,177631232,53735632,2048,2048,0,0,0,0,1711,337,1279,0,117556310,6348716.251,8388608,8883105,331194.459386,0,406848,0
+mixed_tight,copy,4,ok,copy,True,2097152,90560,2097152,2097136,117,28753920,191747145,60306782,177631232,53735632,2048,2048,53727440,2048,0,0,2470,1626,1379,0,134097654,6065392.323,8388608,8895161,347142.858576,0,523712,0
+mixed_tight,threshold2,4,ok,threshold,True,2097152,90560,2097136,2097136,115,28753920,187864582,60112693,177631232,53735632,2048,2048,28479696,1740,308,0,2380,1408,1409,0,130504092,6102214.292,8388608,8884715,341567.414808,0,523712,0
+mixed_tight,project,4,ok,project,True,2097152,90560,2097120,2097120,118,28753920,175293210,56768485,177631232,53735632,2048,2048,0,0,0,0,1722,326,1313,0,121359184,6283898.527,8388608,8849623,326483.546647,0,406848,0
+mixed_tight,threshold8,4,ok,threshold,True,2097152,90560,2097136,2097136,73,28753920,283727960,68131361,177631232,53735632,2048,2048,3824848,1008,1040,0,1988,1068,1394,0,218912386,5707951.51,7340032,9272677,523909.294385,0,386176,0
+mixed_tight,borrow,4,ok,borrow,True,2097152,90560,2094128,2094128,40,28753920,495666215,81002646,177631232,53735632,2048,2048,0,0,2048,0,1336,712,1382,0,418460319,5519510.972,8388608,9930268,935139.458784,0,495872,0
+mixed_tight,copy_no_pool,4,ok,copy,False,2097152,90560,2097136,2097136,116,28753920,190841888,60356559,177631232,53735632,2048,2048,53727440,2048,0,0,4096,0,1382,0,133224289,6038284.196,8388608,8947753,345496.101548,0,0,0
+mixed_tight,threshold4,4,ok,threshold,True,2097152,90560,2097136,2097104,88,28753920,226098419,63538828,177631232,53735632,2048,2048,11229392,1357,691,0,2129,1276,1452,0,165691682,5878789.657,7864320,10264360,415107.899759,0,435392,0
+mixed_tight,pressure,4,ok,pressure,True,2097152,90560,2097136,2097136,115,28753920,192204126,62496629,177631232,53735632,2048,2048,28385168,1727,321,1727,2367,1408,1381,0,132616450,6161110.138,9437184,9782879,349554.881495,0,523712,0
+sparse_fast,pressure,0,ok,pressure,True,8388608,90560,156112,156112,1,28753920,20554720,20527722,134242304,139264,2048,2048,0,0,2048,0,1,2047,0,0,0,9881.978,13312,60759,1273.955005,0,65552,0
+sparse_fast,project,0,ok,project,True,8388608,90560,90640,90640,1,28753920,22216122,22101834,134242304,139264,2048,2048,0,0,0,0,1,2047,0,0,0,10698.669,16384,58241,1.68633,0,80,0
+sparse_fast,threshold4,0,ok,threshold,True,8388608,90560,156192,156192,1,28753920,22839176,22457056,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,10958.209,20480,165851,1227.172318,0,65632,0
+sparse_fast,copy,0,ok,copy,True,8388608,90560,156192,156192,1,28753920,21009107,20955370,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,10112.231,14336,66129,1120.781895,0,65632,0
+sparse_fast,copy_no_pool,0,ok,copy,False,8388608,90560,156192,156192,1,28753920,21132162,21048817,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,0,0,10163.675,16384,68685,1121.783606,0,0,0
+sparse_fast,threshold8,0,ok,threshold,True,8388608,90560,156192,156192,1,28753920,20540535,20499501,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,9884.486,13312,54093,1100.863361,0,65632,0
+sparse_fast,borrow,0,ok,borrow,True,8388608,90560,156112,156112,1,28753920,21727605,21682906,134242304,139264,2048,2048,0,0,2048,0,1,2047,0,0,0,10449.435,20480,65999,1348.749968,0,65552,0
+sparse_fast,threshold2,0,ok,threshold,True,8388608,90560,156192,156192,1,28753920,22373067,22308741,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,10776.724,18432,66703,1207.809872,0,65632,0
+sparse_fast,project,1,ok,project,True,8388608,90560,90640,90640,1,28753920,25768428,25607575,134242304,139264,2048,2048,0,0,0,0,1,2047,0,0,0,12427.336,22528,135518,1.971383,0,80,0
+sparse_fast,threshold8,1,ok,threshold,True,8388608,90560,156192,156192,1,28753920,22601085,22218814,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,10886.611,28672,70518,1220.513584,0,65632,0
+sparse_fast,copy_no_pool,1,ok,copy,False,8388608,90560,156192,156192,1,28753920,22194827,21633689,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,0,0,10673.54,36864,207444,1178.059751,0,0,0
+sparse_fast,pressure,1,ok,pressure,True,8388608,90560,156112,156112,1,28753920,23241749,23003312,134242304,139264,2048,2048,0,0,2048,0,1,2047,0,0,0,11135.177,22528,79185,1441.524009,0,65552,0
+sparse_fast,copy,1,ok,copy,True,8388608,90560,156192,156192,1,28753920,24103618,23832019,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,11617.114,22528,88389,1310.460688,0,65632,0
+sparse_fast,threshold2,1,ok,threshold,True,8388608,90560,156192,156192,1,28753920,21191681,21131537,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,10199.927,14336,68426,1132.085862,0,65632,0
+sparse_fast,threshold4,1,ok,threshold,True,8388608,90560,156192,156192,1,28753920,21871975,21613127,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,10530.066,18432,78704,1171.334175,0,65632,0
+sparse_fast,borrow,1,ok,borrow,True,8388608,90560,156112,156112,1,28753920,21555643,21467723,134242304,139264,2048,2048,0,0,2048,0,1,2047,0,0,0,10366.948,18432,62648,1339.691796,0,65552,0
+sparse_fast,borrow,2,ok,borrow,True,8388608,90560,156112,156112,1,28753920,20704016,20633572,134242304,139264,2048,2048,0,0,2048,0,1,2047,0,0,0,9954.482,14336,84963,1283.092823,0,65552,0
+sparse_fast,threshold2,2,ok,threshold,True,8388608,90560,156192,156192,1,28753920,20854404,20822149,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,10030.324,14336,62445,1108.309428,0,65632,0
+sparse_fast,copy_no_pool,2,ok,copy,False,8388608,90560,156192,156192,1,28753920,21286218,21228201,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,0,0,10237.021,15360,67889,1129.223222,0,0,0
+sparse_fast,project,2,ok,project,True,8388608,90560,90640,90640,1,28753920,22649251,22567445,134242304,139264,2048,2048,0,0,0,0,1,2047,0,0,0,10910.76,15360,61499,1.717551,0,80,0
+sparse_fast,pressure,2,ok,pressure,True,8388608,90560,156112,156112,1,28753920,20767942,20708872,134242304,139264,2048,2048,0,0,2048,0,1,2047,0,0,0,9985.038,15360,65425,1286.595987,0,65552,0
+sparse_fast,copy,2,ok,copy,True,8388608,90560,156192,156192,1,28753920,21065681,21006279,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,10139.793,15360,67018,1124.320165,0,65632,0
+sparse_fast,threshold4,2,ok,threshold,True,8388608,90560,156192,156192,1,28753920,20961885,20931648,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,10087.398,13312,60962,1117.500277,0,65632,0
+sparse_fast,threshold8,2,ok,threshold,True,8388608,90560,156192,156192,1,28753920,20908700,20878832,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,10062.625,14336,70648,1116.46627,0,65632,0
+sparse_fast,threshold2,3,ok,threshold,True,8388608,90560,156192,156192,1,28753920,21328570,21275351,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,10266.949,15360,61241,1144.526904,0,65632,0
+sparse_fast,borrow,3,ok,borrow,True,8388608,90560,156112,156112,1,28753920,20408294,20408999,134242304,139264,2048,2048,0,0,2048,0,1,2047,0,0,0,9812.079,13312,48982,1265.057763,0,65552,0
+sparse_fast,copy,3,ok,copy,True,8388608,90560,156192,156192,1,28753920,20744256,20744722,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,9979.793,13312,42518,1107.901257,0,65632,0
+sparse_fast,project,3,ok,project,True,8388608,90560,90640,90640,1,28753920,21766957,21732111,134242304,139264,2048,2048,0,0,0,0,1,2047,0,0,0,10483.601,13312,74593,1.653919,0,80,0
+sparse_fast,threshold4,3,ok,threshold,True,8388608,90560,156192,156192,1,28753920,23474730,23418353,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,11311.146,24576,72445,1275.148887,0,65632,0
+sparse_fast,threshold8,3,ok,threshold,True,8388608,90560,156192,156192,1,28753920,25891223,25855036,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,12490.423,32768,62019,1433.084986,0,65632,0
+sparse_fast,pressure,3,ok,pressure,True,8388608,90560,156112,156112,1,28753920,25124448,24854663,134242304,139264,2048,2048,0,0,2048,0,1,2047,0,0,0,12097.683,24576,83351,1569.932052,0,65552,0
+sparse_fast,copy_no_pool,3,ok,copy,False,8388608,90560,156192,156192,1,28753920,21725958,21582704,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,0,0,10452.028,16384,197777,1159.292471,0,0,0
+sparse_fast,project,4,ok,project,True,8388608,90560,90640,90640,1,28753920,22202622,22202889,134242304,139264,2048,2048,0,0,0,0,1,2047,0,0,0,10695.292,18432,48444,1.688434,0,80,0
+sparse_fast,threshold2,4,ok,threshold,True,8388608,90560,156192,156192,1,28753920,27294793,27138353,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,13171.363,28672,78185,1515.562825,0,65632,0
+sparse_fast,threshold8,4,ok,threshold,True,8388608,90560,156192,156192,1,28753920,33207148,33180296,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,16048.501,36864,74648,1873.802277,0,65632,0
+sparse_fast,copy,4,ok,copy,True,8388608,90560,156192,156192,1,28753920,40643311,40589351,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,19667.254,49152,147388,2334.403772,0,65632,0
+sparse_fast,threshold4,4,ok,threshold,True,8388608,90560,156192,156192,1,28753920,28395383,28350296,134242304,139264,2048,2048,131072,2048,0,0,2,4094,0,0,0,13707.471,26624,87370,1583.182193,0,65632,0
+sparse_fast,borrow,4,ok,borrow,True,8388608,90560,156112,156112,1,28753920,25754576,25674260,134242304,139264,2048,2048,0,0,2048,0,1,2047,0,0,0,12408.192,20480,98925,1611.048102,0,65552,0
+sparse_fast,pressure,4,ok,pressure,True,8388608,90560,156112,156112,1,28753920,28270087,28259741,134242304,139264,2048,2048,0,0,2048,0,1,2047,0,0,0,13635.652,20480,75407,1772.014643,0,65552,0
+sparse_fast,copy_no_pool,4,ok,copy,False,8388608,90560,156192,156192,1,28753920,30675302,30605147,134242304,139264,2048,2048,131072,2048,0,0,4096,0,0,0,0,14792.559,22528,144222,1690.623657,0,0,0
diff --git a/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/raw.json b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/raw.json new file mode 100644 index 0000000..78400eb --- /dev/null +++ b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/raw.json @@ -0,0 +1,7202 @@ +[ + { + "case": "sparse_slow", + "variant": "copy", + "repeat": 0, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 156440711, + "cpu_ns": 48121065, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 878, + "sleep_ns": 109587045, + "latency_mean_ns": 32718961.288, + "latency_p99_upper_ns": 50331648, + "latency_max_ns": 47686700, + "active_byte_seconds": 7879.414446, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold4", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 152733814, + "cpu_ns": 52980104, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 718, + "sleep_ns": 102189918, + "latency_mean_ns": 30324683.181, + "latency_p99_upper_ns": 54525952, + "latency_max_ns": 52327335, + "active_byte_seconds": 7602.229051, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold2", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 155247640, + "cpu_ns": 47779812, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 809, + "sleep_ns": 108519282, + "latency_mean_ns": 31414916.006, + "latency_p99_upper_ns": 54525952, + "latency_max_ns": 51100228, + "active_byte_seconds": 7369.340036, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "copy_no_pool", + "repeat": 0, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 164046264, + "cpu_ns": 46944898, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 881, + "sleep_ns": 113764083, + "latency_mean_ns": 35133900.267, + "latency_p99_upper_ns": 46137344, + "latency_max_ns": 46051556, + "active_byte_seconds": 8459.440246, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "project", + "repeat": 0, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 131520, + "peak_active_bytes": 131520, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 157789596, + "cpu_ns": 25739163, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 512, + "reuses": 1536, + "budget_waits": 0, + "slot_waits": 1536, + "sleep_ns": 136058109, + "latency_mean_ns": 34150955.425, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 40528961, + "active_byte_seconds": 5595.217111, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1280, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold8", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 154250903, + "cpu_ns": 24028565, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1537, + "sleep_ns": 133827808, + "latency_mean_ns": 33265597.392, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37531339, + "active_byte_seconds": 6504.707846, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "borrow", + "repeat": 0, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 101576920, + "cpu_ns": 50248602, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 825, + "slot_waits": 0, + "sleep_ns": 53200392, + "latency_mean_ns": 5868549.98, + "latency_p99_upper_ns": 10485760, + "latency_max_ns": 10885229, + "active_byte_seconds": 784884.708981, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "pressure", + "repeat": 0, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 4321888, + "peak_active_bytes": 4316448, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 153086035, + "cpu_ns": 29353156, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 113152, + "copied_records": 1768, + "borrowed_records": 280, + "pressure_copies": 1768, + "allocations": 514, + "reuses": 3302, + "budget_waits": 0, + "slot_waits": 1424, + "sleep_ns": 127637166, + "latency_mean_ns": 32763957.697, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 38592411, + "active_byte_seconds": 549197.237404, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 590528, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "borrow", + "repeat": 1, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 132106520, + "cpu_ns": 45409725, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1532, + "slot_waits": 0, + "sleep_ns": 89610425, + "latency_mean_ns": 7801228.044, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 9303567, + "active_byte_seconds": 1041796.843202, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "copy_no_pool", + "repeat": 1, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 154376717, + "cpu_ns": 24625261, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 1534, + "sleep_ns": 133550825, + "latency_mean_ns": 33304515.117, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37563136, + "active_byte_seconds": 6521.304714, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold2", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 154790882, + "cpu_ns": 24092354, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1537, + "sleep_ns": 134531052, + "latency_mean_ns": 33433846.048, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37877431, + "active_byte_seconds": 6519.648368, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold4", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 154495679, + "cpu_ns": 24603184, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1536, + "sleep_ns": 133731727, + "latency_mean_ns": 33331969.71, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37527099, + "active_byte_seconds": 6535.057316, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold8", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 154242976, + "cpu_ns": 24135969, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1535, + "sleep_ns": 133865874, + "latency_mean_ns": 33299370.61, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37484173, + "active_byte_seconds": 6509.096995, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "project", + "repeat": 1, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 131520, + "peak_active_bytes": 131520, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 154024996, + "cpu_ns": 25025451, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 512, + "reuses": 1536, + "budget_waits": 0, + "slot_waits": 1534, + "sleep_ns": 132769732, + "latency_mean_ns": 33212736.419, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37402803, + "active_byte_seconds": 5441.502377, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1280, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "pressure", + "repeat": 1, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 4321888, + "peak_active_bytes": 4316928, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 151466095, + "cpu_ns": 27009927, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 113280, + "copied_records": 1770, + "borrowed_records": 278, + "pressure_copies": 1770, + "allocations": 514, + "reuses": 3304, + "budget_waits": 0, + "slot_waits": 1473, + "sleep_ns": 128099292, + "latency_mean_ns": 32391902.953, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37408099, + "active_byte_seconds": 539531.143577, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 590528, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "copy", + "repeat": 1, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 155007270, + "cpu_ns": 24608283, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1535, + "sleep_ns": 134124966, + "latency_mean_ns": 33382726.714, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37593062, + "active_byte_seconds": 6546.135984, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold4", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 154312902, + "cpu_ns": 23956224, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1535, + "sleep_ns": 134085359, + "latency_mean_ns": 33321820.453, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37660191, + "active_byte_seconds": 6502.811837, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "copy_no_pool", + "repeat": 2, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 154586382, + "cpu_ns": 24703970, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 1534, + "sleep_ns": 133705501, + "latency_mean_ns": 33392210.559, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 37987523, + "active_byte_seconds": 6536.248232, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold2", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 154368809, + "cpu_ns": 24191625, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1534, + "sleep_ns": 133926227, + "latency_mean_ns": 33288663.865, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37544080, + "active_byte_seconds": 6508.096109, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "pressure", + "repeat": 2, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 4321888, + "peak_active_bytes": 4316208, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 151522021, + "cpu_ns": 27174295, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 113088, + "copied_records": 1767, + "borrowed_records": 281, + "pressure_copies": 1767, + "allocations": 514, + "reuses": 3301, + "budget_waits": 0, + "slot_waits": 1465, + "sleep_ns": 128053394, + "latency_mean_ns": 32398179.535, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37585173, + "active_byte_seconds": 545315.69968, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 590528, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "copy", + "repeat": 2, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 154139254, + "cpu_ns": 24156681, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1535, + "sleep_ns": 133742452, + "latency_mean_ns": 33274854.653, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37580636, + "active_byte_seconds": 6504.184345, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "project", + "repeat": 2, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 131520, + "peak_active_bytes": 131520, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 154504494, + "cpu_ns": 25538018, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 512, + "reuses": 1536, + "budget_waits": 0, + "slot_waits": 1533, + "sleep_ns": 132803019, + "latency_mean_ns": 33348679.346, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37696024, + "active_byte_seconds": 5463.772808, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1280, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold8", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 154268606, + "cpu_ns": 24017037, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1537, + "sleep_ns": 134039266, + "latency_mean_ns": 33296530.878, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37600117, + "active_byte_seconds": 6499.765006, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "borrow", + "repeat": 2, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 116617303, + "cpu_ns": 46471284, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1258, + "slot_waits": 0, + "sleep_ns": 72494973, + "latency_mean_ns": 6836360.134, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 9280234, + "active_byte_seconds": 913414.105279, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "project", + "repeat": 3, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 131520, + "peak_active_bytes": 131520, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 155002696, + "cpu_ns": 25290252, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 512, + "reuses": 1536, + "budget_waits": 0, + "slot_waits": 1537, + "sleep_ns": 133467827, + "latency_mean_ns": 33443160.686, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 38061801, + "active_byte_seconds": 5479.253547, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1280, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "borrow", + "repeat": 3, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 122707360, + "cpu_ns": 46832624, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1334, + "slot_waits": 0, + "sleep_ns": 78581274, + "latency_mean_ns": 7210177.487, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 9450215, + "active_byte_seconds": 963195.592926, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "pressure", + "repeat": 3, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 4321888, + "peak_active_bytes": 4316128, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 170735523, + "cpu_ns": 36085789, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 113024, + "copied_records": 1766, + "borrowed_records": 282, + "pressure_copies": 1766, + "allocations": 514, + "reuses": 3300, + "budget_waits": 0, + "slot_waits": 1403, + "sleep_ns": 140741412, + "latency_mean_ns": 37128525.741, + "latency_p99_upper_ns": 50331648, + "latency_max_ns": 49207437, + "active_byte_seconds": 624641.105995, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 590528, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold8", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 161984455, + "cpu_ns": 35308455, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1418, + "sleep_ns": 132544941, + "latency_mean_ns": 34734342.366, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 41927513, + "active_byte_seconds": 7196.657649, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold2", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 183186784, + "cpu_ns": 39562601, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1377, + "sleep_ns": 149944607, + "latency_mean_ns": 39799236.839, + "latency_p99_upper_ns": 50331648, + "latency_max_ns": 49954231, + "active_byte_seconds": 8175.636446, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "copy", + "repeat": 3, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 160896124, + "cpu_ns": 25740442, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1519, + "sleep_ns": 138959714, + "latency_mean_ns": 34942676.828, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 40635979, + "active_byte_seconds": 6866.098036, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "copy_no_pool", + "repeat": 3, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 155242417, + "cpu_ns": 24840078, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 1534, + "sleep_ns": 134375289, + "latency_mean_ns": 33387730.27, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 38123912, + "active_byte_seconds": 6526.934401, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold4", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 153980365, + "cpu_ns": 24665615, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1523, + "sleep_ns": 133098283, + "latency_mean_ns": 33153737.672, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37518117, + "active_byte_seconds": 6514.197106, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "copy_no_pool", + "repeat": 4, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 154143199, + "cpu_ns": 24004931, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 1536, + "sleep_ns": 133901751, + "latency_mean_ns": 33287028.642, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37626617, + "active_byte_seconds": 6483.552028, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "copy", + "repeat": 4, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 153170646, + "cpu_ns": 26299681, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1505, + "sleep_ns": 130663631, + "latency_mean_ns": 33019408.27, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37369469, + "active_byte_seconds": 6585.869234, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold4", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 154103699, + "cpu_ns": 23694419, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1537, + "sleep_ns": 134088060, + "latency_mean_ns": 33271036.464, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37623950, + "active_byte_seconds": 6485.074292, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold8", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 154585216, + "cpu_ns": 23936885, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1536, + "sleep_ns": 134389609, + "latency_mean_ns": 33393120.598, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 38036616, + "active_byte_seconds": 6515.371593, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "borrow", + "repeat": 4, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 124475504, + "cpu_ns": 45943956, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1468, + "slot_waits": 0, + "sleep_ns": 81119761, + "latency_mean_ns": 7320646.162, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 9274900, + "active_byte_seconds": 977840.583339, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "threshold2", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 197072, + "peak_active_bytes": 197072, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 154125217, + "cpu_ns": 24321563, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 513, + "reuses": 3583, + "budget_waits": 0, + "slot_waits": 1536, + "sleep_ns": 133545099, + "latency_mean_ns": 33270620.015, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37515988, + "active_byte_seconds": 6516.994726, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 66752, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "pressure", + "repeat": 4, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 4321888, + "peak_active_bytes": 4317248, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 151398447, + "cpu_ns": 26713792, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 113408, + "copied_records": 1772, + "borrowed_records": 276, + "pressure_copies": 1772, + "allocations": 514, + "reuses": 3306, + "budget_waits": 0, + "slot_waits": 1473, + "sleep_ns": 128307648, + "latency_mean_ns": 32397554.332, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37324395, + "active_byte_seconds": 535707.02646, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 590528, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_slow", + "variant": "project", + "repeat": 4, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 131520, + "peak_active_bytes": 131520, + "peak_queue": 512, + "rss_peak_bytes": 28753920, + "elapsed_ns": 154766567, + "cpu_ns": 24892483, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 512, + "reuses": 1536, + "budget_waits": 0, + "slot_waits": 1537, + "sleep_ns": 133703008, + "latency_mean_ns": 33388895.003, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 37874598, + "active_byte_seconds": 5470.365986, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1280, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "project", + "repeat": 0, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 153699255, + "cpu_ns": 97036844, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 890, + "slot_waits": 0, + "sleep_ns": 59162056, + "latency_mean_ns": 8908081.106, + "latency_p99_upper_ns": 15728640, + "latency_max_ns": 16113048, + "active_byte_seconds": 1191532.621299, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold2", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 130854245, + "cpu_ns": 109226645, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 318, + "slot_waits": 0, + "sleep_ns": 22611916, + "latency_mean_ns": 7607977.365, + "latency_p99_upper_ns": 11534336, + "latency_max_ns": 12586113, + "active_byte_seconds": 1019874.721927, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "copy_no_pool", + "repeat": 0, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 125, + "rss_peak_bytes": 28753920, + "elapsed_ns": 130227024, + "cpu_ns": 112627422, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 100663296, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 1363, + "slot_waits": 0, + "sleep_ns": 17672583, + "latency_mean_ns": 7496902.226, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 12386151, + "active_byte_seconds": 1006822.239807, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "borrow", + "repeat": 0, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 132968553, + "cpu_ns": 110199520, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 230, + "slot_waits": 0, + "sleep_ns": 24087338, + "latency_mean_ns": 7516016.308, + "latency_p99_upper_ns": 16777216, + "latency_max_ns": 17649580, + "active_byte_seconds": 1007870.242312, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "pressure", + "repeat": 0, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 139106888, + "cpu_ns": 110625767, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 217, + "slot_waits": 0, + "sleep_ns": 29387892, + "latency_mean_ns": 8069611.928, + "latency_p99_upper_ns": 16777216, + "latency_max_ns": 17083878, + "active_byte_seconds": 1081569.371059, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "copy", + "repeat": 0, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 125, + "rss_peak_bytes": 28753920, + "elapsed_ns": 139677276, + "cpu_ns": 98850013, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 100663296, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 126, + "reuses": 3970, + "budget_waits": 1911, + "slot_waits": 0, + "sleep_ns": 41099434, + "latency_mean_ns": 8122260.495, + "latency_p99_upper_ns": 11534336, + "latency_max_ns": 11425690, + "active_byte_seconds": 1090782.263887, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold4", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 152388963, + "cpu_ns": 133280290, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 263, + "slot_waits": 0, + "sleep_ns": 19097885, + "latency_mean_ns": 8858624.865, + "latency_p99_upper_ns": 13631488, + "latency_max_ns": 13575925, + "active_byte_seconds": 1188061.088853, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold8", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 158487631, + "cpu_ns": 104607294, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 881, + "slot_waits": 0, + "sleep_ns": 55726830, + "latency_mean_ns": 9142910.493, + "latency_p99_upper_ns": 16777216, + "latency_max_ns": 16508139, + "active_byte_seconds": 1223330.140557, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "pressure", + "repeat": 1, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 148054808, + "cpu_ns": 118930635, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 243, + "slot_waits": 0, + "sleep_ns": 23339314, + "latency_mean_ns": 8545660.143, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 13488795, + "active_byte_seconds": 1145837.182993, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold2", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 127102070, + "cpu_ns": 98389110, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 548, + "slot_waits": 0, + "sleep_ns": 29835471, + "latency_mean_ns": 7376714.273, + "latency_p99_upper_ns": 11534336, + "latency_max_ns": 11721430, + "active_byte_seconds": 988062.578411, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold4", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 137097783, + "cpu_ns": 105658521, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 319, + "slot_waits": 0, + "sleep_ns": 33507567, + "latency_mean_ns": 7492151.426, + "latency_p99_upper_ns": 25165824, + "latency_max_ns": 25521632, + "active_byte_seconds": 1004322.345588, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "copy_no_pool", + "repeat": 1, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 125, + "rss_peak_bytes": 28753920, + "elapsed_ns": 129205398, + "cpu_ns": 106642340, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 100663296, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 1837, + "slot_waits": 0, + "sleep_ns": 23366005, + "latency_mean_ns": 7161052.395, + "latency_p99_upper_ns": 20971520, + "latency_max_ns": 19672000, + "active_byte_seconds": 961708.896247, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold8", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 149831970, + "cpu_ns": 119769747, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 207, + "slot_waits": 0, + "sleep_ns": 22835752, + "latency_mean_ns": 8570181.832, + "latency_p99_upper_ns": 25165824, + "latency_max_ns": 24456487, + "active_byte_seconds": 1149620.580849, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "project", + "repeat": 1, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 138012595, + "cpu_ns": 104050639, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 573, + "slot_waits": 0, + "sleep_ns": 35587895, + "latency_mean_ns": 8024328.08, + "latency_p99_upper_ns": 11534336, + "latency_max_ns": 11967226, + "active_byte_seconds": 1074555.345603, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "copy", + "repeat": 1, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 125, + "rss_peak_bytes": 28753920, + "elapsed_ns": 139897423, + "cpu_ns": 116916607, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 100663296, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 126, + "reuses": 3970, + "budget_waits": 1245, + "slot_waits": 0, + "sleep_ns": 21827476, + "latency_mean_ns": 7467830.775, + "latency_p99_upper_ns": 11534336, + "latency_max_ns": 12057799, + "active_byte_seconds": 1002967.933698, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "borrow", + "repeat": 1, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 124760040, + "cpu_ns": 105059769, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 279, + "slot_waits": 0, + "sleep_ns": 20851427, + "latency_mean_ns": 7121146.062, + "latency_p99_upper_ns": 13631488, + "latency_max_ns": 13454333, + "active_byte_seconds": 954812.49966, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold4", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 128197678, + "cpu_ns": 100339777, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 483, + "slot_waits": 0, + "sleep_ns": 29286062, + "latency_mean_ns": 7442559.441, + "latency_p99_upper_ns": 11534336, + "latency_max_ns": 11489301, + "active_byte_seconds": 997040.290853, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "copy_no_pool", + "repeat": 2, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 125, + "rss_peak_bytes": 28753920, + "elapsed_ns": 205943127, + "cpu_ns": 116032671, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 100663296, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 1454, + "slot_waits": 0, + "sleep_ns": 23092169, + "latency_mean_ns": 12031760.945, + "latency_p99_upper_ns": 20971520, + "latency_max_ns": 20696239, + "active_byte_seconds": 1615356.534078, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold2", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 126630183, + "cpu_ns": 111840417, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 123, + "slot_waits": 0, + "sleep_ns": 14544050, + "latency_mean_ns": 7317376.727, + "latency_p99_upper_ns": 11534336, + "latency_max_ns": 11766189, + "active_byte_seconds": 981675.539219, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold8", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 130400357, + "cpu_ns": 115426208, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 33, + "slot_waits": 0, + "sleep_ns": 15522516, + "latency_mean_ns": 7311488.307, + "latency_p99_upper_ns": 13631488, + "latency_max_ns": 16432805, + "active_byte_seconds": 981225.27374, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "project", + "repeat": 2, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 158617537, + "cpu_ns": 105530265, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 630, + "slot_waits": 0, + "sleep_ns": 53505513, + "latency_mean_ns": 8986415.696, + "latency_p99_upper_ns": 20971520, + "latency_max_ns": 20150036, + "active_byte_seconds": 1202933.657783, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "copy", + "repeat": 2, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 125, + "rss_peak_bytes": 28753920, + "elapsed_ns": 136167489, + "cpu_ns": 109997334, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 100663296, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 126, + "reuses": 3970, + "budget_waits": 1562, + "slot_waits": 0, + "sleep_ns": 27532835, + "latency_mean_ns": 7639923.617, + "latency_p99_upper_ns": 13631488, + "latency_max_ns": 16520028, + "active_byte_seconds": 1026043.651851, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "pressure", + "repeat": 2, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 124401411, + "cpu_ns": 111783663, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 108, + "slot_waits": 0, + "sleep_ns": 12978960, + "latency_mean_ns": 7175143.561, + "latency_p99_upper_ns": 11534336, + "latency_max_ns": 11871096, + "active_byte_seconds": 962716.975355, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "borrow", + "repeat": 2, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 140192626, + "cpu_ns": 129302907, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 32, + "slot_waits": 0, + "sleep_ns": 11304553, + "latency_mean_ns": 8151791.4, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 11985985, + "active_byte_seconds": 1094054.601176, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold4", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 127500625, + "cpu_ns": 109051339, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 86, + "slot_waits": 0, + "sleep_ns": 15655621, + "latency_mean_ns": 7370372.812, + "latency_p99_upper_ns": 13631488, + "latency_max_ns": 13648518, + "active_byte_seconds": 988934.033123, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "copy", + "repeat": 3, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 125, + "rss_peak_bytes": 28753920, + "elapsed_ns": 139629443, + "cpu_ns": 112148433, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 100663296, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 126, + "reuses": 3970, + "budget_waits": 1923, + "slot_waits": 0, + "sleep_ns": 28146396, + "latency_mean_ns": 7999954.838, + "latency_p99_upper_ns": 16777216, + "latency_max_ns": 16468658, + "active_byte_seconds": 1074362.142096, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold8", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 129397045, + "cpu_ns": 108222327, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 210, + "slot_waits": 0, + "sleep_ns": 19281611, + "latency_mean_ns": 7449478.358, + "latency_p99_upper_ns": 13631488, + "latency_max_ns": 13544240, + "active_byte_seconds": 999089.777214, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "copy_no_pool", + "repeat": 3, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 125, + "rss_peak_bytes": 28753920, + "elapsed_ns": 125060409, + "cpu_ns": 101408203, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 100663296, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 1720, + "slot_waits": 0, + "sleep_ns": 24842157, + "latency_mean_ns": 7224036.272, + "latency_p99_upper_ns": 11534336, + "latency_max_ns": 11678097, + "active_byte_seconds": 970120.753206, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold2", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 121944973, + "cpu_ns": 98926473, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 410, + "slot_waits": 0, + "sleep_ns": 24262193, + "latency_mean_ns": 7027416.376, + "latency_p99_upper_ns": 11534336, + "latency_max_ns": 12229040, + "active_byte_seconds": 941745.792822, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "project", + "repeat": 3, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 140664495, + "cpu_ns": 101124724, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 716, + "slot_waits": 0, + "sleep_ns": 41804911, + "latency_mean_ns": 8134234.887, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 13075389, + "active_byte_seconds": 1088709.015188, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "pressure", + "repeat": 3, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 121667696, + "cpu_ns": 101165480, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 330, + "slot_waits": 0, + "sleep_ns": 21242064, + "latency_mean_ns": 7047783.954, + "latency_p99_upper_ns": 11534336, + "latency_max_ns": 11408672, + "active_byte_seconds": 944768.902586, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "borrow", + "repeat": 3, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 122887693, + "cpu_ns": 108048811, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 100, + "slot_waits": 0, + "sleep_ns": 15309844, + "latency_mean_ns": 6960585.889, + "latency_p99_upper_ns": 14680064, + "latency_max_ns": 14962365, + "active_byte_seconds": 933965.439249, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold8", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 127832493, + "cpu_ns": 107011535, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 312, + "slot_waits": 0, + "sleep_ns": 21568032, + "latency_mean_ns": 7387611.189, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 12693631, + "active_byte_seconds": 990437.837956, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "copy", + "repeat": 4, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 125, + "rss_peak_bytes": 28753920, + "elapsed_ns": 132323981, + "cpu_ns": 104579167, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 100663296, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 126, + "reuses": 3970, + "budget_waits": 1868, + "slot_waits": 0, + "sleep_ns": 28280826, + "latency_mean_ns": 7629563.252, + "latency_p99_upper_ns": 11534336, + "latency_max_ns": 12006726, + "active_byte_seconds": 1024670.67878, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold4", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 117467153, + "cpu_ns": 100913544, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 211, + "slot_waits": 0, + "sleep_ns": 17302742, + "latency_mean_ns": 6773721.904, + "latency_p99_upper_ns": 11534336, + "latency_max_ns": 11750486, + "active_byte_seconds": 908428.389283, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "project", + "repeat": 4, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 177547354, + "cpu_ns": 98087776, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 1077, + "slot_waits": 0, + "sleep_ns": 66269238, + "latency_mean_ns": 10478829.253, + "latency_p99_upper_ns": 27262976, + "latency_max_ns": 26359796, + "active_byte_seconds": 1401395.334755, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "copy_no_pool", + "repeat": 4, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 125, + "rss_peak_bytes": 28753920, + "elapsed_ns": 127352551, + "cpu_ns": 95896509, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 100663296, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 1854, + "slot_waits": 0, + "sleep_ns": 33140024, + "latency_mean_ns": 7371263.893, + "latency_p99_upper_ns": 11534336, + "latency_max_ns": 11482598, + "active_byte_seconds": 989890.745684, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "borrow", + "repeat": 4, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 156176896, + "cpu_ns": 135527318, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 8, + "slot_waits": 0, + "sleep_ns": 19302646, + "latency_mean_ns": 8983882.317, + "latency_p99_upper_ns": 23068672, + "latency_max_ns": 21705495, + "active_byte_seconds": 1205798.201258, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "threshold2", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 150967021, + "cpu_ns": 112103512, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 343, + "slot_waits": 0, + "sleep_ns": 27798231, + "latency_mean_ns": 8607200.207, + "latency_p99_upper_ns": 14680064, + "latency_max_ns": 15553678, + "active_byte_seconds": 1153842.867633, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "dense_slow", + "variant": "pressure", + "repeat": 4, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8350112, + "peak_active_bytes": 8350112, + "peak_queue": 126, + "rss_peak_bytes": 28753920, + "elapsed_ns": 131031651, + "cpu_ns": 108678412, + "input_bytes": 134242304, + "output_bytes": 100671488, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 126, + "reuses": 1922, + "budget_waits": 194, + "slot_waits": 0, + "sleep_ns": 17318187, + "latency_mean_ns": 7550902.647, + "latency_p99_upper_ns": 12582912, + "latency_max_ns": 12787335, + "active_byte_seconds": 1012712.39438, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1048832, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "copy_no_pool", + "repeat": 0, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388432, + "peak_active_bytes": 8388432, + "peak_queue": 349, + "rss_peak_bytes": 28753920, + "elapsed_ns": 196227931, + "cpu_ns": 90207409, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 899, + "slot_waits": 0, + "sleep_ns": 106212702, + "latency_mean_ns": 25497204.119, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 38861965, + "active_byte_seconds": 1403800.480768, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold4", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388608, + "peak_active_bytes": 8388608, + "peak_queue": 282, + "rss_peak_bytes": 28753920, + "elapsed_ns": 182099749, + "cpu_ns": 86444975, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 11229392, + "copied_records": 1357, + "borrowed_records": 691, + "pressure_copies": 0, + "allocations": 1834, + "reuses": 1571, + "budget_waits": 951, + "slot_waits": 0, + "sleep_ns": 99448742, + "latency_mean_ns": 18702737.958, + "latency_p99_upper_ns": 27262976, + "latency_max_ns": 26735888, + "active_byte_seconds": 1347766.35285, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1153216, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "pressure", + "repeat": 0, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388480, + "peak_active_bytes": 8388432, + "peak_queue": 345, + "rss_peak_bytes": 28753920, + "elapsed_ns": 170729984, + "cpu_ns": 95177478, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 27916032, + "copied_records": 1699, + "borrowed_records": 349, + "pressure_copies": 1699, + "allocations": 1996, + "reuses": 1751, + "budget_waits": 848, + "slot_waits": 0, + "sleep_ns": 79228418, + "latency_mean_ns": 22318118.532, + "latency_p99_upper_ns": 33554432, + "latency_max_ns": 33636461, + "active_byte_seconds": 1237184.456112, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 522496, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold2", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388560, + "peak_active_bytes": 8388432, + "peak_queue": 344, + "rss_peak_bytes": 28753920, + "elapsed_ns": 248649117, + "cpu_ns": 108815021, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28479696, + "copied_records": 1740, + "borrowed_records": 308, + "pressure_copies": 0, + "allocations": 1911, + "reuses": 1877, + "budget_waits": 806, + "slot_waits": 0, + "sleep_ns": 141754620, + "latency_mean_ns": 32835308.438, + "latency_p99_upper_ns": 50331648, + "latency_max_ns": 52109020, + "active_byte_seconds": 1817663.170181, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 519424, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "copy", + "repeat": 0, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388576, + "peak_active_bytes": 8388432, + "peak_queue": 343, + "rss_peak_bytes": 28753920, + "elapsed_ns": 188497435, + "cpu_ns": 95408242, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2001, + "reuses": 2095, + "budget_waits": 825, + "slot_waits": 0, + "sleep_ns": 93045012, + "latency_mean_ns": 24119999.997, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 36830878, + "active_byte_seconds": 1331578.296683, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 519424, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "borrow", + "repeat": 0, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8386736, + "peak_active_bytes": 8386640, + "peak_queue": 112, + "rss_peak_bytes": 28753920, + "elapsed_ns": 202207266, + "cpu_ns": 112741417, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1260, + "reuses": 788, + "budget_waits": 922, + "slot_waits": 0, + "sleep_ns": 93158576, + "latency_mean_ns": 9030450.097, + "latency_p99_upper_ns": 15728640, + "latency_max_ns": 16897915, + "active_byte_seconds": 1584952.748115, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 667904, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "project", + "repeat": 0, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388608, + "peak_active_bytes": 8388544, + "peak_queue": 358, + "rss_peak_bytes": 28753920, + "elapsed_ns": 196788319, + "cpu_ns": 85794578, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1594, + "reuses": 454, + "budget_waits": 835, + "slot_waits": 0, + "sleep_ns": 111694672, + "latency_mean_ns": 25911259.331, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 39632482, + "active_byte_seconds": 1386620.278442, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 458688, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold8", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388608, + "peak_active_bytes": 8388432, + "peak_queue": 216, + "rss_peak_bytes": 28753920, + "elapsed_ns": 177004559, + "cpu_ns": 88488220, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 3824848, + "copied_records": 1008, + "borrowed_records": 1040, + "pressure_copies": 0, + "allocations": 1769, + "reuses": 1287, + "budget_waits": 956, + "slot_waits": 0, + "sleep_ns": 91999803, + "latency_mean_ns": 13961564.399, + "latency_p99_upper_ns": 20971520, + "latency_max_ns": 20644424, + "active_byte_seconds": 1308343.909911, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1250624, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "copy_no_pool", + "repeat": 1, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388432, + "peak_active_bytes": 8388432, + "peak_queue": 349, + "rss_peak_bytes": 28753920, + "elapsed_ns": 209526727, + "cpu_ns": 99009959, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 852, + "slot_waits": 0, + "sleep_ns": 113158134, + "latency_mean_ns": 27706362.205, + "latency_p99_upper_ns": 50331648, + "latency_max_ns": 49857323, + "active_byte_seconds": 1504182.816335, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold8", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388608, + "peak_active_bytes": 8388432, + "peak_queue": 216, + "rss_peak_bytes": 28753920, + "elapsed_ns": 178695721, + "cpu_ns": 88024506, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 3824848, + "copied_records": 1008, + "borrowed_records": 1040, + "pressure_copies": 0, + "allocations": 1752, + "reuses": 1304, + "budget_waits": 957, + "slot_waits": 0, + "sleep_ns": 93665641, + "latency_mean_ns": 14283495.48, + "latency_p99_upper_ns": 25165824, + "latency_max_ns": 25314392, + "active_byte_seconds": 1350685.597943, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1250624, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "project", + "repeat": 1, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388608, + "peak_active_bytes": 8388544, + "peak_queue": 358, + "rss_peak_bytes": 28753920, + "elapsed_ns": 188062454, + "cpu_ns": 85805781, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1613, + "reuses": 435, + "budget_waits": 876, + "slot_waits": 0, + "sleep_ns": 106943146, + "latency_mean_ns": 25106963.876, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 40388905, + "active_byte_seconds": 1338315.607594, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 463808, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "pressure", + "repeat": 1, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388560, + "peak_active_bytes": 8388432, + "peak_queue": 349, + "rss_peak_bytes": 28753920, + "elapsed_ns": 180476475, + "cpu_ns": 82814346, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 27916032, + "copied_records": 1699, + "borrowed_records": 349, + "pressure_copies": 1699, + "allocations": 2034, + "reuses": 1713, + "budget_waits": 906, + "slot_waits": 0, + "sleep_ns": 101386971, + "latency_mean_ns": 23117968.235, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 34624643, + "active_byte_seconds": 1287754.655314, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 522496, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "copy", + "repeat": 1, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388576, + "peak_active_bytes": 8388432, + "peak_queue": 345, + "rss_peak_bytes": 28753920, + "elapsed_ns": 179916143, + "cpu_ns": 88224841, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2035, + "reuses": 2061, + "budget_waits": 868, + "slot_waits": 0, + "sleep_ns": 95038979, + "latency_mean_ns": 23134688.68, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 38482948, + "active_byte_seconds": 1259295.778761, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 519424, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold2", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388560, + "peak_active_bytes": 8388432, + "peak_queue": 345, + "rss_peak_bytes": 28753920, + "elapsed_ns": 172458424, + "cpu_ns": 95876297, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28479696, + "copied_records": 1740, + "borrowed_records": 308, + "pressure_copies": 0, + "allocations": 1950, + "reuses": 1838, + "budget_waits": 838, + "slot_waits": 0, + "sleep_ns": 80637955, + "latency_mean_ns": 22201893.822, + "latency_p99_upper_ns": 29360128, + "latency_max_ns": 29750009, + "active_byte_seconds": 1218383.798869, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 522496, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "borrow", + "repeat": 1, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8386736, + "peak_active_bytes": 8386688, + "peak_queue": 112, + "rss_peak_bytes": 28753920, + "elapsed_ns": 202718412, + "cpu_ns": 105879101, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1270, + "reuses": 778, + "budget_waits": 933, + "slot_waits": 0, + "sleep_ns": 101496664, + "latency_mean_ns": 8968645.74, + "latency_p99_upper_ns": 15728640, + "latency_max_ns": 15509271, + "active_byte_seconds": 1593585.502544, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 667904, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold4", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388608, + "peak_active_bytes": 8388608, + "peak_queue": 268, + "rss_peak_bytes": 28753920, + "elapsed_ns": 178050667, + "cpu_ns": 95042355, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 11229392, + "copied_records": 1357, + "borrowed_records": 691, + "pressure_copies": 0, + "allocations": 1767, + "reuses": 1638, + "budget_waits": 919, + "slot_waits": 0, + "sleep_ns": 87305079, + "latency_mean_ns": 17737601.933, + "latency_p99_upper_ns": 27262976, + "latency_max_ns": 26498834, + "active_byte_seconds": 1276748.071158, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1154176, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "copy", + "repeat": 2, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388560, + "peak_active_bytes": 8388432, + "peak_queue": 343, + "rss_peak_bytes": 28753920, + "elapsed_ns": 166505070, + "cpu_ns": 87773371, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2029, + "reuses": 2067, + "budget_waits": 855, + "slot_waits": 0, + "sleep_ns": 82039937, + "latency_mean_ns": 21365903.831, + "latency_p99_upper_ns": 31457280, + "latency_max_ns": 30499822, + "active_byte_seconds": 1169734.902412, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 522496, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "project", + "repeat": 2, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388576, + "peak_active_bytes": 8388576, + "peak_queue": 358, + "rss_peak_bytes": 28753920, + "elapsed_ns": 184834889, + "cpu_ns": 77869217, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1654, + "reuses": 394, + "budget_waits": 900, + "slot_waits": 0, + "sleep_ns": 108638540, + "latency_mean_ns": 24466594.426, + "latency_p99_upper_ns": 46137344, + "latency_max_ns": 45971408, + "active_byte_seconds": 1295645.073976, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 458688, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold2", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388432, + "peak_active_bytes": 8388432, + "peak_queue": 346, + "rss_peak_bytes": 28753920, + "elapsed_ns": 191170037, + "cpu_ns": 94174606, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28479696, + "copied_records": 1740, + "borrowed_records": 308, + "pressure_copies": 0, + "allocations": 1933, + "reuses": 1855, + "budget_waits": 839, + "slot_waits": 0, + "sleep_ns": 99297240, + "latency_mean_ns": 24916604.797, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37194081, + "active_byte_seconds": 1364006.158543, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 519424, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold4", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388608, + "peak_active_bytes": 8388608, + "peak_queue": 267, + "rss_peak_bytes": 28753920, + "elapsed_ns": 221114880, + "cpu_ns": 108320175, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 11229392, + "copied_records": 1357, + "borrowed_records": 691, + "pressure_copies": 0, + "allocations": 1725, + "reuses": 1680, + "budget_waits": 867, + "slot_waits": 0, + "sleep_ns": 112272606, + "latency_mean_ns": 22302398.136, + "latency_p99_upper_ns": 31457280, + "latency_max_ns": 31418968, + "active_byte_seconds": 1620151.723755, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1153216, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "pressure", + "repeat": 2, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388560, + "peak_active_bytes": 8388432, + "peak_queue": 343, + "rss_peak_bytes": 28753920, + "elapsed_ns": 200423808, + "cpu_ns": 95868665, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 27916032, + "copied_records": 1699, + "borrowed_records": 349, + "pressure_copies": 1699, + "allocations": 1950, + "reuses": 1797, + "budget_waits": 826, + "slot_waits": 0, + "sleep_ns": 104684245, + "latency_mean_ns": 26149827.952, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37286562, + "active_byte_seconds": 1462564.435239, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 519424, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "copy_no_pool", + "repeat": 2, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388432, + "peak_active_bytes": 8388432, + "peak_queue": 348, + "rss_peak_bytes": 28753920, + "elapsed_ns": 185563183, + "cpu_ns": 99669005, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 824, + "slot_waits": 0, + "sleep_ns": 88520259, + "latency_mean_ns": 24158310.672, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 37578913, + "active_byte_seconds": 1315287.672243, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold8", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388576, + "peak_active_bytes": 8388352, + "peak_queue": 216, + "rss_peak_bytes": 28753920, + "elapsed_ns": 285706068, + "cpu_ns": 123773735, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 3824848, + "copied_records": 1008, + "borrowed_records": 1040, + "pressure_copies": 0, + "allocations": 1639, + "reuses": 1417, + "budget_waits": 811, + "slot_waits": 0, + "sleep_ns": 151915315, + "latency_mean_ns": 22809999.729, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 39308704, + "active_byte_seconds": 2141933.275175, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1250624, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "borrow", + "repeat": 2, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8386736, + "peak_active_bytes": 8386640, + "peak_queue": 112, + "rss_peak_bytes": 28753920, + "elapsed_ns": 277725554, + "cpu_ns": 130508378, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1246, + "reuses": 802, + "budget_waits": 882, + "slot_waits": 0, + "sleep_ns": 145190817, + "latency_mean_ns": 12364716.181, + "latency_p99_upper_ns": 25165824, + "latency_max_ns": 24717468, + "active_byte_seconds": 2188978.814479, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 667904, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "project", + "repeat": 3, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388576, + "peak_active_bytes": 8388544, + "peak_queue": 350, + "rss_peak_bytes": 28753920, + "elapsed_ns": 266408067, + "cpu_ns": 111663429, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1498, + "reuses": 550, + "budget_waits": 732, + "slot_waits": 0, + "sleep_ns": 138942208, + "latency_mean_ns": 34638344.422, + "latency_p99_upper_ns": 54525952, + "latency_max_ns": 52949259, + "active_byte_seconds": 1878408.17389, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 458688, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold2", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388560, + "peak_active_bytes": 8388432, + "peak_queue": 341, + "rss_peak_bytes": 28753920, + "elapsed_ns": 204623815, + "cpu_ns": 104506177, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28479696, + "copied_records": 1740, + "borrowed_records": 308, + "pressure_copies": 0, + "allocations": 1822, + "reuses": 1966, + "budget_waits": 758, + "slot_waits": 0, + "sleep_ns": 97171540, + "latency_mean_ns": 25691162.972, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 40286443, + "active_byte_seconds": 1429280.943963, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 522496, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold4", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388608, + "peak_active_bytes": 8388608, + "peak_queue": 277, + "rss_peak_bytes": 28753920, + "elapsed_ns": 162195656, + "cpu_ns": 80564634, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 11229392, + "copied_records": 1357, + "borrowed_records": 691, + "pressure_copies": 0, + "allocations": 1810, + "reuses": 1595, + "budget_waits": 983, + "slot_waits": 0, + "sleep_ns": 84519072, + "latency_mean_ns": 16670151.746, + "latency_p99_upper_ns": 23068672, + "latency_max_ns": 21537625, + "active_byte_seconds": 1200241.584576, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1153216, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "copy", + "repeat": 3, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388560, + "peak_active_bytes": 8388432, + "peak_queue": 350, + "rss_peak_bytes": 28753920, + "elapsed_ns": 155808970, + "cpu_ns": 73686530, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2181, + "reuses": 1915, + "budget_waits": 970, + "slot_waits": 0, + "sleep_ns": 84997837, + "latency_mean_ns": 20210703.898, + "latency_p99_upper_ns": 29360128, + "latency_max_ns": 29034418, + "active_byte_seconds": 1105823.092919, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 522496, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "copy_no_pool", + "repeat": 3, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388432, + "peak_active_bytes": 8388432, + "peak_queue": 343, + "rss_peak_bytes": 28753920, + "elapsed_ns": 175012120, + "cpu_ns": 86574113, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 847, + "slot_waits": 0, + "sleep_ns": 86153992, + "latency_mean_ns": 21577383.531, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 35170512, + "active_byte_seconds": 1189109.090661, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "borrow", + "repeat": 3, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8386736, + "peak_active_bytes": 8386640, + "peak_queue": 112, + "rss_peak_bytes": 28753920, + "elapsed_ns": 192464571, + "cpu_ns": 109214745, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1270, + "reuses": 778, + "budget_waits": 921, + "slot_waits": 0, + "sleep_ns": 85288420, + "latency_mean_ns": 8548822.691, + "latency_p99_upper_ns": 13631488, + "latency_max_ns": 14178942, + "active_byte_seconds": 1513389.1547, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 667904, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold8", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388496, + "peak_active_bytes": 8388432, + "peak_queue": 216, + "rss_peak_bytes": 28753920, + "elapsed_ns": 180744548, + "cpu_ns": 92447570, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 3824848, + "copied_records": 1008, + "borrowed_records": 1040, + "pressure_copies": 0, + "allocations": 1772, + "reuses": 1284, + "budget_waits": 987, + "slot_waits": 0, + "sleep_ns": 91033265, + "latency_mean_ns": 14634490.266, + "latency_p99_upper_ns": 20971520, + "latency_max_ns": 21334847, + "active_byte_seconds": 1375000.84592, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1250624, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "pressure", + "repeat": 3, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388480, + "peak_active_bytes": 8388432, + "peak_queue": 347, + "rss_peak_bytes": 28753920, + "elapsed_ns": 190539057, + "cpu_ns": 89751173, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 27916032, + "copied_records": 1699, + "borrowed_records": 349, + "pressure_copies": 1699, + "allocations": 1983, + "reuses": 1764, + "budget_waits": 862, + "slot_waits": 0, + "sleep_ns": 102577548, + "latency_mean_ns": 24120880.139, + "latency_p99_upper_ns": 46137344, + "latency_max_ns": 43388027, + "active_byte_seconds": 1333423.649457, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 519424, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "copy", + "repeat": 4, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388432, + "peak_active_bytes": 8388432, + "peak_queue": 339, + "rss_peak_bytes": 28753920, + "elapsed_ns": 221349934, + "cpu_ns": 109576369, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1871, + "reuses": 2225, + "budget_waits": 733, + "slot_waits": 0, + "sleep_ns": 114046592, + "latency_mean_ns": 28163326.597, + "latency_p99_upper_ns": 46137344, + "latency_max_ns": 46133518, + "active_byte_seconds": 1540447.287587, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 519424, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "project", + "repeat": 4, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388576, + "peak_active_bytes": 8388544, + "peak_queue": 351, + "rss_peak_bytes": 28753920, + "elapsed_ns": 182031656, + "cpu_ns": 81559603, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1543, + "reuses": 505, + "budget_waits": 829, + "slot_waits": 0, + "sleep_ns": 98044537, + "latency_mean_ns": 23787174.92, + "latency_p99_upper_ns": 33554432, + "latency_max_ns": 33075333, + "active_byte_seconds": 1288001.912824, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 458688, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold8", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388608, + "peak_active_bytes": 8388432, + "peak_queue": 216, + "rss_peak_bytes": 28753920, + "elapsed_ns": 190119929, + "cpu_ns": 98659849, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 3824848, + "copied_records": 1008, + "borrowed_records": 1040, + "pressure_copies": 0, + "allocations": 1748, + "reuses": 1308, + "budget_waits": 937, + "slot_waits": 0, + "sleep_ns": 91519644, + "latency_mean_ns": 15332315.134, + "latency_p99_upper_ns": 27262976, + "latency_max_ns": 28453087, + "active_byte_seconds": 1432190.421467, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1262912, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "copy_no_pool", + "repeat": 4, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388432, + "peak_active_bytes": 8388432, + "peak_queue": 348, + "rss_peak_bytes": 28753920, + "elapsed_ns": 181246528, + "cpu_ns": 87821814, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 854, + "slot_waits": 0, + "sleep_ns": 96465580, + "latency_mean_ns": 23009953.597, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 35350753, + "active_byte_seconds": 1263667.037898, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold4", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388608, + "peak_active_bytes": 8388608, + "peak_queue": 268, + "rss_peak_bytes": 28753920, + "elapsed_ns": 202902060, + "cpu_ns": 94178139, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 11229392, + "copied_records": 1357, + "borrowed_records": 691, + "pressure_copies": 0, + "allocations": 1778, + "reuses": 1627, + "budget_waits": 948, + "slot_waits": 0, + "sleep_ns": 111627333, + "latency_mean_ns": 20292318.825, + "latency_p99_upper_ns": 41943040, + "latency_max_ns": 42672491, + "active_byte_seconds": 1456891.057432, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 1153216, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "borrow", + "repeat": 4, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8386736, + "peak_active_bytes": 8386640, + "peak_queue": 112, + "rss_peak_bytes": 28753920, + "elapsed_ns": 187355085, + "cpu_ns": 105102970, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1268, + "reuses": 780, + "budget_waits": 942, + "slot_waits": 0, + "sleep_ns": 86194520, + "latency_mean_ns": 8306217.014, + "latency_p99_upper_ns": 16777216, + "latency_max_ns": 16560027, + "active_byte_seconds": 1467132.987688, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 667904, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "threshold2", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388560, + "peak_active_bytes": 8388432, + "peak_queue": 349, + "rss_peak_bytes": 28753920, + "elapsed_ns": 185932830, + "cpu_ns": 88442274, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28479696, + "copied_records": 1740, + "borrowed_records": 308, + "pressure_copies": 0, + "allocations": 1998, + "reuses": 1790, + "budget_waits": 873, + "slot_waits": 0, + "sleep_ns": 100159229, + "latency_mean_ns": 24415772.17, + "latency_p99_upper_ns": 37748736, + "latency_max_ns": 35463160, + "active_byte_seconds": 1333943.667435, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 519424, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_slow", + "variant": "pressure", + "repeat": 4, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 8388560, + "peak_active_bytes": 8388432, + "peak_queue": 351, + "rss_peak_bytes": 28753920, + "elapsed_ns": 175115990, + "cpu_ns": 85590028, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 27916032, + "copied_records": 1699, + "borrowed_records": 349, + "pressure_copies": 1699, + "allocations": 2029, + "reuses": 1718, + "budget_waits": 897, + "slot_waits": 0, + "sleep_ns": 90980114, + "latency_mean_ns": 22901875.606, + "latency_p99_upper_ns": 31457280, + "latency_max_ns": 30636340, + "active_byte_seconds": 1271349.314418, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 519424, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "pressure", + "repeat": 0, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097152, + "peak_active_bytes": 2097136, + "peak_queue": 106, + "rss_peak_bytes": 28753920, + "elapsed_ns": 194998211, + "cpu_ns": 80964449, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28385168, + "copied_records": 1727, + "borrowed_records": 321, + "pressure_copies": 1727, + "allocations": 2265, + "reuses": 1510, + "budget_waits": 1251, + "slot_waits": 0, + "sleep_ns": 117554960, + "latency_mean_ns": 6209271.27, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 9610047, + "active_byte_seconds": 352937.551048, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "project", + "repeat": 0, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097120, + "peak_active_bytes": 2097120, + "peak_queue": 118, + "rss_peak_bytes": 28753920, + "elapsed_ns": 191006927, + "cpu_ns": 80024226, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1659, + "reuses": 389, + "budget_waits": 1164, + "slot_waits": 0, + "sleep_ns": 113283506, + "latency_mean_ns": 6749781.49, + "latency_p99_upper_ns": 10485760, + "latency_max_ns": 10754747, + "active_byte_seconds": 354343.266259, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 406848, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold8", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097120, + "peak_active_bytes": 2097120, + "peak_queue": 72, + "rss_peak_bytes": 28753920, + "elapsed_ns": 315263040, + "cpu_ns": 90750328, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 3824848, + "copied_records": 1008, + "borrowed_records": 1040, + "pressure_copies": 0, + "allocations": 1890, + "reuses": 1166, + "budget_waits": 1248, + "slot_waits": 0, + "sleep_ns": 228816753, + "latency_mean_ns": 6291155.426, + "latency_p99_upper_ns": 13631488, + "latency_max_ns": 13216574, + "active_byte_seconds": 579371.042178, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 386176, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "copy_no_pool", + "repeat": 0, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 116, + "rss_peak_bytes": 28753920, + "elapsed_ns": 215534802, + "cpu_ns": 92135979, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 1179, + "slot_waits": 0, + "sleep_ns": 127073694, + "latency_mean_ns": 6714221.641, + "latency_p99_upper_ns": 10485760, + "latency_max_ns": 12545668, + "active_byte_seconds": 387556.898349, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold4", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097104, + "peak_queue": 91, + "rss_peak_bytes": 28753920, + "elapsed_ns": 240539157, + "cpu_ns": 82888986, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 11229392, + "copied_records": 1357, + "borrowed_records": 691, + "pressure_copies": 0, + "allocations": 2037, + "reuses": 1368, + "budget_waits": 1333, + "slot_waits": 0, + "sleep_ns": 157978818, + "latency_mean_ns": 6115847.212, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 11204691, + "active_byte_seconds": 437508.612236, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 435392, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "copy", + "repeat": 0, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 111, + "rss_peak_bytes": 28753920, + "elapsed_ns": 205803459, + "cpu_ns": 87522857, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2361, + "reuses": 1735, + "budget_waits": 1210, + "slot_waits": 0, + "sleep_ns": 121961836, + "latency_mean_ns": 6356735.332, + "latency_p99_upper_ns": 11534336, + "latency_max_ns": 12149188, + "active_byte_seconds": 363428.263552, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold2", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 103, + "rss_peak_bytes": 28753920, + "elapsed_ns": 218109869, + "cpu_ns": 94383237, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28479696, + "copied_records": 1740, + "borrowed_records": 308, + "pressure_copies": 0, + "allocations": 2188, + "reuses": 1600, + "budget_waits": 1166, + "slot_waits": 0, + "sleep_ns": 128480946, + "latency_mean_ns": 7013746.965, + "latency_p99_upper_ns": 14680064, + "latency_max_ns": 15108236, + "active_byte_seconds": 394831.364885, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "borrow", + "repeat": 0, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2094128, + "peak_active_bytes": 2094032, + "peak_queue": 40, + "rss_peak_bytes": 28753920, + "elapsed_ns": 544543692, + "cpu_ns": 90900399, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1332, + "reuses": 716, + "budget_waits": 1286, + "slot_waits": 0, + "sleep_ns": 453134113, + "latency_mean_ns": 6077465.417, + "latency_p99_upper_ns": 11534336, + "latency_max_ns": 12176243, + "active_byte_seconds": 1028555.825239, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 495872, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "copy", + "repeat": 1, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 117, + "rss_peak_bytes": 28753920, + "elapsed_ns": 191836517, + "cpu_ns": 62332245, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2460, + "reuses": 1636, + "budget_waits": 1362, + "slot_waits": 0, + "sleep_ns": 131898458, + "latency_mean_ns": 6069082.115, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8770216, + "active_byte_seconds": 346911.480275, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold2", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 117, + "rss_peak_bytes": 28753920, + "elapsed_ns": 188885136, + "cpu_ns": 63904326, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28479696, + "copied_records": 1740, + "borrowed_records": 308, + "pressure_copies": 0, + "allocations": 2356, + "reuses": 1432, + "budget_waits": 1390, + "slot_waits": 0, + "sleep_ns": 127844964, + "latency_mean_ns": 6121880.805, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8708698, + "active_byte_seconds": 342822.067006, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "borrow", + "repeat": 1, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2094128, + "peak_active_bytes": 2094128, + "peak_queue": 40, + "rss_peak_bytes": 28753920, + "elapsed_ns": 492789763, + "cpu_ns": 76140523, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1347, + "reuses": 701, + "budget_waits": 1406, + "slot_waits": 0, + "sleep_ns": 420428963, + "latency_mean_ns": 5485700.477, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 9955175, + "active_byte_seconds": 928718.610429, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 495872, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold8", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 72, + "rss_peak_bytes": 28753920, + "elapsed_ns": 282084485, + "cpu_ns": 66066433, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 3824848, + "copied_records": 1008, + "borrowed_records": 1040, + "pressure_copies": 0, + "allocations": 1992, + "reuses": 1064, + "budget_waits": 1398, + "slot_waits": 0, + "sleep_ns": 219096863, + "latency_mean_ns": 5671193.431, + "latency_p99_upper_ns": 7340032, + "latency_max_ns": 9274955, + "active_byte_seconds": 520410.956771, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 386176, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold4", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097104, + "peak_queue": 88, + "rss_peak_bytes": 28753920, + "elapsed_ns": 224500368, + "cpu_ns": 61534673, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 11229392, + "copied_records": 1357, + "borrowed_records": 691, + "pressure_copies": 0, + "allocations": 2145, + "reuses": 1260, + "budget_waits": 1465, + "slot_waits": 0, + "sleep_ns": 165914339, + "latency_mean_ns": 5837746.733, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 10210564, + "active_byte_seconds": 412262.960044, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 435392, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "pressure", + "repeat": 1, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 115, + "rss_peak_bytes": 28753920, + "elapsed_ns": 189684559, + "cpu_ns": 60774942, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28385168, + "copied_records": 1727, + "borrowed_records": 321, + "pressure_copies": 1727, + "allocations": 2383, + "reuses": 1392, + "budget_waits": 1399, + "slot_waits": 0, + "sleep_ns": 131755127, + "latency_mean_ns": 6110993.322, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 9608714, + "active_byte_seconds": 345607.344111, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "copy_no_pool", + "repeat": 1, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 117, + "rss_peak_bytes": 28753920, + "elapsed_ns": 190441538, + "cpu_ns": 59274120, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 1383, + "slot_waits": 0, + "sleep_ns": 133844636, + "latency_mean_ns": 6031707.432, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8881216, + "active_byte_seconds": 344699.365648, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "project", + "repeat": 1, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097120, + "peak_active_bytes": 2097120, + "peak_queue": 118, + "rss_peak_bytes": 28753920, + "elapsed_ns": 175373266, + "cpu_ns": 57346839, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1727, + "reuses": 321, + "budget_waits": 1312, + "slot_waits": 0, + "sleep_ns": 120854151, + "latency_mean_ns": 6287663.374, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8829253, + "active_byte_seconds": 326669.995028, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 406848, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "copy_no_pool", + "repeat": 2, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 115, + "rss_peak_bytes": 28753920, + "elapsed_ns": 190230224, + "cpu_ns": 58883103, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 1379, + "slot_waits": 0, + "sleep_ns": 133923360, + "latency_mean_ns": 6020977.936, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8904123, + "active_byte_seconds": 344486.353015, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "project", + "repeat": 2, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097120, + "peak_active_bytes": 2097120, + "peak_queue": 118, + "rss_peak_bytes": 28753920, + "elapsed_ns": 176712466, + "cpu_ns": 57142470, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1727, + "reuses": 321, + "budget_waits": 1308, + "slot_waits": 0, + "sleep_ns": 122435178, + "latency_mean_ns": 6344282.023, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 9173733, + "active_byte_seconds": 329327.109037, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 406848, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "copy", + "repeat": 2, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097152, + "peak_active_bytes": 2097136, + "peak_queue": 115, + "rss_peak_bytes": 28753920, + "elapsed_ns": 192640551, + "cpu_ns": 62036091, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2463, + "reuses": 1633, + "budget_waits": 1367, + "slot_waits": 0, + "sleep_ns": 133360267, + "latency_mean_ns": 6075663.601, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8830642, + "active_byte_seconds": 347845.920578, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold8", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 73, + "rss_peak_bytes": 28753920, + "elapsed_ns": 284454034, + "cpu_ns": 68644342, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 3824848, + "copied_records": 1008, + "borrowed_records": 1040, + "pressure_copies": 0, + "allocations": 1983, + "reuses": 1073, + "budget_waits": 1386, + "slot_waits": 0, + "sleep_ns": 218577789, + "latency_mean_ns": 5702048.39, + "latency_p99_upper_ns": 7340032, + "latency_max_ns": 9254474, + "active_byte_seconds": 523314.413618, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 386176, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold4", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097104, + "peak_queue": 88, + "rss_peak_bytes": 28753920, + "elapsed_ns": 226008956, + "cpu_ns": 64169718, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 11229392, + "copied_records": 1357, + "borrowed_records": 691, + "pressure_copies": 0, + "allocations": 2125, + "reuses": 1280, + "budget_waits": 1458, + "slot_waits": 0, + "sleep_ns": 164889565, + "latency_mean_ns": 5866464.096, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 10318805, + "active_byte_seconds": 414911.228869, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 435392, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "borrow", + "repeat": 2, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2094128, + "peak_active_bytes": 2094128, + "peak_queue": 40, + "rss_peak_bytes": 28753920, + "elapsed_ns": 494360387, + "cpu_ns": 73512176, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1345, + "reuses": 703, + "budget_waits": 1395, + "slot_waits": 0, + "sleep_ns": 424305645, + "latency_mean_ns": 5500812.732, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 9972009, + "active_byte_seconds": 932412.777581, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 495872, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold2", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 115, + "rss_peak_bytes": 28753920, + "elapsed_ns": 188224878, + "cpu_ns": 60744558, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28479696, + "copied_records": 1740, + "borrowed_records": 308, + "pressure_copies": 0, + "allocations": 2384, + "reuses": 1404, + "budget_waits": 1411, + "slot_waits": 0, + "sleep_ns": 130279846, + "latency_mean_ns": 6114092.392, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8874864, + "active_byte_seconds": 342235.388035, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "pressure", + "repeat": 2, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 115, + "rss_peak_bytes": 28753920, + "elapsed_ns": 189816540, + "cpu_ns": 60109883, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28385168, + "copied_records": 1727, + "borrowed_records": 321, + "pressure_copies": 1727, + "allocations": 2377, + "reuses": 1398, + "budget_waits": 1401, + "slot_waits": 0, + "sleep_ns": 132388467, + "latency_mean_ns": 6115537.712, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 9634918, + "active_byte_seconds": 345575.615482, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "pressure", + "repeat": 3, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 115, + "rss_peak_bytes": 28753920, + "elapsed_ns": 190593723, + "cpu_ns": 62104383, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28385168, + "copied_records": 1727, + "borrowed_records": 321, + "pressure_copies": 1727, + "allocations": 2377, + "reuses": 1398, + "budget_waits": 1387, + "slot_waits": 0, + "sleep_ns": 131246281, + "latency_mean_ns": 6133228.412, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 9617713, + "active_byte_seconds": 346774.138471, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "borrow", + "repeat": 3, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2094128, + "peak_active_bytes": 2094128, + "peak_queue": 40, + "rss_peak_bytes": 28753920, + "elapsed_ns": 491528840, + "cpu_ns": 70906509, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1353, + "reuses": 695, + "budget_waits": 1421, + "slot_waits": 0, + "sleep_ns": 423844868, + "latency_mean_ns": 5472000.565, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 9945028, + "active_byte_seconds": 926418.118409, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 495872, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "copy_no_pool", + "repeat": 3, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 116, + "rss_peak_bytes": 28753920, + "elapsed_ns": 190661223, + "cpu_ns": 60180004, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 1376, + "slot_waits": 0, + "sleep_ns": 133160918, + "latency_mean_ns": 6036141.159, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8916068, + "active_byte_seconds": 345094.680154, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold2", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 116, + "rss_peak_bytes": 28753920, + "elapsed_ns": 193175809, + "cpu_ns": 69008296, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28479696, + "copied_records": 1740, + "borrowed_records": 308, + "pressure_copies": 0, + "allocations": 2336, + "reuses": 1452, + "budget_waits": 1351, + "slot_waits": 0, + "sleep_ns": 125127054, + "latency_mean_ns": 6239198.13, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 9276566, + "active_byte_seconds": 350903.059901, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold8", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097120, + "peak_active_bytes": 2097120, + "peak_queue": 73, + "rss_peak_bytes": 28753920, + "elapsed_ns": 286766304, + "cpu_ns": 73096130, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 3824848, + "copied_records": 1008, + "borrowed_records": 1040, + "pressure_copies": 0, + "allocations": 1974, + "reuses": 1082, + "budget_waits": 1367, + "slot_waits": 0, + "sleep_ns": 215532386, + "latency_mean_ns": 5744366.208, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 8864197, + "active_byte_seconds": 528100.049771, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 386176, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold4", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097104, + "peak_queue": 88, + "rss_peak_bytes": 28753920, + "elapsed_ns": 225938124, + "cpu_ns": 65488664, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 11229392, + "copied_records": 1357, + "borrowed_records": 691, + "pressure_copies": 0, + "allocations": 2121, + "reuses": 1284, + "budget_waits": 1445, + "slot_waits": 0, + "sleep_ns": 163452164, + "latency_mean_ns": 5856203.824, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 10380804, + "active_byte_seconds": 414648.202609, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 435392, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "copy", + "repeat": 3, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097152, + "peak_active_bytes": 2097136, + "peak_queue": 108, + "rss_peak_bytes": 28753920, + "elapsed_ns": 191114147, + "cpu_ns": 63369902, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2453, + "reuses": 1643, + "budget_waits": 1341, + "slot_waits": 0, + "sleep_ns": 130459979, + "latency_mean_ns": 6032302.559, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8833531, + "active_byte_seconds": 345755.184019, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "project", + "repeat": 3, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097120, + "peak_active_bytes": 2097120, + "peak_queue": 118, + "rss_peak_bytes": 28753920, + "elapsed_ns": 177942277, + "cpu_ns": 63483663, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1711, + "reuses": 337, + "budget_waits": 1279, + "slot_waits": 0, + "sleep_ns": 117556310, + "latency_mean_ns": 6348716.251, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8883105, + "active_byte_seconds": 331194.459386, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 406848, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "copy", + "repeat": 4, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097152, + "peak_active_bytes": 2097136, + "peak_queue": 117, + "rss_peak_bytes": 28753920, + "elapsed_ns": 191747145, + "cpu_ns": 60306782, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2470, + "reuses": 1626, + "budget_waits": 1379, + "slot_waits": 0, + "sleep_ns": 134097654, + "latency_mean_ns": 6065392.323, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8895161, + "active_byte_seconds": 347142.858576, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold2", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 115, + "rss_peak_bytes": 28753920, + "elapsed_ns": 187864582, + "cpu_ns": 60112693, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28479696, + "copied_records": 1740, + "borrowed_records": 308, + "pressure_copies": 0, + "allocations": 2380, + "reuses": 1408, + "budget_waits": 1409, + "slot_waits": 0, + "sleep_ns": 130504092, + "latency_mean_ns": 6102214.292, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8884715, + "active_byte_seconds": 341567.414808, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "project", + "repeat": 4, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097120, + "peak_active_bytes": 2097120, + "peak_queue": 118, + "rss_peak_bytes": 28753920, + "elapsed_ns": 175293210, + "cpu_ns": 56768485, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1722, + "reuses": 326, + "budget_waits": 1313, + "slot_waits": 0, + "sleep_ns": 121359184, + "latency_mean_ns": 6283898.527, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8849623, + "active_byte_seconds": 326483.546647, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 406848, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold8", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 73, + "rss_peak_bytes": 28753920, + "elapsed_ns": 283727960, + "cpu_ns": 68131361, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 3824848, + "copied_records": 1008, + "borrowed_records": 1040, + "pressure_copies": 0, + "allocations": 1988, + "reuses": 1068, + "budget_waits": 1394, + "slot_waits": 0, + "sleep_ns": 218912386, + "latency_mean_ns": 5707951.51, + "latency_p99_upper_ns": 7340032, + "latency_max_ns": 9272677, + "active_byte_seconds": 523909.294385, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 386176, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "borrow", + "repeat": 4, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2094128, + "peak_active_bytes": 2094128, + "peak_queue": 40, + "rss_peak_bytes": 28753920, + "elapsed_ns": 495666215, + "cpu_ns": 81002646, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1336, + "reuses": 712, + "budget_waits": 1382, + "slot_waits": 0, + "sleep_ns": 418460319, + "latency_mean_ns": 5519510.972, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 9930268, + "active_byte_seconds": 935139.458784, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 495872, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "copy_no_pool", + "repeat": 4, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 116, + "rss_peak_bytes": 28753920, + "elapsed_ns": 190841888, + "cpu_ns": 60356559, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 53727440, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 1382, + "slot_waits": 0, + "sleep_ns": 133224289, + "latency_mean_ns": 6038284.196, + "latency_p99_upper_ns": 8388608, + "latency_max_ns": 8947753, + "active_byte_seconds": 345496.101548, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "threshold4", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097104, + "peak_queue": 88, + "rss_peak_bytes": 28753920, + "elapsed_ns": 226098419, + "cpu_ns": 63538828, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 11229392, + "copied_records": 1357, + "borrowed_records": 691, + "pressure_copies": 0, + "allocations": 2129, + "reuses": 1276, + "budget_waits": 1452, + "slot_waits": 0, + "sleep_ns": 165691682, + "latency_mean_ns": 5878789.657, + "latency_p99_upper_ns": 7864320, + "latency_max_ns": 10264360, + "active_byte_seconds": 415107.899759, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 435392, + "unreleased_buffer_bytes": 0 + }, + { + "case": "mixed_tight", + "variant": "pressure", + "repeat": 4, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 2097152, + "fixed_bytes": 90560, + "peak_reserved_bytes": 2097136, + "peak_active_bytes": 2097136, + "peak_queue": 115, + "rss_peak_bytes": 28753920, + "elapsed_ns": 192204126, + "cpu_ns": 62496629, + "input_bytes": 177631232, + "output_bytes": 53735632, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 28385168, + "copied_records": 1727, + "borrowed_records": 321, + "pressure_copies": 1727, + "allocations": 2367, + "reuses": 1408, + "budget_waits": 1381, + "slot_waits": 0, + "sleep_ns": 132616450, + "latency_mean_ns": 6161110.138, + "latency_p99_upper_ns": 9437184, + "latency_max_ns": 9782879, + "active_byte_seconds": 349554.881495, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 523712, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "pressure", + "repeat": 0, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156112, + "peak_active_bytes": 156112, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 20554720, + "cpu_ns": 20527722, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9881.978, + "latency_p99_upper_ns": 13312, + "latency_max_ns": 60759, + "active_byte_seconds": 1273.955005, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65552, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "project", + "repeat": 0, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 90640, + "peak_active_bytes": 90640, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 22216122, + "cpu_ns": 22101834, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10698.669, + "latency_p99_upper_ns": 16384, + "latency_max_ns": 58241, + "active_byte_seconds": 1.68633, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 80, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold4", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 22839176, + "cpu_ns": 22457056, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10958.209, + "latency_p99_upper_ns": 20480, + "latency_max_ns": 165851, + "active_byte_seconds": 1227.172318, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "copy", + "repeat": 0, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 21009107, + "cpu_ns": 20955370, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10112.231, + "latency_p99_upper_ns": 14336, + "latency_max_ns": 66129, + "active_byte_seconds": 1120.781895, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "copy_no_pool", + "repeat": 0, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 21132162, + "cpu_ns": 21048817, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10163.675, + "latency_p99_upper_ns": 16384, + "latency_max_ns": 68685, + "active_byte_seconds": 1121.783606, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold8", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 20540535, + "cpu_ns": 20499501, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9884.486, + "latency_p99_upper_ns": 13312, + "latency_max_ns": 54093, + "active_byte_seconds": 1100.863361, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "borrow", + "repeat": 0, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156112, + "peak_active_bytes": 156112, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 21727605, + "cpu_ns": 21682906, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10449.435, + "latency_p99_upper_ns": 20480, + "latency_max_ns": 65999, + "active_byte_seconds": 1348.749968, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65552, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold2", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 22373067, + "cpu_ns": 22308741, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10776.724, + "latency_p99_upper_ns": 18432, + "latency_max_ns": 66703, + "active_byte_seconds": 1207.809872, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "project", + "repeat": 1, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 90640, + "peak_active_bytes": 90640, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 25768428, + "cpu_ns": 25607575, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 12427.336, + "latency_p99_upper_ns": 22528, + "latency_max_ns": 135518, + "active_byte_seconds": 1.971383, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 80, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold8", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 22601085, + "cpu_ns": 22218814, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10886.611, + "latency_p99_upper_ns": 28672, + "latency_max_ns": 70518, + "active_byte_seconds": 1220.513584, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "copy_no_pool", + "repeat": 1, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 22194827, + "cpu_ns": 21633689, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10673.54, + "latency_p99_upper_ns": 36864, + "latency_max_ns": 207444, + "active_byte_seconds": 1178.059751, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "pressure", + "repeat": 1, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156112, + "peak_active_bytes": 156112, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 23241749, + "cpu_ns": 23003312, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 11135.177, + "latency_p99_upper_ns": 22528, + "latency_max_ns": 79185, + "active_byte_seconds": 1441.524009, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65552, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "copy", + "repeat": 1, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 24103618, + "cpu_ns": 23832019, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 11617.114, + "latency_p99_upper_ns": 22528, + "latency_max_ns": 88389, + "active_byte_seconds": 1310.460688, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold2", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 21191681, + "cpu_ns": 21131537, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10199.927, + "latency_p99_upper_ns": 14336, + "latency_max_ns": 68426, + "active_byte_seconds": 1132.085862, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold4", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 21871975, + "cpu_ns": 21613127, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10530.066, + "latency_p99_upper_ns": 18432, + "latency_max_ns": 78704, + "active_byte_seconds": 1171.334175, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "borrow", + "repeat": 1, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156112, + "peak_active_bytes": 156112, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 21555643, + "cpu_ns": 21467723, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10366.948, + "latency_p99_upper_ns": 18432, + "latency_max_ns": 62648, + "active_byte_seconds": 1339.691796, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65552, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "borrow", + "repeat": 2, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156112, + "peak_active_bytes": 156112, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 20704016, + "cpu_ns": 20633572, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9954.482, + "latency_p99_upper_ns": 14336, + "latency_max_ns": 84963, + "active_byte_seconds": 1283.092823, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65552, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold2", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 20854404, + "cpu_ns": 20822149, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10030.324, + "latency_p99_upper_ns": 14336, + "latency_max_ns": 62445, + "active_byte_seconds": 1108.309428, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "copy_no_pool", + "repeat": 2, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 21286218, + "cpu_ns": 21228201, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10237.021, + "latency_p99_upper_ns": 15360, + "latency_max_ns": 67889, + "active_byte_seconds": 1129.223222, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "project", + "repeat": 2, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 90640, + "peak_active_bytes": 90640, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 22649251, + "cpu_ns": 22567445, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10910.76, + "latency_p99_upper_ns": 15360, + "latency_max_ns": 61499, + "active_byte_seconds": 1.717551, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 80, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "pressure", + "repeat": 2, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156112, + "peak_active_bytes": 156112, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 20767942, + "cpu_ns": 20708872, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9985.038, + "latency_p99_upper_ns": 15360, + "latency_max_ns": 65425, + "active_byte_seconds": 1286.595987, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65552, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "copy", + "repeat": 2, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 21065681, + "cpu_ns": 21006279, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10139.793, + "latency_p99_upper_ns": 15360, + "latency_max_ns": 67018, + "active_byte_seconds": 1124.320165, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold4", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 20961885, + "cpu_ns": 20931648, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10087.398, + "latency_p99_upper_ns": 13312, + "latency_max_ns": 60962, + "active_byte_seconds": 1117.500277, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold8", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 20908700, + "cpu_ns": 20878832, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10062.625, + "latency_p99_upper_ns": 14336, + "latency_max_ns": 70648, + "active_byte_seconds": 1116.46627, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold2", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 21328570, + "cpu_ns": 21275351, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10266.949, + "latency_p99_upper_ns": 15360, + "latency_max_ns": 61241, + "active_byte_seconds": 1144.526904, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "borrow", + "repeat": 3, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156112, + "peak_active_bytes": 156112, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 20408294, + "cpu_ns": 20408999, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9812.079, + "latency_p99_upper_ns": 13312, + "latency_max_ns": 48982, + "active_byte_seconds": 1265.057763, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65552, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "copy", + "repeat": 3, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 20744256, + "cpu_ns": 20744722, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 9979.793, + "latency_p99_upper_ns": 13312, + "latency_max_ns": 42518, + "active_byte_seconds": 1107.901257, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "project", + "repeat": 3, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 90640, + "peak_active_bytes": 90640, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 21766957, + "cpu_ns": 21732111, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10483.601, + "latency_p99_upper_ns": 13312, + "latency_max_ns": 74593, + "active_byte_seconds": 1.653919, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 80, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold4", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 23474730, + "cpu_ns": 23418353, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 11311.146, + "latency_p99_upper_ns": 24576, + "latency_max_ns": 72445, + "active_byte_seconds": 1275.148887, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold8", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 25891223, + "cpu_ns": 25855036, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 12490.423, + "latency_p99_upper_ns": 32768, + "latency_max_ns": 62019, + "active_byte_seconds": 1433.084986, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "pressure", + "repeat": 3, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156112, + "peak_active_bytes": 156112, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 25124448, + "cpu_ns": 24854663, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 12097.683, + "latency_p99_upper_ns": 24576, + "latency_max_ns": 83351, + "active_byte_seconds": 1569.932052, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65552, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "copy_no_pool", + "repeat": 3, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 21725958, + "cpu_ns": 21582704, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10452.028, + "latency_p99_upper_ns": 16384, + "latency_max_ns": 197777, + "active_byte_seconds": 1159.292471, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "project", + "repeat": 4, + "status": "ok", + "policy": "project", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 90640, + "peak_active_bytes": 90640, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 22202622, + "cpu_ns": 22202889, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 10695.292, + "latency_p99_upper_ns": 18432, + "latency_max_ns": 48444, + "active_byte_seconds": 1.688434, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 80, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold2", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 27294793, + "cpu_ns": 27138353, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 13171.363, + "latency_p99_upper_ns": 28672, + "latency_max_ns": 78185, + "active_byte_seconds": 1515.562825, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold8", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 33207148, + "cpu_ns": 33180296, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 16048.501, + "latency_p99_upper_ns": 36864, + "latency_max_ns": 74648, + "active_byte_seconds": 1873.802277, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "copy", + "repeat": 4, + "status": "ok", + "policy": "copy", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 40643311, + "cpu_ns": 40589351, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 19667.254, + "latency_p99_upper_ns": 49152, + "latency_max_ns": 147388, + "active_byte_seconds": 2334.403772, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "threshold4", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 28395383, + "cpu_ns": 28350296, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 2, + "reuses": 4094, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 13707.471, + "latency_p99_upper_ns": 26624, + "latency_max_ns": 87370, + "active_byte_seconds": 1583.182193, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65632, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "borrow", + "repeat": 4, + "status": "ok", + "policy": "borrow", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156112, + "peak_active_bytes": 156112, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 25754576, + "cpu_ns": 25674260, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 12408.192, + "latency_p99_upper_ns": 20480, + "latency_max_ns": 98925, + "active_byte_seconds": 1611.048102, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65552, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "pressure", + "repeat": 4, + "status": "ok", + "policy": "pressure", + "pool": true, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156112, + "peak_active_bytes": 156112, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 28270087, + "cpu_ns": 28259741, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 0, + "copied_records": 0, + "borrowed_records": 2048, + "pressure_copies": 0, + "allocations": 1, + "reuses": 2047, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 13635.652, + "latency_p99_upper_ns": 20480, + "latency_max_ns": 75407, + "active_byte_seconds": 1772.014643, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 65552, + "unreleased_buffer_bytes": 0 + }, + { + "case": "sparse_fast", + "variant": "copy_no_pool", + "repeat": 4, + "status": "ok", + "policy": "copy", + "pool": false, + "budget_bytes": 8388608, + "fixed_bytes": 90560, + "peak_reserved_bytes": 156192, + "peak_active_bytes": 156192, + "peak_queue": 1, + "rss_peak_bytes": 28753920, + "elapsed_ns": 30675302, + "cpu_ns": 30605147, + "input_bytes": 134242304, + "output_bytes": 139264, + "accepted": 2048, + "emitted": 2048, + "copy_bytes": 131072, + "copied_records": 2048, + "borrowed_records": 0, + "pressure_copies": 0, + "allocations": 4096, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 0, + "sleep_ns": 0, + "latency_mean_ns": 14792.559, + "latency_p99_upper_ns": 22528, + "latency_max_ns": 144222, + "active_byte_seconds": 1690.623657, + "live_at_stop_bytes": 0, + "cached_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0 + } +] diff --git a/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/sources/benchmark.c b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/sources/benchmark.c new file mode 100644 index 0000000..496ad5e --- /dev/null +++ b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/sources/benchmark.c @@ -0,0 +1,320 @@ +#define _POSIX_C_SOURCE 200809L +#include <assert.h> +#include <errno.h> +#include <inttypes.h> +#include <limits.h> +#include <signal.h> +#include <stdbool.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/resource.h> +#include <time.h> +#include <unistd.h> + +/* A measurement apparatus, not the Pure runtime or a general document parser. */ +enum { CACHE_SLOTS = 16, SCRATCH = 65536, HIST_SIZE = 512, MAX_FRAME = 8*1024*1024 }; +typedef struct Block { size_t capacity; uint64_t since; unsigned char bytes[]; } Block; +typedef struct Item { + Block *block; + size_t offset, length; + uint64_t start, ready; +} Item; +typedef struct Engine { + Item *queue; + Block *cache[CACHE_SLOTS]; + unsigned char scratch[SCRATCH]; + uint64_t histogram[HIST_SIZE]; + size_t slots, head, count, fixed, budget, reserved, active, cached; + size_t peak_reserved, peak_active, peak_queue; + uint64_t allocations, reuses, copies, read_bytes, written_bytes; + uint64_t accepted, emitted, copied_records, borrowed_records, pressure_copies; + uint64_t budget_waits, slot_waits, sleep_ns, hold_ns, service_ns, last_emit; + uint64_t elapsed_ns, cpu_ns, latency_sum, latency_max, start, cancel_after; + long double active_byte_ns; + unsigned ratio; + bool pool; + const char *policy, *status; +} Engine; +static volatile sig_atomic_t interrupted; +static void stop(int sig) { (void)sig; interrupted = 1; } +static uint64_t ns(clockid_t clock) { + struct timespec t; + if (clock_gettime(clock, &t)) { perror("clock_gettime"); exit(2); } + return (uint64_t)t.tv_sec * UINT64_C(1000000000) + (uint64_t)t.tv_nsec; +} +static size_t charge(const Block *b) { return sizeof(*b) + b->capacity; } +static size_t rounded(size_t n) { + size_t r = 64; + while (r < n) r *= 2; + return r; +} +static void peaks(Engine *e) { + assert(e->active + e->cached == e->reserved); + assert(e->fixed + e->reserved <= e->budget); + if (e->reserved > e->peak_reserved) e->peak_reserved = e->reserved; + if (e->active > e->peak_active) e->peak_active = e->active; +} +static void evict(Engine *e, size_t i) { + Block *b = e->cache[i]; + if (!b) return; + e->cached -= charge(b); e->reserved -= charge(b); + free(b); e->cache[i] = NULL; +} +static Block *take(Engine *e, size_t n) { + size_t capacity = rounded(n), need = sizeof(Block) + capacity; + if (e->pool) { + for (size_t i = 0; i < CACHE_SLOTS; ++i) { + Block *b = e->cache[i]; + if (b && b->capacity == capacity) { + e->cache[i] = NULL; e->cached -= need; e->active += need; + ++e->reuses; b->since = ns(CLOCK_MONOTONIC); peaks(e); return b; + } + } + } + for (size_t i = 0; i < CACHE_SLOTS && need > e->budget-e->fixed-e->reserved; ++i) + evict(e, i); + if (need > e->budget-e->fixed-e->reserved) return NULL; + Block *b = malloc(need); + if (!b) { e->status = "allocation_failed"; return NULL; } + b->capacity = capacity; b->since = ns(CLOCK_MONOTONIC); + e->reserved += need; e->active += need; ++e->allocations; peaks(e); return b; +} +static void give(Engine *e, Block *b) { + if (!b) return; + size_t bytes = charge(b); + e->active_byte_ns += (long double)bytes * (ns(CLOCK_MONOTONIC)-b->since); + e->active -= bytes; + if (e->pool && bytes <= e->budget/4-e->cached) { + for (size_t i = 0; i < CACHE_SLOTS; ++i) if (!e->cache[i]) { + e->cache[i] = b; e->cached += bytes; peaks(e); return; + } + } + e->reserved -= bytes; free(b); peaks(e); +} +static bool sleep_until(Engine *e, uint64_t deadline) { + uint64_t t = ns(CLOCK_MONOTONIC), start = t; + while (t < deadline && !interrupted) { + uint64_t delta = deadline-t; + struct timespec request = {(time_t)(delta/1000000000), (long)(delta%1000000000)}; + if (nanosleep(&request, NULL) && errno != EINTR) { e->status="sleep_failed"; return false; } + t = ns(CLOCK_MONOTONIC); + } + e->sleep_ns += t-start; + return !interrupted; +} +/* floor(log2(ns)) with eight subdivisions: upper bound error <= 12.5%. */ +static unsigned bucket(uint64_t n) { + unsigned exponent = 0; + for (uint64_t x = n; x > 1; x >>= 1) ++exponent; + if (exponent < 3) return (unsigned)n; + return exponent*8 + (unsigned)((n-(UINT64_C(1)<<exponent))>>(exponent-3)); +} +static uint64_t upper(unsigned b) { + if (b < 24) return b+1; + unsigned exponent = b/8; + if (exponent >= 63) return UINT64_MAX; + return (UINT64_C(1)<<exponent) + (uint64_t)(b%8+1)*(UINT64_C(1)<<(exponent-3)); +} +static bool write_all(Engine *e, const void *src, size_t n) { + const unsigned char *p = src; + while (n && !interrupted) { + ssize_t written = write(STDOUT_FILENO, p, n); + if (written < 0 && errno == EINTR) continue; + if (written <= 0) { e->status = "output_failed"; return false; } + p += written; n -= (size_t)written; e->written_bytes += (uint64_t)written; + } + return !interrupted; +} +static bool emit(Engine *e) { + assert(e->count); + Item *item = &e->queue[e->head]; + uint64_t ready = item->ready; + if (e->last_emit + e->service_ns > ready) ready = e->last_emit + e->service_ns; + if (!sleep_until(e, ready)) return false; + uint32_t len = (uint32_t)item->length; + unsigned char header[4] = {(unsigned char)len, (unsigned char)(len>>8), + (unsigned char)(len>>16), (unsigned char)(len>>24)}; + if (!write_all(e, header, sizeof header) || + !write_all(e, item->block->bytes+item->offset, item->length)) return false; + uint64_t now = ns(CLOCK_MONOTONIC), latency = now-item->start; + ++e->histogram[bucket(latency)]; e->latency_sum += latency; + if (latency > e->latency_max) e->latency_max = latency; + e->last_emit = now; ++e->emitted; + give(e, item->block); item->block = NULL; + e->head = (e->head+1)%e->slots; --e->count; + if (e->cancel_after && e->emitted >= e->cancel_after) { + e->status = "cancelled"; return false; + } + return true; +} +static Block *acquire(Engine *e, size_t n) { + for (;;) { + Block *b = take(e, n); + if (b) return b; + if (strcmp(e->status, "ok")) return NULL; + if (!e->count) { e->status = "budget_too_small"; return NULL; } + ++e->budget_waits; + if (!emit(e)) return NULL; + } +} +/* Returns 1 on complete read, 0 on clean EOF before any byte, -1 on failure. */ +static int read_exact(Engine *e, void *dst, size_t n) { + unsigned char *p = dst; size_t done = 0; + while (done < n && !interrupted) { + ssize_t got = read(STDIN_FILENO, p+done, n-done); + if (got < 0 && errno == EINTR) continue; + if (got < 0) { e->status="input_failed"; return -1; } + if (!got) { if (!done) return 0; e->status="truncated_input"; return -1; } + done += (size_t)got; e->read_bytes += (uint64_t)got; + } + return interrupted ? -1 : 1; +} +static bool discard(Engine *e, size_t n) { + while (n) { + size_t chunk = n < SCRATCH ? n : SCRATCH; + if (read_exact(e, e->scratch, chunk) != 1) { + if (!strcmp(e->status,"ok")) e->status="truncated_input"; + return false; + } + n -= chunk; + } + return true; +} +static uint32_t le32(const unsigned char *p) { + return (uint32_t)p[0] | (uint32_t)p[1]<<8 | (uint32_t)p[2]<<16 | (uint32_t)p[3]<<24; +} +static void run(Engine *e) { + for (;;) { + if (interrupted) break; + if (e->count) { + Item *head = &e->queue[e->head]; + uint64_t now = ns(CLOCK_MONOTONIC); + if (now >= head->ready && now >= e->last_emit+e->service_ns) { + if (!emit(e)) break; + continue; + } + } + if (e->count == e->slots) { ++e->slot_waits; if (!emit(e)) break; } + unsigned char header[12]; + uint64_t start = ns(CLOCK_MONOTONIC); + int got = read_exact(e, header, sizeof header); + if (got != 1) { + if (!got) while (e->count && !interrupted) if (!emit(e)) break; + break; + } + size_t payload = le32(header), offset = le32(header+4), length = le32(header+8); + if (!payload || payload > MAX_FRAME || !length || offset > payload || length > payload-offset) { + e->status="invalid_frame"; break; + } + bool project = !strcmp(e->policy,"project"); + Block *source = acquire(e, project ? length : payload); + if (!source) break; + bool valid; + if (project) { + valid = discard(e, offset) && read_exact(e, source->bytes, length)==1 && + discard(e, payload-offset-length); + offset = 0; + } else valid = read_exact(e, source->bytes, payload)==1; + if (!valid) { + if (!strcmp(e->status,"ok")) e->status="truncated_input"; + give(e, source); break; + } + bool copy = !strcmp(e->policy,"copy") || + (!strcmp(e->policy,"threshold") && rounded(payload)/rounded(length) >= e->ratio); + if (!strcmp(e->policy,"pressure")) { + /* Online rule using current charged live buffers; no future lifetime. */ + copy = rounded(length) < source->capacity && + e->active > (e->budget-e->fixed)/2; + if (copy) ++e->pressure_copies; + } + if (!project && copy) { + Block *small = acquire(e, length); + if (!small) { give(e, source); break; } + memcpy(small->bytes, source->bytes+offset, length); + e->copies += length; ++e->copied_records; + give(e, source); source = small; offset = 0; + } else if (!project) ++e->borrowed_records; + size_t tail = (e->head+e->count)%e->slots; + e->queue[tail] = (Item){source, offset, length, start, ns(CLOCK_MONOTONIC)+e->hold_ns}; + ++e->count; ++e->accepted; + if (e->count > e->peak_queue) e->peak_queue=e->count; + } + if (interrupted) e->status="cancelled"; +} +static uint64_t number(const char *s, uint64_t maximum) { + char *end; errno=0; + unsigned long long n = strtoull(s, &end, 10); + if (!*s || *s=='-' || *end || errno || n>maximum) { fprintf(stderr,"invalid number\n"); exit(2); } + return n; +} +int main(int argc, char **argv) { + Engine *e = calloc(1, sizeof *e); + if (!e) return 2; + e->policy="borrow"; e->status="ok"; e->budget=8*1024*1024; e->slots=512; + e->ratio=4; e->pool=true; + for (int i=1; i<argc; i+=2) { + if (i+1==argc) { fprintf(stderr,"options require values\n"); free(e); return 2; } + const char *key=argv[i], *value=argv[i+1]; + if (!strcmp(key,"--policy")) e->policy=value; + else if (!strcmp(key,"--budget")) e->budget=(size_t)number(value,1073741824); + else if (!strcmp(key,"--slots")) e->slots=(size_t)number(value,4096); + else if (!strcmp(key,"--hold-us")) e->hold_ns=number(value,10000000)*1000; + else if (!strcmp(key,"--service-us")) e->service_ns=number(value,10000000)*1000; + else if (!strcmp(key,"--ratio")) e->ratio=(unsigned)number(value,UINT_MAX); + else if (!strcmp(key,"--pool")) e->pool=number(value,1)!=0; + else if (!strcmp(key,"--cancel-after")) e->cancel_after=number(value,UINT64_MAX); + else { fprintf(stderr,"unknown option\n"); free(e); return 2; } + } + bool known = !strcmp(e->policy,"borrow") || !strcmp(e->policy,"copy") || + !strcmp(e->policy,"threshold") || !strcmp(e->policy,"pressure") || !strcmp(e->policy,"project"); + if (!known || !e->slots || e->slots>4096 || e->ratio<2 || e->budget>UINT64_C(1073741824) || + e->hold_ns>UINT64_C(10000000000) || e->service_ns>UINT64_C(10000000000)) { + fprintf(stderr,"invalid configuration\n"); free(e); return 2; + } + e->fixed=sizeof(*e)+e->slots*sizeof(Item); + if (e->budget < e->fixed) { fprintf(stderr,"budget below fixed metadata\n"); free(e); return 2; } + e->queue=calloc(e->slots,sizeof(Item)); + if (!e->queue) { free(e); return 2; } + signal(SIGINT,stop); signal(SIGTERM,stop); signal(SIGPIPE,SIG_IGN); + e->start=ns(CLOCK_MONOTONIC); uint64_t cpu=ns(CLOCK_PROCESS_CPUTIME_ID); + run(e); + size_t live_at_stop=e->active, cached_at_stop=e->cached; + while (e->count) { + give(e,e->queue[e->head].block); e->head=(e->head+1)%e->slots; --e->count; + } + for (size_t i=0;i<CACHE_SLOTS;++i) evict(e,i); + assert(!e->active && !e->reserved && !e->cached); + e->elapsed_ns=ns(CLOCK_MONOTONIC)-e->start; e->cpu_ns=ns(CLOCK_PROCESS_CPUTIME_ID)-cpu; + uint64_t target=e->emitted-e->emitted/100, sum=0, p99=0; + for (unsigned b=0; e->emitted && b<HIST_SIZE; ++b) { + sum+=e->histogram[b]; if (sum>=target) { p99=upper(b); break; } + } + struct rusage usage; long rss=0; + if (!getrusage(RUSAGE_SELF,&usage)) rss=usage.ru_maxrss; +#if defined(__APPLE__) + uint64_t rss_bytes=(uint64_t)rss; +#else + uint64_t rss_bytes=(uint64_t)rss*1024; +#endif + fprintf(stderr,"{\"status\":\"%s\",\"policy\":\"%s\",\"pool\":%s," + "\"budget_bytes\":%zu,\"fixed_bytes\":%zu,\"peak_reserved_bytes\":%zu," + "\"peak_active_bytes\":%zu,\"peak_queue\":%zu,\"rss_peak_bytes\":%" PRIu64 "," + "\"elapsed_ns\":%" PRIu64 ",\"cpu_ns\":%" PRIu64 ",\"input_bytes\":%" PRIu64 "," + "\"output_bytes\":%" PRIu64 ",\"accepted\":%" PRIu64 ",\"emitted\":%" PRIu64 "," + "\"copy_bytes\":%" PRIu64 ",\"copied_records\":%" PRIu64 ",\"borrowed_records\":%" PRIu64 "," + "\"pressure_copies\":%" PRIu64 ",\"allocations\":%" PRIu64 ",\"reuses\":%" PRIu64 "," + "\"budget_waits\":%" PRIu64 ",\"slot_waits\":%" PRIu64 ",\"sleep_ns\":%" PRIu64 "," + "\"latency_mean_ns\":%.3f,\"latency_p99_upper_ns\":%" PRIu64 ",\"latency_max_ns\":%" PRIu64 "," + "\"active_byte_seconds\":%.6Lf,\"live_at_stop_bytes\":%zu,\"cached_at_stop_bytes\":%zu," + "\"unreleased_buffer_bytes\":%zu}\n", + e->status,e->policy,e->pool?"true":"false",e->budget,e->fixed,e->fixed+e->peak_reserved, + e->fixed+e->peak_active,e->peak_queue,rss_bytes,e->elapsed_ns,e->cpu_ns,e->read_bytes, + e->written_bytes,e->accepted,e->emitted,e->copies,e->copied_records,e->borrowed_records, + e->pressure_copies,e->allocations,e->reuses,e->budget_waits,e->slot_waits,e->sleep_ns, + e->emitted?(double)e->latency_sum/(double)e->emitted:0,p99,e->latency_max, + e->active_byte_ns/1e9L,live_at_stop,cached_at_stop,e->reserved); + int result=!strcmp(e->status,"ok")?0:!strcmp(e->status,"cancelled")?3:2; + free(e->queue); free(e); return result; +} diff --git a/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/sources/plan.json b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/sources/plan.json new file mode 100644 index 0000000..5040006 --- /dev/null +++ b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/sources/plan.json @@ -0,0 +1,33 @@ +{ + "version": 1, + "written_before_measurement": true, + "seed": 20260922, + "repeats": 5, + "slots": 512, + "policies": [ + {"name": "borrow", "policy": "borrow", "pool": 1}, + {"name": "copy", "policy": "copy", "pool": 1}, + {"name": "threshold2", "policy": "threshold", "ratio": 2, "pool": 1}, + {"name": "threshold4", "policy": "threshold", "ratio": 4, "pool": 1}, + {"name": "threshold8", "policy": "threshold", "ratio": 8, "pool": 1}, + {"name": "pressure", "policy": "pressure", "pool": 1}, + {"name": "project", "policy": "project", "pool": 1}, + {"name": "copy_no_pool", "policy": "copy", "pool": 0} + ], + "cases": [ + {"name": "sparse_slow", "shape": "sparse", "records": 2048, "budget": 8388608, "hold_us": 5000, "service_us": 20}, + {"name": "dense_slow", "shape": "dense", "records": 2048, "budget": 8388608, "hold_us": 5000, "service_us": 20}, + {"name": "mixed_slow", "shape": "mixed", "records": 2048, "budget": 8388608, "hold_us": 5000, "service_us": 20}, + {"name": "mixed_tight", "shape": "mixed", "records": 2048, "budget": 2097152, "hold_us": 5000, "service_us": 20}, + {"name": "sparse_fast", "shape": "sparse", "records": 2048, "budget": 8388608, "hold_us": 0, "service_us": 0} + ], + "expectations": [ + "Borrow retains full source allocations for small selections.", + "Copy can add CPU and transient source plus destination memory for dense selections.", + "A current-pressure rule need not outperform a static size rule or early projection.", + "Pool reuse can reduce allocation calls while increasing reserved idle memory.", + "No Pure-specific advantage, application SLO, or statistical significance is presumed." + ], + "comparison_rule": "Report all presets and repetitions; no post-hoc winner is called an out-of-sample tuned policy.", + "limits": "Single FIFO local pipeline with synthetic delayed sink. No Sonic/Node/.NET benchmark, fan-out, persistent cache, generic JSON parser, external open-loop arrivals, or production SLO." +} diff --git a/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/sources/run.py b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/sources/run.py new file mode 100644 index 0000000..94657cc --- /dev/null +++ b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/sources/run.py @@ -0,0 +1,281 @@ +#!/usr/bin/env python3 +"""Build, independently verify, and measure the retention experiment.""" +import argparse +import csv +import hashlib +import json +import os +from pathlib import Path +import platform +import random +import shlex +import signal +import statistics +import struct +import subprocess +import tempfile +import time + +ROOT = Path(__file__).resolve().parent +FLAGS = ["-std=c17", "-Wall", "-Wextra", "-Wpedantic", "-Werror", "-O2", "-g"] + + +def digest(path): + with open(path, "rb") as stream: + return hashlib.file_digest(stream, "sha256").hexdigest() + + +def dump(path, value): + path.write_text(json.dumps(value, indent=2, ensure_ascii=False) + "\n") + + +def build(cc, output, sanitizer=False): + command = [*cc, *FLAGS] + if sanitizer: + command += ["-fsanitize=address,undefined", "-fno-omit-frame-pointer"] + command += [str(ROOT / "benchmark.c"), "-o", str(output)] + result = subprocess.run(command, capture_output=True, text=True, check=True) + return {"command": command, "stderr": result.stderr, "sha256": digest(output), + "size_bytes": output.stat().st_size} + + +def shape_for(shape, rng, i): + if shape == "sparse": + return 65536, 64 + if shape == "dense": + return 65536, 49152 + if shape == "mixed": + source = rng.choice([4096, 16384, 65536, 262144]) + keep = max(16, source // rng.choice([1, 2, 4, 8, 64, 1024])) + return source, keep + if shape == "test": + return [(1, 1), (63, 17), (4097, 12), (65536, 49152), (127, 127)][i % 5] + raise ValueError(shape) + + +def fixture(path, shape, count, seed): + rng = random.Random(seed) + expected = hashlib.sha256() + total = 0 + with path.open("wb") as stream: + for i in range(count): + size, keep = shape_for(shape, rng, i) + offset = rng.randrange(size - keep + 1) + # All input bytes exist on disk; no sparse files or seeking past data. + tile = rng.randbytes(256) + payload = (tile * ((size + 255) // 256))[:size] + stream.write(struct.pack("<III", size, offset, keep)) + stream.write(payload) + out = struct.pack("<I", keep) + payload[offset:offset + keep] + expected.update(out) + total += len(out) + return {"path": path.name, "shape": shape, "records": count, "seed": seed, + "input_bytes": path.stat().st_size, "input_sha256": digest(path), + "expected_output_bytes": total, "expected_output_sha256": expected.hexdigest()} + + +def reference(data): + result = bytearray() + at = 0 + while at < len(data): + if len(data) - at < 12: + raise ValueError("short header") + size, offset, keep = struct.unpack_from("<III", data, at) + at += 12 + if not 0 < size <= 8 * 1024 * 1024 or not 0 < keep <= size or offset > size - keep: + raise ValueError("invalid frame") + if len(data) - at < size: + raise ValueError("short payload") + result.extend(struct.pack("<I", keep)) + result.extend(data[at + offset:at + offset + keep]) + at += size + return bytes(result) + + +def command(binary, case, policy, *extra): + args = [str(binary), "--policy", policy["policy"], "--pool", str(policy.get("pool", 1)), + "--ratio", str(policy.get("ratio", 4)), "--budget", str(case.get("budget", 8388608)), + "--slots", str(case.get("slots", 512)), "--hold-us", str(case.get("hold_us", 0)), + "--service-us", str(case.get("service_us", 0))] + return args + list(extra) + + +def metrics(stderr): + # Sanitizer diagnostics must not be silently ignored. + text = stderr.decode().strip() + try: + result = json.loads(text) + except json.JSONDecodeError as exc: + raise AssertionError(f"Expected metrics only; tool/runtime diagnostics:\n{text}") from exc + assert result["unreleased_buffer_bytes"] == 0, result + assert result["peak_active_bytes"] <= result["peak_reserved_bytes"] <= result["budget_bytes"], result + return result + + +def check(binary, tmp, policies): + checks = [] + test = tmp / "test.frames" + fixture(test, "test", 45, 177) + data = test.read_bytes() + expected = reference(data) + for policy in policies: + for slow in [False, True]: + case = {"slots": 7, "hold_us": 100 if slow else 0, "budget": 300000} + result = subprocess.run(command(binary, case, policy), input=data, capture_output=True, timeout=15) + m = metrics(result.stderr) + assert result.returncode == 0 and m["status"] == "ok", (policy, result.stderr) + assert result.stdout == expected and m["emitted"] == 45 + assert m["input_bytes"] == len(data) and m["output_bytes"] == len(expected) + assert m["live_at_stop_bytes"] == 0 + checks.append(f'{policy["name"]}: byte equality, accounting, cleanup, slow={slow}') + # Truncation at both header and payload boundaries, including exact missing payload. + bad_inputs = [b"x", struct.pack("<III", 12, 0, 4), + struct.pack("<III", 12, 0, 4) + b"123", + struct.pack("<III", 12, 11, 4) + b"x" * 12, + struct.pack("<III", 0, 0, 0), + struct.pack("<III", 8 * 1024 * 1024 + 1, 0, 1)] + for bad in bad_inputs: + result = subprocess.run(command(binary, {"hold_us": 1000}, policy), + input=data[:13] + bad, capture_output=True, timeout=15) + m = metrics(result.stderr) + assert result.returncode == 2 and m["status"] in {"invalid_frame", "truncated_input"} + checks.append(f'{policy["name"]}: six malformed inputs with pending buffer cleanup') + result = subprocess.run(command(binary, {"hold_us": 1000}, policy, "--cancel-after", "3"), + input=data, capture_output=True, timeout=15) + m = metrics(result.stderr) + prefix_end = 0 + for _ in range(3): + prefix_end += 4 + struct.unpack_from("<I", expected, prefix_end)[0] + assert result.returncode == 3 and m["status"] == "cancelled" and m["emitted"] == 3 + assert result.stdout == expected[:prefix_end] + checks.append(f'{policy["name"]}: cancellation preserves completed output prefix and releases pending buffers') + result = subprocess.run(command(binary, {}, policy), input=b"", capture_output=True, timeout=15) + assert result.returncode == 0 and metrics(result.stderr)["emitted"] == 0 + checks.append(f'{policy["name"]}: empty stream') + # Tight budget must refuse a whole-frame requirement, while streaming projection can work. + large = struct.pack("<III", 1048576, 17, 64) + b"a" * 1048576 + for policy in policies: + result = subprocess.run(command(binary, {"budget": 131072, "slots": 1}, policy), + input=large, capture_output=True, timeout=15) + m = metrics(result.stderr) + assert m["status"] == ("ok" if policy["policy"] == "project" else "budget_too_small") + checks.append("frame larger than buffer budget: bounded refusal versus projection") + if Path("/dev/full").exists(): + with open("/dev/full", "wb") as sink: + result = subprocess.run(command(binary, {"hold_us": 1000}, policies[0]), input=data, + stdout=sink, stderr=subprocess.PIPE, timeout=15) + assert result.returncode == 2 and metrics(result.stderr)["status"] == "output_failed" + checks.append("real output failure through /dev/full, pending buffers released") + # Real signal cancellation after allocation, while waiting for the delayed sink. + with test.open("rb") as source, open(os.devnull, "wb") as sink: + proc = subprocess.Popen(command(binary, {"hold_us": 500000}, policies[0]), + stdin=source, stdout=sink, stderr=subprocess.PIPE) + time.sleep(0.08) + proc.send_signal(signal.SIGTERM) + _, error = proc.communicate(timeout=5) + assert proc.returncode == 3 and metrics(error)["status"] == "cancelled", error + checks.append("SIGTERM interrupts delayed sink and releases buffers") + return checks + + +def sample(binary, source, output, case, policy): + with source.open("rb") as inp, output.open("wb") as out: + result = subprocess.run(command(binary, case, policy), stdin=inp, stdout=out, + stderr=subprocess.PIPE, timeout=30) + m = metrics(result.stderr) + assert result.returncode == 0 and m["status"] == "ok", result.stderr + return m + + +def summarize(rows): + result = [] + names = ["elapsed_ns", "cpu_ns", "peak_reserved_bytes", "peak_active_bytes", "rss_peak_bytes", + "copy_bytes", "active_byte_seconds", "latency_mean_ns", "latency_p99_upper_ns", + "budget_waits", "allocations", "reuses"] + groups = sorted({(r["case"], r["variant"]) for r in rows}) + for case, variant in groups: + group = [r for r in rows if (r["case"], r["variant"]) == (case, variant)] + value = {"case": case, "variant": variant, "samples": len(group)} + for name in names: + values = [r[name] for r in group] + value[name] = {"median": statistics.median(values), "min": min(values), "max": max(values)} + result.append(value) + return result + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--check-only", action="store_true") + parser.add_argument("--output", type=Path) + args = parser.parse_args() + if not args.check_only and args.output is None: + parser.error("provide --check-only or --output (new directory)") + if args.output: + args.output.mkdir(parents=True, exist_ok=False) + cc = shlex.split(os.environ.get("CC", "cc")) + plan = json.loads((ROOT / "plan.json").read_text()) + affinity = None + if hasattr(os, "sched_getaffinity"): + affinity = min(os.sched_getaffinity(0)) + os.sched_setaffinity(0, {affinity}) + with tempfile.TemporaryDirectory(prefix="pure-retention-") as folder: + tmp = Path(folder) + native, sanitized = tmp / "bench", tmp / "bench-sanitized" + builds = [build(cc, native), build(cc, sanitized, True)] + verification = {"native": check(native, tmp, plan["policies"]), + "asan_ubsan": check(sanitized, tmp, plan["policies"])} + print(f'Verified {sum(map(len, verification.values()))} scenario groups (native + ASan/UBSan).', flush=True) + if args.check_only: + return + sources = {name: digest(ROOT / name) for name in ["benchmark.c", "run.py", "plan.json"]} + environment = {"platform": platform.platform(), "machine": platform.machine(), + "python": platform.python_version(), "cpu_affinity": affinity, + "compiler": subprocess.check_output([*cc, "--version"], text=True), + "builds": builds, "source_sha256": sources, + "clock": "CLOCK_MONOTONIC; CPU = CLOCK_PROCESS_CPUTIME_ID", + "timing": "includes file IO, scheduling, deliberate sleep, metrics, buffer cleanup; excludes startup/build/fixture/verification", + "limitations": "shared host; unregulated thermals; cached files; output page cache, no fsync; synthetic closed-loop arrivals", + "started_utc": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())} + if Path("/proc/cpuinfo").exists(): + environment["cpuinfo"] = Path("/proc/cpuinfo").read_text() + dump(args.output / "environment.json", environment) + dump(args.output / "verification.json", verification) + dump(args.output / "plan.json", plan) + fixtures, rows = [], [] + rng = random.Random(plan["seed"]) + for case in plan["cases"]: + source, output = tmp / "input.frames", tmp / "output.frames" + info = fixture(source, case["shape"], case["records"], plan["seed"]) + info["case"] = case["name"] + fixtures.append(info) + # Warm each strategy once. The following measurements use fresh processes. + for policy in plan["policies"]: + sample(native, source, output, case, policy) + assert digest(output) == info["expected_output_sha256"] + for repeat in range(plan["repeats"]): + order = list(plan["policies"]) + rng.shuffle(order) + for policy in order: + m = sample(native, source, output, case, policy) + assert m["accepted"] == m["emitted"] == case["records"] + assert m["input_bytes"] == info["input_bytes"] + assert m["output_bytes"] == info["expected_output_bytes"] + assert digest(output) == info["expected_output_sha256"] + rows.append({"case": case["name"], "variant": policy["name"], "repeat": repeat, **m}) + dump(args.output / "raw.json", rows) + dump(args.output / "fixtures.json", fixtures) + print(f'Completed {case["name"]}: {len(plan["policies"])} variants x {plan["repeats"]} trials.', flush=True) + dump(args.output / "summary.json", summarize(rows)) + with (args.output / "raw.csv").open("w") as out: + writer = csv.DictWriter(out, fieldnames=list(rows[0])) + writer.writeheader() + writer.writerows(rows) + # Detect accidental source edits during a measurement run. + assert sources == {name: digest(ROOT / name) for name in sources} + dump(args.output / "complete.json", {"samples": len(rows), "all_output_hashes_match": True, + "finished_utc": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())}) + print(args.output.resolve()) + + +if __name__ == "__main__": + main() diff --git a/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/summary.json b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/summary.json new file mode 100644 index 0000000..541ce87 --- /dev/null +++ b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/summary.json @@ -0,0 +1,2602 @@ +[ + { + "case": "dense_slow", + "variant": "borrow", + "samples": 5, + "elapsed_ns": { + "median": 132968553, + "min": 122887693, + "max": 156176896 + }, + "cpu_ns": { + "median": 110199520, + "min": 105059769, + "max": 135527318 + }, + "peak_reserved_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "peak_active_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 1007870.242312, + "min": 933965.439249, + "max": 1205798.201258 + }, + "latency_mean_ns": { + "median": 7516016.308, + "min": 6960585.889, + "max": 8983882.317 + }, + "latency_p99_upper_ns": { + "median": 14680064, + "min": 12582912, + "max": 23068672 + }, + "budget_waits": { + "median": 100, + "min": 8, + "max": 279 + }, + "allocations": { + "median": 126, + "min": 126, + "max": 126 + }, + "reuses": { + "median": 1922, + "min": 1922, + "max": 1922 + } + }, + { + "case": "dense_slow", + "variant": "copy", + "samples": 5, + "elapsed_ns": { + "median": 139629443, + "min": 132323981, + "max": 139897423 + }, + "cpu_ns": { + "median": 109997334, + "min": 98850013, + "max": 116916607 + }, + "peak_reserved_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "peak_active_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 100663296, + "min": 100663296, + "max": 100663296 + }, + "active_byte_seconds": { + "median": 1026043.651851, + "min": 1002967.933698, + "max": 1090782.263887 + }, + "latency_mean_ns": { + "median": 7639923.617, + "min": 7467830.775, + "max": 8122260.495 + }, + "latency_p99_upper_ns": { + "median": 11534336, + "min": 11534336, + "max": 16777216 + }, + "budget_waits": { + "median": 1868, + "min": 1245, + "max": 1923 + }, + "allocations": { + "median": 126, + "min": 126, + "max": 126 + }, + "reuses": { + "median": 3970, + "min": 3970, + "max": 3970 + } + }, + { + "case": "dense_slow", + "variant": "copy_no_pool", + "samples": 5, + "elapsed_ns": { + "median": 129205398, + "min": 125060409, + "max": 205943127 + }, + "cpu_ns": { + "median": 106642340, + "min": 95896509, + "max": 116032671 + }, + "peak_reserved_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "peak_active_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 100663296, + "min": 100663296, + "max": 100663296 + }, + "active_byte_seconds": { + "median": 989890.745684, + "min": 961708.896247, + "max": 1615356.534078 + }, + "latency_mean_ns": { + "median": 7371263.893, + "min": 7161052.395, + "max": 12031760.945 + }, + "latency_p99_upper_ns": { + "median": 12582912, + "min": 11534336, + "max": 20971520 + }, + "budget_waits": { + "median": 1720, + "min": 1363, + "max": 1854 + }, + "allocations": { + "median": 4096, + "min": 4096, + "max": 4096 + }, + "reuses": { + "median": 0, + "min": 0, + "max": 0 + } + }, + { + "case": "dense_slow", + "variant": "pressure", + "samples": 5, + "elapsed_ns": { + "median": 131031651, + "min": 121667696, + "max": 148054808 + }, + "cpu_ns": { + "median": 110625767, + "min": 101165480, + "max": 118930635 + }, + "peak_reserved_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "peak_active_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 1012712.39438, + "min": 944768.902586, + "max": 1145837.182993 + }, + "latency_mean_ns": { + "median": 7550902.647, + "min": 7047783.954, + "max": 8545660.143 + }, + "latency_p99_upper_ns": { + "median": 12582912, + "min": 11534336, + "max": 16777216 + }, + "budget_waits": { + "median": 217, + "min": 108, + "max": 330 + }, + "allocations": { + "median": 126, + "min": 126, + "max": 126 + }, + "reuses": { + "median": 1922, + "min": 1922, + "max": 1922 + } + }, + { + "case": "dense_slow", + "variant": "project", + "samples": 5, + "elapsed_ns": { + "median": 153699255, + "min": 138012595, + "max": 177547354 + }, + "cpu_ns": { + "median": 101124724, + "min": 97036844, + "max": 105530265 + }, + "peak_reserved_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "peak_active_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 1191532.621299, + "min": 1074555.345603, + "max": 1401395.334755 + }, + "latency_mean_ns": { + "median": 8908081.106, + "min": 8024328.08, + "max": 10478829.253 + }, + "latency_p99_upper_ns": { + "median": 15728640, + "min": 11534336, + "max": 27262976 + }, + "budget_waits": { + "median": 716, + "min": 573, + "max": 1077 + }, + "allocations": { + "median": 126, + "min": 126, + "max": 126 + }, + "reuses": { + "median": 1922, + "min": 1922, + "max": 1922 + } + }, + { + "case": "dense_slow", + "variant": "threshold2", + "samples": 5, + "elapsed_ns": { + "median": 127102070, + "min": 121944973, + "max": 150967021 + }, + "cpu_ns": { + "median": 109226645, + "min": 98389110, + "max": 112103512 + }, + "peak_reserved_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "peak_active_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 988062.578411, + "min": 941745.792822, + "max": 1153842.867633 + }, + "latency_mean_ns": { + "median": 7376714.273, + "min": 7027416.376, + "max": 8607200.207 + }, + "latency_p99_upper_ns": { + "median": 11534336, + "min": 11534336, + "max": 14680064 + }, + "budget_waits": { + "median": 343, + "min": 123, + "max": 548 + }, + "allocations": { + "median": 126, + "min": 126, + "max": 126 + }, + "reuses": { + "median": 1922, + "min": 1922, + "max": 1922 + } + }, + { + "case": "dense_slow", + "variant": "threshold4", + "samples": 5, + "elapsed_ns": { + "median": 128197678, + "min": 117467153, + "max": 152388963 + }, + "cpu_ns": { + "median": 105658521, + "min": 100339777, + "max": 133280290 + }, + "peak_reserved_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "peak_active_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 997040.290853, + "min": 908428.389283, + "max": 1188061.088853 + }, + "latency_mean_ns": { + "median": 7442559.441, + "min": 6773721.904, + "max": 8858624.865 + }, + "latency_p99_upper_ns": { + "median": 13631488, + "min": 11534336, + "max": 25165824 + }, + "budget_waits": { + "median": 263, + "min": 86, + "max": 483 + }, + "allocations": { + "median": 126, + "min": 126, + "max": 126 + }, + "reuses": { + "median": 1922, + "min": 1922, + "max": 1922 + } + }, + { + "case": "dense_slow", + "variant": "threshold8", + "samples": 5, + "elapsed_ns": { + "median": 130400357, + "min": 127832493, + "max": 158487631 + }, + "cpu_ns": { + "median": 108222327, + "min": 104607294, + "max": 119769747 + }, + "peak_reserved_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "peak_active_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 999089.777214, + "min": 981225.27374, + "max": 1223330.140557 + }, + "latency_mean_ns": { + "median": 7449478.358, + "min": 7311488.307, + "max": 9142910.493 + }, + "latency_p99_upper_ns": { + "median": 13631488, + "min": 12582912, + "max": 25165824 + }, + "budget_waits": { + "median": 210, + "min": 33, + "max": 881 + }, + "allocations": { + "median": 126, + "min": 126, + "max": 126 + }, + "reuses": { + "median": 1922, + "min": 1922, + "max": 1922 + } + }, + { + "case": "mixed_slow", + "variant": "borrow", + "samples": 5, + "elapsed_ns": { + "median": 202207266, + "min": 187355085, + "max": 277725554 + }, + "cpu_ns": { + "median": 109214745, + "min": 105102970, + "max": 130508378 + }, + "peak_reserved_bytes": { + "median": 8386736, + "min": 8386736, + "max": 8386736 + }, + "peak_active_bytes": { + "median": 8386640, + "min": 8386640, + "max": 8386688 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 1584952.748115, + "min": 1467132.987688, + "max": 2188978.814479 + }, + "latency_mean_ns": { + "median": 8968645.74, + "min": 8306217.014, + "max": 12364716.181 + }, + "latency_p99_upper_ns": { + "median": 15728640, + "min": 13631488, + "max": 25165824 + }, + "budget_waits": { + "median": 922, + "min": 882, + "max": 942 + }, + "allocations": { + "median": 1268, + "min": 1246, + "max": 1270 + }, + "reuses": { + "median": 780, + "min": 778, + "max": 802 + } + }, + { + "case": "mixed_slow", + "variant": "copy", + "samples": 5, + "elapsed_ns": { + "median": 179916143, + "min": 155808970, + "max": 221349934 + }, + "cpu_ns": { + "median": 88224841, + "min": 73686530, + "max": 109576369 + }, + "peak_reserved_bytes": { + "median": 8388560, + "min": 8388432, + "max": 8388576 + }, + "peak_active_bytes": { + "median": 8388432, + "min": 8388432, + "max": 8388432 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 53727440, + "min": 53727440, + "max": 53727440 + }, + "active_byte_seconds": { + "median": 1259295.778761, + "min": 1105823.092919, + "max": 1540447.287587 + }, + "latency_mean_ns": { + "median": 23134688.68, + "min": 20210703.898, + "max": 28163326.597 + }, + "latency_p99_upper_ns": { + "median": 37748736, + "min": 29360128, + "max": 46137344 + }, + "budget_waits": { + "median": 855, + "min": 733, + "max": 970 + }, + "allocations": { + "median": 2029, + "min": 1871, + "max": 2181 + }, + "reuses": { + "median": 2067, + "min": 1915, + "max": 2225 + } + }, + { + "case": "mixed_slow", + "variant": "copy_no_pool", + "samples": 5, + "elapsed_ns": { + "median": 185563183, + "min": 175012120, + "max": 209526727 + }, + "cpu_ns": { + "median": 90207409, + "min": 86574113, + "max": 99669005 + }, + "peak_reserved_bytes": { + "median": 8388432, + "min": 8388432, + "max": 8388432 + }, + "peak_active_bytes": { + "median": 8388432, + "min": 8388432, + "max": 8388432 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 53727440, + "min": 53727440, + "max": 53727440 + }, + "active_byte_seconds": { + "median": 1315287.672243, + "min": 1189109.090661, + "max": 1504182.816335 + }, + "latency_mean_ns": { + "median": 24158310.672, + "min": 21577383.531, + "max": 27706362.205 + }, + "latency_p99_upper_ns": { + "median": 37748736, + "min": 37748736, + "max": 50331648 + }, + "budget_waits": { + "median": 852, + "min": 824, + "max": 899 + }, + "allocations": { + "median": 4096, + "min": 4096, + "max": 4096 + }, + "reuses": { + "median": 0, + "min": 0, + "max": 0 + } + }, + { + "case": "mixed_slow", + "variant": "pressure", + "samples": 5, + "elapsed_ns": { + "median": 180476475, + "min": 170729984, + "max": 200423808 + }, + "cpu_ns": { + "median": 89751173, + "min": 82814346, + "max": 95868665 + }, + "peak_reserved_bytes": { + "median": 8388560, + "min": 8388480, + "max": 8388560 + }, + "peak_active_bytes": { + "median": 8388432, + "min": 8388432, + "max": 8388432 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 27916032, + "min": 27916032, + "max": 27916032 + }, + "active_byte_seconds": { + "median": 1287754.655314, + "min": 1237184.456112, + "max": 1462564.435239 + }, + "latency_mean_ns": { + "median": 23117968.235, + "min": 22318118.532, + "max": 26149827.952 + }, + "latency_p99_upper_ns": { + "median": 37748736, + "min": 31457280, + "max": 46137344 + }, + "budget_waits": { + "median": 862, + "min": 826, + "max": 906 + }, + "allocations": { + "median": 1996, + "min": 1950, + "max": 2034 + }, + "reuses": { + "median": 1751, + "min": 1713, + "max": 1797 + } + }, + { + "case": "mixed_slow", + "variant": "project", + "samples": 5, + "elapsed_ns": { + "median": 188062454, + "min": 182031656, + "max": 266408067 + }, + "cpu_ns": { + "median": 85794578, + "min": 77869217, + "max": 111663429 + }, + "peak_reserved_bytes": { + "median": 8388576, + "min": 8388576, + "max": 8388608 + }, + "peak_active_bytes": { + "median": 8388544, + "min": 8388544, + "max": 8388576 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 1338315.607594, + "min": 1288001.912824, + "max": 1878408.17389 + }, + "latency_mean_ns": { + "median": 25106963.876, + "min": 23787174.92, + "max": 34638344.422 + }, + "latency_p99_upper_ns": { + "median": 41943040, + "min": 33554432, + "max": 54525952 + }, + "budget_waits": { + "median": 835, + "min": 732, + "max": 900 + }, + "allocations": { + "median": 1594, + "min": 1498, + "max": 1654 + }, + "reuses": { + "median": 454, + "min": 394, + "max": 550 + } + }, + { + "case": "mixed_slow", + "variant": "threshold2", + "samples": 5, + "elapsed_ns": { + "median": 191170037, + "min": 172458424, + "max": 248649117 + }, + "cpu_ns": { + "median": 95876297, + "min": 88442274, + "max": 108815021 + }, + "peak_reserved_bytes": { + "median": 8388560, + "min": 8388432, + "max": 8388560 + }, + "peak_active_bytes": { + "median": 8388432, + "min": 8388432, + "max": 8388432 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 28479696, + "min": 28479696, + "max": 28479696 + }, + "active_byte_seconds": { + "median": 1364006.158543, + "min": 1218383.798869, + "max": 1817663.170181 + }, + "latency_mean_ns": { + "median": 24916604.797, + "min": 22201893.822, + "max": 32835308.438 + }, + "latency_p99_upper_ns": { + "median": 37748736, + "min": 29360128, + "max": 50331648 + }, + "budget_waits": { + "median": 838, + "min": 758, + "max": 873 + }, + "allocations": { + "median": 1933, + "min": 1822, + "max": 1998 + }, + "reuses": { + "median": 1855, + "min": 1790, + "max": 1966 + } + }, + { + "case": "mixed_slow", + "variant": "threshold4", + "samples": 5, + "elapsed_ns": { + "median": 182099749, + "min": 162195656, + "max": 221114880 + }, + "cpu_ns": { + "median": 94178139, + "min": 80564634, + "max": 108320175 + }, + "peak_reserved_bytes": { + "median": 8388608, + "min": 8388608, + "max": 8388608 + }, + "peak_active_bytes": { + "median": 8388608, + "min": 8388608, + "max": 8388608 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 11229392, + "min": 11229392, + "max": 11229392 + }, + "active_byte_seconds": { + "median": 1347766.35285, + "min": 1200241.584576, + "max": 1620151.723755 + }, + "latency_mean_ns": { + "median": 18702737.958, + "min": 16670151.746, + "max": 22302398.136 + }, + "latency_p99_upper_ns": { + "median": 27262976, + "min": 23068672, + "max": 41943040 + }, + "budget_waits": { + "median": 948, + "min": 867, + "max": 983 + }, + "allocations": { + "median": 1778, + "min": 1725, + "max": 1834 + }, + "reuses": { + "median": 1627, + "min": 1571, + "max": 1680 + } + }, + { + "case": "mixed_slow", + "variant": "threshold8", + "samples": 5, + "elapsed_ns": { + "median": 180744548, + "min": 177004559, + "max": 285706068 + }, + "cpu_ns": { + "median": 92447570, + "min": 88024506, + "max": 123773735 + }, + "peak_reserved_bytes": { + "median": 8388608, + "min": 8388496, + "max": 8388608 + }, + "peak_active_bytes": { + "median": 8388432, + "min": 8388352, + "max": 8388432 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 3824848, + "min": 3824848, + "max": 3824848 + }, + "active_byte_seconds": { + "median": 1375000.84592, + "min": 1308343.909911, + "max": 2141933.275175 + }, + "latency_mean_ns": { + "median": 14634490.266, + "min": 13961564.399, + "max": 22809999.729 + }, + "latency_p99_upper_ns": { + "median": 25165824, + "min": 20971520, + "max": 41943040 + }, + "budget_waits": { + "median": 956, + "min": 811, + "max": 987 + }, + "allocations": { + "median": 1752, + "min": 1639, + "max": 1772 + }, + "reuses": { + "median": 1304, + "min": 1284, + "max": 1417 + } + }, + { + "case": "mixed_tight", + "variant": "borrow", + "samples": 5, + "elapsed_ns": { + "median": 494360387, + "min": 491528840, + "max": 544543692 + }, + "cpu_ns": { + "median": 76140523, + "min": 70906509, + "max": 90900399 + }, + "peak_reserved_bytes": { + "median": 2094128, + "min": 2094128, + "max": 2094128 + }, + "peak_active_bytes": { + "median": 2094128, + "min": 2094032, + "max": 2094128 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 932412.777581, + "min": 926418.118409, + "max": 1028555.825239 + }, + "latency_mean_ns": { + "median": 5500812.732, + "min": 5472000.565, + "max": 6077465.417 + }, + "latency_p99_upper_ns": { + "median": 8388608, + "min": 8388608, + "max": 11534336 + }, + "budget_waits": { + "median": 1395, + "min": 1286, + "max": 1421 + }, + "allocations": { + "median": 1345, + "min": 1332, + "max": 1353 + }, + "reuses": { + "median": 703, + "min": 695, + "max": 716 + } + }, + { + "case": "mixed_tight", + "variant": "copy", + "samples": 5, + "elapsed_ns": { + "median": 191836517, + "min": 191114147, + "max": 205803459 + }, + "cpu_ns": { + "median": 62332245, + "min": 60306782, + "max": 87522857 + }, + "peak_reserved_bytes": { + "median": 2097152, + "min": 2097136, + "max": 2097152 + }, + "peak_active_bytes": { + "median": 2097136, + "min": 2097136, + "max": 2097136 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 53727440, + "min": 53727440, + "max": 53727440 + }, + "active_byte_seconds": { + "median": 347142.858576, + "min": 345755.184019, + "max": 363428.263552 + }, + "latency_mean_ns": { + "median": 6069082.115, + "min": 6032302.559, + "max": 6356735.332 + }, + "latency_p99_upper_ns": { + "median": 8388608, + "min": 8388608, + "max": 11534336 + }, + "budget_waits": { + "median": 1362, + "min": 1210, + "max": 1379 + }, + "allocations": { + "median": 2460, + "min": 2361, + "max": 2470 + }, + "reuses": { + "median": 1636, + "min": 1626, + "max": 1735 + } + }, + { + "case": "mixed_tight", + "variant": "copy_no_pool", + "samples": 5, + "elapsed_ns": { + "median": 190661223, + "min": 190230224, + "max": 215534802 + }, + "cpu_ns": { + "median": 60180004, + "min": 58883103, + "max": 92135979 + }, + "peak_reserved_bytes": { + "median": 2097136, + "min": 2097136, + "max": 2097136 + }, + "peak_active_bytes": { + "median": 2097136, + "min": 2097136, + "max": 2097136 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 53727440, + "min": 53727440, + "max": 53727440 + }, + "active_byte_seconds": { + "median": 345094.680154, + "min": 344486.353015, + "max": 387556.898349 + }, + "latency_mean_ns": { + "median": 6036141.159, + "min": 6020977.936, + "max": 6714221.641 + }, + "latency_p99_upper_ns": { + "median": 8388608, + "min": 8388608, + "max": 10485760 + }, + "budget_waits": { + "median": 1379, + "min": 1179, + "max": 1383 + }, + "allocations": { + "median": 4096, + "min": 4096, + "max": 4096 + }, + "reuses": { + "median": 0, + "min": 0, + "max": 0 + } + }, + { + "case": "mixed_tight", + "variant": "pressure", + "samples": 5, + "elapsed_ns": { + "median": 190593723, + "min": 189684559, + "max": 194998211 + }, + "cpu_ns": { + "median": 62104383, + "min": 60109883, + "max": 80964449 + }, + "peak_reserved_bytes": { + "median": 2097136, + "min": 2097136, + "max": 2097152 + }, + "peak_active_bytes": { + "median": 2097136, + "min": 2097136, + "max": 2097136 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 28385168, + "min": 28385168, + "max": 28385168 + }, + "active_byte_seconds": { + "median": 346774.138471, + "min": 345575.615482, + "max": 352937.551048 + }, + "latency_mean_ns": { + "median": 6133228.412, + "min": 6110993.322, + "max": 6209271.27 + }, + "latency_p99_upper_ns": { + "median": 8388608, + "min": 8388608, + "max": 9437184 + }, + "budget_waits": { + "median": 1387, + "min": 1251, + "max": 1401 + }, + "allocations": { + "median": 2377, + "min": 2265, + "max": 2383 + }, + "reuses": { + "median": 1398, + "min": 1392, + "max": 1510 + } + }, + { + "case": "mixed_tight", + "variant": "project", + "samples": 5, + "elapsed_ns": { + "median": 176712466, + "min": 175293210, + "max": 191006927 + }, + "cpu_ns": { + "median": 57346839, + "min": 56768485, + "max": 80024226 + }, + "peak_reserved_bytes": { + "median": 2097120, + "min": 2097120, + "max": 2097120 + }, + "peak_active_bytes": { + "median": 2097120, + "min": 2097120, + "max": 2097120 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 329327.109037, + "min": 326483.546647, + "max": 354343.266259 + }, + "latency_mean_ns": { + "median": 6344282.023, + "min": 6283898.527, + "max": 6749781.49 + }, + "latency_p99_upper_ns": { + "median": 8388608, + "min": 8388608, + "max": 10485760 + }, + "budget_waits": { + "median": 1308, + "min": 1164, + "max": 1313 + }, + "allocations": { + "median": 1722, + "min": 1659, + "max": 1727 + }, + "reuses": { + "median": 326, + "min": 321, + "max": 389 + } + }, + { + "case": "mixed_tight", + "variant": "threshold2", + "samples": 5, + "elapsed_ns": { + "median": 188885136, + "min": 187864582, + "max": 218109869 + }, + "cpu_ns": { + "median": 63904326, + "min": 60112693, + "max": 94383237 + }, + "peak_reserved_bytes": { + "median": 2097136, + "min": 2097136, + "max": 2097136 + }, + "peak_active_bytes": { + "median": 2097136, + "min": 2097136, + "max": 2097136 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 28479696, + "min": 28479696, + "max": 28479696 + }, + "active_byte_seconds": { + "median": 342822.067006, + "min": 341567.414808, + "max": 394831.364885 + }, + "latency_mean_ns": { + "median": 6121880.805, + "min": 6102214.292, + "max": 7013746.965 + }, + "latency_p99_upper_ns": { + "median": 8388608, + "min": 8388608, + "max": 14680064 + }, + "budget_waits": { + "median": 1390, + "min": 1166, + "max": 1411 + }, + "allocations": { + "median": 2356, + "min": 2188, + "max": 2384 + }, + "reuses": { + "median": 1432, + "min": 1404, + "max": 1600 + } + }, + { + "case": "mixed_tight", + "variant": "threshold4", + "samples": 5, + "elapsed_ns": { + "median": 226008956, + "min": 224500368, + "max": 240539157 + }, + "cpu_ns": { + "median": 64169718, + "min": 61534673, + "max": 82888986 + }, + "peak_reserved_bytes": { + "median": 2097136, + "min": 2097136, + "max": 2097136 + }, + "peak_active_bytes": { + "median": 2097104, + "min": 2097104, + "max": 2097104 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 11229392, + "min": 11229392, + "max": 11229392 + }, + "active_byte_seconds": { + "median": 414911.228869, + "min": 412262.960044, + "max": 437508.612236 + }, + "latency_mean_ns": { + "median": 5866464.096, + "min": 5837746.733, + "max": 6115847.212 + }, + "latency_p99_upper_ns": { + "median": 8388608, + "min": 7864320, + "max": 9437184 + }, + "budget_waits": { + "median": 1452, + "min": 1333, + "max": 1465 + }, + "allocations": { + "median": 2125, + "min": 2037, + "max": 2145 + }, + "reuses": { + "median": 1280, + "min": 1260, + "max": 1368 + } + }, + { + "case": "mixed_tight", + "variant": "threshold8", + "samples": 5, + "elapsed_ns": { + "median": 284454034, + "min": 282084485, + "max": 315263040 + }, + "cpu_ns": { + "median": 68644342, + "min": 66066433, + "max": 90750328 + }, + "peak_reserved_bytes": { + "median": 2097136, + "min": 2097120, + "max": 2097136 + }, + "peak_active_bytes": { + "median": 2097136, + "min": 2097120, + "max": 2097136 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 3824848, + "min": 3824848, + "max": 3824848 + }, + "active_byte_seconds": { + "median": 523909.294385, + "min": 520410.956771, + "max": 579371.042178 + }, + "latency_mean_ns": { + "median": 5707951.51, + "min": 5671193.431, + "max": 6291155.426 + }, + "latency_p99_upper_ns": { + "median": 7340032, + "min": 7340032, + "max": 13631488 + }, + "budget_waits": { + "median": 1386, + "min": 1248, + "max": 1398 + }, + "allocations": { + "median": 1983, + "min": 1890, + "max": 1992 + }, + "reuses": { + "median": 1073, + "min": 1064, + "max": 1166 + } + }, + { + "case": "sparse_fast", + "variant": "borrow", + "samples": 5, + "elapsed_ns": { + "median": 21555643, + "min": 20408294, + "max": 25754576 + }, + "cpu_ns": { + "median": 21467723, + "min": 20408999, + "max": 25674260 + }, + "peak_reserved_bytes": { + "median": 156112, + "min": 156112, + "max": 156112 + }, + "peak_active_bytes": { + "median": 156112, + "min": 156112, + "max": 156112 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 1339.691796, + "min": 1265.057763, + "max": 1611.048102 + }, + "latency_mean_ns": { + "median": 10366.948, + "min": 9812.079, + "max": 12408.192 + }, + "latency_p99_upper_ns": { + "median": 18432, + "min": 13312, + "max": 20480 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 1, + "min": 1, + "max": 1 + }, + "reuses": { + "median": 2047, + "min": 2047, + "max": 2047 + } + }, + { + "case": "sparse_fast", + "variant": "copy", + "samples": 5, + "elapsed_ns": { + "median": 21065681, + "min": 20744256, + "max": 40643311 + }, + "cpu_ns": { + "median": 21006279, + "min": 20744722, + "max": 40589351 + }, + "peak_reserved_bytes": { + "median": 156192, + "min": 156192, + "max": 156192 + }, + "peak_active_bytes": { + "median": 156192, + "min": 156192, + "max": 156192 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 1124.320165, + "min": 1107.901257, + "max": 2334.403772 + }, + "latency_mean_ns": { + "median": 10139.793, + "min": 9979.793, + "max": 19667.254 + }, + "latency_p99_upper_ns": { + "median": 15360, + "min": 13312, + "max": 49152 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 2, + "min": 2, + "max": 2 + }, + "reuses": { + "median": 4094, + "min": 4094, + "max": 4094 + } + }, + { + "case": "sparse_fast", + "variant": "copy_no_pool", + "samples": 5, + "elapsed_ns": { + "median": 21725958, + "min": 21132162, + "max": 30675302 + }, + "cpu_ns": { + "median": 21582704, + "min": 21048817, + "max": 30605147 + }, + "peak_reserved_bytes": { + "median": 156192, + "min": 156192, + "max": 156192 + }, + "peak_active_bytes": { + "median": 156192, + "min": 156192, + "max": 156192 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 1159.292471, + "min": 1121.783606, + "max": 1690.623657 + }, + "latency_mean_ns": { + "median": 10452.028, + "min": 10163.675, + "max": 14792.559 + }, + "latency_p99_upper_ns": { + "median": 16384, + "min": 15360, + "max": 36864 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 4096, + "min": 4096, + "max": 4096 + }, + "reuses": { + "median": 0, + "min": 0, + "max": 0 + } + }, + { + "case": "sparse_fast", + "variant": "pressure", + "samples": 5, + "elapsed_ns": { + "median": 23241749, + "min": 20554720, + "max": 28270087 + }, + "cpu_ns": { + "median": 23003312, + "min": 20527722, + "max": 28259741 + }, + "peak_reserved_bytes": { + "median": 156112, + "min": 156112, + "max": 156112 + }, + "peak_active_bytes": { + "median": 156112, + "min": 156112, + "max": 156112 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 1441.524009, + "min": 1273.955005, + "max": 1772.014643 + }, + "latency_mean_ns": { + "median": 11135.177, + "min": 9881.978, + "max": 13635.652 + }, + "latency_p99_upper_ns": { + "median": 20480, + "min": 13312, + "max": 24576 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 1, + "min": 1, + "max": 1 + }, + "reuses": { + "median": 2047, + "min": 2047, + "max": 2047 + } + }, + { + "case": "sparse_fast", + "variant": "project", + "samples": 5, + "elapsed_ns": { + "median": 22216122, + "min": 21766957, + "max": 25768428 + }, + "cpu_ns": { + "median": 22202889, + "min": 21732111, + "max": 25607575 + }, + "peak_reserved_bytes": { + "median": 90640, + "min": 90640, + "max": 90640 + }, + "peak_active_bytes": { + "median": 90640, + "min": 90640, + "max": 90640 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 1.688434, + "min": 1.653919, + "max": 1.971383 + }, + "latency_mean_ns": { + "median": 10698.669, + "min": 10483.601, + "max": 12427.336 + }, + "latency_p99_upper_ns": { + "median": 16384, + "min": 13312, + "max": 22528 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 1, + "min": 1, + "max": 1 + }, + "reuses": { + "median": 2047, + "min": 2047, + "max": 2047 + } + }, + { + "case": "sparse_fast", + "variant": "threshold2", + "samples": 5, + "elapsed_ns": { + "median": 21328570, + "min": 20854404, + "max": 27294793 + }, + "cpu_ns": { + "median": 21275351, + "min": 20822149, + "max": 27138353 + }, + "peak_reserved_bytes": { + "median": 156192, + "min": 156192, + "max": 156192 + }, + "peak_active_bytes": { + "median": 156192, + "min": 156192, + "max": 156192 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 1144.526904, + "min": 1108.309428, + "max": 1515.562825 + }, + "latency_mean_ns": { + "median": 10266.949, + "min": 10030.324, + "max": 13171.363 + }, + "latency_p99_upper_ns": { + "median": 15360, + "min": 14336, + "max": 28672 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 2, + "min": 2, + "max": 2 + }, + "reuses": { + "median": 4094, + "min": 4094, + "max": 4094 + } + }, + { + "case": "sparse_fast", + "variant": "threshold4", + "samples": 5, + "elapsed_ns": { + "median": 22839176, + "min": 20961885, + "max": 28395383 + }, + "cpu_ns": { + "median": 22457056, + "min": 20931648, + "max": 28350296 + }, + "peak_reserved_bytes": { + "median": 156192, + "min": 156192, + "max": 156192 + }, + "peak_active_bytes": { + "median": 156192, + "min": 156192, + "max": 156192 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 1227.172318, + "min": 1117.500277, + "max": 1583.182193 + }, + "latency_mean_ns": { + "median": 10958.209, + "min": 10087.398, + "max": 13707.471 + }, + "latency_p99_upper_ns": { + "median": 20480, + "min": 13312, + "max": 26624 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 2, + "min": 2, + "max": 2 + }, + "reuses": { + "median": 4094, + "min": 4094, + "max": 4094 + } + }, + { + "case": "sparse_fast", + "variant": "threshold8", + "samples": 5, + "elapsed_ns": { + "median": 22601085, + "min": 20540535, + "max": 33207148 + }, + "cpu_ns": { + "median": 22218814, + "min": 20499501, + "max": 33180296 + }, + "peak_reserved_bytes": { + "median": 156192, + "min": 156192, + "max": 156192 + }, + "peak_active_bytes": { + "median": 156192, + "min": 156192, + "max": 156192 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 1220.513584, + "min": 1100.863361, + "max": 1873.802277 + }, + "latency_mean_ns": { + "median": 10886.611, + "min": 9884.486, + "max": 16048.501 + }, + "latency_p99_upper_ns": { + "median": 28672, + "min": 13312, + "max": 36864 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 2, + "min": 2, + "max": 2 + }, + "reuses": { + "median": 4094, + "min": 4094, + "max": 4094 + } + }, + { + "case": "sparse_slow", + "variant": "borrow", + "samples": 5, + "elapsed_ns": { + "median": 122707360, + "min": 101576920, + "max": 132106520 + }, + "cpu_ns": { + "median": 46471284, + "min": 45409725, + "max": 50248602 + }, + "peak_reserved_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "peak_active_bytes": { + "median": 8350112, + "min": 8350112, + "max": 8350112 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 963195.592926, + "min": 784884.708981, + "max": 1041796.843202 + }, + "latency_mean_ns": { + "median": 7210177.487, + "min": 5868549.98, + "max": 7801228.044 + }, + "latency_p99_upper_ns": { + "median": 9437184, + "min": 9437184, + "max": 10485760 + }, + "budget_waits": { + "median": 1334, + "min": 825, + "max": 1532 + }, + "allocations": { + "median": 126, + "min": 126, + "max": 126 + }, + "reuses": { + "median": 1922, + "min": 1922, + "max": 1922 + } + }, + { + "case": "sparse_slow", + "variant": "copy", + "samples": 5, + "elapsed_ns": { + "median": 155007270, + "min": 153170646, + "max": 160896124 + }, + "cpu_ns": { + "median": 25740442, + "min": 24156681, + "max": 48121065 + }, + "peak_reserved_bytes": { + "median": 197072, + "min": 197072, + "max": 197072 + }, + "peak_active_bytes": { + "median": 197072, + "min": 197072, + "max": 197072 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 6585.869234, + "min": 6504.184345, + "max": 7879.414446 + }, + "latency_mean_ns": { + "median": 33274854.653, + "min": 32718961.288, + "max": 34942676.828 + }, + "latency_p99_upper_ns": { + "median": 37748736, + "min": 37748736, + "max": 50331648 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 513, + "min": 513, + "max": 513 + }, + "reuses": { + "median": 3583, + "min": 3583, + "max": 3583 + } + }, + { + "case": "sparse_slow", + "variant": "copy_no_pool", + "samples": 5, + "elapsed_ns": { + "median": 154586382, + "min": 154143199, + "max": 164046264 + }, + "cpu_ns": { + "median": 24703970, + "min": 24004931, + "max": 46944898 + }, + "peak_reserved_bytes": { + "median": 197072, + "min": 197072, + "max": 197072 + }, + "peak_active_bytes": { + "median": 197072, + "min": 197072, + "max": 197072 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 6526.934401, + "min": 6483.552028, + "max": 8459.440246 + }, + "latency_mean_ns": { + "median": 33387730.27, + "min": 33287028.642, + "max": 35133900.267 + }, + "latency_p99_upper_ns": { + "median": 41943040, + "min": 37748736, + "max": 46137344 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 4096, + "min": 4096, + "max": 4096 + }, + "reuses": { + "median": 0, + "min": 0, + "max": 0 + } + }, + { + "case": "sparse_slow", + "variant": "pressure", + "samples": 5, + "elapsed_ns": { + "median": 151522021, + "min": 151398447, + "max": 170735523 + }, + "cpu_ns": { + "median": 27174295, + "min": 26713792, + "max": 36085789 + }, + "peak_reserved_bytes": { + "median": 4321888, + "min": 4321888, + "max": 4321888 + }, + "peak_active_bytes": { + "median": 4316448, + "min": 4316128, + "max": 4317248 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 113152, + "min": 113024, + "max": 113408 + }, + "active_byte_seconds": { + "median": 545315.69968, + "min": 535707.02646, + "max": 624641.105995 + }, + "latency_mean_ns": { + "median": 32398179.535, + "min": 32391902.953, + "max": 37128525.741 + }, + "latency_p99_upper_ns": { + "median": 37748736, + "min": 37748736, + "max": 50331648 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 514, + "min": 514, + "max": 514 + }, + "reuses": { + "median": 3302, + "min": 3300, + "max": 3306 + } + }, + { + "case": "sparse_slow", + "variant": "project", + "samples": 5, + "elapsed_ns": { + "median": 154766567, + "min": 154024996, + "max": 157789596 + }, + "cpu_ns": { + "median": 25290252, + "min": 24892483, + "max": 25739163 + }, + "peak_reserved_bytes": { + "median": 131520, + "min": 131520, + "max": 131520 + }, + "peak_active_bytes": { + "median": 131520, + "min": 131520, + "max": 131520 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "active_byte_seconds": { + "median": 5470.365986, + "min": 5441.502377, + "max": 5595.217111 + }, + "latency_mean_ns": { + "median": 33388895.003, + "min": 33212736.419, + "max": 34150955.425 + }, + "latency_p99_upper_ns": { + "median": 41943040, + "min": 37748736, + "max": 41943040 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 512, + "min": 512, + "max": 512 + }, + "reuses": { + "median": 1536, + "min": 1536, + "max": 1536 + } + }, + { + "case": "sparse_slow", + "variant": "threshold2", + "samples": 5, + "elapsed_ns": { + "median": 154790882, + "min": 154125217, + "max": 183186784 + }, + "cpu_ns": { + "median": 24321563, + "min": 24092354, + "max": 47779812 + }, + "peak_reserved_bytes": { + "median": 197072, + "min": 197072, + "max": 197072 + }, + "peak_active_bytes": { + "median": 197072, + "min": 197072, + "max": 197072 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 6519.648368, + "min": 6508.096109, + "max": 8175.636446 + }, + "latency_mean_ns": { + "median": 33288663.865, + "min": 31414916.006, + "max": 39799236.839 + }, + "latency_p99_upper_ns": { + "median": 37748736, + "min": 37748736, + "max": 54525952 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 513, + "min": 513, + "max": 513 + }, + "reuses": { + "median": 3583, + "min": 3583, + "max": 3583 + } + }, + { + "case": "sparse_slow", + "variant": "threshold4", + "samples": 5, + "elapsed_ns": { + "median": 154103699, + "min": 152733814, + "max": 154495679 + }, + "cpu_ns": { + "median": 24603184, + "min": 23694419, + "max": 52980104 + }, + "peak_reserved_bytes": { + "median": 197072, + "min": 197072, + "max": 197072 + }, + "peak_active_bytes": { + "median": 197072, + "min": 197072, + "max": 197072 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 6514.197106, + "min": 6485.074292, + "max": 7602.229051 + }, + "latency_mean_ns": { + "median": 33271036.464, + "min": 30324683.181, + "max": 33331969.71 + }, + "latency_p99_upper_ns": { + "median": 37748736, + "min": 37748736, + "max": 54525952 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 513, + "min": 513, + "max": 513 + }, + "reuses": { + "median": 3583, + "min": 3583, + "max": 3583 + } + }, + { + "case": "sparse_slow", + "variant": "threshold8", + "samples": 5, + "elapsed_ns": { + "median": 154268606, + "min": 154242976, + "max": 161984455 + }, + "cpu_ns": { + "median": 24028565, + "min": 23936885, + "max": 35308455 + }, + "peak_reserved_bytes": { + "median": 197072, + "min": 197072, + "max": 197072 + }, + "peak_active_bytes": { + "median": 197072, + "min": 197072, + "max": 197072 + }, + "rss_peak_bytes": { + "median": 28753920, + "min": 28753920, + "max": 28753920 + }, + "copy_bytes": { + "median": 131072, + "min": 131072, + "max": 131072 + }, + "active_byte_seconds": { + "median": 6509.096995, + "min": 6499.765006, + "max": 7196.657649 + }, + "latency_mean_ns": { + "median": 33299370.61, + "min": 33265597.392, + "max": 34734342.366 + }, + "latency_p99_upper_ns": { + "median": 37748736, + "min": 37748736, + "max": 41943040 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "allocations": { + "median": 513, + "min": 513, + "max": 513 + }, + "reuses": { + "median": 3583, + "min": 3583, + "max": 3583 + } + } +] diff --git a/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/verification.json b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/verification.json new file mode 100644 index 0000000..60f0b18 --- /dev/null +++ b/research/experiments/002-buffer-retention/results/2026-09-22-linux-aarch64/verification.json @@ -0,0 +1,92 @@ +{ + "native": [ + "borrow: byte equality, accounting, cleanup, slow=False", + "borrow: byte equality, accounting, cleanup, slow=True", + "borrow: six malformed inputs with pending buffer cleanup", + "borrow: cancellation preserves completed output prefix and releases pending buffers", + "borrow: empty stream", + "copy: byte equality, accounting, cleanup, slow=False", + "copy: byte equality, accounting, cleanup, slow=True", + "copy: six malformed inputs with pending buffer cleanup", + "copy: cancellation preserves completed output prefix and releases pending buffers", + "copy: empty stream", + "threshold2: byte equality, accounting, cleanup, slow=False", + "threshold2: byte equality, accounting, cleanup, slow=True", + "threshold2: six malformed inputs with pending buffer cleanup", + "threshold2: cancellation preserves completed output prefix and releases pending buffers", + "threshold2: empty stream", + "threshold4: byte equality, accounting, cleanup, slow=False", + "threshold4: byte equality, accounting, cleanup, slow=True", + "threshold4: six malformed inputs with pending buffer cleanup", + "threshold4: cancellation preserves completed output prefix and releases pending buffers", + "threshold4: empty stream", + "threshold8: byte equality, accounting, cleanup, slow=False", + "threshold8: byte equality, accounting, cleanup, slow=True", + "threshold8: six malformed inputs with pending buffer cleanup", + "threshold8: cancellation preserves completed output prefix and releases pending buffers", + "threshold8: empty stream", + "pressure: byte equality, accounting, cleanup, slow=False", + "pressure: byte equality, accounting, cleanup, slow=True", + "pressure: six malformed inputs with pending buffer cleanup", + "pressure: cancellation preserves completed output prefix and releases pending buffers", + "pressure: empty stream", + "project: byte equality, accounting, cleanup, slow=False", + "project: byte equality, accounting, cleanup, slow=True", + "project: six malformed inputs with pending buffer cleanup", + "project: cancellation preserves completed output prefix and releases pending buffers", + "project: empty stream", + "copy_no_pool: byte equality, accounting, cleanup, slow=False", + "copy_no_pool: byte equality, accounting, cleanup, slow=True", + "copy_no_pool: six malformed inputs with pending buffer cleanup", + "copy_no_pool: cancellation preserves completed output prefix and releases pending buffers", + "copy_no_pool: empty stream", + "frame larger than buffer budget: bounded refusal versus projection", + "real output failure through /dev/full, pending buffers released", + "SIGTERM interrupts delayed sink and releases buffers" + ], + "asan_ubsan": [ + "borrow: byte equality, accounting, cleanup, slow=False", + "borrow: byte equality, accounting, cleanup, slow=True", + "borrow: six malformed inputs with pending buffer cleanup", + "borrow: cancellation preserves completed output prefix and releases pending buffers", + "borrow: empty stream", + "copy: byte equality, accounting, cleanup, slow=False", + "copy: byte equality, accounting, cleanup, slow=True", + "copy: six malformed inputs with pending buffer cleanup", + "copy: cancellation preserves completed output prefix and releases pending buffers", + "copy: empty stream", + "threshold2: byte equality, accounting, cleanup, slow=False", + "threshold2: byte equality, accounting, cleanup, slow=True", + "threshold2: six malformed inputs with pending buffer cleanup", + "threshold2: cancellation preserves completed output prefix and releases pending buffers", + "threshold2: empty stream", + "threshold4: byte equality, accounting, cleanup, slow=False", + "threshold4: byte equality, accounting, cleanup, slow=True", + "threshold4: six malformed inputs with pending buffer cleanup", + "threshold4: cancellation preserves completed output prefix and releases pending buffers", + "threshold4: empty stream", + "threshold8: byte equality, accounting, cleanup, slow=False", + "threshold8: byte equality, accounting, cleanup, slow=True", + "threshold8: six malformed inputs with pending buffer cleanup", + "threshold8: cancellation preserves completed output prefix and releases pending buffers", + "threshold8: empty stream", + "pressure: byte equality, accounting, cleanup, slow=False", + "pressure: byte equality, accounting, cleanup, slow=True", + "pressure: six malformed inputs with pending buffer cleanup", + "pressure: cancellation preserves completed output prefix and releases pending buffers", + "pressure: empty stream", + "project: byte equality, accounting, cleanup, slow=False", + "project: byte equality, accounting, cleanup, slow=True", + "project: six malformed inputs with pending buffer cleanup", + "project: cancellation preserves completed output prefix and releases pending buffers", + "project: empty stream", + "copy_no_pool: byte equality, accounting, cleanup, slow=False", + "copy_no_pool: byte equality, accounting, cleanup, slow=True", + "copy_no_pool: six malformed inputs with pending buffer cleanup", + "copy_no_pool: cancellation preserves completed output prefix and releases pending buffers", + "copy_no_pool: empty stream", + "frame larger than buffer budget: bounded refusal versus projection", + "real output failure through /dev/full, pending buffers released", + "SIGTERM interrupts delayed sink and releases buffers" + ] +} diff --git a/research/experiments/002-buffer-retention/run.py b/research/experiments/002-buffer-retention/run.py new file mode 100644 index 0000000..49a693c --- /dev/null +++ b/research/experiments/002-buffer-retention/run.py @@ -0,0 +1,300 @@ +#!/usr/bin/env python3 +"""Build, independently verify, and measure the retention experiment.""" +import argparse +import csv +import hashlib +import json +import os +from pathlib import Path +import platform +import random +import shlex +import signal +import statistics +import struct +import subprocess +import tempfile +import time + +ROOT = Path(__file__).resolve().parent +FLAGS = ["-std=c17", "-Wall", "-Wextra", "-Wpedantic", "-Werror", "-O2", "-g"] + + +def digest(path): + with open(path, "rb") as stream: + return hashlib.file_digest(stream, "sha256").hexdigest() + + +def dump(path, value): + path.write_text(json.dumps(value, indent=2, ensure_ascii=False) + "\n") + + +def build(cc, output, sanitizer=False): + command = [*cc, *FLAGS] + if sanitizer: + command += ["-fsanitize=address,undefined", "-fno-omit-frame-pointer"] + command += [str(ROOT / "benchmark.c"), "-o", str(output)] + result = subprocess.run(command, capture_output=True, text=True, check=True) + return {"command": command, "stderr": result.stderr, "sha256": digest(output), + "size_bytes": output.stat().st_size} + + +def shape_for(shape, rng, i): + if shape == "sparse": + return 65536, 64 + if shape == "dense": + return 65536, 49152 + if shape == "mixed": + source = rng.choice([4096, 16384, 65536, 262144]) + keep = max(16, source // rng.choice([1, 2, 4, 8, 64, 1024])) + return source, keep + if shape == "test": + return [(1, 1), (63, 17), (4097, 12), (65536, 49152), (127, 127)][i % 5] + raise ValueError(shape) + + +def fixture(path, shape, count, seed): + rng = random.Random(seed) + expected = hashlib.sha256() + total = 0 + with path.open("wb") as stream: + for i in range(count): + size, keep = shape_for(shape, rng, i) + offset = rng.randrange(size - keep + 1) + # All input bytes exist on disk; no sparse files or seeking past data. + tile = rng.randbytes(256) + payload = (tile * ((size + 255) // 256))[:size] + stream.write(struct.pack("<III", size, offset, keep)) + stream.write(payload) + out = struct.pack("<I", keep) + payload[offset:offset + keep] + expected.update(out) + total += len(out) + return {"path": path.name, "shape": shape, "records": count, "seed": seed, + "input_bytes": path.stat().st_size, "input_sha256": digest(path), + "expected_output_bytes": total, "expected_output_sha256": expected.hexdigest()} + + +def reference(data): + result = bytearray() + at = 0 + while at < len(data): + if len(data) - at < 12: + raise ValueError("short header") + size, offset, keep = struct.unpack_from("<III", data, at) + at += 12 + if not 0 < size <= 8 * 1024 * 1024 or not 0 < keep <= size or offset > size - keep: + raise ValueError("invalid frame") + if len(data) - at < size: + raise ValueError("short payload") + result.extend(struct.pack("<I", keep)) + result.extend(data[at + offset:at + offset + keep]) + at += size + return bytes(result) + + +def command(binary, case, policy, *extra): + args = [str(binary), "--policy", policy["policy"], "--pool", str(policy.get("pool", 1)), + "--ratio", str(policy.get("ratio", 4)), "--budget", str(case.get("budget", 8388608)), + "--slots", str(case.get("slots", 512)), "--hold-us", str(case.get("hold_us", 0)), + "--service-us", str(case.get("service_us", 0))] + return args + list(extra) + + +def metrics(stderr): + # Sanitizer diagnostics must not be silently ignored. + text = stderr.decode().strip() + try: + result = json.loads(text) + except json.JSONDecodeError as exc: + raise AssertionError(f"Expected metrics only; tool/runtime diagnostics:\n{text}") from exc + assert result["unreleased_buffer_bytes"] == 0, result + assert result["peak_active_bytes"] <= result["peak_reserved_bytes"] <= result["budget_bytes"], result + return result + + +def check(binary, tmp, policies): + checks = [] + test = tmp / "test.frames" + fixture(test, "test", 45, 177) + data = test.read_bytes() + expected = reference(data) + for policy in policies: + for slow in [False, True]: + case = {"slots": 7, "hold_us": 100 if slow else 0, "budget": 300000} + result = subprocess.run(command(binary, case, policy), input=data, capture_output=True, timeout=15) + m = metrics(result.stderr) + assert result.returncode == 0 and m["status"] == "ok", (policy, result.stderr) + assert result.stdout == expected and m["emitted"] == 45 + assert m["input_bytes"] == len(data) and m["output_bytes"] == len(expected) + assert m["live_at_stop_bytes"] == 0 + checks.append(f'{policy["name"]}: byte equality, accounting, cleanup, slow={slow}') + # Truncation at both header and payload boundaries, including exact missing payload. + bad_inputs = [b"x", struct.pack("<III", 12, 0, 4), + struct.pack("<III", 12, 0, 4) + b"123", + struct.pack("<III", 12, 11, 4) + b"x" * 12, + struct.pack("<III", 0, 0, 0), + struct.pack("<III", 8 * 1024 * 1024 + 1, 0, 1)] + for bad in bad_inputs: + result = subprocess.run(command(binary, {"hold_us": 1000}, policy), + input=data[:13] + bad, capture_output=True, timeout=15) + m = metrics(result.stderr) + assert result.returncode == 2 and m["status"] in {"invalid_frame", "truncated_input"} + checks.append(f'{policy["name"]}: six malformed inputs with pending buffer cleanup') + result = subprocess.run(command(binary, {"hold_us": 1000}, policy, "--cancel-after", "3"), + input=data, capture_output=True, timeout=15) + m = metrics(result.stderr) + prefix_end = 0 + for _ in range(3): + prefix_end += 4 + struct.unpack_from("<I", expected, prefix_end)[0] + assert result.returncode == 3 and m["status"] == "cancelled" and m["emitted"] == 3 + assert result.stdout == expected[:prefix_end] + checks.append(f'{policy["name"]}: cancellation preserves completed output prefix and releases pending buffers') + result = subprocess.run(command(binary, {}, policy), input=b"", capture_output=True, timeout=15) + assert result.returncode == 0 and metrics(result.stderr)["emitted"] == 0 + checks.append(f'{policy["name"]}: empty stream') + # Tight budget must refuse a whole-frame requirement, while streaming projection can work. + large = struct.pack("<III", 1048576, 17, 64) + b"a" * 1048576 + for policy in policies: + result = subprocess.run(command(binary, {"budget": 131072, "slots": 1}, policy), + input=large, capture_output=True, timeout=15) + m = metrics(result.stderr) + assert m["status"] == ("ok" if policy["policy"] == "project" else "budget_too_small") + checks.append("frame larger than buffer budget: bounded refusal versus projection") + if Path("/dev/full").exists(): + with open("/dev/full", "wb") as sink: + result = subprocess.run(command(binary, {"hold_us": 1000}, policies[0]), input=data, + stdout=sink, stderr=subprocess.PIPE, timeout=15) + assert result.returncode == 2 and metrics(result.stderr)["status"] == "output_failed" + checks.append("real output failure through /dev/full, pending buffers released") + # Real signal cancellation after allocation, while waiting for the delayed sink. + with test.open("rb") as source, open(os.devnull, "wb") as sink: + proc = subprocess.Popen(command(binary, {"hold_us": 500000}, policies[0]), + stdin=source, stdout=sink, stderr=subprocess.PIPE) + time.sleep(0.08) + proc.send_signal(signal.SIGTERM) + _, error = proc.communicate(timeout=5) + assert proc.returncode == 3 and metrics(error)["status"] == "cancelled", error + checks.append("SIGTERM interrupts delayed sink and releases buffers") + if platform.system() == "Linux": + # Regression: inherited rusage peak cannot stand in for current-image HWM. + resident = tmp / "rss.frames" + fixture(resident, "sparse", 512, 817) + values = {} + for policy in [{"policy": "borrow"}, {"policy": "project"}]: + with resident.open("rb") as source, open(os.devnull, "wb") as sink: + result = subprocess.run(command(binary, {"hold_us": 10000}, policy), + stdin=source, stdout=sink, stderr=subprocess.PIPE, timeout=15) + m = metrics(result.stderr) + assert result.returncode == 0 and m["rss_peak_source"] == "linux_proc_vmhwm_approximate" + assert m["rss_peak_bytes"] > 0 + values[policy["policy"]] = m["rss_peak_bytes"] + # Only a sanity check for this deliberately wide memory gap, not exact RSS arithmetic. + assert values["borrow"] > values["project"], values + checks.append("current-image VmHWM distinguishes large retained sources from small projections") + return checks + + +def sample(binary, source, output, case, policy): + with source.open("rb") as inp, output.open("wb") as out: + result = subprocess.run(command(binary, case, policy), stdin=inp, stdout=out, + stderr=subprocess.PIPE, timeout=30) + m = metrics(result.stderr) + assert result.returncode == 0 and m["status"] == "ok", result.stderr + return m + + +def summarize(rows): + result = [] + names = ["elapsed_ns", "cpu_ns", "peak_reserved_bytes", "peak_active_bytes", "rss_peak_bytes", + "copy_bytes", "active_byte_seconds", "latency_mean_ns", "latency_p99_upper_ns", + "budget_waits", "allocations", "reuses"] + groups = sorted({(r["case"], r["variant"]) for r in rows}) + for case, variant in groups: + group = [r for r in rows if (r["case"], r["variant"]) == (case, variant)] + value = {"case": case, "variant": variant, "samples": len(group)} + for name in names: + values = [r[name] for r in group] + value[name] = {"median": statistics.median(values), "min": min(values), "max": max(values)} + result.append(value) + return result + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--check-only", action="store_true") + parser.add_argument("--output", type=Path) + args = parser.parse_args() + if not args.check_only and args.output is None: + parser.error("provide --check-only or --output (new directory)") + if args.output: + args.output.mkdir(parents=True, exist_ok=False) + cc = shlex.split(os.environ.get("CC", "cc")) + plan = json.loads((ROOT / "plan.json").read_text()) + affinity = None + if hasattr(os, "sched_getaffinity"): + affinity = min(os.sched_getaffinity(0)) + os.sched_setaffinity(0, {affinity}) + with tempfile.TemporaryDirectory(prefix="pure-retention-") as folder: + tmp = Path(folder) + native, sanitized = tmp / "bench", tmp / "bench-sanitized" + builds = [build(cc, native), build(cc, sanitized, True)] + verification = {"native": check(native, tmp, plan["policies"]), + "asan_ubsan": check(sanitized, tmp, plan["policies"])} + print(f'Verified {sum(map(len, verification.values()))} scenario groups (native + ASan/UBSan).', flush=True) + if args.check_only: + return + sources = {name: digest(ROOT / name) for name in ["benchmark.c", "run.py", "plan.json"]} + environment = {"platform": platform.platform(), "machine": platform.machine(), + "python": platform.python_version(), "cpu_affinity": affinity, + "compiler": subprocess.check_output([*cc, "--version"], text=True), + "builds": builds, "source_sha256": sources, + "clock": "CLOCK_MONOTONIC; CPU = CLOCK_PROCESS_CPUTIME_ID", + "timing": "includes file IO, scheduling, deliberate sleep, metrics, buffer cleanup; excludes startup/build/fixture/verification", + "limitations": "shared host; unregulated thermals; cached files; output page cache, no fsync; synthetic closed-loop arrivals", + "started_utc": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())} + if Path("/proc/cpuinfo").exists(): + environment["cpuinfo"] = Path("/proc/cpuinfo").read_text() + dump(args.output / "environment.json", environment) + dump(args.output / "verification.json", verification) + dump(args.output / "plan.json", plan) + (args.output / "sources").mkdir() + for name in sources: + (args.output / "sources" / name).write_bytes((ROOT / name).read_bytes()) + fixtures, rows = [], [] + rng = random.Random(plan["seed"]) + for case in plan["cases"]: + source, output = tmp / "input.frames", tmp / "output.frames" + info = fixture(source, case["shape"], case["records"], plan["seed"]) + info["case"] = case["name"] + fixtures.append(info) + # Warm each strategy once. The following measurements use fresh processes. + for policy in plan["policies"]: + sample(native, source, output, case, policy) + assert digest(output) == info["expected_output_sha256"] + for repeat in range(plan["repeats"]): + order = list(plan["policies"]) + rng.shuffle(order) + for policy in order: + m = sample(native, source, output, case, policy) + assert m["accepted"] == m["emitted"] == case["records"] + assert m["input_bytes"] == info["input_bytes"] + assert m["output_bytes"] == info["expected_output_bytes"] + assert digest(output) == info["expected_output_sha256"] + rows.append({"case": case["name"], "variant": policy["name"], "repeat": repeat, **m}) + dump(args.output / "raw.json", rows) + dump(args.output / "fixtures.json", fixtures) + print(f'Completed {case["name"]}: {len(plan["policies"])} variants x {plan["repeats"]} trials.', flush=True) + dump(args.output / "summary.json", summarize(rows)) + with (args.output / "raw.csv").open("w") as out: + writer = csv.DictWriter(out, fieldnames=list(rows[0])) + writer.writeheader() + writer.writerows(rows) + # Detect accidental source edits during a measurement run. + assert sources == {name: digest(ROOT / name) for name in sources} + dump(args.output / "complete.json", {"samples": len(rows), "all_output_hashes_match": True, + "finished_utc": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())}) + print(args.output.resolve()) + + +if __name__ == "__main__": + main() diff --git a/research/experiments/003-json-fanout/.gitignore b/research/experiments/003-json-fanout/.gitignore new file mode 100644 index 0000000..c18dd8d --- /dev/null +++ b/research/experiments/003-json-fanout/.gitignore @@ -0,0 +1 @@ +__pycache__/ diff --git a/research/experiments/003-json-fanout/README.md b/research/experiments/003-json-fanout/README.md new file mode 100644 index 0000000..bab7ee4 --- /dev/null +++ b/research/experiments/003-json-fanout/README.md @@ -0,0 +1,164 @@ +# Experiment 003: actual JSON parsing and shared-buffer fan-out + +This apparatus extends the [single-consumer experiment](../002-buffer-retention/README.md) +with a real JSON parser and up to three independently paced consumers. It is C17 +code for comparing ordinary ownership policies, not the Pure execution core. + +## Dependency and semantics + +The MIT-licensed **yyjson 0.12.0** source and license are vendored unchanged at +commit [`8b4a38dc994a110abaec8a400615567bd996105f`](https://github.com/ibireme/yyjson/tree/8b4a38dc994a110abaec8a400615567bd996105f). +[UPSTREAM.json](vendor/yyjson/UPSTREAM.json) records source URLs and hashes, which +the runner verifies. Reproduction requires no dependency download. + +Input is newline-delimited JSON, with a maximum of 1 MiB per record excluding its +newline. A complete last JSON object may omit the newline. Blank lines are errors. +Each object must have string-valued selected fields (`body`, `tag`, `tag` by +default). Other members are parsed and validated too. Duplicate selected names +use yyjson's first matching member; the Python reference uses the same explicit +first-member rule. This is an experiment schema, not a general JSON application. + +All variants use `YYJSON_READ_INSITU`, with required zero padding. The parser +decodes strings into the input buffer. We extract offsets and byte lengths, then +immediately free document metadata. Queued views retain their input allocation +or a compact copy. No document node outlives the document. Unicode escapes, +embedded NULs and empty strings are compared as decoded UTF-8 bytes, not C strings. +The pinned [header](vendor/yyjson/yyjson.h) and [implementation](vendor/yyjson/yyjson.c) +are the authority for this lifetime behavior; the official +[API guide](https://ibireme.github.io/yyjson/doc/doxygen/html/api.html) explains +in-situ input ownership and the allocator interface. + +Output is an experimental multiplexed binary stream. Each selection has a +16-byte little-endian header: uint32 consumer index, uint32 byte length, uint64 +input sequence number, followed by the decoded selected bytes. Interleaving can +change with scheduling; each consumer's sequence and contents must match exactly. +The verifier checks separate per-consumer digests and counts rather than requiring +an identical whole-file interleaving. + +## Compared policies + +| Name | Choice | +|---|---| +| borrow | Every consumer keeps a view of the original input allocation. | +| copy | Copy each consumer's selection independently. | +| shared_copy | Copy each distinct selected range once; consumers of that range share the copy. | +| threshold2/8 | Copy when rounded input capacity / selected capacity reaches 2/8, sharing identical copies. | +| compact | Initially borrow; after a consumer finishes, compact a smaller final remaining view if the ratio reaches 2 and byte credits allow it. | +| copy_no_pool | Independent copies with buffer caching disabled, using the same capacity classes. | + +Identical selections mean the same offset and length in one parsed record. This +does not hash or intern equal string contents across unrelated fields/records. +The compact heuristic uses current ownership only, never future consumer times. +It does not move storage still referenced by multiple consumers. No particular +heuristic is claimed to be new or to require a language/compiler change. + +Every allocation has a reference count and a list of its queued views. A buffer +is charged once, even when several consumers reference it. Completion unlinks its +view; only the final owner can return the allocation to the pool. This is a +single-threaded implementation with non-atomic counts, not a concurrency proof. + +## Memory accounting + +One shared requested-byte budget includes: + +- Engine state, input read buffer, latency histograms and all consumer queue slots. +- Input allocations and simultaneous old/new allocations during reader growth. +- Compact selection allocations, including overlap with their original input. +- Parser allocations through yyjson's custom malloc/realloc/free callbacks. +- Allocation headers and cached idle allocations. + +Capacity classes are powers of two, starting at 64 bytes. The pool caches at most +16 idle blocks and at most one quarter of the total budget. Reuse requires an +exact class match; idle blocks are evicted before an allocation is refused. Parser, +input and selection allocations can reuse the same class after their owners +release them. This is a small baseline cache, not a claim about the best allocator. + +When byte credits run out, existing queued outputs are serviced before retrying. +This can occur inside the parser allocator. If no queued consumer can release +enough space, parsing fails explicitly within the cap. Reallocation charges both +old and new storage until the copy finishes. Shrinking may retain existing capacity. + +The budget is **not process RAM**: allocator overhead, executable/library pages, +other stack frames, kernel buffering and filesystem cache are outside it. Linux +current-image `VmHWM` is reported separately as approximate RSS; zero means the +RSS metric is unavailable on another OS. Peak SOURCE/OUTPUT/PARSER counters occur +at potentially different times and must not be summed as a simultaneous peak. + +## Scheduling and metrics + +Every variant uses the same event loop and per-consumer FIFO slot limit. At each +iteration, an eligible queue head is served before another input record. If any +queue is full or the byte budget prevents allocation, the earliest eligible +consumer is serviced, sleeping until its deadline if necessary. The input waits +until all consumers have room for the next record. This is ordinary backpressure. + +The corpus and delays are synthetic. Reads, JSON parsing, copies, writes, buffer +ownership and sleeps are real. Consumers run in one thread; independent delays +do not mean concurrent CPU execution. There are no external open-loop arrivals, +network connections, durable writes, or production latency targets. + +- `peak_reserved_bytes`: peak requested apparatus storage including idle cache. +- `source_peak_bytes`, `output_peak_bytes`, `parser_peak_bytes`: active charges by + role, including headers; cache reuse changes the role for the next lease. +- `*_byte_seconds`: charged active allocation bytes times lifetime, counted once + until the last reference releases a block. Fixed storage and idle cache time + are excluded. +- `selection_copy_bytes`: explicit policy copies only. Reader assembly/growth and + parser realloc copies have separate counters. yyjson's decoding, kernel and + other hidden data movements are not included in these counters. +- `parse_call_ns`: wall time inside `yyjson_read_opts`. Because allocator callbacks + can service consumers under pressure, this includes their work and waiting. + It is not isolated parser CPU time and is a subset of elapsed time. +- `elapsed_ns`: input, parsing, policies, consumers, instrumentation and buffer + cleanup. Excludes build, process startup, fixed setup and output verification. +- `cpu_ns`: process CPU clock for the same timed region. +- Per-consumer latency starts before its input record begins to be assembled and + ends after that consumer's output write. Time waiting upstream before that + start is excluded. P99 is a histogram upper bound, with at most 12.5% normal + bin rounding. These are not end-to-end service latency measurements. + +Five fresh-process trials per case/policy follow one warm-up per policy. Variant +order is randomized within each trial; case order is fixed. All measurements are +instrumented. The host CPU affinity is recorded, but thermals and power are not +controlled. Output is a cached temporary file with no `fsync`. Medians and ranges +describe this apparatus; no significance or universal performance claim is made. + +## Reproduction and verification + +From the repository root: + +```sh +python3 research/experiments/003-json-fanout/run.py --check-only +python3 research/experiments/003-json-fanout/run.py --output /tmp/pure-json-fanout-results +``` + +Use a new result directory; the runner refuses to overwrite one. `CC` can choose +a compiler. Native and ASan/UBSan checks run before measurements. LeakSanitizer +requires an environment without ptrace tracing; its diagnostics are not hidden. +Compiler flags, source snapshots (including the parser), hashes, input rules and +digests, every measurement and verification results are saved. Binary sizes +include debug information. `complete.json` marks successful completion. +The runner disables yyjson's unused writer, utilities and incremental-reader +modules using upstream build switches. The normal reader remains enabled for all +policies. Native measurement uses `-O2`; the sanitizer check uses `-O1`. + +Checks cover decoded byte equality with Python, 1/2/3 consumers, UTF-8 and escapes, +queue-slot reuse, shared-copy final ownership, final-owner compaction, malformed +JSON/schema, parser budget refusal, long records, partial-work cancellation, +SIGTERM and real output failure where `/dev/full` exists. These are functional +tests, not an exhaustive audit of yyjson or thread/device cancellation races. + +For direct use: + +```sh +cc -std=c17 -O2 -DYYJSON_DISABLE_WRITER=1 -DYYJSON_DISABLE_UTILS=1 -DYYJSON_DISABLE_INCR_READER=1 research/experiments/003-json-fanout/benchmark.c research/experiments/003-json-fanout/vendor/yyjson/yyjson.c -o /tmp/pure-json-fanout +/tmp/pure-json-fanout --policy threshold --ratio 2 < records.ndjson > selections.bin 2> metrics.json +``` + +Exit 0 means completion, 2 means failure, 3 means cancellation. Earlier completed +selections are not rolled back. Output failure or a signal during a write may +leave a partial last output frame. Cleanup releases all apparatus-owned buffers; +it is not an atomic-output or asynchronous backend guarantee. + +Measured results and their interpretation are in +[Korean report 008](../../../docs/research/008-json-fanout-results.md). diff --git a/research/experiments/003-json-fanout/benchmark.c b/research/experiments/003-json-fanout/benchmark.c new file mode 100644 index 0000000..474bc7f --- /dev/null +++ b/research/experiments/003-json-fanout/benchmark.c @@ -0,0 +1,391 @@ +#define _POSIX_C_SOURCE 200809L +#include <assert.h> +#include <errno.h> +#include <inttypes.h> +#include <signal.h> +#include <stddef.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include <unistd.h> +#include "vendor/yyjson/yyjson.h" + +enum { BRANCHES=3, CACHE=16, READ_SIZE=16384, MAX_JSON=1024*1024, HIST=512 }; +enum { SOURCE, OUTPUT, PARSER, KINDS }; +typedef struct Item Item; +typedef struct Block { + size_t capacity, refs; + uint64_t since; + unsigned kind; + Item *views; + _Alignas(max_align_t) unsigned char data[]; +} Block; +struct Item { + Block *block; + Item *prev, *next; + size_t offset, length; + uint64_t sequence, start, ready; +}; +typedef struct Queue { + Item *items; + size_t head, count, peak; + const char *key; + uint64_t hold, service, last, emitted, bytes, latency_sum, histogram[HIST]; +} Queue; +typedef struct Engine { + Queue q[BRANCHES]; + Block *cache[CACHE]; + unsigned char read_buffer[READ_SIZE]; + size_t read_at, read_end; + size_t budget, fixed, slots, fanout, reserved, active, cached, peak; + size_t by_kind[KINDS], peak_kind[KINDS]; + long double byte_ns[KINDS]; + uint64_t allocations[KINDS], reuses, accepted, emitted, input_bytes; + uint64_t selection_copies, reader_copies, parser_copies, parse_ns; + uint64_t budget_waits, slot_waits, compacted, compact_skipped, dedup_hits; + uint64_t sleep_ns, elapsed_ns, cpu_ns, cancel_after; + unsigned ratio; + int pool; + const char *policy, *status; +} Engine; +static volatile sig_atomic_t stopped; +static void stop(int sig) { (void)sig; stopped=1; } +static uint64_t ns(clockid_t clock) { + struct timespec t; + if (clock_gettime(clock,&t)) abort(); + return (uint64_t)t.tv_sec*UINT64_C(1000000000)+(uint64_t)t.tv_nsec; +} +static size_t rounded(size_t n) { size_t c=64; while(c<n)c*=2; return c; } +static size_t charge(const Block *b) { return sizeof(*b)+b->capacity; } +static void check(Engine *e) { + assert(e->active+e->cached==e->reserved); + assert(e->by_kind[0]+e->by_kind[1]+e->by_kind[2]==e->active); + assert(e->fixed+e->reserved<=e->budget); + if(e->reserved>e->peak)e->peak=e->reserved; + for(unsigned k=0;k<KINDS;++k)if(e->by_kind[k]>e->peak_kind[k])e->peak_kind[k]=e->by_kind[k]; +} +static void evict(Engine *e,size_t i) { + Block *b=e->cache[i]; if(!b)return; + assert(!b->refs && !b->views); + e->reserved-=charge(b); e->cached-=charge(b); free(b); e->cache[i]=NULL; +} +static Block *take(Engine *e,size_t n,unsigned kind) { + size_t capacity=rounded(n),need=sizeof(Block)+capacity; + Block *b=NULL; + if(e->pool)for(size_t i=0;i<CACHE;++i)if(e->cache[i] && e->cache[i]->capacity==capacity) { + b=e->cache[i]; e->cache[i]=NULL; e->cached-=need; ++e->reuses; break; + } + if(!b) { + for(size_t i=0;i<CACHE && need>e->budget-e->fixed-e->reserved;++i)evict(e,i); + if(need>e->budget-e->fixed-e->reserved)return NULL; + b=malloc(need); + if(!b){e->status="allocation_failed";return NULL;} + b->capacity=capacity; e->reserved+=need; ++e->allocations[kind]; + } + b->kind=kind;b->refs=1;b->views=NULL;b->since=ns(CLOCK_MONOTONIC); + e->active+=need;e->by_kind[kind]+=need;check(e);return b; +} +static void drop(Engine *e,Block *b) { + if(!b)return; + assert(b->refs); + if(--b->refs)return; + assert(!b->views); + size_t bytes=charge(b); + e->byte_ns[b->kind]+=(long double)bytes*(ns(CLOCK_MONOTONIC)-b->since); + e->active-=bytes;e->by_kind[b->kind]-=bytes; + if(e->pool && bytes<=e->budget/4-e->cached)for(size_t i=0;i<CACHE;++i)if(!e->cache[i]) { + e->cache[i]=b;e->cached+=bytes;check(e);return; + } + e->reserved-=bytes;free(b);check(e); +} +static void attach(Item *item) { + Block *b=item->block; + item->prev=NULL;item->next=b->views; + if(b->views)b->views->prev=item; + b->views=item; +} +static void detach(Item *item) { + if(item->prev)item->prev->next=item->next;else item->block->views=item->next; + if(item->next)item->next->prev=item->prev; + item->prev=item->next=NULL; +} +static void compact(Engine *e,Block *source) { + if(strcmp(e->policy,"compact") || source->kind!=SOURCE || source->refs!=1 || !source->views)return; + Item *item=source->views; + assert(!item->next); + if(source->capacity/rounded(item->length)<e->ratio)return; + /* Opportunistic only: never block or recurse from a completion callback. */ + Block *small=take(e,item->length,OUTPUT); + if(!small){++e->compact_skipped;return;} + memcpy(small->data,source->data+item->offset,item->length); + e->selection_copies+=item->length;++e->compacted; + detach(item);item->block=small;item->offset=0;attach(item);drop(e,source); +} +static uint64_t deadline(Queue *q) { + uint64_t ready=q->items[q->head].ready; + return ready>q->last+q->service?ready:q->last+q->service; +} +static int next_queue(Engine *e) { + int selected=-1;uint64_t soon=UINT64_MAX; + for(size_t k=0;k<e->fanout;++k)if(e->q[k].count && deadline(&e->q[k])<soon) { + selected=(int)k;soon=deadline(&e->q[k]); + } + return selected; +} +static int sleep_to(Engine *e,uint64_t until) { + uint64_t start=ns(CLOCK_MONOTONIC),now=start; + while(now<until && !stopped) { + uint64_t left=until-now; + struct timespec t={(time_t)(left/1000000000),(long)(left%1000000000)}; + if(nanosleep(&t,NULL) && errno!=EINTR){e->status="sleep_failed";return 0;} + now=ns(CLOCK_MONOTONIC); + } + e->sleep_ns+=now-start;return !stopped; +} +static unsigned bucket(uint64_t n) { + unsigned k=0;for(uint64_t x=n;x>1;x>>=1)++k; + return k<3?(unsigned)n:k*8+(unsigned)((n-(UINT64_C(1)<<k))>>(k-3)); +} +static uint64_t upper(unsigned b) { + unsigned k=b/8; + if(b<24)return b+1; + if(k>=63)return UINT64_MAX; + return (UINT64_C(1)<<k)+(uint64_t)(b%8+1)*(UINT64_C(1)<<(k-3)); +} +static int write_all(Engine *e,const void *data,size_t n) { + const unsigned char *p=data; + while(n && !stopped) { + ssize_t w=write(STDOUT_FILENO,p,n); + if(w<0 && errno==EINTR)continue; + if(w<=0){e->status="output_failed";return 0;} + p+=w;n-=(size_t)w; + } + return !stopped; +} +static int emit(Engine *e) { + int k=next_queue(e);assert(k>=0); + Queue *q=&e->q[k];Item *item=&q->items[q->head]; + if(!sleep_to(e,deadline(q)))return 0; + unsigned char header[16]; + for(unsigned i=0;i<4;++i){header[i]=(unsigned char)((unsigned)k>>(8*i));header[4+i]=(unsigned char)(item->length>>(8*i));} + for(unsigned i=0;i<8;++i)header[8+i]=(unsigned char)(item->sequence>>(8*i)); + if(!write_all(e,header,16) || !write_all(e,item->block->data+item->offset,item->length))return 0; + uint64_t now=ns(CLOCK_MONOTONIC),latency=now-item->start; + q->last=now;q->latency_sum+=latency;++q->histogram[bucket(latency)]; + ++q->emitted;q->bytes+=item->length;++e->emitted; + Block *b=item->block;size_t old_refs=b->refs; + detach(item);drop(e,b);item->block=NULL; + q->head=(q->head+1)%e->slots;--q->count; + if(old_refs>1)compact(e,b); + if(e->cancel_after && e->emitted>=e->cancel_after){e->status="cancelled";return 0;} + return !strcmp(e->status,"ok"); +} +static Block *acquire(Engine *e,size_t n,unsigned kind) { + for(;;) { + Block *b=take(e,n,kind);if(b)return b; + if(strcmp(e->status,"ok"))return NULL; + if(next_queue(e)<0){e->status="budget_too_small";return NULL;} + ++e->budget_waits;if(!emit(e))return NULL; + } +} +static void *parser_alloc(void *ctx,size_t n) { + Block *b=acquire(ctx,n,PARSER);return b?b->data:NULL; +} +static Block *from_data(void *p) {return (Block *)((unsigned char *)p-sizeof(Block));} +static void parser_free(void *ctx,void *p) {if(p)drop(ctx,from_data(p));} +static void *parser_realloc(void *ctx,void *p,size_t old,size_t n) { + if(!p)return parser_alloc(ctx,n); + Block *b=from_data(p);assert(b->refs==1 && b->kind==PARSER && old<=b->capacity); + if(n<=b->capacity)return p; + void *fresh=parser_alloc(ctx,n);if(!fresh)return NULL; + memcpy(fresh,p,old);((Engine *)ctx)->parser_copies+=old;parser_free(ctx,p);return fresh; +} +/* Bounded NDJSON reader, accepting a final complete JSON without a newline. */ +static Block *read_record(Engine *e,size_t *length) { + Block *b=acquire(e,256,SOURCE);if(!b)return NULL; + *length=0; + for(;;) { + if(stopped){drop(e,b);return NULL;} + if(e->read_at==e->read_end) { + ssize_t got=read(STDIN_FILENO,e->read_buffer,READ_SIZE); + if(got<0 && errno==EINTR)continue; + if(got<0){e->status="input_failed";drop(e,b);return NULL;} + if(!got){if(*length)break;drop(e,b);return NULL;} + e->read_at=0;e->read_end=(size_t)got;e->input_bytes+=(uint64_t)got; + } + unsigned char *p=e->read_buffer+e->read_at; + size_t available=e->read_end-e->read_at; + unsigned char *newline=memchr(p,'\n',available); + size_t amount=newline?(size_t)(newline-p):available; + if(amount>MAX_JSON-*length){e->status="record_too_large";drop(e,b);return NULL;} + size_t need=*length+amount+YYJSON_PADDING_SIZE; + if(need>b->capacity) { + Block *larger=acquire(e,need,SOURCE); + if(!larger){drop(e,b);return NULL;} + memcpy(larger->data,b->data,*length);e->reader_copies+=*length; + drop(e,b);b=larger; + } + memcpy(b->data+*length,p,amount);e->reader_copies+=amount; + *length+=amount;e->read_at+=amount+(newline?1:0); + if(newline)break; + } + memset(b->data+*length,0,YYJSON_PADDING_SIZE);return b; +} +static int submit(Engine *e,Block *source,size_t length,uint64_t start) { + size_t offsets[BRANCHES]={0},lengths[BRANCHES]={0}; + yyjson_alc alc={parser_alloc,parser_realloc,parser_free,e}; + yyjson_read_err error; + uint64_t before=ns(CLOCK_MONOTONIC); + yyjson_doc *doc=yyjson_read_opts((char *)source->data,length,YYJSON_READ_INSITU,&alc,&error); + e->parse_ns+=ns(CLOCK_MONOTONIC)-before; + if(!doc){if(!strcmp(e->status,"ok"))e->status="invalid_json";drop(e,source);return 0;} + yyjson_val *root=yyjson_doc_get_root(doc); + int valid=yyjson_is_obj(root); + for(size_t k=0;valid && k<e->fanout;++k) { + yyjson_val *value=yyjson_obj_get(root,e->q[k].key); + const char *str=yyjson_get_str(value);size_t size=yyjson_get_len(value); + uintptr_t address=(uintptr_t)str,base=(uintptr_t)source->data; + if(!yyjson_is_str(value) || address<base || address-base>length || size>length-(address-base))valid=0; + else{offsets[k]=(size_t)(address-base);lengths[k]=size;} + } + /* Only decoded string offsets/lengths survive. No DOM nodes escape. */ + yyjson_doc_free(doc); + if(!valid){e->status="invalid_schema";drop(e,source);return 0;} + Item pending[BRANCHES]={{0}}; + for(size_t k=0;k<e->fanout;++k) { + int copy=!strcmp(e->policy,"copy") || !strcmp(e->policy,"shared_copy") || + (!strcmp(e->policy,"threshold") && source->capacity/rounded(lengths[k])>=e->ratio); + int reuse=copy && (!strcmp(e->policy,"shared_copy") || !strcmp(e->policy,"threshold")); + Block *b=NULL;size_t offset=offsets[k]; + if(reuse)for(size_t j=0;j<k;++j)if(offsets[j]==offsets[k] && lengths[j]==lengths[k] && pending[j].block!=source) { + b=pending[j].block;++b->refs;offset=0;++e->dedup_hits;break; + } + if(!b && copy) { + b=acquire(e,lengths[k],OUTPUT); + if(!b) { + for(size_t j=0;j<k;++j)drop(e,pending[j].block); + drop(e,source);return 0; + } + memcpy(b->data,source->data+offset,lengths[k]);e->selection_copies+=lengths[k];offset=0; + } else if(!b){b=source;++b->refs;} + pending[k]=(Item){.block=b,.offset=offset,.length=lengths[k],.sequence=e->accepted,.start=start}; + } + uint64_t now=ns(CLOCK_MONOTONIC); + for(size_t k=0;k<e->fanout;++k) { + Queue *q=&e->q[k];assert(q->count<e->slots); + Item *item=&q->items[(q->head+q->count)%e->slots]; + *item=pending[k];item->ready=now+q->hold;attach(item);++q->count; + if(q->count>q->peak)q->peak=q->count; + } + ++e->accepted;drop(e,source);return 1; +} +static void run(Engine *e) { + while(!stopped && !strcmp(e->status,"ok")) { + int k=next_queue(e); + if(k>=0 && deadline(&e->q[k])<=ns(CLOCK_MONOTONIC)){if(!emit(e))break;continue;} + int full=0;for(size_t j=0;j<e->fanout;++j)if(e->q[j].count==e->slots)full=1; + if(full){++e->slot_waits;if(!emit(e))break;continue;} + size_t length;uint64_t start=ns(CLOCK_MONOTONIC); + Block *source=read_record(e,&length); + if(!source) { + while(!stopped && !strcmp(e->status,"ok") && next_queue(e)>=0)if(!emit(e))break; + break; + } + if(!submit(e,source,length,start))break; + } + if(stopped)e->status="cancelled"; +} +static uint64_t number(const char *s,uint64_t max) { + char *end;errno=0;unsigned long long n=strtoull(s,&end,10); + if(!*s || *s=='-' || *end || errno || n>max){fprintf(stderr,"invalid number\n");exit(2);} + return n; +} +static uint64_t rss(void) { +#if defined(__linux__) + FILE *f=fopen("/proc/self/status","r");if(!f)return 0; + char line[256];unsigned long long kib=0; + while(fgets(line,sizeof(line),f))if(sscanf(line,"VmHWM: %llu kB",&kib)==1)break; + fclose(f);return (uint64_t)kib*1024; +#else + return 0; +#endif +} +int main(int argc,char **argv) { + _Static_assert(sizeof(Block)==offsetof(Block,data),"aligned block header"); + Engine storage={0},*e=&storage; + e->policy="borrow";e->status="ok";e->slots=64;e->fanout=3;e->budget=8*1024*1024;e->ratio=2;e->pool=1; + e->q[0].key="body";e->q[1].key=e->q[2].key="tag"; + e->q[1].hold=5000000;e->q[2].hold=8000000; + for(int i=1;i<argc;i+=2) { + if(i+1==argc){fprintf(stderr,"option needs value\n");return 2;} + const char *key=argv[i],*value=argv[i+1]; + if(!strcmp(key,"--policy"))e->policy=value; + else if(!strcmp(key,"--budget"))e->budget=(size_t)number(value,1073741824); + else if(!strcmp(key,"--slots"))e->slots=(size_t)number(value,4096); + else if(!strcmp(key,"--fanout"))e->fanout=(size_t)number(value,BRANCHES); + else if(!strcmp(key,"--ratio"))e->ratio=(unsigned)number(value,1024); + else if(!strcmp(key,"--pool"))e->pool=(int)number(value,1); + else if(!strcmp(key,"--cancel-after"))e->cancel_after=number(value,UINT64_MAX); + else { + int recognized=0; + for(size_t k=0;k<BRANCHES;++k) { + char option[32]; + snprintf(option,sizeof(option),"--key%zu",k); + if(!strcmp(key,option)){e->q[k].key=value;recognized=1;} + snprintf(option,sizeof(option),"--hold%zu-us",k); + if(!strcmp(key,option)){e->q[k].hold=number(value,10000000)*1000;recognized=1;} + snprintf(option,sizeof(option),"--service%zu-us",k); + if(!strcmp(key,option)){e->q[k].service=number(value,10000000)*1000;recognized=1;} + } + if(!recognized){fprintf(stderr,"unknown option\n");return 2;} + } + } + if(!e->slots || !e->fanout || e->ratio<2 || (strcmp(e->policy,"borrow") && strcmp(e->policy,"copy") && + strcmp(e->policy,"shared_copy") && strcmp(e->policy,"threshold") && strcmp(e->policy,"compact"))) { + fprintf(stderr,"invalid configuration\n");return 2; + } + e->fixed=sizeof(*e)+e->fanout*e->slots*sizeof(Item); + if(e->fixed>e->budget){fprintf(stderr,"budget below metadata\n");return 2;} + for(size_t k=0;k<e->fanout;++k) { + e->q[k].items=calloc(e->slots,sizeof(Item)); + if(!e->q[k].items){for(size_t j=0;j<k;++j)free(e->q[j].items);return 2;} + } + signal(SIGINT,stop);signal(SIGTERM,stop);signal(SIGPIPE,SIG_IGN); + uint64_t start=ns(CLOCK_MONOTONIC),cpu=ns(CLOCK_PROCESS_CPUTIME_ID); + run(e); + size_t live_at_stop=e->active; + for(size_t k=0;k<e->fanout;++k) { + Queue *q=&e->q[k]; + while(q->count){Item *item=&q->items[q->head];detach(item);drop(e,item->block);q->head=(q->head+1)%e->slots;--q->count;} + } + for(size_t i=0;i<CACHE;++i)evict(e,i); + assert(!e->active && !e->reserved); + e->elapsed_ns=ns(CLOCK_MONOTONIC)-start;e->cpu_ns=ns(CLOCK_PROCESS_CPUTIME_ID)-cpu; + fprintf(stderr,"{\"status\":\"%s\",\"policy\":\"%s\",\"parser_version\":\"%s\",\"budget_bytes\":%zu," + "\"fixed_bytes\":%zu,\"peak_reserved_bytes\":%zu,\"source_peak_bytes\":%zu,\"output_peak_bytes\":%zu," + "\"parser_peak_bytes\":%zu,\"rss_peak_bytes\":%" PRIu64 ",\"elapsed_ns\":%" PRIu64 ",\"cpu_ns\":%" PRIu64 "," + "\"parse_call_ns\":%" PRIu64 ",\"accepted\":%" PRIu64 ",\"emitted\":%" PRIu64 ",\"input_bytes\":%" PRIu64 "," + "\"selection_copy_bytes\":%" PRIu64 ",\"reader_copy_bytes\":%" PRIu64 ",\"parser_realloc_copy_bytes\":%" PRIu64 "," + "\"source_byte_seconds\":%.6Lf,\"output_byte_seconds\":%.6Lf,\"parser_byte_seconds\":%.6Lf," + "\"source_allocations\":%" PRIu64 ",\"output_allocations\":%" PRIu64 ",\"parser_allocations\":%" PRIu64 "," + "\"reuses\":%" PRIu64 ",\"budget_waits\":%" PRIu64 ",\"slot_waits\":%" PRIu64 "," + "\"compacted\":%" PRIu64 ",\"compact_skipped\":%" PRIu64 ",\"dedup_hits\":%" PRIu64 ",\"sleep_ns\":%" PRIu64 "," + "\"live_at_stop_bytes\":%zu,\"unreleased_buffer_bytes\":%zu,\"queues\":[", + e->status,e->policy,YYJSON_VERSION_STRING,e->budget,e->fixed,e->fixed+e->peak,e->peak_kind[SOURCE], + e->peak_kind[OUTPUT],e->peak_kind[PARSER],rss(),e->elapsed_ns,e->cpu_ns,e->parse_ns,e->accepted,e->emitted, + e->input_bytes,e->selection_copies,e->reader_copies,e->parser_copies,e->byte_ns[SOURCE]/1e9L, + e->byte_ns[OUTPUT]/1e9L,e->byte_ns[PARSER]/1e9L,e->allocations[SOURCE],e->allocations[OUTPUT], + e->allocations[PARSER],e->reuses,e->budget_waits,e->slot_waits,e->compacted,e->compact_skipped, + e->dedup_hits,e->sleep_ns,live_at_stop,e->reserved); + for(size_t k=0;k<e->fanout;++k) { + Queue *q=&e->q[k];uint64_t target=q->emitted-q->emitted/100,sum=0,p99=0; + for(unsigned b=0;q->emitted && b<HIST;++b){sum+=q->histogram[b];if(sum>=target){p99=upper(b);break;}} + fprintf(stderr,"%s{\"emitted\":%" PRIu64 ",\"bytes\":%" PRIu64 ",\"peak_count\":%zu," + "\"latency_mean_ns\":%.3f,\"latency_p99_upper_ns\":%" PRIu64 "}",k?",":"",q->emitted,q->bytes,q->peak, + q->emitted?(double)q->latency_sum/q->emitted:0,p99); + free(q->items); + } + fprintf(stderr,"]}\n");return !strcmp(e->status,"ok")?0:!strcmp(e->status,"cancelled")?3:2; +} diff --git a/research/experiments/003-json-fanout/plan.json b/research/experiments/003-json-fanout/plan.json new file mode 100644 index 0000000..60c179b --- /dev/null +++ b/research/experiments/003-json-fanout/plan.json @@ -0,0 +1,32 @@ +{ + "version": 1, + "written_before_measurement": true, + "seed": 20260923, + "repeats": 5, + "policies": [ + {"name": "borrow", "policy": "borrow"}, + {"name": "copy", "policy": "copy"}, + {"name": "shared_copy", "policy": "shared_copy"}, + {"name": "threshold2", "policy": "threshold", "ratio": 2}, + {"name": "threshold8", "policy": "threshold", "ratio": 8}, + {"name": "compact", "policy": "compact", "ratio": 2}, + {"name": "copy_no_pool", "policy": "copy", "pool": 0} + ], + "cases": [ + {"name": "one_slow", "shape": "large", "records": 1024, "keys": ["tag"], "hold_us": [8000], "service_us": [0], "budget": 8388608, "slots": 64}, + {"name": "three_distinct_speeds", "shape": "large", "records": 1024, "keys": ["body", "tag", "tag"], "hold_us": [0, 5000, 8000], "service_us": [0, 0, 0], "budget": 8388608, "slots": 64}, + {"name": "same_large_field", "shape": "large", "records": 1024, "keys": ["body", "body", "body"], "hold_us": [0, 5000, 8000], "service_us": [0, 0, 0], "budget": 8388608, "slots": 64}, + {"name": "slow_large_field", "shape": "large", "records": 1024, "keys": ["tag", "tag", "body"], "hold_us": [0, 5000, 8000], "service_us": [0, 0, 0], "budget": 8388608, "slots": 64}, + {"name": "mixed_tight", "shape": "mixed", "records": 1024, "keys": ["body", "tag", "tag"], "hold_us": [0, 5000, 8000], "service_us": [0, 0, 0], "budget": 2097152, "slots": 64}, + {"name": "metadata_heavy", "shape": "metadata", "records": 512, "keys": ["body", "tag", "tag"], "hold_us": [0, 5000, 8000], "service_us": [0, 0, 0], "budget": 2097152, "slots": 64} + ], + "expectations": [ + "A slow small-field consumer can retain the input after a fast large-field consumer finishes.", + "Sharing identical compact copies can remove duplicate per-consumer copies without a new runtime.", + "Late compaction may save copied bytes or fail to beat early size-based copying; all remaining owners matter.", + "Parser temporary memory and reader growth must be charged, even when retained selections are small.", + "No novel-policy advantage or production service SLO is presumed." + ], + "comparison_rule": "Report all fixed presets; exploratory measurements, no trained/held-out policy or significance claim.", + "limits": "Real yyjson parser and actual bytes, but synthetic NDJSON corpus and sink delays, three synchronous consumers in one event loop, no open-loop arrivals, thread races, durable output, or independent parser comparison." +} diff --git a/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/complete.json b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/complete.json new file mode 100644 index 0000000..5bde4c3 --- /dev/null +++ b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/complete.json @@ -0,0 +1,5 @@ +{ + "samples": 210, + "all_branch_outputs_match": true, + "finished_utc": "2026-09-22T13:11:31Z" +} diff --git a/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/environment.json b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/environment.json new file mode 100644 index 0000000..3aa2455 --- /dev/null +++ b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/environment.json @@ -0,0 +1,96 @@ +{ + "platform": "Linux-6.18.39+rpt-rpi-2712-aarch64-with-glibc2.41", + "machine": "aarch64", + "python": "3.14.7", + "compiler": "cc (Debian 14.2.0-19) 14.2.0\nCopyright (C) 2024 Free Software Foundation, Inc.\nThis is free software; see the source for copying conditions. There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n", + "cpu_affinity": 0, + "builds": [ + { + "command": [ + "cc", + "-std=c17", + "-O2", + "-g", + "-Wall", + "-Wextra", + "-Wpedantic", + "-Werror", + "-DYYJSON_DISABLE_WRITER=1", + "-DYYJSON_DISABLE_UTILS=1", + "-DYYJSON_DISABLE_INCR_READER=1", + "/home/eunhhu/work/pure/research/experiments/003-json-fanout/benchmark.c", + "/home/eunhhu/work/pure/research/experiments/003-json-fanout/vendor/yyjson/yyjson.c", + "-o", + "/tmp/pure-fanout-i4xs4fhg/benchmark" + ], + "stderr": "", + "sha256": "adfd209a990abe11bfd93337c56eb2c9266d6529899fc91cd2f3844c93ef67db", + "size_bytes": 842056, + "build_wall_ns": 15110774980 + }, + { + "command": [ + "cc", + "-std=c17", + "-O2", + "-g", + "-Wall", + "-Wextra", + "-Wpedantic", + "-Werror", + "-DYYJSON_DISABLE_WRITER=1", + "-DYYJSON_DISABLE_UTILS=1", + "-DYYJSON_DISABLE_INCR_READER=1", + "-O1", + "-fsanitize=address,undefined", + "-fno-omit-frame-pointer", + "/home/eunhhu/work/pure/research/experiments/003-json-fanout/benchmark.c", + "/home/eunhhu/work/pure/research/experiments/003-json-fanout/vendor/yyjson/yyjson.c", + "-o", + "/tmp/pure-fanout-i4xs4fhg/benchmark-sanitized" + ], + "stderr": "", + "sha256": "c7516cf3c1c18463c72b96a75d70cc326a0ff43873fa278e0b13fb94d6e180d2", + "size_bytes": 5441872, + "build_wall_ns": 160671462690 + } + ], + "source_sha256": { + "benchmark.c": "c9ccc4544ef296eb59a8d071ad7fb25afc4b3fe5a94a8978c415c557b8ea8d0d", + "run.py": "7ab64e454f3ce0a48c20a477d8924b06ece6ad29a442d0bb49f48b5a6ecffe49", + "plan.json": "69f1258b3afd616404c6853526a5fbb6523d406eb43db479fd4be43905bc9f5d", + "vendor/yyjson/UPSTREAM.json": "eab60a505ff59ca1f3271792c16aa57d61f596cb5c57ff04dcff15d22ba29cee", + "vendor/yyjson/yyjson.c": "ac2e9bbb2e2d9149d90878d40506a1d624fa0b33c979a11b61075c54782c6d6a", + "vendor/yyjson/yyjson.h": "175867c5493a5df648cec566717fa1c29aa2f6096f5f0cf1efad0b65e1f6d7b3", + "vendor/yyjson/LICENSE": "45e384d3d52c73cba3a64d6e6c25d47cd738cd8a55c30629e3201046eda62947" + }, + "upstream": { + "project": "yyjson", + "version": "0.12.0", + "commit": "8b4a38dc994a110abaec8a400615567bd996105f", + "license": "MIT", + "files": { + "yyjson.c": { + "url": "https://raw.githubusercontent.com/ibireme/yyjson/8b4a38dc994a110abaec8a400615567bd996105f/src/yyjson.c", + "sha256": "ac2e9bbb2e2d9149d90878d40506a1d624fa0b33c979a11b61075c54782c6d6a", + "bytes": 410813 + }, + "yyjson.h": { + "url": "https://raw.githubusercontent.com/ibireme/yyjson/8b4a38dc994a110abaec8a400615567bd996105f/src/yyjson.h", + "sha256": "175867c5493a5df648cec566717fa1c29aa2f6096f5f0cf1efad0b65e1f6d7b3", + "bytes": 322407 + }, + "LICENSE": { + "url": "https://raw.githubusercontent.com/ibireme/yyjson/8b4a38dc994a110abaec8a400615567bd996105f/LICENSE", + "sha256": "45e384d3d52c73cba3a64d6e6c25d47cd738cd8a55c30629e3201046eda62947", + "bytes": 1084 + } + } + }, + "timing": "I/O, parsing, selection, consumers, instrumentation, cleanup; excludes setup/build/verification", + "parse_call_ns": "wall duration inside yyjson_read_opts including allocator backpressure and serviced consumers", + "rss": "Linux current-image VmHWM approximate; zero means unavailable on other OSes", + "limits": "synthetic closed-loop arrivals/delays; one thread; uncontrolled thermals/power; cached file I/O; no fsync", + "started_utc": "2026-09-22T13:10:45Z", + "cpuinfo": "processor\t: 0\nBogoMIPS\t: 108.00\nFeatures\t: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp\nCPU implementer\t: 0x41\nCPU architecture: 8\nCPU variant\t: 0x4\nCPU part\t: 0xd0b\nCPU revision\t: 1\n\nprocessor\t: 1\nBogoMIPS\t: 108.00\nFeatures\t: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp\nCPU implementer\t: 0x41\nCPU architecture: 8\nCPU variant\t: 0x4\nCPU part\t: 0xd0b\nCPU revision\t: 1\n\nprocessor\t: 2\nBogoMIPS\t: 108.00\nFeatures\t: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp\nCPU implementer\t: 0x41\nCPU architecture: 8\nCPU variant\t: 0x4\nCPU part\t: 0xd0b\nCPU revision\t: 1\n\nprocessor\t: 3\nBogoMIPS\t: 108.00\nFeatures\t: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp\nCPU implementer\t: 0x41\nCPU architecture: 8\nCPU variant\t: 0x4\nCPU part\t: 0xd0b\nCPU revision\t: 1\n\nRevision\t: d04171\nSerial\t\t: d3ba8e625dbe42ac\nModel\t\t: Raspberry Pi 5 Model B Rev 1.1\n" +} diff --git a/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/fixtures.json b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/fixtures.json new file mode 100644 index 0000000..dbd23e2 --- /dev/null +++ b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/fixtures.json @@ -0,0 +1,128 @@ +[ + { + "case": "one_slow", + "seed": 20260923, + "records": 1024, + "input_bytes": 42083156, + "input_sha256": "ebd22d4a12c1369ce27459e454df0a93545ca816fe13a82401160130772a3bfd", + "keys": [ + "tag" + ], + "output_bytes_by_branch": [ + 57344 + ], + "output_sha256_by_branch": [ + "1acead91fea700e5a94dc4285a37251f71876a0b505d2638cae3b9abf99915dd" + ] + }, + { + "case": "three_distinct_speeds", + "seed": 20260923, + "records": 1024, + "input_bytes": 42083156, + "input_sha256": "ebd22d4a12c1369ce27459e454df0a93545ca816fe13a82401160130772a3bfd", + "keys": [ + "body", + "tag", + "tag" + ], + "output_bytes_by_branch": [ + 33554432, + 57344, + 57344 + ], + "output_sha256_by_branch": [ + "a48ec20b430e737841289f18d08572d3630f92bac4778c7b0aa5d23acf5361bd", + "1acead91fea700e5a94dc4285a37251f71876a0b505d2638cae3b9abf99915dd", + "1acead91fea700e5a94dc4285a37251f71876a0b505d2638cae3b9abf99915dd" + ] + }, + { + "case": "same_large_field", + "seed": 20260923, + "records": 1024, + "input_bytes": 42083156, + "input_sha256": "ebd22d4a12c1369ce27459e454df0a93545ca816fe13a82401160130772a3bfd", + "keys": [ + "body", + "body", + "body" + ], + "output_bytes_by_branch": [ + 33554432, + 33554432, + 33554432 + ], + "output_sha256_by_branch": [ + "a48ec20b430e737841289f18d08572d3630f92bac4778c7b0aa5d23acf5361bd", + "a48ec20b430e737841289f18d08572d3630f92bac4778c7b0aa5d23acf5361bd", + "a48ec20b430e737841289f18d08572d3630f92bac4778c7b0aa5d23acf5361bd" + ] + }, + { + "case": "slow_large_field", + "seed": 20260923, + "records": 1024, + "input_bytes": 42083156, + "input_sha256": "ebd22d4a12c1369ce27459e454df0a93545ca816fe13a82401160130772a3bfd", + "keys": [ + "tag", + "tag", + "body" + ], + "output_bytes_by_branch": [ + 57344, + 57344, + 33554432 + ], + "output_sha256_by_branch": [ + "1acead91fea700e5a94dc4285a37251f71876a0b505d2638cae3b9abf99915dd", + "1acead91fea700e5a94dc4285a37251f71876a0b505d2638cae3b9abf99915dd", + "a48ec20b430e737841289f18d08572d3630f92bac4778c7b0aa5d23acf5361bd" + ] + }, + { + "case": "mixed_tight", + "seed": 20260923, + "records": 1024, + "input_bytes": 49877076, + "input_sha256": "3bba97318415a0c32a6eb61b04b7d73214ffcca90ae00469b45c2db6b28f600c", + "keys": [ + "body", + "tag", + "tag" + ], + "output_bytes_by_branch": [ + 26757376, + 57344, + 57344 + ], + "output_sha256_by_branch": [ + "89a5a0467e4473dd4afb7307366793ba4840463a6e9d44cd1f13090f2775bac9", + "f9bdd5932d1e9201f9dfeaf5e85d14572740d5a13dd31491654f75dd4999b5cf", + "f9bdd5932d1e9201f9dfeaf5e85d14572740d5a13dd31491654f75dd4999b5cf" + ] + }, + { + "case": "metadata_heavy", + "seed": 20260923, + "records": 512, + "input_bytes": 5259666, + "input_sha256": "b3ddc9f18b946c466f3b5819538de80e062f734fcba70d2ed578445b0bd5392f", + "keys": [ + "body", + "tag", + "tag" + ], + "output_bytes_by_branch": [ + 262144, + 28672, + 28672 + ], + "output_sha256_by_branch": [ + "9aa5e0f4c17a62255942c9d23be621e437630e5fa34ef908d7c88033e132d700", + "a65807b99ca84b43058312cfdd6892e252bb47585f37f257f7dae2dcd7ee4be2", + "a65807b99ca84b43058312cfdd6892e252bb47585f37f257f7dae2dcd7ee4be2" + ] + } +] diff --git a/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/plan.json b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/plan.json new file mode 100644 index 0000000..3ee7b4a --- /dev/null +++ b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/plan.json @@ -0,0 +1,177 @@ +{ + "version": 1, + "written_before_measurement": true, + "seed": 20260923, + "repeats": 5, + "policies": [ + { + "name": "borrow", + "policy": "borrow" + }, + { + "name": "copy", + "policy": "copy" + }, + { + "name": "shared_copy", + "policy": "shared_copy" + }, + { + "name": "threshold2", + "policy": "threshold", + "ratio": 2 + }, + { + "name": "threshold8", + "policy": "threshold", + "ratio": 8 + }, + { + "name": "compact", + "policy": "compact", + "ratio": 2 + }, + { + "name": "copy_no_pool", + "policy": "copy", + "pool": 0 + } + ], + "cases": [ + { + "name": "one_slow", + "shape": "large", + "records": 1024, + "keys": [ + "tag" + ], + "hold_us": [ + 8000 + ], + "service_us": [ + 0 + ], + "budget": 8388608, + "slots": 64 + }, + { + "name": "three_distinct_speeds", + "shape": "large", + "records": 1024, + "keys": [ + "body", + "tag", + "tag" + ], + "hold_us": [ + 0, + 5000, + 8000 + ], + "service_us": [ + 0, + 0, + 0 + ], + "budget": 8388608, + "slots": 64 + }, + { + "name": "same_large_field", + "shape": "large", + "records": 1024, + "keys": [ + "body", + "body", + "body" + ], + "hold_us": [ + 0, + 5000, + 8000 + ], + "service_us": [ + 0, + 0, + 0 + ], + "budget": 8388608, + "slots": 64 + }, + { + "name": "slow_large_field", + "shape": "large", + "records": 1024, + "keys": [ + "tag", + "tag", + "body" + ], + "hold_us": [ + 0, + 5000, + 8000 + ], + "service_us": [ + 0, + 0, + 0 + ], + "budget": 8388608, + "slots": 64 + }, + { + "name": "mixed_tight", + "shape": "mixed", + "records": 1024, + "keys": [ + "body", + "tag", + "tag" + ], + "hold_us": [ + 0, + 5000, + 8000 + ], + "service_us": [ + 0, + 0, + 0 + ], + "budget": 2097152, + "slots": 64 + }, + { + "name": "metadata_heavy", + "shape": "metadata", + "records": 512, + "keys": [ + "body", + "tag", + "tag" + ], + "hold_us": [ + 0, + 5000, + 8000 + ], + "service_us": [ + 0, + 0, + 0 + ], + "budget": 2097152, + "slots": 64 + } + ], + "expectations": [ + "A slow small-field consumer can retain the input after a fast large-field consumer finishes.", + "Sharing identical compact copies can remove duplicate per-consumer copies without a new runtime.", + "Late compaction may save copied bytes or fail to beat early size-based copying; all remaining owners matter.", + "Parser temporary memory and reader growth must be charged, even when retained selections are small.", + "No novel-policy advantage or production service SLO is presumed." + ], + "comparison_rule": "Report all fixed presets; exploratory measurements, no trained/held-out policy or significance claim.", + "limits": "Real yyjson parser and actual bytes, but synthetic NDJSON corpus and sink delays, three synchronous consumers in one event loop, no open-loop arrivals, thread races, durable output, or independent parser comparison." +} diff --git a/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/raw.csv b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/raw.csv new file mode 100644 index 0000000..d2b9a02 --- /dev/null +++ b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/raw.csv @@ -0,0 +1,211 @@ +case,variant,repeat,status,policy,parser_version,budget_bytes,fixed_bytes,peak_reserved_bytes,source_peak_bytes,output_peak_bytes,parser_peak_bytes,rss_peak_bytes,elapsed_ns,cpu_ns,parse_call_ns,accepted,emitted,input_bytes,selection_copy_bytes,reader_copy_bytes,parser_realloc_copy_bytes,source_byte_seconds,output_byte_seconds,parser_byte_seconds,source_allocations,output_allocations,parser_allocations,reuses,budget_waits,slot_waits,compacted,compact_skipped,dedup_hits,sleep_ns,live_at_stop_bytes,unreleased_buffer_bytes,queues
+one_slow,threshold2,0,ok,threshold,0.12.0,8388608,33536,303072,98400,7168,131120,1835008,131703634,34750648,21989760,1024,1024,42083156,57344,75711296,0,1842.615404,919.75921,2883.244752,9,64,1,6056,0,16,0,0,0,97097912,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8051720.034, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,compact,0,ok,compact,0.12.0,8388608,33536,4427696,4230192,0,131120,5537792,131996119,38004572,22434299,1024,1024,42083156,0,75711296,0,540791.270719,0.0,2928.256675,72,0,1,5033,0,26,0,0,0,94192606,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8057605.331, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,borrow,0,ok,borrow,0.12.0,8388608,33536,4427696,4230192,0,131120,5521408,132124751,37612015,22444229,1024,1024,42083156,0,75711296,0,540845.471315,0.0,2930.090388,72,0,1,5033,0,53,0,0,0,94791711,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8058299.849, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,threshold8,0,ok,threshold,0.12.0,8388608,33536,303072,98400,7168,131120,1818624,131620844,34446035,21905479,1024,1024,42083156,57344,75711296,0,1832.609103,920.078119,2872.388672,9,64,1,6056,0,16,0,0,0,97293567,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8054286.008, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,copy_no_pool,0,ok,copy,0.12.0,8388608,33536,237296,98400,7168,131120,1835008,132233158,41767998,24756316,1024,1024,42083156,57344,75711296,0,2069.543688,920.140424,2901.308237,4082,1024,1024,0,0,19,0,0,0,90619067,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8059175.662, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,copy,0,ok,copy,0.12.0,8388608,33536,303072,98400,7168,131120,1818624,131600270,34455850,21964978,1024,1024,42083156,57344,75711296,0,1832.537919,920.025416,2880.380829,9,64,1,6056,0,16,0,0,0,97270417,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8053796.131, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,shared_copy,0,ok,shared_copy,0.12.0,8388608,33536,303072,98400,7168,131120,1802240,131715584,34456703,21940218,1024,1024,42083156,57344,75711296,0,1833.007769,920.07894,2877.016945,9,64,1,6056,0,16,0,0,0,97393619,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8054276.953, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,compact,1,ok,compact,0.12.0,8388608,33536,4427696,4230192,0,131120,5537792,132171843,38070312,22523797,1024,1024,42083156,0,75711296,0,540815.06589,0.0,2937.269732,72,0,1,5033,0,40,0,0,0,94338529,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8057936.641, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,copy_no_pool,1,ok,copy,0.12.0,8388608,33536,237296,98400,7168,131120,1835008,132199048,42202499,24805054,1024,1024,42083156,57344,75711296,0,2084.967873,920.132302,2905.942804,4082,1024,1024,0,0,29,0,0,0,90146770,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8059478.906, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,shared_copy,1,ok,shared_copy,0.12.0,8388608,33536,303072,98400,7168,131120,1818624,131708165,34804961,22044118,1024,1024,42083156,57344,75711296,0,1844.634105,919.759432,2890.857973,9,64,1,6056,0,16,0,0,0,97053198,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8051751.524, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,threshold8,1,ok,threshold,0.12.0,8388608,33536,303072,98400,7168,131120,1818624,131798127,34803856,22044512,1024,1024,42083156,57344,75711296,0,1846.36305,919.612987,2891.382584,9,64,1,6056,0,16,0,0,0,97156768,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8050483.774, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,borrow,1,ok,borrow,0.12.0,8388608,33536,4427696,4230192,0,131120,5521408,131976979,38591495,22573964,1024,1024,42083156,0,75711296,0,540860.949553,0.0,2940.513903,72,0,1,5033,0,28,0,0,0,93626665,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8058679.423, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,copy,1,ok,copy,0.12.0,8388608,33536,303072,98400,7168,131120,1818624,131752053,34888537,21974890,1024,1024,42083156,57344,75711296,0,1845.194241,919.599974,2880.87266,9,64,1,6056,0,17,0,0,0,97030621,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8050419.036, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,threshold2,1,ok,threshold,0.12.0,8388608,33536,303072,98400,7168,131120,1818624,131720609,34747849,21999728,1024,1024,42083156,57344,75711296,0,1843.805295,919.628727,2884.923744,9,64,1,6056,0,16,0,0,0,97113750,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8050578.244, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,copy,2,ok,copy,0.12.0,8388608,33536,303072,98400,7168,131120,1818624,131735071,34877739,22030534,1024,1024,42083156,57344,75711296,0,1847.409016,919.636562,2888.89668,9,64,1,6056,0,16,0,0,0,96987832,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8050770.82, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,compact,2,ok,compact,0.12.0,8388608,33536,4427696,4230192,0,131120,5537792,132186905,38709650,22486562,1024,1024,42083156,0,75711296,0,540826.901328,0.0,2931.839266,72,0,1,5033,0,36,0,0,0,93736446,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8058254.455, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,shared_copy,2,ok,shared_copy,0.12.0,8388608,33536,303072,98400,7168,131120,1835008,134003964,36820353,22141327,1024,1024,42083156,57344,75711296,0,1907.646695,924.396419,2903.071145,9,116,1,6004,0,25,0,0,0,97345374,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8093864.112, ""latency_p99_upper_ns"": 9437184}]"
+one_slow,threshold2,2,ok,threshold,0.12.0,8388608,33536,303072,98400,7168,131120,1818624,132093280,37140317,22338927,1024,1024,42083156,57344,75711296,0,1928.638533,919.864631,2930.310014,9,68,1,6052,0,20,0,0,0,95013211,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8054865.09, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,borrow,2,ok,borrow,0.12.0,8388608,33536,4427696,4230192,0,131120,5554176,132469040,41862764,22964342,1024,1024,42083156,0,75711296,0,541099.43903,0.0,2986.938382,73,0,1,5032,0,49,0,0,0,90878204,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8063020.332, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,copy_no_pool,2,ok,copy,0.12.0,8388608,33536,237296,98400,7168,131120,1802240,137450461,46306762,25720817,1024,1024,42083156,57344,75711296,0,2217.245474,934.97033,2945.941354,4082,1024,1024,0,0,23,0,0,0,91429169,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8191749.104, ""latency_p99_upper_ns"": 11534336}]"
+one_slow,threshold8,2,ok,threshold,0.12.0,8388608,33536,303072,98400,7168,131120,1818624,131976855,36997295,22056693,1024,1024,42083156,57344,75711296,0,1904.528214,920.059714,2891.295258,9,65,1,6055,0,21,0,0,0,95230128,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8056258.001, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,threshold2,3,ok,threshold,0.12.0,8388608,33536,303072,98400,7168,131120,1818624,132144262,36810738,22394390,1024,1024,42083156,57344,75711296,0,1914.610493,920.080986,2937.462741,9,71,1,6049,0,39,0,0,0,95437850,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8056316.891, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,threshold8,3,ok,threshold,0.12.0,8388608,33536,303072,98400,7168,131120,1818624,131627799,34748983,22050963,1024,1024,42083156,57344,75711296,0,1845.118437,920.020651,2891.313221,9,64,1,6056,0,19,0,0,0,96996391,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8054019.278, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,compact,3,ok,compact,0.12.0,8388608,33536,4427696,4230192,0,131120,5537792,132093080,38378509,22460168,1024,1024,42083156,0,75711296,0,540907.798619,0.0,2928.186919,72,0,1,5033,0,43,0,0,0,93965206,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8059384.654, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,copy_no_pool,3,ok,copy,0.12.0,8388608,33536,237296,98400,7168,131120,1802240,132246841,41768202,24673720,1024,1024,42083156,57344,75711296,0,2066.312998,920.19798,2896.434244,4082,1024,1024,0,0,16,0,0,0,90608121,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8059680.607, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,copy,3,ok,copy,0.12.0,8388608,33536,303072,98400,7168,131120,1818624,131689453,35243759,22012604,1024,1024,42083156,57344,75711296,0,1857.757504,919.947028,2887.51415,9,68,1,6052,0,27,0,0,0,96622803,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8053765.222, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,shared_copy,3,ok,shared_copy,0.12.0,8388608,33536,303072,98400,7168,131120,1802240,132103712,35248408,22004780,1024,1024,42083156,57344,75711296,0,1858.44117,919.973445,2885.070598,9,73,1,6047,0,22,0,0,0,97018510,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8054006.321, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,borrow,3,ok,borrow,0.12.0,8388608,33536,4427696,4230192,0,131120,5537792,132436008,40869521,22656213,1024,1024,42083156,0,75711296,0,540941.338269,0.0,2953.318689,75,0,1,5030,0,52,0,0,0,91954404,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8060462.982, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,compact,4,ok,compact,0.12.0,8388608,33536,4427696,4230192,0,131120,5554176,132110379,38257181,22557256,1024,1024,42083156,0,75711296,0,540811.125254,0.0,2944.323595,72,0,1,5033,0,56,0,0,0,94112952,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8057929.717, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,threshold8,4,ok,threshold,0.12.0,8388608,33536,303072,98400,7168,131120,1802240,131804916,34977352,22094634,1024,1024,42083156,57344,75711296,0,1853.831647,920.149467,2897.713188,9,67,1,6053,0,31,0,0,0,96937037,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8055361.395, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,copy_no_pool,4,ok,copy,0.12.0,8388608,33536,237296,98400,7168,131120,1818624,135161451,44330024,25503982,1024,1024,42083156,57344,75711296,0,2157.809223,924.543547,2946.975235,4082,1024,1024,0,0,35,0,0,0,91118882,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8099348.558, ""latency_p99_upper_ns"": 10485760}]"
+one_slow,threshold2,4,ok,threshold,0.12.0,8388608,33536,303072,98400,7168,131120,1802240,132588310,37673671,22518430,1024,1024,42083156,57344,75711296,0,1949.11739,920.155569,2954.042078,9,78,1,6042,0,36,0,0,0,94895218,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8057756.78, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,copy,4,ok,copy,0.12.0,8388608,33536,303072,98400,7168,131120,1818624,131620718,34580946,21993246,1024,1024,42083156,57344,75711296,0,1837.245494,919.925321,2884.001314,9,64,1,6056,0,16,0,0,0,97154068,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8053071.22, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,borrow,4,ok,borrow,0.12.0,8388608,33536,4427696,4230192,0,131120,5537792,132000791,37927424,22507290,1024,1024,42083156,0,75711296,0,540831.163899,0.0,2938.768696,72,0,1,5033,0,30,0,0,0,94241105,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8058140.749, ""latency_p99_upper_ns"": 8388608}]"
+one_slow,shared_copy,4,ok,shared_copy,0.12.0,8388608,33536,303072,98400,7168,131120,1818624,132283829,37157688,22116989,1024,1024,42083156,57344,75711296,0,1917.711679,920.053817,2900.603467,9,67,1,6053,0,38,0,0,0,95415784,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8056291.708, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,borrow,0,ok,borrow,0.12.0,8388608,41728,4435888,4230192,0,131120,5373952,132804710,49883960,22784485,1024,3072,42083156,0,75711296,0,540593.356702,0.0,2990.235132,72,0,1,5033,0,578,0,0,0,84130488,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 45505.588, ""latency_p99_upper_ns"": 65536}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5070252.164, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8055489.045, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,compact,0,ok,compact,0.12.0,8388608,41728,4436784,4230192,6944,131120,5537792,132699783,50261222,22546544,1024,3072,42083156,57344,75711296,0,340105.36302,342.277671,2958.801865,897,913,1,4319,0,550,1024,0,0,83652241,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 45463.711, ""latency_p99_upper_ns"": 65536}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5069982.729, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8054576.42, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,shared_copy,0,ok,shared_copy,0.12.0,8388608,41728,311264,98400,39984,131120,1835008,132438636,46508730,22104890,1024,3072,42083156,33611776,75711296,0,1994.687521,1188.73405,2903.952009,9,64,1,7080,0,538,0,0,1024,87037859,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 42492.519, ""latency_p99_upper_ns"": 57344}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5069205.345, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8052022.729, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,copy,0,ok,copy,0.12.0,8388608,41728,318432,98400,47152,131120,1851392,132301692,46274024,22012014,1024,3072,42083156,33669120,75711296,0,1991.776071,1766.57547,2891.89841,9,1025,1,7143,0,563,0,0,0,87083196,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 42221.575, ""latency_p99_upper_ns"": 57344}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5068352.743, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8049671.308, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,copy_no_pool,0,ok,copy,0.12.0,8388608,41728,252544,98400,47152,131120,1933312,132221655,46432790,22094470,1024,3072,42083156,33669120,75711296,0,2002.66499,1764.18462,2896.537304,4082,3072,1024,0,0,534,0,0,0,86822233,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 42461.52, ""latency_p99_upper_ns"": 57344}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5068300.921, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8054065.407, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,threshold2,0,ok,threshold,0.12.0,8388608,41728,311264,98400,39984,131120,1851392,132423215,46202689,22137673,1024,3072,42083156,33611776,75711296,0,1992.776523,1183.803646,2909.259091,9,64,1,7080,0,559,0,0,1024,87298460,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 42209.067, ""latency_p99_upper_ns"": 57344}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5068504.791, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8052025.9, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,threshold8,0,ok,threshold,0.12.0,8388608,41728,311264,98400,7168,131120,1851392,132072752,44818714,22007505,1024,3072,42083156,57344,75711296,0,2372.402719,919.579066,2891.111165,9,64,1,6056,0,531,0,0,1024,88271004,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 41081.91, ""latency_p99_upper_ns"": 49152}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5067409.945, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8052229.961, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,copy,1,ok,copy,0.12.0,8388608,41728,318432,98400,47152,131120,1851392,132122049,45960158,22062914,1024,3072,42083156,33669120,75711296,0,1985.913742,1766.681864,2899.647733,9,1025,1,7143,0,530,0,0,0,87159643,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 42080.341, ""latency_p99_upper_ns"": 53248}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5068084.019, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8053834.564, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,copy_no_pool,1,ok,copy,0.12.0,8388608,41728,252544,98400,47152,131120,1884160,132225178,46345346,22106440,1024,3072,42083156,33669120,75711296,0,1998.568774,1764.360213,2898.609,4082,3072,1024,0,0,531,0,0,0,86929226,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 42412.925, ""latency_p99_upper_ns"": 57344}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5068204.178, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8052346.592, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,threshold2,1,ok,threshold,0.12.0,8388608,41728,311264,98400,39984,131120,1851392,132119197,45785542,22119160,1024,3072,42083156,33611776,75711296,0,1985.975023,1182.61037,2906.107753,9,64,1,7080,0,535,0,0,1024,87289352,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 42063.476, ""latency_p99_upper_ns"": 61440}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5068193.573, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8051854.179, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,compact,1,ok,compact,0.12.0,8388608,41728,4436784,4230192,6944,131120,5603328,132689456,50225388,22679397,1024,3072,42083156,57344,75711296,0,340115.562513,342.313483,2976.797692,896,908,1,4325,0,548,1024,0,0,83654110,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 45534.298, ""latency_p99_upper_ns"": 65536}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5070135.917, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8055038.37, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,threshold8,1,ok,threshold,0.12.0,8388608,41728,311264,98400,7168,131120,1851392,132687220,45610919,22143479,1024,3072,42083156,57344,75711296,0,2398.303122,919.310014,2908.551305,9,73,1,6047,0,557,0,0,1024,88180228,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 41592.506, ""latency_p99_upper_ns"": 65536}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5067924.312, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8050249.576, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,shared_copy,1,ok,shared_copy,0.12.0,8388608,41728,311264,98400,39984,131120,1851392,133179387,47009567,22053622,1024,3072,42083156,33611776,75711296,0,2001.098596,1195.094634,2898.481421,9,64,1,7080,0,619,0,0,1024,87400987,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 42811.697, ""latency_p99_upper_ns"": 90112}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5068344.258, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8054983.926, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,borrow,1,ok,borrow,0.12.0,8388608,41728,4435888,4230192,0,131120,5373952,132590517,49691116,22667622,1024,3072,42083156,0,75711296,0,540625.036225,0.0,2974.002082,72,0,1,5033,0,555,0,0,0,84069041,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 45356.652, ""latency_p99_upper_ns"": 65536}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5069262.154, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8055874.806, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,borrow,2,ok,borrow,0.12.0,8388608,41728,4435888,4230192,0,131120,5373952,132595906,48936945,22622066,1024,3072,42083156,0,75711296,0,540538.226737,0.0,2969.006017,72,0,1,5033,0,550,0,0,0,84820014,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 44590.665, ""latency_p99_upper_ns"": 61440}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5069713.765, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8054486.477, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,threshold2,2,ok,threshold,0.12.0,8388608,41728,311264,98400,39984,131120,1851392,132243573,45674856,22029775,1024,3072,42083156,33611776,75711296,0,1978.146096,1181.588579,2894.51268,9,64,1,7080,0,547,0,0,1024,87607899,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 41881.888, ""latency_p99_upper_ns"": 53248}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5067912.655, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8049931.179, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,compact,2,ok,compact,0.12.0,8388608,41728,4436784,4230192,6944,131120,5603328,132732463,49739534,22671992,1024,3072,42083156,57344,75711296,0,340105.112239,342.468555,2974.922545,893,887,1,4349,0,562,1024,0,0,84142850,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 44979.318, ""latency_p99_upper_ns"": 65536}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5069891.561, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8056164.197, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,threshold8,2,ok,threshold,0.12.0,8388608,41728,311264,98400,7168,131120,1851392,132272059,45320979,22141356,1024,3072,42083156,57344,75711296,0,2389.486333,919.390876,2908.882515,9,64,1,6056,0,563,0,0,1024,88007671,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 41406.16, ""latency_p99_upper_ns"": 57344}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5068143.112, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8050851.553, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,copy,2,ok,copy,0.12.0,8388608,41728,318432,98400,47152,131120,1867776,132351078,46122525,22082400,1024,3072,42083156,33669120,75711296,0,1991.903399,1762.771138,2900.645032,9,1026,1,7142,0,558,0,0,0,87297075,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 42091.413, ""latency_p99_upper_ns"": 53248}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5068444.485, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8048834.24, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,shared_copy,2,ok,shared_copy,0.12.0,8388608,41728,311264,98400,39984,131120,1851392,132284819,45823432,22066434,1024,3072,42083156,33611776,75711296,0,1983.569581,1182.323172,2898.432644,9,64,1,7080,0,542,0,0,1024,87424368,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 42064.699, ""latency_p99_upper_ns"": 53248}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5068229.227, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8050900.843, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,copy_no_pool,2,ok,copy,0.12.0,8388608,41728,252544,98400,47152,131120,1900544,132459707,47692750,22170762,1024,3072,42083156,33669120,75711296,0,2023.677274,1777.322506,2907.132194,4082,3072,1024,0,0,540,0,0,0,85990890,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 43327.485, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5070694.294, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8055086.674, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,shared_copy,3,ok,shared_copy,0.12.0,8388608,41728,311264,98400,39984,131120,1851392,132140503,45825210,22125197,1024,3072,42083156,33611776,75711296,0,1985.69773,1183.215978,2906.687041,9,64,1,7080,0,533,0,0,1024,87310088,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 42062.03, ""latency_p99_upper_ns"": 57344}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5068036.782, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8050191.375, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,copy_no_pool,3,ok,copy,0.12.0,8388608,41728,252544,98400,47152,131120,1916928,132297747,46669804,22175323,1024,3072,42083156,33669120,75711296,0,2009.648765,1766.146335,2907.094824,4082,3072,1024,0,0,542,0,0,0,86663675,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 42678.905, ""latency_p99_upper_ns"": 61440}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5068637.263, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8054142.04, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,copy,3,ok,copy,0.12.0,8388608,41728,318432,98400,47152,131120,1851392,132282510,46415608,22079359,1024,3072,42083156,33669120,75711296,0,1996.444688,1765.761752,2901.17633,9,1025,1,7143,0,554,0,0,0,86986908,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 42277.028, ""latency_p99_upper_ns"": 57344}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5070038.574, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8050279.443, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,borrow,3,ok,borrow,0.12.0,8388608,41728,4435888,4230192,0,131120,5373952,132489898,48808681,22654163,1024,3072,42083156,0,75711296,0,540484.370521,0.0,2972.753951,72,0,1,5033,0,556,0,0,0,84863248,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 44578.165, ""latency_p99_upper_ns"": 61440}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5069410.422, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8053620.063, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,threshold2,3,ok,threshold,0.12.0,8388608,41728,311264,98400,39984,131120,1835008,132283398,45911917,22085581,1024,3072,42083156,33611776,75711296,0,1984.871517,1183.416247,2903.347153,9,64,1,7080,0,561,0,0,1024,87433143,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 42043.254, ""latency_p99_upper_ns"": 57344}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5068356.958, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8050581.195, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,threshold8,3,ok,threshold,0.12.0,8388608,41728,311264,98400,7168,131120,1851392,132082805,44815017,22070822,1024,3072,42083156,57344,75711296,0,2374.331913,919.214871,2899.672121,9,64,1,6056,0,534,0,0,1024,88275454,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 41070.548, ""latency_p99_upper_ns"": 53248}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5067369.015, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8049008.122, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,compact,3,ok,compact,0.12.0,8388608,41728,4436784,4230192,7056,131120,5488640,132597323,49981497,22749218,1024,3072,42083156,57344,75711296,0,340108.105991,342.554096,2986.081381,912,907,1,4310,0,563,1024,0,0,83819563,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 45265.223, ""latency_p99_upper_ns"": 65536}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5069991.558, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8056976.805, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,copy_no_pool,4,ok,copy,0.12.0,8388608,41728,252544,98400,47152,131120,1900544,132985160,49981054,23442854,1024,3072,42083156,33669120,75711296,0,2129.142526,1795.211172,3074.346252,4082,3072,1024,0,0,542,0,0,0,84089494,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 45510.754, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5098662.604, ""latency_p99_upper_ns"": 6291456}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8056999.864, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,borrow,4,ok,borrow,0.12.0,8388608,41728,4435888,4230192,0,131120,5373952,133433884,51462618,23747967,1024,3072,42083156,0,75711296,0,540814.68462,0.0,3118.422109,72,0,1,5033,0,596,0,0,0,83315856,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 46811.327, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5070925.9, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8058845.673, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,threshold2,4,ok,threshold,0.12.0,8388608,41728,311264,98400,39984,131120,1867776,132186422,45811373,22083462,1024,3072,42083156,33611776,75711296,0,1983.12097,1182.647891,2900.448352,9,64,1,7080,0,532,0,0,1024,87421696,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 42006.171, ""latency_p99_upper_ns"": 57344}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5068025.061, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8049545.414, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,shared_copy,4,ok,shared_copy,0.12.0,8388608,41728,311264,98400,39984,131120,1851392,132188663,45991210,22145612,1024,3072,42083156,33611776,75711296,0,1991.371251,1184.961172,2909.800223,9,64,1,7080,0,543,0,0,1024,87186189,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 42139.616, ""latency_p99_upper_ns"": 57344}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5068490.238, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8052428.242, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,compact,4,ok,compact,0.12.0,8388608,41728,4436784,4230192,7056,131120,5537792,132746292,50870250,22660664,1024,3072,42083156,57344,75711296,0,340246.674827,342.038296,2973.982939,893,895,1,4341,0,545,1024,0,0,83141858,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 45809.599, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5072116.599, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8054634.315, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,threshold8,4,ok,threshold,0.12.0,8388608,41728,311264,98400,7168,131120,1851392,132177385,44977578,22128368,1024,3072,42083156,57344,75711296,0,2381.095196,919.555429,2907.397974,9,64,1,6056,0,539,0,0,1024,88187889,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 41268.295, ""latency_p99_upper_ns"": 57344}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5067698.961, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8052209.973, ""latency_p99_upper_ns"": 8388608}]"
+three_distinct_speeds,copy,4,ok,copy,0.12.0,8388608,41728,318432,98400,47152,131120,1867776,132225648,46118905,22053057,1024,3072,42083156,33669120,75711296,0,1988.501642,1767.427593,2896.491937,9,1025,1,7143,0,536,0,0,0,87128865,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 42165.024, ""latency_p99_upper_ns"": 53248}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5068266.918, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8051060.116, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,copy_no_pool,0,ok,copy,0.12.0,8388608,41728,4373248,98400,4233264,131120,6078464,216945564,116157398,25703347,1024,3072,42083156,100663296,75711296,0,3917.681175,512250.563648,3150.964519,4082,3072,1024,0,0,383,0,0,0,48939452,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 117402.264, ""latency_p99_upper_ns"": 524288}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 6063368.282, ""latency_p99_upper_ns"": 31457280}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 9260486.827, ""latency_p99_upper_ns"": 33554432}]"
+same_large_field,shared_copy,0,ok,shared_copy,0.12.0,8388608,41728,2371504,98400,2100224,131120,3178496,133534289,66640259,22303696,1024,3072,42083156,33554432,75711296,0,2044.238204,269834.895225,2930.529378,82,0,1,6047,0,500,0,0,2048,67897726,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 51484.234, ""latency_p99_upper_ns"": 81920}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5078396.125, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8065897.697, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,borrow,0,ok,borrow,0.12.0,8388608,41728,4435888,4230192,0,131120,4767744,133553215,68694192,22344284,1024,3072,42083156,0,75711296,0,541236.958782,0.0,2932.875901,76,0,1,5029,0,479,0,0,0,65966946,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 52115.836, ""latency_p99_upper_ns"": 81920}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5078241.217, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8065472.756, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,copy,0,ok,copy,0.12.0,8388608,41728,4504544,98400,4233264,131120,5292032,134319516,74842901,22151327,1024,3072,42083156,100663296,75711296,0,2277.11069,440218.115158,2909.330552,9,841,1,7327,0,490,0,0,0,60554269,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 57181.88, ""latency_p99_upper_ns"": 90112}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5083619.048, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8071315.085, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,threshold2,0,ok,threshold,0.12.0,8388608,41728,2371504,98400,2100224,131120,3194880,133454646,66234578,22159339,1024,3072,42083156,33554432,75711296,0,2031.818258,269861.554419,2910.266617,78,0,1,6051,0,487,0,0,2048,68332882,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 51484.504, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5077341.499, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8066441.419, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,compact,0,ok,compact,0.12.0,8388608,41728,4730672,4230192,2001776,131120,6340608,134096312,74886880,22733900,1024,3072,42083156,33554432,75711296,0,341111.908821,100293.13752,2983.138393,921,779,1,4429,0,471,1024,0,0,60362834,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 54080.027, ""latency_p99_upper_ns"": 90112}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5083405.479, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8068401.165, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,threshold8,0,ok,threshold,0.12.0,8388608,41728,4435888,4230192,0,131120,4767744,133447386,68765370,22353361,1024,3072,42083156,0,75711296,0,541359.828153,0.0,2934.692831,77,0,1,5028,0,487,0,0,0,65809490,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 52372.427, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5078845.858, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8067374.837, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,compact,1,ok,compact,0.12.0,8388608,41728,4730672,4230192,2034592,131120,6340608,134204038,74836392,22853483,1024,3072,42083156,33554432,75711296,0,341117.919471,100364.674661,2998.098529,881,767,1,4481,0,478,1024,0,0,60375968,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 54356.541, ""latency_p99_upper_ns"": 90112}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5083649.875, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8070735.206, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,shared_copy,1,ok,shared_copy,0.12.0,8388608,41728,2371504,98400,2100224,131120,3244032,133593447,66172548,22181499,1024,3072,42083156,33554432,75711296,0,2031.917671,269851.910584,2913.380586,80,0,1,6049,0,471,0,0,2048,68489180,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 51688.946, ""latency_p99_upper_ns"": 81920}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5077231.39, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8066199.086, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,copy,1,ok,copy,0.12.0,8388608,41728,4504544,98400,4233264,131120,5292032,134436483,75053693,22215239,1024,3072,42083156,100663296,75711296,0,2284.410516,440251.541897,2917.091676,9,832,1,7336,0,483,0,0,0,60480780,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 57382.812, ""latency_p99_upper_ns"": 81920}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5083530.123, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8072471.683, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,threshold2,1,ok,threshold,0.12.0,8388608,41728,2371504,98400,2100224,131120,3194880,134034428,69077852,22386881,1024,3072,42083156,33554432,75711296,0,2071.219143,269907.925264,2941.415878,82,0,1,6047,0,521,0,0,2048,66160244,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 52463.206, ""latency_p99_upper_ns"": 90112}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5079970.677, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8068543.087, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,threshold8,1,ok,threshold,0.12.0,8388608,41728,4435888,4230192,0,131120,4767744,133602318,69361342,22347294,1024,3072,42083156,0,75711296,0,541336.354919,0.0,2933.602437,76,0,1,5029,0,500,0,0,0,65433839,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 52034.221, ""latency_p99_upper_ns"": 81920}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5079700.568, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8067086.654, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,borrow,1,ok,borrow,0.12.0,8388608,41728,4435888,4230192,0,131120,4767744,133878082,69431646,22393309,1024,3072,42083156,0,75711296,0,541341.633608,0.0,2938.771712,78,0,1,5027,0,504,0,0,0,65629618,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 52136.236, ""latency_p99_upper_ns"": 81920}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5078986.712, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8067041.718, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,copy_no_pool,1,ok,copy,0.12.0,8388608,41728,4373248,98400,4233264,131120,5816320,134331933,75355273,22600489,1024,3072,42083156,100663296,75711296,0,2317.391148,440282.284319,2923.56271,4082,3072,1024,0,0,497,0,0,0,60100461,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 58242.85, ""latency_p99_upper_ns"": 90112}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5084649.973, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8073924.058, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,compact,2,ok,compact,0.12.0,8388608,41728,4730672,4230192,2001776,131120,6340608,134074359,74679639,22736073,1024,3072,42083156,33554432,75711296,0,341236.488763,100267.211633,2982.994817,917,794,1,4418,0,471,1024,0,0,60515136,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 53738.105, ""latency_p99_upper_ns"": 90112}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5085195.058, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8069412.397, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,copy,2,ok,copy,0.12.0,8388608,41728,4504544,98400,4233264,131120,5275648,136064340,79416596,22572078,1024,3072,42083156,100663296,75711296,0,2363.378088,440586.829499,2964.218039,9,623,1,7545,0,463,0,0,0,57551670,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 60112.085, ""latency_p99_upper_ns"": 114688}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5087074.439, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8080314.649, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,threshold2,2,ok,threshold,0.12.0,8388608,41728,2371504,98400,2100224,131120,3244032,133655494,66354625,22289900,1024,3072,42083156,33554432,75711296,0,2049.709126,269797.797722,2927.700988,78,0,1,6051,0,500,0,0,2048,68212138,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 51495.073, ""latency_p99_upper_ns"": 81920}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5078118.015, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8064823.351, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,shared_copy,2,ok,shared_copy,0.12.0,8388608,41728,2371504,98400,2100224,131120,3293184,133683827,66973903,22176603,1024,3072,42083156,33554432,75711296,0,2039.054037,269818.155226,2912.084727,78,0,1,6051,0,494,0,0,2048,67816366,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 51459.966, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5079235.137, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8065334.704, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,threshold8,2,ok,threshold,0.12.0,8388608,41728,4435888,4230192,0,131120,4767744,133681327,68797289,22338685,1024,3072,42083156,0,75711296,0,541289.267391,0.0,2932.086428,77,0,1,5028,0,482,0,0,0,65978872,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 52563.022, ""latency_p99_upper_ns"": 81920}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5078578.492, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8066255.165, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,borrow,2,ok,borrow,0.12.0,8388608,41728,4435888,4230192,0,131120,4767744,133814643,68888479,22335355,1024,3072,42083156,0,75711296,0,541341.207084,0.0,2930.637289,79,0,1,5026,0,510,0,0,0,66149871,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 51550.405, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5079607.126, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8067127.786, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,copy_no_pool,2,ok,copy,0.12.0,8388608,41728,4373248,98400,4233264,131120,5816320,134471775,75393460,22629325,1024,3072,42083156,100663296,75711296,0,2321.181236,440258.792854,2921.16977,4082,3072,1024,0,0,508,0,0,0,60227676,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 57516.822, ""latency_p99_upper_ns"": 90112}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5084982.783, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8073926.553, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,threshold2,3,ok,threshold,0.12.0,8388608,41728,2371504,98400,2100224,131120,3194880,133441147,66434679,22119254,1024,3072,42083156,33554432,75711296,0,2030.079604,269825.85573,2905.779822,80,0,1,6049,0,482,0,0,2048,68150063,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 51190.857, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5077733.031, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8065349.133, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,copy_no_pool,3,ok,copy,0.12.0,8388608,41728,4373248,98400,4233264,131120,5816320,134289332,76002725,22740343,1024,3072,42083156,100663296,75711296,0,2334.193158,440332.993703,2936.962125,4082,3072,1024,0,0,504,0,0,0,59412631,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 59077.132, ""latency_p99_upper_ns"": 90112}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5084960.638, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8075279.097, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,shared_copy,3,ok,shared_copy,0.12.0,8388608,41728,2371504,98400,2100224,131120,3309568,133495777,66421587,22309367,1024,3072,42083156,33554432,75711296,0,2045.123956,269842.975673,2931.949276,76,0,1,6053,0,497,0,0,2048,68249668,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 51216.396, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5078028.333, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8066089.677, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,borrow,3,ok,borrow,0.12.0,8388608,41728,4435888,4230192,0,131120,4767744,134337593,71105404,22575073,1024,3072,42083156,0,75711296,0,541448.462493,0.0,2962.344728,83,0,1,5022,0,495,0,0,0,64431294,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 53339.614, ""latency_p99_upper_ns"": 81920}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5080292.879, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8068765.424, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,copy,3,ok,copy,0.12.0,8388608,41728,4504544,98400,4233264,131120,5292032,134254523,76196602,22285338,1024,3072,42083156,100663296,75711296,0,2295.795833,440394.753415,2927.722098,9,820,1,7348,0,485,0,0,0,59133245,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 58635.959, ""latency_p99_upper_ns"": 90112}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5084371.237, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8075247.27, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,compact,3,ok,compact,0.12.0,8388608,41728,4730672,4230192,2034592,131120,6340608,134306041,75274107,22714288,1024,3072,42083156,33554432,75711296,0,341191.973388,100297.728905,2980.354846,917,749,1,4463,0,478,1024,0,0,60108647,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 54208.683, ""latency_p99_upper_ns"": 90112}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5084673.227, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8069796.873, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,threshold8,3,ok,threshold,0.12.0,8388608,41728,4435888,4230192,0,131120,4767744,133817208,69542587,22437830,1024,3072,42083156,0,75711296,0,541408.186663,0.0,2945.936502,80,0,1,5025,0,483,0,0,0,65488224,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 52016.168, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5080750.668, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8068031.861, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,copy_no_pool,4,ok,copy,0.12.0,8388608,41728,4373248,98400,4233264,131120,5799936,134597856,77396908,22833216,1024,3072,42083156,100663296,75711296,0,2355.524795,440416.150759,2941.859195,4082,3072,1024,0,0,512,0,0,0,58493375,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 59008.762, ""latency_p99_upper_ns"": 98304}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5086107.088, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8076875.839, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,copy,4,ok,copy,0.12.0,8388608,41728,4504544,98400,4233264,131120,5292032,139508137,88332555,22864596,1024,3072,42083156,100663296,75711296,0,2528.253394,442384.852596,3002.901193,9,688,1,7480,0,372,0,0,0,51495885,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 66698.854, ""latency_p99_upper_ns"": 147456}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5129096.339, ""latency_p99_upper_ns"": 6815744}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8093643.623, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,threshold8,4,ok,threshold,0.12.0,8388608,41728,4435888,4230192,0,131120,4833280,134457305,70251788,22431999,1024,3072,42083156,0,75711296,0,541395.863387,0.0,2942.397573,87,0,1,5018,0,495,0,0,0,65292089,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 53169.212, ""latency_p99_upper_ns"": 90112}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5080238.856, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8068047.314, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,threshold2,4,ok,threshold,0.12.0,8388608,41728,2371504,98400,2100224,131120,3211264,133756102,67373341,22155214,1024,3072,42083156,33554432,75711296,0,2045.927873,269868.863264,2910.706656,81,0,1,6048,0,506,0,0,2048,67548515,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 51135.428, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5078670.025, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8066898.388, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,shared_copy,4,ok,shared_copy,0.12.0,8388608,41728,2371504,98400,2100224,131120,3571712,135030934,71236281,22446961,1024,3072,42083156,33554432,75711296,0,2100.123381,269953.875704,2948.934561,94,0,1,6035,0,507,0,0,2048,65033726,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 53626.014, ""latency_p99_upper_ns"": 90112}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5087279.412, ""latency_p99_upper_ns"": 5767168}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8070672.959, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,compact,4,ok,compact,0.12.0,8388608,41728,4730672,4230192,1936144,131120,6340608,135831514,84355786,23107923,1024,3072,42083156,33554432,75711296,0,341580.411374,100419.005421,3032.899482,853,676,1,4600,0,455,1024,0,0,52913091,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 60319.001, ""latency_p99_upper_ns"": 114688}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5091148.147, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8079928.47, ""latency_p99_upper_ns"": 8388608}]"
+same_large_field,borrow,4,ok,borrow,0.12.0,8388608,41728,4435888,4230192,0,131120,4767744,133667291,68534602,22264001,1024,3072,42083156,0,75711296,0,541292.227145,0.0,2921.518156,77,0,1,5028,0,481,0,0,0,66216721,0,0,"[{""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 1, ""latency_mean_ns"": 52072.538, ""latency_p99_upper_ns"": 81920}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 5078370.622, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8066280.939, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,copy,0,ok,copy,0.12.0,8388608,41728,2378784,98400,2107504,131120,3899392,133407209,54623208,22433685,1024,3072,42083156,33669120,75711296,0,2079.608844,270519.575773,2946.904954,118,838,1,7221,0,547,0,0,0,79664236,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 47700.066, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5070062.768, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8069584.641, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,threshold2,0,ok,threshold,0.12.0,8388608,41728,2378672,98400,2107392,131120,3751936,133312135,53364925,22316231,1024,3072,42083156,33611776,75711296,0,2049.372724,270524.406644,2928.92106,137,841,1,6175,0,552,0,0,1024,80930688,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 46742.189, ""latency_p99_upper_ns"": 65536}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5068879.809, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8069119.599, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,shared_copy,0,ok,shared_copy,0.12.0,8388608,41728,2378672,98400,2107392,131120,3948544,154001095,65368726,23437273,1024,3072,42083156,33611776,75711296,0,2683.230182,276097.966097,3083.783614,228,746,1,6179,0,542,0,0,1024,75659422,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 64443.196, ""latency_p99_upper_ns"": 147456}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5134851.331, ""latency_p99_upper_ns"": 7340032}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8252758.487, ""latency_p99_upper_ns"": 15728640}]"
+slow_large_field,copy_no_pool,0,ok,copy,0.12.0,8388608,41728,2312896,98400,2107504,131120,3194880,133648283,61986524,25370210,1024,3072,42083156,33669120,75711296,0,2299.022458,270612.233717,2983.123314,4082,3072,1024,0,0,653,0,0,0,72630111,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 53967.42, ""latency_p99_upper_ns"": 81920}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5080263.648, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8075763.615, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,compact,0,ok,compact,0.12.0,8388608,41728,4730672,4230192,2067408,131120,6340608,133472857,62602975,23134595,1024,3072,42083156,33554432,75711296,0,340709.17918,100724.838498,3036.377571,923,841,1,4365,0,526,1024,0,0,71679132,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 48473.289, ""latency_p99_upper_ns"": 81920}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5073065.738, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8070772.518, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,threshold8,0,ok,threshold,0.12.0,8388608,41728,4443056,4230192,7168,131120,4751360,133297584,55094453,22718797,1024,3072,42083156,57344,75711296,0,541537.659914,577.166247,2982.289653,130,809,1,5190,0,541,0,0,1024,79050000,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 48100.386, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5069482.618, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8070037.129, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,borrow,0,ok,borrow,0.12.0,8388608,41728,4435888,4230192,0,131120,4767744,133477288,54372368,22466675,1024,3072,42083156,0,75711296,0,541562.393801,0.0,2949.789857,80,0,1,5025,0,554,0,0,0,80055686,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 46918.51, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5069158.581, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8070277.888, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,threshold2,1,ok,threshold,0.12.0,8388608,41728,2378672,98400,2107392,131120,3932160,133312509,53734268,22533891,1024,3072,42083156,33611776,75711296,0,2071.170012,270512.249274,2959.58098,159,828,1,6166,0,575,0,0,1024,80473327,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 46789.037, ""latency_p99_upper_ns"": 65536}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5070040.373, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8069081.323, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,copy_no_pool,1,ok,copy,0.12.0,8388608,41728,2312896,98400,2107504,131120,3194880,134281084,62190824,25213500,1024,3072,42083156,33669120,75711296,0,2300.277794,270647.838041,2975.251132,4082,3072,1024,0,0,663,0,0,0,73016473,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 54287.927, ""latency_p99_upper_ns"": 98304}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5080276.456, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8077074.059, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,copy,1,ok,copy,0.12.0,8388608,41728,2378784,98400,2107504,131120,3948544,133395362,55263103,22335683,1024,3072,42083156,33669120,75711296,0,2070.323199,270570.958879,2935.679247,123,825,1,7229,0,563,0,0,0,79157676,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 47428.456, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5070071.895, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8070912.004, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,shared_copy,1,ok,shared_copy,0.12.0,8388608,41728,2378672,98400,2107392,131120,3522560,133405307,53873137,22349414,1024,3072,42083156,33611776,75711296,0,2061.271642,270527.998952,2936.171471,144,811,1,6198,0,551,0,0,1024,80515381,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 46564.507, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5069570.9, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8069438.264, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,compact,1,ok,compact,0.12.0,8388608,41728,4730672,4230192,2100224,131120,6340608,133295478,60929076,22892803,1024,3072,42083156,33554432,75711296,0,340588.424197,100730.999866,3007.852808,919,842,1,4368,0,524,1024,0,0,73271182,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 48259.733, ""latency_p99_upper_ns"": 81920}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5071843.127, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8069717.131, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,borrow,1,ok,borrow,0.12.0,8388608,41728,4435888,4230192,0,131120,5390336,133317978,54530428,22789187,1024,3072,42083156,0,75711296,0,541551.170985,0.0,2991.654899,72,0,1,5033,0,541,0,0,0,79523636,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 47420.19, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5069779.505, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8070214.071, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,threshold8,1,ok,threshold,0.12.0,8388608,41728,4443056,4230192,7168,131120,5357568,133341496,54857945,22618201,1024,3072,42083156,57344,75711296,0,541518.37496,577.265132,2971.205031,122,835,1,5172,0,562,0,0,1024,79396532,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 47550.497, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5070242.543, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8069675.14, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,threshold8,2,ok,threshold,0.12.0,8388608,41728,4443056,4230192,7168,131120,5292032,134650847,58145169,22801055,1024,3072,42083156,57344,75711296,0,542663.104532,578.298773,2995.063232,127,804,1,5198,0,553,0,0,1024,77457652,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 49310.575, ""latency_p99_upper_ns"": 81920}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5080294.837, ""latency_p99_upper_ns"": 5767168}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8086977.866, ""latency_p99_upper_ns"": 9437184}]"
+slow_large_field,copy,2,ok,copy,0.12.0,8388608,41728,2378784,98400,2107504,131120,3964928,133179940,52486508,22146823,1024,3072,42083156,33669120,75711296,0,2028.917653,270508.558846,2910.035715,119,875,1,7183,0,532,0,0,0,81744820,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 46179.91, ""latency_p99_upper_ns"": 61440}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5068139.702, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8068218.996, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,borrow,2,ok,borrow,0.12.0,8388608,41728,4435888,4230192,0,131120,4767744,133254368,52756869,22242096,1024,3072,42083156,0,75711296,0,541465.495701,0.0,2919.456949,79,0,1,5026,0,537,0,0,0,81620293,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 45804.026, ""latency_p99_upper_ns"": 61440}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5067325.337, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8068611.8, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,compact,2,ok,compact,0.12.0,8388608,41728,4730672,4230192,2100224,131120,6340608,133273853,59503628,22579568,1024,3072,42083156,33554432,75711296,0,340521.103381,100725.988305,2964.439632,921,839,1,4369,0,529,1024,0,0,75001351,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 46820.147, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5071087.53, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8068767.35, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,shared_copy,2,ok,shared_copy,0.12.0,8388608,41728,2378672,98400,2107392,131120,3293184,133216315,51631438,22079426,1024,3072,42083156,33611776,75711296,0,2014.496107,270449.091989,2901.711431,152,827,1,6174,0,543,0,0,1024,82698735,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 45041.785, ""latency_p99_upper_ns"": 57344}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5068002.393, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8066161.602, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,copy_no_pool,2,ok,copy,0.12.0,8388608,41728,2312896,98400,2107504,131120,3178496,133362779,58084129,24178012,1024,3072,42083156,33669120,75711296,0,2196.167723,270535.919777,2934.024512,4082,3072,1024,0,0,605,0,0,0,76526627,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 50758.917, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5074265.021, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8071772.438, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,threshold2,2,ok,threshold,0.12.0,8388608,41728,2378672,98400,2107392,131120,3751936,133094723,52669444,22153975,1024,3072,42083156,33611776,75711296,0,2026.350691,270487.081841,2910.446252,162,813,1,6178,0,529,0,0,1024,81515465,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 46192.459, ""latency_p99_upper_ns"": 65536}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5067955.414, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8067608.796, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,compact,3,ok,compact,0.12.0,8388608,41728,4730672,4230192,2100224,131120,6340608,133282278,59568109,22558632,1024,3072,42083156,33554432,75711296,0,340502.324772,100714.490169,2961.00573,923,826,1,4380,0,521,1024,0,0,74934523,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 46941.425, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5070856.899, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8068200.595, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,copy_no_pool,3,ok,copy,0.12.0,8388608,41728,2312896,98400,2107504,131120,3194880,133540522,58472614,24345793,1024,3072,42083156,33669120,75711296,0,2208.417867,270579.890216,2933.62499,4082,3072,1024,0,0,602,0,0,0,76325826,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 51364.197, ""latency_p99_upper_ns"": 81920}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5074603.185, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8073207.582, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,borrow,3,ok,borrow,0.12.0,8388608,41728,4435888,4230192,0,131120,4767744,133275839,52234245,22266351,1024,3072,42083156,0,75711296,0,541367.893955,0.0,2922.935825,79,0,1,5026,0,545,0,0,0,82113024,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 45842.847, ""latency_p99_upper_ns"": 61440}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5066801.978, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8067096.868, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,shared_copy,3,ok,shared_copy,0.12.0,8388608,41728,2378672,98400,2107392,131120,3899392,133064931,52117164,22057182,1024,3072,42083156,33611776,75711296,0,2015.469116,270480.700872,2897.68644,130,842,1,6181,0,555,0,0,1024,82111301,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 45400.789, ""latency_p99_upper_ns"": 57344}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5068255.587, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8067189.304, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,threshold8,3,ok,threshold,0.12.0,8388608,41728,4443056,4230192,7168,131120,5292032,133337450,53670610,22263776,1024,3072,42083156,57344,75711296,0,541459.255198,577.165832,2922.14622,137,796,1,5196,0,551,0,0,1024,80837357,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 46321.397, ""latency_p99_upper_ns"": 65536}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5068514.702, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8068639.91, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,threshold2,3,ok,threshold,0.12.0,8388608,41728,2378672,98400,2107392,131120,3522560,134333542,52726291,22219255,1024,3072,42083156,33611776,75711296,0,2039.714059,270798.061653,2918.877137,140,894,1,6119,0,516,0,0,1024,82638596,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 46056.021, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5218345.888, ""latency_p99_upper_ns"": 9437184}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8076530.434, ""latency_p99_upper_ns"": 9437184}]"
+slow_large_field,copy,3,ok,copy,0.12.0,8388608,41728,2378784,98400,2107504,131120,3948544,133174357,52057974,22117835,1024,3072,42083156,33669120,75711296,0,2021.284206,270501.113842,2905.858494,114,849,1,7214,0,548,0,0,0,82257586,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 45428.889, ""latency_p99_upper_ns"": 61440}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5068142.38, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8067808.96, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,copy_no_pool,4,ok,copy,0.12.0,8388608,41728,2312896,98400,2107504,131120,3178496,133410638,57999768,24134627,1024,3072,42083156,33669120,75711296,0,2191.645151,270510.58659,2926.663567,4082,3072,1024,0,0,603,0,0,0,76638749,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 51016.097, ""latency_p99_upper_ns"": 81920}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5074074.877, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8071032.382, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,threshold2,4,ok,threshold,0.12.0,8388608,41728,2378672,98400,2107392,131120,3342336,133213102,52362717,22103023,1024,3072,42083156,33611776,75711296,0,2022.420003,270482.639278,2904.168619,127,855,1,6171,0,539,0,0,1024,81964913,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 46044.098, ""latency_p99_upper_ns"": 61440}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5068262.707, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8067371.07, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,copy,4,ok,copy,0.12.0,8388608,41728,2378784,98400,2107504,131120,3751936,133177547,52033688,22154380,1024,3072,42083156,33669120,75711296,0,2025.354638,270478.813202,2910.934805,129,851,1,7197,0,527,0,0,0,82109654,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 45825.604, ""latency_p99_upper_ns"": 61440}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5067937.156, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8067321.024, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,borrow,4,ok,borrow,0.12.0,8388608,41728,4435888,4230192,0,131120,4767744,133311566,53725285,22239925,1024,3072,42083156,0,75711296,0,541575.408384,0.0,2920.340305,80,0,1,5025,0,555,0,0,0,80727666,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 46306.509, ""latency_p99_upper_ns"": 61440}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5067147.548, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8070390.562, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,threshold8,4,ok,threshold,0.12.0,8388608,41728,4443056,4230192,7168,131120,5439488,134101658,54158047,22315394,1024,3072,42083156,57344,75711296,0,541512.874989,578.716358,2931.279646,161,826,1,5142,0,533,0,0,1024,81103821,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 46533.691, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5082538.041, ""latency_p99_upper_ns"": 6291456}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8069591.938, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,shared_copy,4,ok,shared_copy,0.12.0,8388608,41728,2378672,98400,2107392,131120,3948544,133134639,52075173,22128273,1024,3072,42083156,33611776,75711296,0,2026.862393,270471.476005,2908.200691,122,816,1,6215,0,512,0,0,1024,82080012,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 46182.627, ""latency_p99_upper_ns"": 61440}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5067504.389, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8067072.688, ""latency_p99_upper_ns"": 8388608}]"
+slow_large_field,compact,4,ok,compact,0.12.0,8388608,41728,4730672,4230192,2100224,131120,6406144,133118662,59607669,22648269,1024,3072,42083156,33554432,75711296,0,340524.867797,100684.088672,2973.798584,921,855,1,4353,0,532,1024,0,0,74562185,0,0,"[{""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 1, ""latency_mean_ns"": 47236.674, ""latency_p99_upper_ns"": 73728}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5071269.907, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 33554432, ""peak_count"": 64, ""latency_mean_ns"": 8067723.707, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,copy,0,ok,copy,0.12.0,2097152,41728,1104848,393312,79920,524336,1884160,134798098,52545277,26282225,1024,3072,49877076,26872064,114814580,0,6883.203763,1809.304759,10115.296993,367,948,374,6256,0,579,0,0,0,83482902,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 47583.467, ""latency_p99_upper_ns"": 147456}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5081460.678, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8083520.998, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,threshold8,0,ok,threshold,0.12.0,2097152,41728,1097792,393312,11312,524336,2031616,134514858,50924568,26180831,1024,3072,49877076,1059072,114814580,0,7475.627393,924.635553,10091.334952,237,96,257,5800,0,593,0,0,1024,84806597,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 46212.018, ""latency_p99_upper_ns"": 147456}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5080764.964, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8080296.584, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,copy_no_pool,0,ok,copy,0.12.0,2097152,41728,842368,393312,79920,524336,1949696,135580728,59055276,27303180,1024,3072,49877076,26872064,114814580,0,8268.860241,1866.643736,10141.702783,3849,3072,1024,0,0,540,0,0,0,77683199,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 53763.312, ""latency_p99_upper_ns"": 163840}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5090947.59, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8093934.847, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,shared_copy,0,ok,shared_copy,0.12.0,2097152,41728,1097792,393312,72752,524336,1884160,134733970,52189389,26273407,1024,3072,49877076,26814720,114814580,0,6865.482399,1226.436074,10135.432887,365,246,368,5942,0,587,0,0,1024,83766349,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 47383.279, ""latency_p99_upper_ns"": 147456}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5081532.837, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8082383.547, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,threshold2,0,ok,threshold,0.12.0,2097152,41728,1097792,393312,72752,524336,1884160,134703694,51981424,26239241,1024,3072,49877076,26814720,114814580,0,6818.11346,1220.93584,10109.238408,368,240,366,5947,0,592,0,0,1024,83962412,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 47186.16, ""latency_p99_upper_ns"": 147456}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5082027.365, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8082717.212, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,compact,0,ok,compact,0.12.0,2097152,41728,2096880,2047296,3360,524336,3702784,330325402,56526552,257818693,1024,3072,49877076,57344,114814580,0,542057.64214,342.456081,10454.037412,1653,1018,587,2639,1256,0,1024,0,0,275134226,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 313916.181, ""latency_p99_upper_ns"": 4718592}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 30, ""latency_mean_ns"": 5359649.404, ""latency_p99_upper_ns"": 10485760}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 49, ""latency_mean_ns"": 8345801.06, ""latency_p99_upper_ns"": 12582912}]"
+mixed_tight,borrow,0,ok,borrow,0.12.0,2097152,41728,2097024,2047296,0,524336,3702784,517444947,58385263,414175159,1024,3072,49877076,0,114814580,0,866552.611778,0.0,10646.478365,1612,0,580,2681,1250,0,0,0,0,460552293,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 496739.613, ""latency_p99_upper_ns"": 7864320}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 30, ""latency_mean_ns"": 5531099.266, ""latency_p99_upper_ns"": 12582912}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 30, ""latency_mean_ns"": 8547759.071, ""latency_p99_upper_ns"": 15728640}]"
+mixed_tight,copy_no_pool,1,ok,copy,0.12.0,2097152,41728,842368,393312,79920,524336,1916928,135818181,60130654,27699522,1024,3072,49877076,26872064,114814580,0,8398.686166,1885.555543,10206.603011,3849,3072,1024,0,0,537,0,0,0,76838088,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 54782.86, ""latency_p99_upper_ns"": 180224}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5093567.929, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8096201.349, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,threshold8,1,ok,threshold,0.12.0,2097152,41728,1097792,393312,11312,524336,2064384,134627181,51051158,26242598,1024,3072,49877076,1059072,114814580,0,7499.787736,924.734083,10090.493068,237,100,258,5795,0,587,0,0,1024,84733901,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 46365.068, ""latency_p99_upper_ns"": 147456}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5080938.783, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8081319.231, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,shared_copy,1,ok,shared_copy,0.12.0,2097152,41728,1097792,393312,72752,524336,1900544,134660107,51849496,26235438,1024,3072,49877076,26814720,114814580,0,6785.330268,1222.453816,10103.005533,366,239,366,5950,0,579,0,0,1024,84013028,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 47133.761, ""latency_p99_upper_ns"": 147456}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5081549.099, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8082113.784, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,borrow,1,ok,borrow,0.12.0,2097152,41728,2097024,2047296,0,524336,3719168,516876187,58189132,413488109,1024,3072,49877076,0,114814580,0,866155.703795,0.0,10618.392921,1617,0,581,2675,1263,0,0,0,0,460124695,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 496219.126, ""latency_p99_upper_ns"": 7864320}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 30, ""latency_mean_ns"": 5528237.536, ""latency_p99_upper_ns"": 12582912}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 30, ""latency_mean_ns"": 8541844.312, ""latency_p99_upper_ns"": 15728640}]"
+mixed_tight,threshold2,1,ok,threshold,0.12.0,2097152,41728,1097792,393312,72752,524336,1867776,134596389,51879163,26207832,1024,3072,49877076,26814720,114814580,0,6795.293198,1224.224319,10089.609534,369,233,365,5954,0,596,0,0,1024,83947198,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 47146.396, ""latency_p99_upper_ns"": 147456}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5082305.345, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8082431.98, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,copy,1,ok,copy,0.12.0,2097152,41728,1104848,393312,79920,524336,1884160,134667407,52286009,26255995,1024,3072,49877076,26872064,114814580,0,6830.10163,1802.54536,10104.51946,370,952,375,6248,0,590,0,0,0,83595691,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 47383.187, ""latency_p99_upper_ns"": 147456}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5081689.522, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8082200.92, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,compact,1,ok,compact,0.12.0,2097152,41728,2097104,2047296,3360,524336,3833856,330507221,57227425,258042238,1024,3072,49877076,57344,114814580,0,542403.396989,342.198165,10516.149038,1657,1018,592,2630,1262,0,1024,0,0,274671771,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 314160.033, ""latency_p99_upper_ns"": 4718592}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 30, ""latency_mean_ns"": 5361935.781, ""latency_p99_upper_ns"": 10485760}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 49, ""latency_mean_ns"": 8345834.982, ""latency_p99_upper_ns"": 12582912}]"
+mixed_tight,threshold2,2,ok,threshold,0.12.0,2097152,41728,1097792,393312,72752,524336,1900544,134805557,52099602,26201196,1024,3072,49877076,26814720,114814580,0,6802.764732,1222.5673,10082.699192,363,241,368,5949,0,592,0,0,1024,83969655,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 47229.56, ""latency_p99_upper_ns"": 147456}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5083369.83, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8082868.22, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,copy,2,ok,copy,0.12.0,2097152,41728,1104736,393312,79920,524336,1900544,135397301,55535720,28191073,1024,3072,49877076,26872064,114814580,0,7296.683374,1825.786254,10851.770961,364,925,376,6280,0,556,0,0,0,81078620,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 50441.328, ""latency_p99_upper_ns"": 163840}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5086253.071, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8088040.091, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,threshold8,2,ok,threshold,0.12.0,2097152,41728,1097792,393312,11312,524336,2048000,135143135,54181725,28073539,1024,3072,49877076,1059072,114814580,0,7971.142415,924.89692,10793.387694,237,89,259,5805,0,587,0,0,1024,82256234,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 49150.131, ""latency_p99_upper_ns"": 163840}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5084346.661, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8083800.547, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,borrow,2,ok,borrow,0.12.0,2097152,41728,2097024,2047296,0,524336,3719168,519737827,63401151,410873515,1024,3072,49877076,0,114814580,0,869390.688093,0.0,10874.854354,1612,0,584,2677,1267,0,0,0,0,457480540,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 498894.016, ""latency_p99_upper_ns"": 7864320}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 30, ""latency_mean_ns"": 5554388.391, ""latency_p99_upper_ns"": 12582912}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 30, ""latency_mean_ns"": 8572436.932, ""latency_p99_upper_ns"": 15728640}]"
+mixed_tight,copy_no_pool,2,ok,copy,0.12.0,2097152,41728,842368,393312,79920,524336,1933312,135808674,61310764,27409732,1024,3072,49877076,26872064,114814580,0,8492.13471,1909.35548,10184.015437,3849,3072,1024,0,0,538,0,0,0,75774039,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 55750.675, ""latency_p99_upper_ns"": 196608}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5097561.83, ""latency_p99_upper_ns"": 5767168}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8097147.871, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,compact,2,ok,compact,0.12.0,2097152,41728,2096496,2047296,3360,524336,3719168,330655613,57992572,257126466,1024,3072,49877076,57344,114814580,0,542286.835871,342.201335,10592.82654,1620,1018,589,2670,1246,0,1024,0,0,274045502,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 314214.117, ""latency_p99_upper_ns"": 4718592}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 30, ""latency_mean_ns"": 5361784.028, ""latency_p99_upper_ns"": 10485760}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 49, ""latency_mean_ns"": 8345733.162, ""latency_p99_upper_ns"": 12582912}]"
+mixed_tight,shared_copy,2,ok,shared_copy,0.12.0,2097152,41728,1097792,393312,72752,524336,1900544,134725602,52125932,26256537,1024,3072,49877076,26814720,114814580,0,6831.305534,1226.062002,10092.239062,365,226,360,5970,0,576,0,0,1024,83779201,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 47423.973, ""latency_p99_upper_ns"": 147456}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5082508.901, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8082650.268, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,compact,3,ok,compact,0.12.0,2097152,41728,2096656,2047296,3360,524336,3719168,332809762,64506702,255295188,1024,3072,49877076,57344,114814580,0,544031.993873,348.13532,10927.535411,1623,1008,583,2683,1227,0,1024,0,0,270135277,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 316210.616, ""latency_p99_upper_ns"": 4718592}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 30, ""latency_mean_ns"": 5373501.093, ""latency_p99_upper_ns"": 10485760}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 49, ""latency_mean_ns"": 8409239.137, ""latency_p99_upper_ns"": 12582912}]"
+mixed_tight,threshold2,3,ok,threshold,0.12.0,2097152,41728,1097792,393312,72752,524336,1884160,134646087,51969989,26192074,1024,3072,49877076,26814720,114814580,0,6812.54134,1229.637184,10083.25152,369,241,365,5946,0,582,0,0,1024,83864700,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 47274.193, ""latency_p99_upper_ns"": 147456}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5082291.09, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8084035.099, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,copy,3,ok,copy,0.12.0,2097152,41728,1104848,393312,79920,524336,1900544,134732754,52218674,26241260,1024,3072,49877076,26872064,114814580,0,6810.984162,1804.529206,10104.502269,368,949,374,6254,0,584,0,0,0,83719457,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 47404.955, ""latency_p99_upper_ns"": 147456}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5082343.96, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8082308.803, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,shared_copy,3,ok,shared_copy,0.12.0,2097152,41728,1097792,393312,72752,524336,1884160,134687032,52085095,26215409,1024,3072,49877076,26814720,114814580,0,6852.502663,1223.987439,10100.060122,365,235,364,5957,0,585,0,0,1024,83840818,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 47354.551, ""latency_p99_upper_ns"": 147456}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5081713.058, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8082095.55, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,borrow,3,ok,borrow,0.12.0,2097152,41728,2097072,2047296,0,524336,3719168,516415971,57490634,412616864,1024,3072,49877076,0,114814580,0,865936.173669,0.0,10532.202462,1624,0,582,2667,1258,0,0,0,0,460245677,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 495746.732, ""latency_p99_upper_ns"": 7864320}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 30, ""latency_mean_ns"": 5527499.187, ""latency_p99_upper_ns"": 12582912}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 30, ""latency_mean_ns"": 8541909.699, ""latency_p99_upper_ns"": 15728640}]"
+mixed_tight,copy_no_pool,3,ok,copy,0.12.0,2097152,41728,842368,393312,79920,524336,1916928,135708499,59498427,27293452,1024,3072,49877076,26872064,114814580,0,8320.069469,1853.590142,10172.640074,3849,3072,1024,0,0,550,0,0,0,77469437,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 53679.489, ""latency_p99_upper_ns"": 180224}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5093041.554, ""latency_p99_upper_ns"": 5767168}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8093789.758, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,threshold8,3,ok,threshold,0.12.0,2097152,41728,1097792,393312,11312,524336,2048000,134580129,50901202,26138215,1024,3072,49877076,1059072,114814580,0,7468.893211,924.833553,10074.589742,237,99,260,5794,0,603,0,0,1024,84894241,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 46199.245, ""latency_p99_upper_ns"": 147456}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5080295.214, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8082153.254, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,compact,4,ok,compact,0.12.0,2097152,41728,2095936,2047296,3360,524336,3768320,330364653,56737666,257390641,1024,3072,49877076,57344,114814580,0,542129.496495,342.3922,10487.947668,1626,1018,584,2669,1234,0,1024,0,0,274961005,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 314000.227, ""latency_p99_upper_ns"": 4718592}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 30, ""latency_mean_ns"": 5359881.678, ""latency_p99_upper_ns"": 10485760}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 49, ""latency_mean_ns"": 8345470.393, ""latency_p99_upper_ns"": 12582912}]"
+mixed_tight,threshold2,4,ok,threshold,0.12.0,2097152,41728,1097792,393312,72752,524336,1884160,134641407,51772899,26303805,1024,3072,49877076,26814720,114814580,0,6823.249522,1222.425123,10156.044791,363,239,367,5952,0,584,0,0,1024,83930889,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 47208.702, ""latency_p99_upper_ns"": 131072}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5081715.549, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8082551.032, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,threshold8,4,ok,threshold,0.12.0,2097152,41728,1097792,393312,11312,524336,2048000,134636889,51692325,26232175,1024,3072,49877076,1059072,114814580,0,7604.090343,924.831397,10109.160375,237,97,259,5797,0,600,0,0,1024,84203974,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 46850.104, ""latency_p99_upper_ns"": 147456}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5081772.482, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8081990.295, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,borrow,4,ok,borrow,0.12.0,2097152,41728,2097024,2047296,0,524336,3719168,516507633,56956626,413462854,1024,3072,49877076,0,114814580,0,866066.604394,0.0,10498.181654,1635,0,588,2650,1258,0,0,0,0,460890935,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 495819.875, ""latency_p99_upper_ns"": 7864320}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 30, ""latency_mean_ns"": 5527650.658, ""latency_p99_upper_ns"": 12582912}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 30, ""latency_mean_ns"": 8542682.03, ""latency_p99_upper_ns"": 15728640}]"
+mixed_tight,shared_copy,4,ok,shared_copy,0.12.0,2097152,41728,1097792,393312,72752,524336,1884160,134698503,52062419,26232455,1024,3072,49877076,26814720,114814580,0,6807.634601,1226.698884,10096.010075,358,229,363,5971,0,573,0,0,1024,83820760,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 47338.287, ""latency_p99_upper_ns"": 147456}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5082803.919, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8081430.476, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,copy_no_pool,4,ok,copy,0.12.0,2097152,41728,842368,393312,79920,524336,1933312,135617374,59370307,27370335,1024,3072,49877076,26872064,114814580,0,8306.118105,1881.770411,10193.350967,3849,3072,1024,0,0,541,0,0,0,77447978,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 54118.737, ""latency_p99_upper_ns"": 180224}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5093193.132, ""latency_p99_upper_ns"": 5767168}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8094306.969, ""latency_p99_upper_ns"": 8388608}]"
+mixed_tight,copy,4,ok,copy,0.12.0,2097152,41728,1104736,393312,79920,524336,1884160,135101765,53612089,26369173,1024,3072,49877076,26872064,114814580,0,6944.794448,1822.831558,10130.150831,348,886,368,6343,0,561,0,0,0,82695691,0,0,"[{""emitted"": 1024, ""bytes"": 26757376, ""peak_count"": 1, ""latency_mean_ns"": 48573.396, ""latency_p99_upper_ns"": 147456}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 5083912.79, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 1024, ""bytes"": 57344, ""peak_count"": 64, ""latency_mean_ns"": 8083831.809, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,copy_no_pool,0,ok,copy,0.12.0,2097152,41728,170672,24672,14896,98400,1835008,66381179,14937944,10634360,512,1536,5259666,319488,6312628,14086144,191.835816,748.822762,436.544508,1273,1536,1024,0,0,200,0,0,0,51858352,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26502.654, ""latency_p99_upper_ns"": 36864}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5055591.338, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8038187.436, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,borrow,0,ok,borrow,0.12.0,2097152,41728,1208192,1059888,0,98400,2785280,66395496,14949295,10748920,512,1536,5259666,0,6312628,14086144,67632.156584,0.0,441.340054,70,0,2,2225,0,210,0,0,0,51867983,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26677.738, ""latency_p99_upper_ns"": 40960}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5055635.91, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8040456.355, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,threshold8,0,ok,threshold,0.12.0,2097152,41728,180144,24672,7728,98400,1851392,66344311,14626628,10598197,512,1536,5259666,290816,6312628,14086144,189.993439,460.282359,437.832685,6,65,2,3248,0,201,0,0,512,52108022,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26057.676, ""latency_p99_upper_ns"": 30720}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5054707.516, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8038718.686, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,shared_copy,0,ok,shared_copy,0.12.0,2097152,41728,180144,24672,7728,98400,1835008,66360126,14610198,10558947,512,1536,5259666,290816,6312628,14086144,189.278595,460.358957,433.475216,6,65,2,3248,0,210,0,0,512,52155647,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26056.072, ""latency_p99_upper_ns"": 30720}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5054720.746, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8039527.611, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,compact,0,ok,compact,0.12.0,2097152,41728,1209200,1059888,7168,98400,2899968,66352515,15174956,10767457,512,1536,5259666,28672,6312628,14086144,42522.512719,170.992644,444.338525,462,456,2,1889,0,203,512,0,0,51584350,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26833.023, ""latency_p99_upper_ns"": 40960}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5055824.906, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8037818.045, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,copy,0,ok,copy,0.12.0,2097152,41728,187312,24672,14896,98400,1835008,66358774,14704746,10580140,512,1536,5259666,319488,6312628,14086144,190.401936,748.797361,434.190092,6,546,2,3279,0,198,0,0,0,52055904,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26138.373, ""latency_p99_upper_ns"": 32768}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5054837.756, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8038347.354, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,threshold2,0,ok,threshold,0.12.0,2097152,41728,180144,24672,7728,98400,1851392,66343256,14610428,10601249,512,1536,5259666,290816,6312628,14086144,190.005404,460.293238,435.304664,6,65,2,3248,0,199,0,0,512,52113330,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26103.785, ""latency_p99_upper_ns"": 32768}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5054791.455, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8038668.434, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,threshold8,1,ok,threshold,0.12.0,2097152,41728,180144,24672,7728,98400,1835008,66620533,15009658,10599246,512,1536,5259666,290816,6312628,14086144,190.711835,461.162485,439.194778,6,67,2,3246,0,195,0,0,512,52089340,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26514.744, ""latency_p99_upper_ns"": 36864}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5059599.168, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8052646.494, ""latency_p99_upper_ns"": 9437184}]"
+metadata_heavy,copy_no_pool,1,ok,copy,0.12.0,2097152,41728,170672,24672,14896,98400,1835008,69246534,16610834,11758115,512,1536,5259666,319488,6312628,14086144,215.365911,778.347747,481.501477,1273,1536,1024,0,0,164,0,0,0,52395416,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 29861.328, ""latency_p99_upper_ns"": 57344}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5481519.523, ""latency_p99_upper_ns"": 10485760}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8132478.682, ""latency_p99_upper_ns"": 10485760}]"
+metadata_heavy,shared_copy,1,ok,shared_copy,0.12.0,2097152,41728,180144,24672,7728,98400,1835008,67338922,15543047,10965512,512,1536,5259666,290816,6312628,14086144,198.833427,461.43294,455.786835,6,88,2,3225,0,170,0,0,512,52096250,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 27620.291, ""latency_p99_upper_ns"": 53248}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5405312.287, ""latency_p99_upper_ns"": 9437184}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8058747.33, ""latency_p99_upper_ns"": 9437184}]"
+metadata_heavy,copy,1,ok,copy,0.12.0,2097152,41728,187312,24672,14896,98400,1835008,66437867,14887131,10719986,512,1536,5259666,319488,6312628,14086144,192.97609,748.927344,442.835871,6,546,2,3279,0,206,0,0,0,51911693,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26502.299, ""latency_p99_upper_ns"": 36864}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5055229.1, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8040517.863, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,threshold2,1,ok,threshold,0.12.0,2097152,41728,180144,24672,7728,98400,1835008,66341459,14573003,10555283,512,1536,5259666,290816,6312628,14086144,189.19959,460.262935,433.563583,6,65,2,3248,0,202,0,0,512,52150322,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26047.523, ""latency_p99_upper_ns"": 30720}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5054844.742, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8037890.609, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,borrow,1,ok,borrow,0.12.0,2097152,41728,1208192,1059888,0,98400,2801664,66302663,14680433,10680579,512,1536,5259666,0,6312628,14086144,67603.216745,0.0,441.482243,70,0,2,2225,0,203,0,0,0,52022749,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26241.209, ""latency_p99_upper_ns"": 32768}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5054887.895, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8036938.547, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,compact,1,ok,compact,0.12.0,2097152,41728,1209200,1059888,7168,98400,2916352,66647996,15645769,10897093,512,1536,5259666,28672,6312628,14086144,42531.184104,171.185155,448.382215,462,456,2,1889,0,208,512,0,0,51484721,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 27363.605, ""latency_p99_upper_ns"": 49152}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5056927.043, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8042303.346, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,shared_copy,2,ok,shared_copy,0.12.0,2097152,41728,180144,24672,7728,98400,1835008,66509552,15439851,10723161,512,1536,5259666,290816,6312628,14086144,194.692414,460.401472,443.814792,6,65,2,3248,0,188,0,0,512,51559999,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 27221.904, ""latency_p99_upper_ns"": 40960}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5102159.828, ""latency_p99_upper_ns"": 6291456}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8039936.652, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,threshold2,2,ok,threshold,0.12.0,2097152,41728,180144,24672,7728,98400,1851392,66675868,15617313,10794500,512,1536,5259666,290816,6312628,14086144,196.368374,460.582208,453.168708,6,72,2,3241,0,206,0,0,512,51576007,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 27391.873, ""latency_p99_upper_ns"": 45056}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5063401.098, ""latency_p99_upper_ns"": 5767168}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8043009.266, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,threshold8,2,ok,threshold,0.12.0,2097152,41728,180144,24672,7728,98400,1835008,66346091,14749114,10663838,512,1536,5259666,290816,6312628,14086144,191.566293,460.387978,441.272197,6,65,2,3248,0,198,0,0,512,51956135,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26444.111, ""latency_p99_upper_ns"": 40960}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5055009.982, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8040053.549, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,borrow,2,ok,borrow,0.12.0,2097152,41728,1208192,1059888,0,98400,2768896,66340906,14840713,10710339,512,1536,5259666,0,6312628,14086144,67628.848076,0.0,441.911742,70,0,2,2225,0,214,0,0,0,51926596,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26533.881, ""latency_p99_upper_ns"": 36864}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5055556.934, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8040046.408, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,copy_no_pool,2,ok,copy,0.12.0,2097152,41728,170672,24672,14896,98400,1851392,66367572,14844612,10626817,512,1536,5259666,319488,6312628,14086144,191.787957,748.742987,439.039763,1273,1536,1024,0,0,202,0,0,0,51918865,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26443.496, ""latency_p99_upper_ns"": 32768}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5055503.67, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8037164.848, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,compact,2,ok,compact,0.12.0,2097152,41728,1209200,1059888,7168,98400,2916352,66456221,15237761,10832907,512,1536,5259666,28672,6312628,14086144,42524.965388,171.106633,446.50427,462,456,2,1889,0,211,512,0,0,51628844,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26894.043, ""latency_p99_upper_ns"": 36864}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5056115.033, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8040094.787, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,copy,2,ok,copy,0.12.0,2097152,41728,187312,24672,14896,98400,1818624,66358054,14786258,10588699,512,1536,5259666,319488,6312628,14086144,190.767691,748.949984,437.20655,6,546,2,3279,0,202,0,0,0,51982953,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26290.178, ""latency_p99_upper_ns"": 36864}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5055243.682, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8040476.592, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,shared_copy,3,ok,shared_copy,0.12.0,2097152,41728,180144,24672,7728,98400,1835008,66340017,14641398,10583202,512,1536,5259666,290816,6312628,14086144,189.850967,460.201756,434.46664,6,65,2,3248,0,200,0,0,512,52101474,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26126.43, ""latency_p99_upper_ns"": 32768}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5054896.006, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8037126.236, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,borrow,3,ok,borrow,0.12.0,2097152,41728,1208192,1059888,0,98400,2768896,66397387,14926280,10743184,512,1536,5259666,0,6312628,14086144,67622.063537,0.0,442.942199,70,0,2,2225,0,212,0,0,0,51935519,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26540.598, ""latency_p99_upper_ns"": 36864}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5055706.689, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8039215.434, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,copy,3,ok,copy,0.12.0,2097152,41728,187312,24672,14896,98400,1835008,66347591,14688841,10558757,512,1536,5259666,319488,6312628,14086144,190.237303,748.906445,434.052077,6,546,2,3279,0,201,0,0,0,52048363,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26185.322, ""latency_p99_upper_ns"": 30720}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5054934.725, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8039957.693, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,compact,3,ok,compact,0.12.0,2097152,41728,1209200,1059888,7168,98400,2916352,66425702,15126826,10762572,512,1536,5259666,28672,6312628,14086144,42518.234312,171.124375,442.813559,462,456,2,1889,0,207,512,0,0,51722109,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26699.592, ""latency_p99_upper_ns"": 36864}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5055311.875, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8039588.77, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,threshold8,3,ok,threshold,0.12.0,2097152,41728,180144,24672,7728,98400,1835008,66342183,14624958,10558072,512,1536,5259666,290816,6312628,14086144,189.596919,460.250779,436.103934,6,65,2,3248,0,199,0,0,512,52113950,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26082.711, ""latency_p99_upper_ns"": 32768}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5054439.891, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8037911.916, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,copy_no_pool,3,ok,copy,0.12.0,2097152,41728,170672,24672,14896,98400,1835008,66421906,14924036,10733514,512,1536,5259666,319488,6312628,14086144,193.388376,748.846289,443.059571,1273,1536,1024,0,0,207,0,0,0,51871512,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26630.812, ""latency_p99_upper_ns"": 40960}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5055263.076, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8039399.533, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,threshold2,3,ok,threshold,0.12.0,2097152,41728,180144,24672,7728,98400,1835008,66363184,14629240,10568715,512,1536,5259666,290816,6312628,14086144,189.501318,460.195707,436.121559,6,65,2,3248,0,199,0,0,512,52142767,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26129.004, ""latency_p99_upper_ns"": 30720}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5054684.932, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8036606.693, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,threshold2,4,ok,threshold,0.12.0,2097152,41728,180144,24672,7728,98400,1835008,66354498,14608671,10552983,512,1536,5259666,290816,6312628,14086144,189.286265,460.245208,433.358809,6,65,2,3248,0,197,0,0,512,52143565,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26044.074, ""latency_p99_upper_ns"": 30720}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5054765.459, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8037717.471, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,copy_no_pool,4,ok,copy,0.12.0,2097152,41728,170672,24672,14896,98400,1851392,66440315,15042208,10714630,512,1536,5259666,319488,6312628,14086144,193.34471,749.072578,442.776453,1273,1536,1024,0,0,203,0,0,0,51818059,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26719.596, ""latency_p99_upper_ns"": 40960}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5055539.021, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8042928.75, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,shared_copy,4,ok,shared_copy,0.12.0,2097152,41728,180144,24672,7728,98400,1835008,66550686,14565611,10569760,512,1536,5259666,290816,6312628,14086144,189.196651,460.427963,435.936714,6,70,2,3243,0,199,0,0,512,52394259,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26054.17, ""latency_p99_upper_ns"": 30720}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5054468.873, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8040821.889, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,compact,4,ok,compact,0.12.0,2097152,41728,1209200,1059888,7168,98400,2932736,66346982,15115580,10730381,512,1536,5259666,28672,6312628,14086144,42539.689103,170.963142,440.137993,462,456,2,1889,0,200,512,0,0,51642878,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26772.898, ""latency_p99_upper_ns"": 36864}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5057876.094, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8039346.365, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,threshold8,4,ok,threshold,0.12.0,2097152,41728,180144,24672,7728,98400,1851392,66367685,14678765,10612300,512,1536,5259666,290816,6312628,14086144,190.199351,460.290364,438.024028,6,65,2,3248,0,200,0,0,512,52099788,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26178.92, ""latency_p99_upper_ns"": 36864}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5054797.43, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8038471.338, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,borrow,4,ok,borrow,0.12.0,2097152,41728,1208192,1059888,0,98400,2785280,66395630,14769876,10679603,512,1536,5259666,0,6312628,14086144,67615.986637,0.0,438.40001,70,0,2,2225,0,207,0,0,0,52035492,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26350.551, ""latency_p99_upper_ns"": 36864}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5054965.338, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8038469.066, ""latency_p99_upper_ns"": 8388608}]"
+metadata_heavy,copy,4,ok,copy,0.12.0,2097152,41728,187312,24672,14896,98400,1835008,66338315,14754424,10609310,512,1536,5259666,319488,6312628,14086144,190.968242,748.772024,435.574111,6,546,2,3279,0,199,0,0,0,51978025,0,0,"[{""emitted"": 512, ""bytes"": 262144, ""peak_count"": 1, ""latency_mean_ns"": 26285.051, ""latency_p99_upper_ns"": 36864}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 5055200.059, ""latency_p99_upper_ns"": 5242880}, {""emitted"": 512, ""bytes"": 28672, ""peak_count"": 64, ""latency_mean_ns"": 8037468.172, ""latency_p99_upper_ns"": 8388608}]"
diff --git a/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/raw.json b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/raw.json new file mode 100644 index 0000000..9bf47cb --- /dev/null +++ b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/raw.json @@ -0,0 +1,12532 @@ +[ + { + "case": "one_slow", + "variant": "threshold2", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 303072, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1835008, + "elapsed_ns": 131703634, + "cpu_ns": 34750648, + "parse_call_ns": 21989760, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1842.615404, + "output_byte_seconds": 919.75921, + "parser_byte_seconds": 2883.244752, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 6056, + "budget_waits": 0, + "slot_waits": 16, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 97097912, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8051720.034, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "compact", + "repeat": 0, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 4427696, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5537792, + "elapsed_ns": 131996119, + "cpu_ns": 38004572, + "parse_call_ns": 22434299, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 540791.270719, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2928.256675, + "source_allocations": 72, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5033, + "budget_waits": 0, + "slot_waits": 26, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 94192606, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8057605.331, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "borrow", + "repeat": 0, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 4427696, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5521408, + "elapsed_ns": 132124751, + "cpu_ns": 37612015, + "parse_call_ns": 22444229, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 540845.471315, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2930.090388, + "source_allocations": 72, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5033, + "budget_waits": 0, + "slot_waits": 53, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 94791711, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8058299.849, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "threshold8", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 303072, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1818624, + "elapsed_ns": 131620844, + "cpu_ns": 34446035, + "parse_call_ns": 21905479, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1832.609103, + "output_byte_seconds": 920.078119, + "parser_byte_seconds": 2872.388672, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 6056, + "budget_waits": 0, + "slot_waits": 16, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 97293567, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8054286.008, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "copy_no_pool", + "repeat": 0, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 237296, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1835008, + "elapsed_ns": 132233158, + "cpu_ns": 41767998, + "parse_call_ns": 24756316, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2069.543688, + "output_byte_seconds": 920.140424, + "parser_byte_seconds": 2901.308237, + "source_allocations": 4082, + "output_allocations": 1024, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 19, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 90619067, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8059175.662, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "copy", + "repeat": 0, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 303072, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1818624, + "elapsed_ns": 131600270, + "cpu_ns": 34455850, + "parse_call_ns": 21964978, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1832.537919, + "output_byte_seconds": 920.025416, + "parser_byte_seconds": 2880.380829, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 6056, + "budget_waits": 0, + "slot_waits": 16, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 97270417, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8053796.131, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "shared_copy", + "repeat": 0, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 303072, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1802240, + "elapsed_ns": 131715584, + "cpu_ns": 34456703, + "parse_call_ns": 21940218, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1833.007769, + "output_byte_seconds": 920.07894, + "parser_byte_seconds": 2877.016945, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 6056, + "budget_waits": 0, + "slot_waits": 16, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 97393619, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8054276.953, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "compact", + "repeat": 1, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 4427696, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5537792, + "elapsed_ns": 132171843, + "cpu_ns": 38070312, + "parse_call_ns": 22523797, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 540815.06589, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2937.269732, + "source_allocations": 72, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5033, + "budget_waits": 0, + "slot_waits": 40, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 94338529, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8057936.641, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "copy_no_pool", + "repeat": 1, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 237296, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1835008, + "elapsed_ns": 132199048, + "cpu_ns": 42202499, + "parse_call_ns": 24805054, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2084.967873, + "output_byte_seconds": 920.132302, + "parser_byte_seconds": 2905.942804, + "source_allocations": 4082, + "output_allocations": 1024, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 29, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 90146770, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8059478.906, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "shared_copy", + "repeat": 1, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 303072, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1818624, + "elapsed_ns": 131708165, + "cpu_ns": 34804961, + "parse_call_ns": 22044118, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1844.634105, + "output_byte_seconds": 919.759432, + "parser_byte_seconds": 2890.857973, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 6056, + "budget_waits": 0, + "slot_waits": 16, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 97053198, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8051751.524, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "threshold8", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 303072, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1818624, + "elapsed_ns": 131798127, + "cpu_ns": 34803856, + "parse_call_ns": 22044512, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1846.36305, + "output_byte_seconds": 919.612987, + "parser_byte_seconds": 2891.382584, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 6056, + "budget_waits": 0, + "slot_waits": 16, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 97156768, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8050483.774, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "borrow", + "repeat": 1, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 4427696, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5521408, + "elapsed_ns": 131976979, + "cpu_ns": 38591495, + "parse_call_ns": 22573964, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 540860.949553, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2940.513903, + "source_allocations": 72, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5033, + "budget_waits": 0, + "slot_waits": 28, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 93626665, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8058679.423, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "copy", + "repeat": 1, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 303072, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1818624, + "elapsed_ns": 131752053, + "cpu_ns": 34888537, + "parse_call_ns": 21974890, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1845.194241, + "output_byte_seconds": 919.599974, + "parser_byte_seconds": 2880.87266, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 6056, + "budget_waits": 0, + "slot_waits": 17, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 97030621, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8050419.036, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "threshold2", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 303072, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1818624, + "elapsed_ns": 131720609, + "cpu_ns": 34747849, + "parse_call_ns": 21999728, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1843.805295, + "output_byte_seconds": 919.628727, + "parser_byte_seconds": 2884.923744, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 6056, + "budget_waits": 0, + "slot_waits": 16, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 97113750, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8050578.244, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "copy", + "repeat": 2, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 303072, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1818624, + "elapsed_ns": 131735071, + "cpu_ns": 34877739, + "parse_call_ns": 22030534, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1847.409016, + "output_byte_seconds": 919.636562, + "parser_byte_seconds": 2888.89668, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 6056, + "budget_waits": 0, + "slot_waits": 16, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 96987832, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8050770.82, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "compact", + "repeat": 2, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 4427696, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5537792, + "elapsed_ns": 132186905, + "cpu_ns": 38709650, + "parse_call_ns": 22486562, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 540826.901328, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2931.839266, + "source_allocations": 72, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5033, + "budget_waits": 0, + "slot_waits": 36, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 93736446, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8058254.455, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "shared_copy", + "repeat": 2, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 303072, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1835008, + "elapsed_ns": 134003964, + "cpu_ns": 36820353, + "parse_call_ns": 22141327, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1907.646695, + "output_byte_seconds": 924.396419, + "parser_byte_seconds": 2903.071145, + "source_allocations": 9, + "output_allocations": 116, + "parser_allocations": 1, + "reuses": 6004, + "budget_waits": 0, + "slot_waits": 25, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 97345374, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8093864.112, + "latency_p99_upper_ns": 9437184 + } + ] + }, + { + "case": "one_slow", + "variant": "threshold2", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 303072, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1818624, + "elapsed_ns": 132093280, + "cpu_ns": 37140317, + "parse_call_ns": 22338927, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1928.638533, + "output_byte_seconds": 919.864631, + "parser_byte_seconds": 2930.310014, + "source_allocations": 9, + "output_allocations": 68, + "parser_allocations": 1, + "reuses": 6052, + "budget_waits": 0, + "slot_waits": 20, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 95013211, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8054865.09, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "borrow", + "repeat": 2, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 4427696, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5554176, + "elapsed_ns": 132469040, + "cpu_ns": 41862764, + "parse_call_ns": 22964342, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 541099.43903, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2986.938382, + "source_allocations": 73, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5032, + "budget_waits": 0, + "slot_waits": 49, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 90878204, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8063020.332, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "copy_no_pool", + "repeat": 2, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 237296, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1802240, + "elapsed_ns": 137450461, + "cpu_ns": 46306762, + "parse_call_ns": 25720817, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2217.245474, + "output_byte_seconds": 934.97033, + "parser_byte_seconds": 2945.941354, + "source_allocations": 4082, + "output_allocations": 1024, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 23, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 91429169, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8191749.104, + "latency_p99_upper_ns": 11534336 + } + ] + }, + { + "case": "one_slow", + "variant": "threshold8", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 303072, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1818624, + "elapsed_ns": 131976855, + "cpu_ns": 36997295, + "parse_call_ns": 22056693, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1904.528214, + "output_byte_seconds": 920.059714, + "parser_byte_seconds": 2891.295258, + "source_allocations": 9, + "output_allocations": 65, + "parser_allocations": 1, + "reuses": 6055, + "budget_waits": 0, + "slot_waits": 21, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 95230128, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8056258.001, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "threshold2", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 303072, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1818624, + "elapsed_ns": 132144262, + "cpu_ns": 36810738, + "parse_call_ns": 22394390, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1914.610493, + "output_byte_seconds": 920.080986, + "parser_byte_seconds": 2937.462741, + "source_allocations": 9, + "output_allocations": 71, + "parser_allocations": 1, + "reuses": 6049, + "budget_waits": 0, + "slot_waits": 39, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 95437850, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8056316.891, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "threshold8", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 303072, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1818624, + "elapsed_ns": 131627799, + "cpu_ns": 34748983, + "parse_call_ns": 22050963, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1845.118437, + "output_byte_seconds": 920.020651, + "parser_byte_seconds": 2891.313221, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 6056, + "budget_waits": 0, + "slot_waits": 19, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 96996391, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8054019.278, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "compact", + "repeat": 3, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 4427696, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5537792, + "elapsed_ns": 132093080, + "cpu_ns": 38378509, + "parse_call_ns": 22460168, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 540907.798619, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2928.186919, + "source_allocations": 72, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5033, + "budget_waits": 0, + "slot_waits": 43, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 93965206, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8059384.654, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "copy_no_pool", + "repeat": 3, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 237296, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1802240, + "elapsed_ns": 132246841, + "cpu_ns": 41768202, + "parse_call_ns": 24673720, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2066.312998, + "output_byte_seconds": 920.19798, + "parser_byte_seconds": 2896.434244, + "source_allocations": 4082, + "output_allocations": 1024, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 16, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 90608121, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8059680.607, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "copy", + "repeat": 3, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 303072, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1818624, + "elapsed_ns": 131689453, + "cpu_ns": 35243759, + "parse_call_ns": 22012604, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1857.757504, + "output_byte_seconds": 919.947028, + "parser_byte_seconds": 2887.51415, + "source_allocations": 9, + "output_allocations": 68, + "parser_allocations": 1, + "reuses": 6052, + "budget_waits": 0, + "slot_waits": 27, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 96622803, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8053765.222, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "shared_copy", + "repeat": 3, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 303072, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1802240, + "elapsed_ns": 132103712, + "cpu_ns": 35248408, + "parse_call_ns": 22004780, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1858.44117, + "output_byte_seconds": 919.973445, + "parser_byte_seconds": 2885.070598, + "source_allocations": 9, + "output_allocations": 73, + "parser_allocations": 1, + "reuses": 6047, + "budget_waits": 0, + "slot_waits": 22, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 97018510, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8054006.321, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "borrow", + "repeat": 3, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 4427696, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5537792, + "elapsed_ns": 132436008, + "cpu_ns": 40869521, + "parse_call_ns": 22656213, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 540941.338269, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2953.318689, + "source_allocations": 75, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5030, + "budget_waits": 0, + "slot_waits": 52, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 91954404, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8060462.982, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "compact", + "repeat": 4, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 4427696, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5554176, + "elapsed_ns": 132110379, + "cpu_ns": 38257181, + "parse_call_ns": 22557256, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 540811.125254, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2944.323595, + "source_allocations": 72, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5033, + "budget_waits": 0, + "slot_waits": 56, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 94112952, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8057929.717, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "threshold8", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 303072, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1802240, + "elapsed_ns": 131804916, + "cpu_ns": 34977352, + "parse_call_ns": 22094634, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1853.831647, + "output_byte_seconds": 920.149467, + "parser_byte_seconds": 2897.713188, + "source_allocations": 9, + "output_allocations": 67, + "parser_allocations": 1, + "reuses": 6053, + "budget_waits": 0, + "slot_waits": 31, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 96937037, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8055361.395, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "copy_no_pool", + "repeat": 4, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 237296, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1818624, + "elapsed_ns": 135161451, + "cpu_ns": 44330024, + "parse_call_ns": 25503982, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2157.809223, + "output_byte_seconds": 924.543547, + "parser_byte_seconds": 2946.975235, + "source_allocations": 4082, + "output_allocations": 1024, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 35, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 91118882, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8099348.558, + "latency_p99_upper_ns": 10485760 + } + ] + }, + { + "case": "one_slow", + "variant": "threshold2", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 303072, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1802240, + "elapsed_ns": 132588310, + "cpu_ns": 37673671, + "parse_call_ns": 22518430, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1949.11739, + "output_byte_seconds": 920.155569, + "parser_byte_seconds": 2954.042078, + "source_allocations": 9, + "output_allocations": 78, + "parser_allocations": 1, + "reuses": 6042, + "budget_waits": 0, + "slot_waits": 36, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 94895218, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8057756.78, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "copy", + "repeat": 4, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 303072, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1818624, + "elapsed_ns": 131620718, + "cpu_ns": 34580946, + "parse_call_ns": 21993246, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1837.245494, + "output_byte_seconds": 919.925321, + "parser_byte_seconds": 2884.001314, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 6056, + "budget_waits": 0, + "slot_waits": 16, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 97154068, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8053071.22, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "borrow", + "repeat": 4, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 4427696, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5537792, + "elapsed_ns": 132000791, + "cpu_ns": 37927424, + "parse_call_ns": 22507290, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 540831.163899, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2938.768696, + "source_allocations": 72, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5033, + "budget_waits": 0, + "slot_waits": 30, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 94241105, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8058140.749, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "shared_copy", + "repeat": 4, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 33536, + "peak_reserved_bytes": 303072, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1818624, + "elapsed_ns": 132283829, + "cpu_ns": 37157688, + "parse_call_ns": 22116989, + "accepted": 1024, + "emitted": 1024, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1917.711679, + "output_byte_seconds": 920.053817, + "parser_byte_seconds": 2900.603467, + "source_allocations": 9, + "output_allocations": 67, + "parser_allocations": 1, + "reuses": 6053, + "budget_waits": 0, + "slot_waits": 38, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 95415784, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8056291.708, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "borrow", + "repeat": 0, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4435888, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5373952, + "elapsed_ns": 132804710, + "cpu_ns": 49883960, + "parse_call_ns": 22784485, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 540593.356702, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2990.235132, + "source_allocations": 72, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5033, + "budget_waits": 0, + "slot_waits": 578, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 84130488, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 45505.588, + "latency_p99_upper_ns": 65536 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5070252.164, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8055489.045, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "compact", + "repeat": 0, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4436784, + "source_peak_bytes": 4230192, + "output_peak_bytes": 6944, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5537792, + "elapsed_ns": 132699783, + "cpu_ns": 50261222, + "parse_call_ns": 22546544, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 340105.36302, + "output_byte_seconds": 342.277671, + "parser_byte_seconds": 2958.801865, + "source_allocations": 897, + "output_allocations": 913, + "parser_allocations": 1, + "reuses": 4319, + "budget_waits": 0, + "slot_waits": 550, + "compacted": 1024, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 83652241, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 45463.711, + "latency_p99_upper_ns": 65536 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5069982.729, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8054576.42, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "shared_copy", + "repeat": 0, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 311264, + "source_peak_bytes": 98400, + "output_peak_bytes": 39984, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1835008, + "elapsed_ns": 132438636, + "cpu_ns": 46508730, + "parse_call_ns": 22104890, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33611776, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1994.687521, + "output_byte_seconds": 1188.73405, + "parser_byte_seconds": 2903.952009, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 7080, + "budget_waits": 0, + "slot_waits": 538, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 87037859, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 42492.519, + "latency_p99_upper_ns": 57344 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5069205.345, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8052022.729, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "copy", + "repeat": 0, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 318432, + "source_peak_bytes": 98400, + "output_peak_bytes": 47152, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1851392, + "elapsed_ns": 132301692, + "cpu_ns": 46274024, + "parse_call_ns": 22012014, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33669120, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1991.776071, + "output_byte_seconds": 1766.57547, + "parser_byte_seconds": 2891.89841, + "source_allocations": 9, + "output_allocations": 1025, + "parser_allocations": 1, + "reuses": 7143, + "budget_waits": 0, + "slot_waits": 563, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 87083196, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 42221.575, + "latency_p99_upper_ns": 57344 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5068352.743, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8049671.308, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "copy_no_pool", + "repeat": 0, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 252544, + "source_peak_bytes": 98400, + "output_peak_bytes": 47152, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1933312, + "elapsed_ns": 132221655, + "cpu_ns": 46432790, + "parse_call_ns": 22094470, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33669120, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2002.66499, + "output_byte_seconds": 1764.18462, + "parser_byte_seconds": 2896.537304, + "source_allocations": 4082, + "output_allocations": 3072, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 534, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 86822233, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 42461.52, + "latency_p99_upper_ns": 57344 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5068300.921, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8054065.407, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "threshold2", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 311264, + "source_peak_bytes": 98400, + "output_peak_bytes": 39984, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1851392, + "elapsed_ns": 132423215, + "cpu_ns": 46202689, + "parse_call_ns": 22137673, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33611776, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1992.776523, + "output_byte_seconds": 1183.803646, + "parser_byte_seconds": 2909.259091, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 7080, + "budget_waits": 0, + "slot_waits": 559, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 87298460, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 42209.067, + "latency_p99_upper_ns": 57344 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5068504.791, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8052025.9, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "threshold8", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 311264, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1851392, + "elapsed_ns": 132072752, + "cpu_ns": 44818714, + "parse_call_ns": 22007505, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2372.402719, + "output_byte_seconds": 919.579066, + "parser_byte_seconds": 2891.111165, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 6056, + "budget_waits": 0, + "slot_waits": 531, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 88271004, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 41081.91, + "latency_p99_upper_ns": 49152 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5067409.945, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8052229.961, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "copy", + "repeat": 1, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 318432, + "source_peak_bytes": 98400, + "output_peak_bytes": 47152, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1851392, + "elapsed_ns": 132122049, + "cpu_ns": 45960158, + "parse_call_ns": 22062914, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33669120, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1985.913742, + "output_byte_seconds": 1766.681864, + "parser_byte_seconds": 2899.647733, + "source_allocations": 9, + "output_allocations": 1025, + "parser_allocations": 1, + "reuses": 7143, + "budget_waits": 0, + "slot_waits": 530, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 87159643, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 42080.341, + "latency_p99_upper_ns": 53248 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5068084.019, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8053834.564, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "copy_no_pool", + "repeat": 1, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 252544, + "source_peak_bytes": 98400, + "output_peak_bytes": 47152, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1884160, + "elapsed_ns": 132225178, + "cpu_ns": 46345346, + "parse_call_ns": 22106440, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33669120, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1998.568774, + "output_byte_seconds": 1764.360213, + "parser_byte_seconds": 2898.609, + "source_allocations": 4082, + "output_allocations": 3072, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 531, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 86929226, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 42412.925, + "latency_p99_upper_ns": 57344 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5068204.178, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8052346.592, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "threshold2", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 311264, + "source_peak_bytes": 98400, + "output_peak_bytes": 39984, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1851392, + "elapsed_ns": 132119197, + "cpu_ns": 45785542, + "parse_call_ns": 22119160, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33611776, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1985.975023, + "output_byte_seconds": 1182.61037, + "parser_byte_seconds": 2906.107753, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 7080, + "budget_waits": 0, + "slot_waits": 535, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 87289352, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 42063.476, + "latency_p99_upper_ns": 61440 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5068193.573, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8051854.179, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "compact", + "repeat": 1, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4436784, + "source_peak_bytes": 4230192, + "output_peak_bytes": 6944, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5603328, + "elapsed_ns": 132689456, + "cpu_ns": 50225388, + "parse_call_ns": 22679397, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 340115.562513, + "output_byte_seconds": 342.313483, + "parser_byte_seconds": 2976.797692, + "source_allocations": 896, + "output_allocations": 908, + "parser_allocations": 1, + "reuses": 4325, + "budget_waits": 0, + "slot_waits": 548, + "compacted": 1024, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 83654110, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 45534.298, + "latency_p99_upper_ns": 65536 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5070135.917, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8055038.37, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "threshold8", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 311264, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1851392, + "elapsed_ns": 132687220, + "cpu_ns": 45610919, + "parse_call_ns": 22143479, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2398.303122, + "output_byte_seconds": 919.310014, + "parser_byte_seconds": 2908.551305, + "source_allocations": 9, + "output_allocations": 73, + "parser_allocations": 1, + "reuses": 6047, + "budget_waits": 0, + "slot_waits": 557, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 88180228, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 41592.506, + "latency_p99_upper_ns": 65536 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5067924.312, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8050249.576, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "shared_copy", + "repeat": 1, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 311264, + "source_peak_bytes": 98400, + "output_peak_bytes": 39984, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1851392, + "elapsed_ns": 133179387, + "cpu_ns": 47009567, + "parse_call_ns": 22053622, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33611776, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2001.098596, + "output_byte_seconds": 1195.094634, + "parser_byte_seconds": 2898.481421, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 7080, + "budget_waits": 0, + "slot_waits": 619, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 87400987, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 42811.697, + "latency_p99_upper_ns": 90112 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5068344.258, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8054983.926, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "borrow", + "repeat": 1, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4435888, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5373952, + "elapsed_ns": 132590517, + "cpu_ns": 49691116, + "parse_call_ns": 22667622, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 540625.036225, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2974.002082, + "source_allocations": 72, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5033, + "budget_waits": 0, + "slot_waits": 555, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 84069041, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 45356.652, + "latency_p99_upper_ns": 65536 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5069262.154, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8055874.806, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "borrow", + "repeat": 2, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4435888, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5373952, + "elapsed_ns": 132595906, + "cpu_ns": 48936945, + "parse_call_ns": 22622066, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 540538.226737, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2969.006017, + "source_allocations": 72, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5033, + "budget_waits": 0, + "slot_waits": 550, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 84820014, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 44590.665, + "latency_p99_upper_ns": 61440 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5069713.765, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8054486.477, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "threshold2", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 311264, + "source_peak_bytes": 98400, + "output_peak_bytes": 39984, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1851392, + "elapsed_ns": 132243573, + "cpu_ns": 45674856, + "parse_call_ns": 22029775, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33611776, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1978.146096, + "output_byte_seconds": 1181.588579, + "parser_byte_seconds": 2894.51268, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 7080, + "budget_waits": 0, + "slot_waits": 547, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 87607899, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 41881.888, + "latency_p99_upper_ns": 53248 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5067912.655, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8049931.179, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "compact", + "repeat": 2, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4436784, + "source_peak_bytes": 4230192, + "output_peak_bytes": 6944, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5603328, + "elapsed_ns": 132732463, + "cpu_ns": 49739534, + "parse_call_ns": 22671992, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 340105.112239, + "output_byte_seconds": 342.468555, + "parser_byte_seconds": 2974.922545, + "source_allocations": 893, + "output_allocations": 887, + "parser_allocations": 1, + "reuses": 4349, + "budget_waits": 0, + "slot_waits": 562, + "compacted": 1024, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 84142850, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 44979.318, + "latency_p99_upper_ns": 65536 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5069891.561, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8056164.197, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "threshold8", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 311264, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1851392, + "elapsed_ns": 132272059, + "cpu_ns": 45320979, + "parse_call_ns": 22141356, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2389.486333, + "output_byte_seconds": 919.390876, + "parser_byte_seconds": 2908.882515, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 6056, + "budget_waits": 0, + "slot_waits": 563, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 88007671, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 41406.16, + "latency_p99_upper_ns": 57344 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5068143.112, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8050851.553, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "copy", + "repeat": 2, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 318432, + "source_peak_bytes": 98400, + "output_peak_bytes": 47152, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1867776, + "elapsed_ns": 132351078, + "cpu_ns": 46122525, + "parse_call_ns": 22082400, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33669120, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1991.903399, + "output_byte_seconds": 1762.771138, + "parser_byte_seconds": 2900.645032, + "source_allocations": 9, + "output_allocations": 1026, + "parser_allocations": 1, + "reuses": 7142, + "budget_waits": 0, + "slot_waits": 558, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 87297075, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 42091.413, + "latency_p99_upper_ns": 53248 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5068444.485, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8048834.24, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "shared_copy", + "repeat": 2, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 311264, + "source_peak_bytes": 98400, + "output_peak_bytes": 39984, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1851392, + "elapsed_ns": 132284819, + "cpu_ns": 45823432, + "parse_call_ns": 22066434, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33611776, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1983.569581, + "output_byte_seconds": 1182.323172, + "parser_byte_seconds": 2898.432644, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 7080, + "budget_waits": 0, + "slot_waits": 542, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 87424368, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 42064.699, + "latency_p99_upper_ns": 53248 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5068229.227, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8050900.843, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "copy_no_pool", + "repeat": 2, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 252544, + "source_peak_bytes": 98400, + "output_peak_bytes": 47152, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1900544, + "elapsed_ns": 132459707, + "cpu_ns": 47692750, + "parse_call_ns": 22170762, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33669120, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2023.677274, + "output_byte_seconds": 1777.322506, + "parser_byte_seconds": 2907.132194, + "source_allocations": 4082, + "output_allocations": 3072, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 540, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 85990890, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 43327.485, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5070694.294, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8055086.674, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "shared_copy", + "repeat": 3, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 311264, + "source_peak_bytes": 98400, + "output_peak_bytes": 39984, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1851392, + "elapsed_ns": 132140503, + "cpu_ns": 45825210, + "parse_call_ns": 22125197, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33611776, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1985.69773, + "output_byte_seconds": 1183.215978, + "parser_byte_seconds": 2906.687041, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 7080, + "budget_waits": 0, + "slot_waits": 533, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 87310088, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 42062.03, + "latency_p99_upper_ns": 57344 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5068036.782, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8050191.375, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "copy_no_pool", + "repeat": 3, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 252544, + "source_peak_bytes": 98400, + "output_peak_bytes": 47152, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1916928, + "elapsed_ns": 132297747, + "cpu_ns": 46669804, + "parse_call_ns": 22175323, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33669120, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2009.648765, + "output_byte_seconds": 1766.146335, + "parser_byte_seconds": 2907.094824, + "source_allocations": 4082, + "output_allocations": 3072, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 542, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 86663675, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 42678.905, + "latency_p99_upper_ns": 61440 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5068637.263, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8054142.04, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "copy", + "repeat": 3, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 318432, + "source_peak_bytes": 98400, + "output_peak_bytes": 47152, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1851392, + "elapsed_ns": 132282510, + "cpu_ns": 46415608, + "parse_call_ns": 22079359, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33669120, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1996.444688, + "output_byte_seconds": 1765.761752, + "parser_byte_seconds": 2901.17633, + "source_allocations": 9, + "output_allocations": 1025, + "parser_allocations": 1, + "reuses": 7143, + "budget_waits": 0, + "slot_waits": 554, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 86986908, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 42277.028, + "latency_p99_upper_ns": 57344 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5070038.574, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8050279.443, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "borrow", + "repeat": 3, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4435888, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5373952, + "elapsed_ns": 132489898, + "cpu_ns": 48808681, + "parse_call_ns": 22654163, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 540484.370521, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2972.753951, + "source_allocations": 72, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5033, + "budget_waits": 0, + "slot_waits": 556, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 84863248, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 44578.165, + "latency_p99_upper_ns": 61440 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5069410.422, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8053620.063, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "threshold2", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 311264, + "source_peak_bytes": 98400, + "output_peak_bytes": 39984, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1835008, + "elapsed_ns": 132283398, + "cpu_ns": 45911917, + "parse_call_ns": 22085581, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33611776, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1984.871517, + "output_byte_seconds": 1183.416247, + "parser_byte_seconds": 2903.347153, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 7080, + "budget_waits": 0, + "slot_waits": 561, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 87433143, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 42043.254, + "latency_p99_upper_ns": 57344 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5068356.958, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8050581.195, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "threshold8", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 311264, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1851392, + "elapsed_ns": 132082805, + "cpu_ns": 44815017, + "parse_call_ns": 22070822, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2374.331913, + "output_byte_seconds": 919.214871, + "parser_byte_seconds": 2899.672121, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 6056, + "budget_waits": 0, + "slot_waits": 534, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 88275454, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 41070.548, + "latency_p99_upper_ns": 53248 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5067369.015, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8049008.122, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "compact", + "repeat": 3, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4436784, + "source_peak_bytes": 4230192, + "output_peak_bytes": 7056, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5488640, + "elapsed_ns": 132597323, + "cpu_ns": 49981497, + "parse_call_ns": 22749218, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 340108.105991, + "output_byte_seconds": 342.554096, + "parser_byte_seconds": 2986.081381, + "source_allocations": 912, + "output_allocations": 907, + "parser_allocations": 1, + "reuses": 4310, + "budget_waits": 0, + "slot_waits": 563, + "compacted": 1024, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 83819563, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 45265.223, + "latency_p99_upper_ns": 65536 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5069991.558, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8056976.805, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "copy_no_pool", + "repeat": 4, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 252544, + "source_peak_bytes": 98400, + "output_peak_bytes": 47152, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1900544, + "elapsed_ns": 132985160, + "cpu_ns": 49981054, + "parse_call_ns": 23442854, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33669120, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2129.142526, + "output_byte_seconds": 1795.211172, + "parser_byte_seconds": 3074.346252, + "source_allocations": 4082, + "output_allocations": 3072, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 542, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 84089494, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 45510.754, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5098662.604, + "latency_p99_upper_ns": 6291456 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8056999.864, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "borrow", + "repeat": 4, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4435888, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5373952, + "elapsed_ns": 133433884, + "cpu_ns": 51462618, + "parse_call_ns": 23747967, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 540814.68462, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 3118.422109, + "source_allocations": 72, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5033, + "budget_waits": 0, + "slot_waits": 596, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 83315856, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 46811.327, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5070925.9, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8058845.673, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "threshold2", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 311264, + "source_peak_bytes": 98400, + "output_peak_bytes": 39984, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1867776, + "elapsed_ns": 132186422, + "cpu_ns": 45811373, + "parse_call_ns": 22083462, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33611776, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1983.12097, + "output_byte_seconds": 1182.647891, + "parser_byte_seconds": 2900.448352, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 7080, + "budget_waits": 0, + "slot_waits": 532, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 87421696, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 42006.171, + "latency_p99_upper_ns": 57344 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5068025.061, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8049545.414, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "shared_copy", + "repeat": 4, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 311264, + "source_peak_bytes": 98400, + "output_peak_bytes": 39984, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1851392, + "elapsed_ns": 132188663, + "cpu_ns": 45991210, + "parse_call_ns": 22145612, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33611776, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1991.371251, + "output_byte_seconds": 1184.961172, + "parser_byte_seconds": 2909.800223, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 7080, + "budget_waits": 0, + "slot_waits": 543, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 87186189, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 42139.616, + "latency_p99_upper_ns": 57344 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5068490.238, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8052428.242, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "compact", + "repeat": 4, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4436784, + "source_peak_bytes": 4230192, + "output_peak_bytes": 7056, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5537792, + "elapsed_ns": 132746292, + "cpu_ns": 50870250, + "parse_call_ns": 22660664, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 340246.674827, + "output_byte_seconds": 342.038296, + "parser_byte_seconds": 2973.982939, + "source_allocations": 893, + "output_allocations": 895, + "parser_allocations": 1, + "reuses": 4341, + "budget_waits": 0, + "slot_waits": 545, + "compacted": 1024, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 83141858, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 45809.599, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5072116.599, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8054634.315, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "threshold8", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 311264, + "source_peak_bytes": 98400, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1851392, + "elapsed_ns": 132177385, + "cpu_ns": 44977578, + "parse_call_ns": 22128368, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2381.095196, + "output_byte_seconds": 919.555429, + "parser_byte_seconds": 2907.397974, + "source_allocations": 9, + "output_allocations": 64, + "parser_allocations": 1, + "reuses": 6056, + "budget_waits": 0, + "slot_waits": 539, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 88187889, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 41268.295, + "latency_p99_upper_ns": 57344 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5067698.961, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8052209.973, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "copy", + "repeat": 4, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 318432, + "source_peak_bytes": 98400, + "output_peak_bytes": 47152, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 1867776, + "elapsed_ns": 132225648, + "cpu_ns": 46118905, + "parse_call_ns": 22053057, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33669120, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 1988.501642, + "output_byte_seconds": 1767.427593, + "parser_byte_seconds": 2896.491937, + "source_allocations": 9, + "output_allocations": 1025, + "parser_allocations": 1, + "reuses": 7143, + "budget_waits": 0, + "slot_waits": 536, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 87128865, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 42165.024, + "latency_p99_upper_ns": 53248 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5068266.918, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8051060.116, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "copy_no_pool", + "repeat": 0, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4373248, + "source_peak_bytes": 98400, + "output_peak_bytes": 4233264, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 6078464, + "elapsed_ns": 216945564, + "cpu_ns": 116157398, + "parse_call_ns": 25703347, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 100663296, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 3917.681175, + "output_byte_seconds": 512250.563648, + "parser_byte_seconds": 3150.964519, + "source_allocations": 4082, + "output_allocations": 3072, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 383, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 48939452, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 117402.264, + "latency_p99_upper_ns": 524288 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 6063368.282, + "latency_p99_upper_ns": 31457280 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 9260486.827, + "latency_p99_upper_ns": 33554432 + } + ] + }, + { + "case": "same_large_field", + "variant": "shared_copy", + "repeat": 0, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2371504, + "source_peak_bytes": 98400, + "output_peak_bytes": 2100224, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3178496, + "elapsed_ns": 133534289, + "cpu_ns": 66640259, + "parse_call_ns": 22303696, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33554432, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2044.238204, + "output_byte_seconds": 269834.895225, + "parser_byte_seconds": 2930.529378, + "source_allocations": 82, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 6047, + "budget_waits": 0, + "slot_waits": 500, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 2048, + "sleep_ns": 67897726, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 51484.234, + "latency_p99_upper_ns": 81920 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5078396.125, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8065897.697, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "borrow", + "repeat": 0, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4435888, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 4767744, + "elapsed_ns": 133553215, + "cpu_ns": 68694192, + "parse_call_ns": 22344284, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 541236.958782, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2932.875901, + "source_allocations": 76, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5029, + "budget_waits": 0, + "slot_waits": 479, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 65966946, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 52115.836, + "latency_p99_upper_ns": 81920 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5078241.217, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8065472.756, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "copy", + "repeat": 0, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4504544, + "source_peak_bytes": 98400, + "output_peak_bytes": 4233264, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5292032, + "elapsed_ns": 134319516, + "cpu_ns": 74842901, + "parse_call_ns": 22151327, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 100663296, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2277.11069, + "output_byte_seconds": 440218.115158, + "parser_byte_seconds": 2909.330552, + "source_allocations": 9, + "output_allocations": 841, + "parser_allocations": 1, + "reuses": 7327, + "budget_waits": 0, + "slot_waits": 490, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 60554269, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 57181.88, + "latency_p99_upper_ns": 90112 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5083619.048, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8071315.085, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "threshold2", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2371504, + "source_peak_bytes": 98400, + "output_peak_bytes": 2100224, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3194880, + "elapsed_ns": 133454646, + "cpu_ns": 66234578, + "parse_call_ns": 22159339, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33554432, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2031.818258, + "output_byte_seconds": 269861.554419, + "parser_byte_seconds": 2910.266617, + "source_allocations": 78, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 6051, + "budget_waits": 0, + "slot_waits": 487, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 2048, + "sleep_ns": 68332882, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 51484.504, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5077341.499, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8066441.419, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "compact", + "repeat": 0, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4730672, + "source_peak_bytes": 4230192, + "output_peak_bytes": 2001776, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 6340608, + "elapsed_ns": 134096312, + "cpu_ns": 74886880, + "parse_call_ns": 22733900, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33554432, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 341111.908821, + "output_byte_seconds": 100293.13752, + "parser_byte_seconds": 2983.138393, + "source_allocations": 921, + "output_allocations": 779, + "parser_allocations": 1, + "reuses": 4429, + "budget_waits": 0, + "slot_waits": 471, + "compacted": 1024, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 60362834, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 54080.027, + "latency_p99_upper_ns": 90112 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5083405.479, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8068401.165, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "threshold8", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4435888, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 4767744, + "elapsed_ns": 133447386, + "cpu_ns": 68765370, + "parse_call_ns": 22353361, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 541359.828153, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2934.692831, + "source_allocations": 77, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5028, + "budget_waits": 0, + "slot_waits": 487, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 65809490, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 52372.427, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5078845.858, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8067374.837, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "compact", + "repeat": 1, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4730672, + "source_peak_bytes": 4230192, + "output_peak_bytes": 2034592, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 6340608, + "elapsed_ns": 134204038, + "cpu_ns": 74836392, + "parse_call_ns": 22853483, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33554432, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 341117.919471, + "output_byte_seconds": 100364.674661, + "parser_byte_seconds": 2998.098529, + "source_allocations": 881, + "output_allocations": 767, + "parser_allocations": 1, + "reuses": 4481, + "budget_waits": 0, + "slot_waits": 478, + "compacted": 1024, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 60375968, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 54356.541, + "latency_p99_upper_ns": 90112 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5083649.875, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8070735.206, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "shared_copy", + "repeat": 1, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2371504, + "source_peak_bytes": 98400, + "output_peak_bytes": 2100224, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3244032, + "elapsed_ns": 133593447, + "cpu_ns": 66172548, + "parse_call_ns": 22181499, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33554432, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2031.917671, + "output_byte_seconds": 269851.910584, + "parser_byte_seconds": 2913.380586, + "source_allocations": 80, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 6049, + "budget_waits": 0, + "slot_waits": 471, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 2048, + "sleep_ns": 68489180, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 51688.946, + "latency_p99_upper_ns": 81920 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5077231.39, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8066199.086, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "copy", + "repeat": 1, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4504544, + "source_peak_bytes": 98400, + "output_peak_bytes": 4233264, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5292032, + "elapsed_ns": 134436483, + "cpu_ns": 75053693, + "parse_call_ns": 22215239, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 100663296, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2284.410516, + "output_byte_seconds": 440251.541897, + "parser_byte_seconds": 2917.091676, + "source_allocations": 9, + "output_allocations": 832, + "parser_allocations": 1, + "reuses": 7336, + "budget_waits": 0, + "slot_waits": 483, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 60480780, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 57382.812, + "latency_p99_upper_ns": 81920 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5083530.123, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8072471.683, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "threshold2", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2371504, + "source_peak_bytes": 98400, + "output_peak_bytes": 2100224, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3194880, + "elapsed_ns": 134034428, + "cpu_ns": 69077852, + "parse_call_ns": 22386881, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33554432, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2071.219143, + "output_byte_seconds": 269907.925264, + "parser_byte_seconds": 2941.415878, + "source_allocations": 82, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 6047, + "budget_waits": 0, + "slot_waits": 521, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 2048, + "sleep_ns": 66160244, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 52463.206, + "latency_p99_upper_ns": 90112 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5079970.677, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8068543.087, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "threshold8", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4435888, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 4767744, + "elapsed_ns": 133602318, + "cpu_ns": 69361342, + "parse_call_ns": 22347294, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 541336.354919, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2933.602437, + "source_allocations": 76, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5029, + "budget_waits": 0, + "slot_waits": 500, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 65433839, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 52034.221, + "latency_p99_upper_ns": 81920 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5079700.568, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8067086.654, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "borrow", + "repeat": 1, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4435888, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 4767744, + "elapsed_ns": 133878082, + "cpu_ns": 69431646, + "parse_call_ns": 22393309, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 541341.633608, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2938.771712, + "source_allocations": 78, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5027, + "budget_waits": 0, + "slot_waits": 504, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 65629618, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 52136.236, + "latency_p99_upper_ns": 81920 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5078986.712, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8067041.718, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "copy_no_pool", + "repeat": 1, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4373248, + "source_peak_bytes": 98400, + "output_peak_bytes": 4233264, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5816320, + "elapsed_ns": 134331933, + "cpu_ns": 75355273, + "parse_call_ns": 22600489, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 100663296, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2317.391148, + "output_byte_seconds": 440282.284319, + "parser_byte_seconds": 2923.56271, + "source_allocations": 4082, + "output_allocations": 3072, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 497, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 60100461, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 58242.85, + "latency_p99_upper_ns": 90112 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5084649.973, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8073924.058, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "compact", + "repeat": 2, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4730672, + "source_peak_bytes": 4230192, + "output_peak_bytes": 2001776, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 6340608, + "elapsed_ns": 134074359, + "cpu_ns": 74679639, + "parse_call_ns": 22736073, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33554432, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 341236.488763, + "output_byte_seconds": 100267.211633, + "parser_byte_seconds": 2982.994817, + "source_allocations": 917, + "output_allocations": 794, + "parser_allocations": 1, + "reuses": 4418, + "budget_waits": 0, + "slot_waits": 471, + "compacted": 1024, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 60515136, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 53738.105, + "latency_p99_upper_ns": 90112 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5085195.058, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8069412.397, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "copy", + "repeat": 2, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4504544, + "source_peak_bytes": 98400, + "output_peak_bytes": 4233264, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5275648, + "elapsed_ns": 136064340, + "cpu_ns": 79416596, + "parse_call_ns": 22572078, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 100663296, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2363.378088, + "output_byte_seconds": 440586.829499, + "parser_byte_seconds": 2964.218039, + "source_allocations": 9, + "output_allocations": 623, + "parser_allocations": 1, + "reuses": 7545, + "budget_waits": 0, + "slot_waits": 463, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 57551670, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 60112.085, + "latency_p99_upper_ns": 114688 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5087074.439, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8080314.649, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "threshold2", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2371504, + "source_peak_bytes": 98400, + "output_peak_bytes": 2100224, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3244032, + "elapsed_ns": 133655494, + "cpu_ns": 66354625, + "parse_call_ns": 22289900, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33554432, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2049.709126, + "output_byte_seconds": 269797.797722, + "parser_byte_seconds": 2927.700988, + "source_allocations": 78, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 6051, + "budget_waits": 0, + "slot_waits": 500, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 2048, + "sleep_ns": 68212138, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 51495.073, + "latency_p99_upper_ns": 81920 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5078118.015, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8064823.351, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "shared_copy", + "repeat": 2, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2371504, + "source_peak_bytes": 98400, + "output_peak_bytes": 2100224, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3293184, + "elapsed_ns": 133683827, + "cpu_ns": 66973903, + "parse_call_ns": 22176603, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33554432, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2039.054037, + "output_byte_seconds": 269818.155226, + "parser_byte_seconds": 2912.084727, + "source_allocations": 78, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 6051, + "budget_waits": 0, + "slot_waits": 494, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 2048, + "sleep_ns": 67816366, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 51459.966, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5079235.137, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8065334.704, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "threshold8", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4435888, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 4767744, + "elapsed_ns": 133681327, + "cpu_ns": 68797289, + "parse_call_ns": 22338685, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 541289.267391, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2932.086428, + "source_allocations": 77, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5028, + "budget_waits": 0, + "slot_waits": 482, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 65978872, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 52563.022, + "latency_p99_upper_ns": 81920 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5078578.492, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8066255.165, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "borrow", + "repeat": 2, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4435888, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 4767744, + "elapsed_ns": 133814643, + "cpu_ns": 68888479, + "parse_call_ns": 22335355, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 541341.207084, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2930.637289, + "source_allocations": 79, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5026, + "budget_waits": 0, + "slot_waits": 510, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 66149871, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 51550.405, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5079607.126, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8067127.786, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "copy_no_pool", + "repeat": 2, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4373248, + "source_peak_bytes": 98400, + "output_peak_bytes": 4233264, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5816320, + "elapsed_ns": 134471775, + "cpu_ns": 75393460, + "parse_call_ns": 22629325, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 100663296, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2321.181236, + "output_byte_seconds": 440258.792854, + "parser_byte_seconds": 2921.16977, + "source_allocations": 4082, + "output_allocations": 3072, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 508, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 60227676, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 57516.822, + "latency_p99_upper_ns": 90112 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5084982.783, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8073926.553, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "threshold2", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2371504, + "source_peak_bytes": 98400, + "output_peak_bytes": 2100224, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3194880, + "elapsed_ns": 133441147, + "cpu_ns": 66434679, + "parse_call_ns": 22119254, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33554432, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2030.079604, + "output_byte_seconds": 269825.85573, + "parser_byte_seconds": 2905.779822, + "source_allocations": 80, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 6049, + "budget_waits": 0, + "slot_waits": 482, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 2048, + "sleep_ns": 68150063, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 51190.857, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5077733.031, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8065349.133, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "copy_no_pool", + "repeat": 3, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4373248, + "source_peak_bytes": 98400, + "output_peak_bytes": 4233264, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5816320, + "elapsed_ns": 134289332, + "cpu_ns": 76002725, + "parse_call_ns": 22740343, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 100663296, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2334.193158, + "output_byte_seconds": 440332.993703, + "parser_byte_seconds": 2936.962125, + "source_allocations": 4082, + "output_allocations": 3072, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 504, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 59412631, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 59077.132, + "latency_p99_upper_ns": 90112 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5084960.638, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8075279.097, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "shared_copy", + "repeat": 3, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2371504, + "source_peak_bytes": 98400, + "output_peak_bytes": 2100224, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3309568, + "elapsed_ns": 133495777, + "cpu_ns": 66421587, + "parse_call_ns": 22309367, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33554432, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2045.123956, + "output_byte_seconds": 269842.975673, + "parser_byte_seconds": 2931.949276, + "source_allocations": 76, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 6053, + "budget_waits": 0, + "slot_waits": 497, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 2048, + "sleep_ns": 68249668, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 51216.396, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5078028.333, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8066089.677, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "borrow", + "repeat": 3, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4435888, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 4767744, + "elapsed_ns": 134337593, + "cpu_ns": 71105404, + "parse_call_ns": 22575073, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 541448.462493, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2962.344728, + "source_allocations": 83, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5022, + "budget_waits": 0, + "slot_waits": 495, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 64431294, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 53339.614, + "latency_p99_upper_ns": 81920 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5080292.879, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8068765.424, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "copy", + "repeat": 3, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4504544, + "source_peak_bytes": 98400, + "output_peak_bytes": 4233264, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5292032, + "elapsed_ns": 134254523, + "cpu_ns": 76196602, + "parse_call_ns": 22285338, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 100663296, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2295.795833, + "output_byte_seconds": 440394.753415, + "parser_byte_seconds": 2927.722098, + "source_allocations": 9, + "output_allocations": 820, + "parser_allocations": 1, + "reuses": 7348, + "budget_waits": 0, + "slot_waits": 485, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 59133245, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 58635.959, + "latency_p99_upper_ns": 90112 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5084371.237, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8075247.27, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "compact", + "repeat": 3, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4730672, + "source_peak_bytes": 4230192, + "output_peak_bytes": 2034592, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 6340608, + "elapsed_ns": 134306041, + "cpu_ns": 75274107, + "parse_call_ns": 22714288, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33554432, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 341191.973388, + "output_byte_seconds": 100297.728905, + "parser_byte_seconds": 2980.354846, + "source_allocations": 917, + "output_allocations": 749, + "parser_allocations": 1, + "reuses": 4463, + "budget_waits": 0, + "slot_waits": 478, + "compacted": 1024, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 60108647, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 54208.683, + "latency_p99_upper_ns": 90112 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5084673.227, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8069796.873, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "threshold8", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4435888, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 4767744, + "elapsed_ns": 133817208, + "cpu_ns": 69542587, + "parse_call_ns": 22437830, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 541408.186663, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2945.936502, + "source_allocations": 80, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5025, + "budget_waits": 0, + "slot_waits": 483, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 65488224, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 52016.168, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5080750.668, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8068031.861, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "copy_no_pool", + "repeat": 4, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4373248, + "source_peak_bytes": 98400, + "output_peak_bytes": 4233264, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5799936, + "elapsed_ns": 134597856, + "cpu_ns": 77396908, + "parse_call_ns": 22833216, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 100663296, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2355.524795, + "output_byte_seconds": 440416.150759, + "parser_byte_seconds": 2941.859195, + "source_allocations": 4082, + "output_allocations": 3072, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 512, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 58493375, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 59008.762, + "latency_p99_upper_ns": 98304 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5086107.088, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8076875.839, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "copy", + "repeat": 4, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4504544, + "source_peak_bytes": 98400, + "output_peak_bytes": 4233264, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5292032, + "elapsed_ns": 139508137, + "cpu_ns": 88332555, + "parse_call_ns": 22864596, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 100663296, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2528.253394, + "output_byte_seconds": 442384.852596, + "parser_byte_seconds": 3002.901193, + "source_allocations": 9, + "output_allocations": 688, + "parser_allocations": 1, + "reuses": 7480, + "budget_waits": 0, + "slot_waits": 372, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 51495885, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 66698.854, + "latency_p99_upper_ns": 147456 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5129096.339, + "latency_p99_upper_ns": 6815744 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8093643.623, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "threshold8", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4435888, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 4833280, + "elapsed_ns": 134457305, + "cpu_ns": 70251788, + "parse_call_ns": 22431999, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 541395.863387, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2942.397573, + "source_allocations": 87, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5018, + "budget_waits": 0, + "slot_waits": 495, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 65292089, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 53169.212, + "latency_p99_upper_ns": 90112 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5080238.856, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8068047.314, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "threshold2", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2371504, + "source_peak_bytes": 98400, + "output_peak_bytes": 2100224, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3211264, + "elapsed_ns": 133756102, + "cpu_ns": 67373341, + "parse_call_ns": 22155214, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33554432, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2045.927873, + "output_byte_seconds": 269868.863264, + "parser_byte_seconds": 2910.706656, + "source_allocations": 81, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 6048, + "budget_waits": 0, + "slot_waits": 506, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 2048, + "sleep_ns": 67548515, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 51135.428, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5078670.025, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8066898.388, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "shared_copy", + "repeat": 4, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2371504, + "source_peak_bytes": 98400, + "output_peak_bytes": 2100224, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3571712, + "elapsed_ns": 135030934, + "cpu_ns": 71236281, + "parse_call_ns": 22446961, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33554432, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2100.123381, + "output_byte_seconds": 269953.875704, + "parser_byte_seconds": 2948.934561, + "source_allocations": 94, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 6035, + "budget_waits": 0, + "slot_waits": 507, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 2048, + "sleep_ns": 65033726, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 53626.014, + "latency_p99_upper_ns": 90112 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5087279.412, + "latency_p99_upper_ns": 5767168 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8070672.959, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "compact", + "repeat": 4, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4730672, + "source_peak_bytes": 4230192, + "output_peak_bytes": 1936144, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 6340608, + "elapsed_ns": 135831514, + "cpu_ns": 84355786, + "parse_call_ns": 23107923, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33554432, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 341580.411374, + "output_byte_seconds": 100419.005421, + "parser_byte_seconds": 3032.899482, + "source_allocations": 853, + "output_allocations": 676, + "parser_allocations": 1, + "reuses": 4600, + "budget_waits": 0, + "slot_waits": 455, + "compacted": 1024, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 52913091, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 60319.001, + "latency_p99_upper_ns": 114688 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5091148.147, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8079928.47, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "borrow", + "repeat": 4, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4435888, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 4767744, + "elapsed_ns": 133667291, + "cpu_ns": 68534602, + "parse_call_ns": 22264001, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 541292.227145, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2921.518156, + "source_allocations": 77, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5028, + "budget_waits": 0, + "slot_waits": 481, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 66216721, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 1, + "latency_mean_ns": 52072.538, + "latency_p99_upper_ns": 81920 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 5078370.622, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8066280.939, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "copy", + "repeat": 0, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2378784, + "source_peak_bytes": 98400, + "output_peak_bytes": 2107504, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3899392, + "elapsed_ns": 133407209, + "cpu_ns": 54623208, + "parse_call_ns": 22433685, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33669120, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2079.608844, + "output_byte_seconds": 270519.575773, + "parser_byte_seconds": 2946.904954, + "source_allocations": 118, + "output_allocations": 838, + "parser_allocations": 1, + "reuses": 7221, + "budget_waits": 0, + "slot_waits": 547, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 79664236, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 47700.066, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5070062.768, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8069584.641, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "threshold2", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2378672, + "source_peak_bytes": 98400, + "output_peak_bytes": 2107392, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3751936, + "elapsed_ns": 133312135, + "cpu_ns": 53364925, + "parse_call_ns": 22316231, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33611776, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2049.372724, + "output_byte_seconds": 270524.406644, + "parser_byte_seconds": 2928.92106, + "source_allocations": 137, + "output_allocations": 841, + "parser_allocations": 1, + "reuses": 6175, + "budget_waits": 0, + "slot_waits": 552, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 80930688, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 46742.189, + "latency_p99_upper_ns": 65536 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5068879.809, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8069119.599, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "shared_copy", + "repeat": 0, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2378672, + "source_peak_bytes": 98400, + "output_peak_bytes": 2107392, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3948544, + "elapsed_ns": 154001095, + "cpu_ns": 65368726, + "parse_call_ns": 23437273, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33611776, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2683.230182, + "output_byte_seconds": 276097.966097, + "parser_byte_seconds": 3083.783614, + "source_allocations": 228, + "output_allocations": 746, + "parser_allocations": 1, + "reuses": 6179, + "budget_waits": 0, + "slot_waits": 542, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 75659422, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 64443.196, + "latency_p99_upper_ns": 147456 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5134851.331, + "latency_p99_upper_ns": 7340032 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8252758.487, + "latency_p99_upper_ns": 15728640 + } + ] + }, + { + "case": "slow_large_field", + "variant": "copy_no_pool", + "repeat": 0, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2312896, + "source_peak_bytes": 98400, + "output_peak_bytes": 2107504, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3194880, + "elapsed_ns": 133648283, + "cpu_ns": 61986524, + "parse_call_ns": 25370210, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33669120, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2299.022458, + "output_byte_seconds": 270612.233717, + "parser_byte_seconds": 2983.123314, + "source_allocations": 4082, + "output_allocations": 3072, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 653, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 72630111, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 53967.42, + "latency_p99_upper_ns": 81920 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5080263.648, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8075763.615, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "compact", + "repeat": 0, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4730672, + "source_peak_bytes": 4230192, + "output_peak_bytes": 2067408, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 6340608, + "elapsed_ns": 133472857, + "cpu_ns": 62602975, + "parse_call_ns": 23134595, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33554432, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 340709.17918, + "output_byte_seconds": 100724.838498, + "parser_byte_seconds": 3036.377571, + "source_allocations": 923, + "output_allocations": 841, + "parser_allocations": 1, + "reuses": 4365, + "budget_waits": 0, + "slot_waits": 526, + "compacted": 1024, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 71679132, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 48473.289, + "latency_p99_upper_ns": 81920 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5073065.738, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8070772.518, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "threshold8", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4443056, + "source_peak_bytes": 4230192, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 4751360, + "elapsed_ns": 133297584, + "cpu_ns": 55094453, + "parse_call_ns": 22718797, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 541537.659914, + "output_byte_seconds": 577.166247, + "parser_byte_seconds": 2982.289653, + "source_allocations": 130, + "output_allocations": 809, + "parser_allocations": 1, + "reuses": 5190, + "budget_waits": 0, + "slot_waits": 541, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 79050000, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 48100.386, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5069482.618, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8070037.129, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "borrow", + "repeat": 0, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4435888, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 4767744, + "elapsed_ns": 133477288, + "cpu_ns": 54372368, + "parse_call_ns": 22466675, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 541562.393801, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2949.789857, + "source_allocations": 80, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5025, + "budget_waits": 0, + "slot_waits": 554, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 80055686, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 46918.51, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5069158.581, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8070277.888, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "threshold2", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2378672, + "source_peak_bytes": 98400, + "output_peak_bytes": 2107392, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3932160, + "elapsed_ns": 133312509, + "cpu_ns": 53734268, + "parse_call_ns": 22533891, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33611776, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2071.170012, + "output_byte_seconds": 270512.249274, + "parser_byte_seconds": 2959.58098, + "source_allocations": 159, + "output_allocations": 828, + "parser_allocations": 1, + "reuses": 6166, + "budget_waits": 0, + "slot_waits": 575, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 80473327, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 46789.037, + "latency_p99_upper_ns": 65536 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5070040.373, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8069081.323, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "copy_no_pool", + "repeat": 1, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2312896, + "source_peak_bytes": 98400, + "output_peak_bytes": 2107504, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3194880, + "elapsed_ns": 134281084, + "cpu_ns": 62190824, + "parse_call_ns": 25213500, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33669120, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2300.277794, + "output_byte_seconds": 270647.838041, + "parser_byte_seconds": 2975.251132, + "source_allocations": 4082, + "output_allocations": 3072, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 663, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 73016473, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 54287.927, + "latency_p99_upper_ns": 98304 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5080276.456, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8077074.059, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "copy", + "repeat": 1, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2378784, + "source_peak_bytes": 98400, + "output_peak_bytes": 2107504, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3948544, + "elapsed_ns": 133395362, + "cpu_ns": 55263103, + "parse_call_ns": 22335683, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33669120, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2070.323199, + "output_byte_seconds": 270570.958879, + "parser_byte_seconds": 2935.679247, + "source_allocations": 123, + "output_allocations": 825, + "parser_allocations": 1, + "reuses": 7229, + "budget_waits": 0, + "slot_waits": 563, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 79157676, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 47428.456, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5070071.895, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8070912.004, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "shared_copy", + "repeat": 1, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2378672, + "source_peak_bytes": 98400, + "output_peak_bytes": 2107392, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3522560, + "elapsed_ns": 133405307, + "cpu_ns": 53873137, + "parse_call_ns": 22349414, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33611776, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2061.271642, + "output_byte_seconds": 270527.998952, + "parser_byte_seconds": 2936.171471, + "source_allocations": 144, + "output_allocations": 811, + "parser_allocations": 1, + "reuses": 6198, + "budget_waits": 0, + "slot_waits": 551, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 80515381, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 46564.507, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5069570.9, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8069438.264, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "compact", + "repeat": 1, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4730672, + "source_peak_bytes": 4230192, + "output_peak_bytes": 2100224, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 6340608, + "elapsed_ns": 133295478, + "cpu_ns": 60929076, + "parse_call_ns": 22892803, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33554432, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 340588.424197, + "output_byte_seconds": 100730.999866, + "parser_byte_seconds": 3007.852808, + "source_allocations": 919, + "output_allocations": 842, + "parser_allocations": 1, + "reuses": 4368, + "budget_waits": 0, + "slot_waits": 524, + "compacted": 1024, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 73271182, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 48259.733, + "latency_p99_upper_ns": 81920 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5071843.127, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8069717.131, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "borrow", + "repeat": 1, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4435888, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5390336, + "elapsed_ns": 133317978, + "cpu_ns": 54530428, + "parse_call_ns": 22789187, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 541551.170985, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2991.654899, + "source_allocations": 72, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5033, + "budget_waits": 0, + "slot_waits": 541, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 79523636, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 47420.19, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5069779.505, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8070214.071, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "threshold8", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4443056, + "source_peak_bytes": 4230192, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5357568, + "elapsed_ns": 133341496, + "cpu_ns": 54857945, + "parse_call_ns": 22618201, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 541518.37496, + "output_byte_seconds": 577.265132, + "parser_byte_seconds": 2971.205031, + "source_allocations": 122, + "output_allocations": 835, + "parser_allocations": 1, + "reuses": 5172, + "budget_waits": 0, + "slot_waits": 562, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 79396532, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 47550.497, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5070242.543, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8069675.14, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "threshold8", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4443056, + "source_peak_bytes": 4230192, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5292032, + "elapsed_ns": 134650847, + "cpu_ns": 58145169, + "parse_call_ns": 22801055, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 542663.104532, + "output_byte_seconds": 578.298773, + "parser_byte_seconds": 2995.063232, + "source_allocations": 127, + "output_allocations": 804, + "parser_allocations": 1, + "reuses": 5198, + "budget_waits": 0, + "slot_waits": 553, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 77457652, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 49310.575, + "latency_p99_upper_ns": 81920 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5080294.837, + "latency_p99_upper_ns": 5767168 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8086977.866, + "latency_p99_upper_ns": 9437184 + } + ] + }, + { + "case": "slow_large_field", + "variant": "copy", + "repeat": 2, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2378784, + "source_peak_bytes": 98400, + "output_peak_bytes": 2107504, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3964928, + "elapsed_ns": 133179940, + "cpu_ns": 52486508, + "parse_call_ns": 22146823, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33669120, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2028.917653, + "output_byte_seconds": 270508.558846, + "parser_byte_seconds": 2910.035715, + "source_allocations": 119, + "output_allocations": 875, + "parser_allocations": 1, + "reuses": 7183, + "budget_waits": 0, + "slot_waits": 532, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 81744820, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 46179.91, + "latency_p99_upper_ns": 61440 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5068139.702, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8068218.996, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "borrow", + "repeat": 2, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4435888, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 4767744, + "elapsed_ns": 133254368, + "cpu_ns": 52756869, + "parse_call_ns": 22242096, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 541465.495701, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2919.456949, + "source_allocations": 79, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5026, + "budget_waits": 0, + "slot_waits": 537, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 81620293, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 45804.026, + "latency_p99_upper_ns": 61440 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5067325.337, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8068611.8, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "compact", + "repeat": 2, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4730672, + "source_peak_bytes": 4230192, + "output_peak_bytes": 2100224, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 6340608, + "elapsed_ns": 133273853, + "cpu_ns": 59503628, + "parse_call_ns": 22579568, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33554432, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 340521.103381, + "output_byte_seconds": 100725.988305, + "parser_byte_seconds": 2964.439632, + "source_allocations": 921, + "output_allocations": 839, + "parser_allocations": 1, + "reuses": 4369, + "budget_waits": 0, + "slot_waits": 529, + "compacted": 1024, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 75001351, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 46820.147, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5071087.53, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8068767.35, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "shared_copy", + "repeat": 2, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2378672, + "source_peak_bytes": 98400, + "output_peak_bytes": 2107392, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3293184, + "elapsed_ns": 133216315, + "cpu_ns": 51631438, + "parse_call_ns": 22079426, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33611776, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2014.496107, + "output_byte_seconds": 270449.091989, + "parser_byte_seconds": 2901.711431, + "source_allocations": 152, + "output_allocations": 827, + "parser_allocations": 1, + "reuses": 6174, + "budget_waits": 0, + "slot_waits": 543, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 82698735, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 45041.785, + "latency_p99_upper_ns": 57344 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5068002.393, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8066161.602, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "copy_no_pool", + "repeat": 2, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2312896, + "source_peak_bytes": 98400, + "output_peak_bytes": 2107504, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3178496, + "elapsed_ns": 133362779, + "cpu_ns": 58084129, + "parse_call_ns": 24178012, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33669120, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2196.167723, + "output_byte_seconds": 270535.919777, + "parser_byte_seconds": 2934.024512, + "source_allocations": 4082, + "output_allocations": 3072, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 605, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 76526627, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 50758.917, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5074265.021, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8071772.438, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "threshold2", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2378672, + "source_peak_bytes": 98400, + "output_peak_bytes": 2107392, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3751936, + "elapsed_ns": 133094723, + "cpu_ns": 52669444, + "parse_call_ns": 22153975, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33611776, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2026.350691, + "output_byte_seconds": 270487.081841, + "parser_byte_seconds": 2910.446252, + "source_allocations": 162, + "output_allocations": 813, + "parser_allocations": 1, + "reuses": 6178, + "budget_waits": 0, + "slot_waits": 529, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 81515465, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 46192.459, + "latency_p99_upper_ns": 65536 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5067955.414, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8067608.796, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "compact", + "repeat": 3, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4730672, + "source_peak_bytes": 4230192, + "output_peak_bytes": 2100224, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 6340608, + "elapsed_ns": 133282278, + "cpu_ns": 59568109, + "parse_call_ns": 22558632, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33554432, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 340502.324772, + "output_byte_seconds": 100714.490169, + "parser_byte_seconds": 2961.00573, + "source_allocations": 923, + "output_allocations": 826, + "parser_allocations": 1, + "reuses": 4380, + "budget_waits": 0, + "slot_waits": 521, + "compacted": 1024, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 74934523, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 46941.425, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5070856.899, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8068200.595, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "copy_no_pool", + "repeat": 3, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2312896, + "source_peak_bytes": 98400, + "output_peak_bytes": 2107504, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3194880, + "elapsed_ns": 133540522, + "cpu_ns": 58472614, + "parse_call_ns": 24345793, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33669120, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2208.417867, + "output_byte_seconds": 270579.890216, + "parser_byte_seconds": 2933.62499, + "source_allocations": 4082, + "output_allocations": 3072, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 602, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 76325826, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 51364.197, + "latency_p99_upper_ns": 81920 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5074603.185, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8073207.582, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "borrow", + "repeat": 3, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4435888, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 4767744, + "elapsed_ns": 133275839, + "cpu_ns": 52234245, + "parse_call_ns": 22266351, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 541367.893955, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2922.935825, + "source_allocations": 79, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5026, + "budget_waits": 0, + "slot_waits": 545, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 82113024, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 45842.847, + "latency_p99_upper_ns": 61440 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5066801.978, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8067096.868, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "shared_copy", + "repeat": 3, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2378672, + "source_peak_bytes": 98400, + "output_peak_bytes": 2107392, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3899392, + "elapsed_ns": 133064931, + "cpu_ns": 52117164, + "parse_call_ns": 22057182, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33611776, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2015.469116, + "output_byte_seconds": 270480.700872, + "parser_byte_seconds": 2897.68644, + "source_allocations": 130, + "output_allocations": 842, + "parser_allocations": 1, + "reuses": 6181, + "budget_waits": 0, + "slot_waits": 555, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 82111301, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 45400.789, + "latency_p99_upper_ns": 57344 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5068255.587, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8067189.304, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "threshold8", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4443056, + "source_peak_bytes": 4230192, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5292032, + "elapsed_ns": 133337450, + "cpu_ns": 53670610, + "parse_call_ns": 22263776, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 541459.255198, + "output_byte_seconds": 577.165832, + "parser_byte_seconds": 2922.14622, + "source_allocations": 137, + "output_allocations": 796, + "parser_allocations": 1, + "reuses": 5196, + "budget_waits": 0, + "slot_waits": 551, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 80837357, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 46321.397, + "latency_p99_upper_ns": 65536 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5068514.702, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8068639.91, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "threshold2", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2378672, + "source_peak_bytes": 98400, + "output_peak_bytes": 2107392, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3522560, + "elapsed_ns": 134333542, + "cpu_ns": 52726291, + "parse_call_ns": 22219255, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33611776, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2039.714059, + "output_byte_seconds": 270798.061653, + "parser_byte_seconds": 2918.877137, + "source_allocations": 140, + "output_allocations": 894, + "parser_allocations": 1, + "reuses": 6119, + "budget_waits": 0, + "slot_waits": 516, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 82638596, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 46056.021, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5218345.888, + "latency_p99_upper_ns": 9437184 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8076530.434, + "latency_p99_upper_ns": 9437184 + } + ] + }, + { + "case": "slow_large_field", + "variant": "copy", + "repeat": 3, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2378784, + "source_peak_bytes": 98400, + "output_peak_bytes": 2107504, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3948544, + "elapsed_ns": 133174357, + "cpu_ns": 52057974, + "parse_call_ns": 22117835, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33669120, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2021.284206, + "output_byte_seconds": 270501.113842, + "parser_byte_seconds": 2905.858494, + "source_allocations": 114, + "output_allocations": 849, + "parser_allocations": 1, + "reuses": 7214, + "budget_waits": 0, + "slot_waits": 548, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 82257586, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 45428.889, + "latency_p99_upper_ns": 61440 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5068142.38, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8067808.96, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "copy_no_pool", + "repeat": 4, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2312896, + "source_peak_bytes": 98400, + "output_peak_bytes": 2107504, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3178496, + "elapsed_ns": 133410638, + "cpu_ns": 57999768, + "parse_call_ns": 24134627, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33669120, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2191.645151, + "output_byte_seconds": 270510.58659, + "parser_byte_seconds": 2926.663567, + "source_allocations": 4082, + "output_allocations": 3072, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 603, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 76638749, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 51016.097, + "latency_p99_upper_ns": 81920 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5074074.877, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8071032.382, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "threshold2", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2378672, + "source_peak_bytes": 98400, + "output_peak_bytes": 2107392, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3342336, + "elapsed_ns": 133213102, + "cpu_ns": 52362717, + "parse_call_ns": 22103023, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33611776, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2022.420003, + "output_byte_seconds": 270482.639278, + "parser_byte_seconds": 2904.168619, + "source_allocations": 127, + "output_allocations": 855, + "parser_allocations": 1, + "reuses": 6171, + "budget_waits": 0, + "slot_waits": 539, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 81964913, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 46044.098, + "latency_p99_upper_ns": 61440 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5068262.707, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8067371.07, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "copy", + "repeat": 4, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2378784, + "source_peak_bytes": 98400, + "output_peak_bytes": 2107504, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3751936, + "elapsed_ns": 133177547, + "cpu_ns": 52033688, + "parse_call_ns": 22154380, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33669120, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2025.354638, + "output_byte_seconds": 270478.813202, + "parser_byte_seconds": 2910.934805, + "source_allocations": 129, + "output_allocations": 851, + "parser_allocations": 1, + "reuses": 7197, + "budget_waits": 0, + "slot_waits": 527, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 82109654, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 45825.604, + "latency_p99_upper_ns": 61440 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5067937.156, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8067321.024, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "borrow", + "repeat": 4, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4435888, + "source_peak_bytes": 4230192, + "output_peak_bytes": 0, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 4767744, + "elapsed_ns": 133311566, + "cpu_ns": 53725285, + "parse_call_ns": 22239925, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 0, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 541575.408384, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 2920.340305, + "source_allocations": 80, + "output_allocations": 0, + "parser_allocations": 1, + "reuses": 5025, + "budget_waits": 0, + "slot_waits": 555, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 80727666, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 46306.509, + "latency_p99_upper_ns": 61440 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5067147.548, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8070390.562, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "threshold8", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4443056, + "source_peak_bytes": 4230192, + "output_peak_bytes": 7168, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 5439488, + "elapsed_ns": 134101658, + "cpu_ns": 54158047, + "parse_call_ns": 22315394, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 541512.874989, + "output_byte_seconds": 578.716358, + "parser_byte_seconds": 2931.279646, + "source_allocations": 161, + "output_allocations": 826, + "parser_allocations": 1, + "reuses": 5142, + "budget_waits": 0, + "slot_waits": 533, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 81103821, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 46533.691, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5082538.041, + "latency_p99_upper_ns": 6291456 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8069591.938, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "shared_copy", + "repeat": 4, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2378672, + "source_peak_bytes": 98400, + "output_peak_bytes": 2107392, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 3948544, + "elapsed_ns": 133134639, + "cpu_ns": 52075173, + "parse_call_ns": 22128273, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33611776, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 2026.862393, + "output_byte_seconds": 270471.476005, + "parser_byte_seconds": 2908.200691, + "source_allocations": 122, + "output_allocations": 816, + "parser_allocations": 1, + "reuses": 6215, + "budget_waits": 0, + "slot_waits": 512, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 82080012, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 46182.627, + "latency_p99_upper_ns": 61440 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5067504.389, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8067072.688, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "compact", + "repeat": 4, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 8388608, + "fixed_bytes": 41728, + "peak_reserved_bytes": 4730672, + "source_peak_bytes": 4230192, + "output_peak_bytes": 2100224, + "parser_peak_bytes": 131120, + "rss_peak_bytes": 6406144, + "elapsed_ns": 133118662, + "cpu_ns": 59607669, + "parse_call_ns": 22648269, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 42083156, + "selection_copy_bytes": 33554432, + "reader_copy_bytes": 75711296, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 340524.867797, + "output_byte_seconds": 100684.088672, + "parser_byte_seconds": 2973.798584, + "source_allocations": 921, + "output_allocations": 855, + "parser_allocations": 1, + "reuses": 4353, + "budget_waits": 0, + "slot_waits": 532, + "compacted": 1024, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 74562185, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 1, + "latency_mean_ns": 47236.674, + "latency_p99_upper_ns": 73728 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5071269.907, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 33554432, + "peak_count": 64, + "latency_mean_ns": 8067723.707, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "copy", + "repeat": 0, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1104848, + "source_peak_bytes": 393312, + "output_peak_bytes": 79920, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 1884160, + "elapsed_ns": 134798098, + "cpu_ns": 52545277, + "parse_call_ns": 26282225, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 26872064, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 6883.203763, + "output_byte_seconds": 1809.304759, + "parser_byte_seconds": 10115.296993, + "source_allocations": 367, + "output_allocations": 948, + "parser_allocations": 374, + "reuses": 6256, + "budget_waits": 0, + "slot_waits": 579, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 83482902, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 47583.467, + "latency_p99_upper_ns": 147456 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5081460.678, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8083520.998, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "threshold8", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1097792, + "source_peak_bytes": 393312, + "output_peak_bytes": 11312, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 2031616, + "elapsed_ns": 134514858, + "cpu_ns": 50924568, + "parse_call_ns": 26180831, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 1059072, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 7475.627393, + "output_byte_seconds": 924.635553, + "parser_byte_seconds": 10091.334952, + "source_allocations": 237, + "output_allocations": 96, + "parser_allocations": 257, + "reuses": 5800, + "budget_waits": 0, + "slot_waits": 593, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 84806597, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 46212.018, + "latency_p99_upper_ns": 147456 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5080764.964, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8080296.584, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "copy_no_pool", + "repeat": 0, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 842368, + "source_peak_bytes": 393312, + "output_peak_bytes": 79920, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 1949696, + "elapsed_ns": 135580728, + "cpu_ns": 59055276, + "parse_call_ns": 27303180, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 26872064, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 8268.860241, + "output_byte_seconds": 1866.643736, + "parser_byte_seconds": 10141.702783, + "source_allocations": 3849, + "output_allocations": 3072, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 540, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 77683199, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 53763.312, + "latency_p99_upper_ns": 163840 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5090947.59, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8093934.847, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "shared_copy", + "repeat": 0, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1097792, + "source_peak_bytes": 393312, + "output_peak_bytes": 72752, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 1884160, + "elapsed_ns": 134733970, + "cpu_ns": 52189389, + "parse_call_ns": 26273407, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 26814720, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 6865.482399, + "output_byte_seconds": 1226.436074, + "parser_byte_seconds": 10135.432887, + "source_allocations": 365, + "output_allocations": 246, + "parser_allocations": 368, + "reuses": 5942, + "budget_waits": 0, + "slot_waits": 587, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 83766349, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 47383.279, + "latency_p99_upper_ns": 147456 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5081532.837, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8082383.547, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "threshold2", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1097792, + "source_peak_bytes": 393312, + "output_peak_bytes": 72752, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 1884160, + "elapsed_ns": 134703694, + "cpu_ns": 51981424, + "parse_call_ns": 26239241, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 26814720, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 6818.11346, + "output_byte_seconds": 1220.93584, + "parser_byte_seconds": 10109.238408, + "source_allocations": 368, + "output_allocations": 240, + "parser_allocations": 366, + "reuses": 5947, + "budget_waits": 0, + "slot_waits": 592, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 83962412, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 47186.16, + "latency_p99_upper_ns": 147456 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5082027.365, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8082717.212, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "compact", + "repeat": 0, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2096880, + "source_peak_bytes": 2047296, + "output_peak_bytes": 3360, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 3702784, + "elapsed_ns": 330325402, + "cpu_ns": 56526552, + "parse_call_ns": 257818693, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 542057.64214, + "output_byte_seconds": 342.456081, + "parser_byte_seconds": 10454.037412, + "source_allocations": 1653, + "output_allocations": 1018, + "parser_allocations": 587, + "reuses": 2639, + "budget_waits": 1256, + "slot_waits": 0, + "compacted": 1024, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 275134226, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 313916.181, + "latency_p99_upper_ns": 4718592 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 30, + "latency_mean_ns": 5359649.404, + "latency_p99_upper_ns": 10485760 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 49, + "latency_mean_ns": 8345801.06, + "latency_p99_upper_ns": 12582912 + } + ] + }, + { + "case": "mixed_tight", + "variant": "borrow", + "repeat": 0, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2097024, + "source_peak_bytes": 2047296, + "output_peak_bytes": 0, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 3702784, + "elapsed_ns": 517444947, + "cpu_ns": 58385263, + "parse_call_ns": 414175159, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 0, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 866552.611778, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 10646.478365, + "source_allocations": 1612, + "output_allocations": 0, + "parser_allocations": 580, + "reuses": 2681, + "budget_waits": 1250, + "slot_waits": 0, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 460552293, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 496739.613, + "latency_p99_upper_ns": 7864320 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 30, + "latency_mean_ns": 5531099.266, + "latency_p99_upper_ns": 12582912 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 30, + "latency_mean_ns": 8547759.071, + "latency_p99_upper_ns": 15728640 + } + ] + }, + { + "case": "mixed_tight", + "variant": "copy_no_pool", + "repeat": 1, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 842368, + "source_peak_bytes": 393312, + "output_peak_bytes": 79920, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 1916928, + "elapsed_ns": 135818181, + "cpu_ns": 60130654, + "parse_call_ns": 27699522, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 26872064, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 8398.686166, + "output_byte_seconds": 1885.555543, + "parser_byte_seconds": 10206.603011, + "source_allocations": 3849, + "output_allocations": 3072, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 537, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 76838088, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 54782.86, + "latency_p99_upper_ns": 180224 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5093567.929, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8096201.349, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "threshold8", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1097792, + "source_peak_bytes": 393312, + "output_peak_bytes": 11312, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 2064384, + "elapsed_ns": 134627181, + "cpu_ns": 51051158, + "parse_call_ns": 26242598, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 1059072, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 7499.787736, + "output_byte_seconds": 924.734083, + "parser_byte_seconds": 10090.493068, + "source_allocations": 237, + "output_allocations": 100, + "parser_allocations": 258, + "reuses": 5795, + "budget_waits": 0, + "slot_waits": 587, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 84733901, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 46365.068, + "latency_p99_upper_ns": 147456 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5080938.783, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8081319.231, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "shared_copy", + "repeat": 1, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1097792, + "source_peak_bytes": 393312, + "output_peak_bytes": 72752, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 1900544, + "elapsed_ns": 134660107, + "cpu_ns": 51849496, + "parse_call_ns": 26235438, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 26814720, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 6785.330268, + "output_byte_seconds": 1222.453816, + "parser_byte_seconds": 10103.005533, + "source_allocations": 366, + "output_allocations": 239, + "parser_allocations": 366, + "reuses": 5950, + "budget_waits": 0, + "slot_waits": 579, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 84013028, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 47133.761, + "latency_p99_upper_ns": 147456 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5081549.099, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8082113.784, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "borrow", + "repeat": 1, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2097024, + "source_peak_bytes": 2047296, + "output_peak_bytes": 0, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 3719168, + "elapsed_ns": 516876187, + "cpu_ns": 58189132, + "parse_call_ns": 413488109, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 0, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 866155.703795, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 10618.392921, + "source_allocations": 1617, + "output_allocations": 0, + "parser_allocations": 581, + "reuses": 2675, + "budget_waits": 1263, + "slot_waits": 0, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 460124695, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 496219.126, + "latency_p99_upper_ns": 7864320 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 30, + "latency_mean_ns": 5528237.536, + "latency_p99_upper_ns": 12582912 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 30, + "latency_mean_ns": 8541844.312, + "latency_p99_upper_ns": 15728640 + } + ] + }, + { + "case": "mixed_tight", + "variant": "threshold2", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1097792, + "source_peak_bytes": 393312, + "output_peak_bytes": 72752, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 1867776, + "elapsed_ns": 134596389, + "cpu_ns": 51879163, + "parse_call_ns": 26207832, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 26814720, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 6795.293198, + "output_byte_seconds": 1224.224319, + "parser_byte_seconds": 10089.609534, + "source_allocations": 369, + "output_allocations": 233, + "parser_allocations": 365, + "reuses": 5954, + "budget_waits": 0, + "slot_waits": 596, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 83947198, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 47146.396, + "latency_p99_upper_ns": 147456 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5082305.345, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8082431.98, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "copy", + "repeat": 1, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1104848, + "source_peak_bytes": 393312, + "output_peak_bytes": 79920, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 1884160, + "elapsed_ns": 134667407, + "cpu_ns": 52286009, + "parse_call_ns": 26255995, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 26872064, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 6830.10163, + "output_byte_seconds": 1802.54536, + "parser_byte_seconds": 10104.51946, + "source_allocations": 370, + "output_allocations": 952, + "parser_allocations": 375, + "reuses": 6248, + "budget_waits": 0, + "slot_waits": 590, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 83595691, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 47383.187, + "latency_p99_upper_ns": 147456 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5081689.522, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8082200.92, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "compact", + "repeat": 1, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2097104, + "source_peak_bytes": 2047296, + "output_peak_bytes": 3360, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 3833856, + "elapsed_ns": 330507221, + "cpu_ns": 57227425, + "parse_call_ns": 258042238, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 542403.396989, + "output_byte_seconds": 342.198165, + "parser_byte_seconds": 10516.149038, + "source_allocations": 1657, + "output_allocations": 1018, + "parser_allocations": 592, + "reuses": 2630, + "budget_waits": 1262, + "slot_waits": 0, + "compacted": 1024, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 274671771, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 314160.033, + "latency_p99_upper_ns": 4718592 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 30, + "latency_mean_ns": 5361935.781, + "latency_p99_upper_ns": 10485760 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 49, + "latency_mean_ns": 8345834.982, + "latency_p99_upper_ns": 12582912 + } + ] + }, + { + "case": "mixed_tight", + "variant": "threshold2", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1097792, + "source_peak_bytes": 393312, + "output_peak_bytes": 72752, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 1900544, + "elapsed_ns": 134805557, + "cpu_ns": 52099602, + "parse_call_ns": 26201196, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 26814720, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 6802.764732, + "output_byte_seconds": 1222.5673, + "parser_byte_seconds": 10082.699192, + "source_allocations": 363, + "output_allocations": 241, + "parser_allocations": 368, + "reuses": 5949, + "budget_waits": 0, + "slot_waits": 592, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 83969655, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 47229.56, + "latency_p99_upper_ns": 147456 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5083369.83, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8082868.22, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "copy", + "repeat": 2, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1104736, + "source_peak_bytes": 393312, + "output_peak_bytes": 79920, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 1900544, + "elapsed_ns": 135397301, + "cpu_ns": 55535720, + "parse_call_ns": 28191073, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 26872064, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 7296.683374, + "output_byte_seconds": 1825.786254, + "parser_byte_seconds": 10851.770961, + "source_allocations": 364, + "output_allocations": 925, + "parser_allocations": 376, + "reuses": 6280, + "budget_waits": 0, + "slot_waits": 556, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 81078620, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 50441.328, + "latency_p99_upper_ns": 163840 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5086253.071, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8088040.091, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "threshold8", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1097792, + "source_peak_bytes": 393312, + "output_peak_bytes": 11312, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 2048000, + "elapsed_ns": 135143135, + "cpu_ns": 54181725, + "parse_call_ns": 28073539, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 1059072, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 7971.142415, + "output_byte_seconds": 924.89692, + "parser_byte_seconds": 10793.387694, + "source_allocations": 237, + "output_allocations": 89, + "parser_allocations": 259, + "reuses": 5805, + "budget_waits": 0, + "slot_waits": 587, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 82256234, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 49150.131, + "latency_p99_upper_ns": 163840 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5084346.661, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8083800.547, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "borrow", + "repeat": 2, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2097024, + "source_peak_bytes": 2047296, + "output_peak_bytes": 0, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 3719168, + "elapsed_ns": 519737827, + "cpu_ns": 63401151, + "parse_call_ns": 410873515, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 0, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 869390.688093, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 10874.854354, + "source_allocations": 1612, + "output_allocations": 0, + "parser_allocations": 584, + "reuses": 2677, + "budget_waits": 1267, + "slot_waits": 0, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 457480540, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 498894.016, + "latency_p99_upper_ns": 7864320 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 30, + "latency_mean_ns": 5554388.391, + "latency_p99_upper_ns": 12582912 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 30, + "latency_mean_ns": 8572436.932, + "latency_p99_upper_ns": 15728640 + } + ] + }, + { + "case": "mixed_tight", + "variant": "copy_no_pool", + "repeat": 2, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 842368, + "source_peak_bytes": 393312, + "output_peak_bytes": 79920, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 1933312, + "elapsed_ns": 135808674, + "cpu_ns": 61310764, + "parse_call_ns": 27409732, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 26872064, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 8492.13471, + "output_byte_seconds": 1909.35548, + "parser_byte_seconds": 10184.015437, + "source_allocations": 3849, + "output_allocations": 3072, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 538, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 75774039, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 55750.675, + "latency_p99_upper_ns": 196608 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5097561.83, + "latency_p99_upper_ns": 5767168 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8097147.871, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "compact", + "repeat": 2, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2096496, + "source_peak_bytes": 2047296, + "output_peak_bytes": 3360, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 3719168, + "elapsed_ns": 330655613, + "cpu_ns": 57992572, + "parse_call_ns": 257126466, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 542286.835871, + "output_byte_seconds": 342.201335, + "parser_byte_seconds": 10592.82654, + "source_allocations": 1620, + "output_allocations": 1018, + "parser_allocations": 589, + "reuses": 2670, + "budget_waits": 1246, + "slot_waits": 0, + "compacted": 1024, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 274045502, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 314214.117, + "latency_p99_upper_ns": 4718592 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 30, + "latency_mean_ns": 5361784.028, + "latency_p99_upper_ns": 10485760 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 49, + "latency_mean_ns": 8345733.162, + "latency_p99_upper_ns": 12582912 + } + ] + }, + { + "case": "mixed_tight", + "variant": "shared_copy", + "repeat": 2, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1097792, + "source_peak_bytes": 393312, + "output_peak_bytes": 72752, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 1900544, + "elapsed_ns": 134725602, + "cpu_ns": 52125932, + "parse_call_ns": 26256537, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 26814720, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 6831.305534, + "output_byte_seconds": 1226.062002, + "parser_byte_seconds": 10092.239062, + "source_allocations": 365, + "output_allocations": 226, + "parser_allocations": 360, + "reuses": 5970, + "budget_waits": 0, + "slot_waits": 576, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 83779201, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 47423.973, + "latency_p99_upper_ns": 147456 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5082508.901, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8082650.268, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "compact", + "repeat": 3, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2096656, + "source_peak_bytes": 2047296, + "output_peak_bytes": 3360, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 3719168, + "elapsed_ns": 332809762, + "cpu_ns": 64506702, + "parse_call_ns": 255295188, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 544031.993873, + "output_byte_seconds": 348.13532, + "parser_byte_seconds": 10927.535411, + "source_allocations": 1623, + "output_allocations": 1008, + "parser_allocations": 583, + "reuses": 2683, + "budget_waits": 1227, + "slot_waits": 0, + "compacted": 1024, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 270135277, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 316210.616, + "latency_p99_upper_ns": 4718592 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 30, + "latency_mean_ns": 5373501.093, + "latency_p99_upper_ns": 10485760 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 49, + "latency_mean_ns": 8409239.137, + "latency_p99_upper_ns": 12582912 + } + ] + }, + { + "case": "mixed_tight", + "variant": "threshold2", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1097792, + "source_peak_bytes": 393312, + "output_peak_bytes": 72752, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 1884160, + "elapsed_ns": 134646087, + "cpu_ns": 51969989, + "parse_call_ns": 26192074, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 26814720, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 6812.54134, + "output_byte_seconds": 1229.637184, + "parser_byte_seconds": 10083.25152, + "source_allocations": 369, + "output_allocations": 241, + "parser_allocations": 365, + "reuses": 5946, + "budget_waits": 0, + "slot_waits": 582, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 83864700, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 47274.193, + "latency_p99_upper_ns": 147456 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5082291.09, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8084035.099, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "copy", + "repeat": 3, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1104848, + "source_peak_bytes": 393312, + "output_peak_bytes": 79920, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 1900544, + "elapsed_ns": 134732754, + "cpu_ns": 52218674, + "parse_call_ns": 26241260, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 26872064, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 6810.984162, + "output_byte_seconds": 1804.529206, + "parser_byte_seconds": 10104.502269, + "source_allocations": 368, + "output_allocations": 949, + "parser_allocations": 374, + "reuses": 6254, + "budget_waits": 0, + "slot_waits": 584, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 83719457, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 47404.955, + "latency_p99_upper_ns": 147456 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5082343.96, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8082308.803, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "shared_copy", + "repeat": 3, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1097792, + "source_peak_bytes": 393312, + "output_peak_bytes": 72752, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 1884160, + "elapsed_ns": 134687032, + "cpu_ns": 52085095, + "parse_call_ns": 26215409, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 26814720, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 6852.502663, + "output_byte_seconds": 1223.987439, + "parser_byte_seconds": 10100.060122, + "source_allocations": 365, + "output_allocations": 235, + "parser_allocations": 364, + "reuses": 5957, + "budget_waits": 0, + "slot_waits": 585, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 83840818, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 47354.551, + "latency_p99_upper_ns": 147456 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5081713.058, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8082095.55, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "borrow", + "repeat": 3, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2097072, + "source_peak_bytes": 2047296, + "output_peak_bytes": 0, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 3719168, + "elapsed_ns": 516415971, + "cpu_ns": 57490634, + "parse_call_ns": 412616864, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 0, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 865936.173669, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 10532.202462, + "source_allocations": 1624, + "output_allocations": 0, + "parser_allocations": 582, + "reuses": 2667, + "budget_waits": 1258, + "slot_waits": 0, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 460245677, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 495746.732, + "latency_p99_upper_ns": 7864320 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 30, + "latency_mean_ns": 5527499.187, + "latency_p99_upper_ns": 12582912 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 30, + "latency_mean_ns": 8541909.699, + "latency_p99_upper_ns": 15728640 + } + ] + }, + { + "case": "mixed_tight", + "variant": "copy_no_pool", + "repeat": 3, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 842368, + "source_peak_bytes": 393312, + "output_peak_bytes": 79920, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 1916928, + "elapsed_ns": 135708499, + "cpu_ns": 59498427, + "parse_call_ns": 27293452, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 26872064, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 8320.069469, + "output_byte_seconds": 1853.590142, + "parser_byte_seconds": 10172.640074, + "source_allocations": 3849, + "output_allocations": 3072, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 550, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 77469437, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 53679.489, + "latency_p99_upper_ns": 180224 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5093041.554, + "latency_p99_upper_ns": 5767168 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8093789.758, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "threshold8", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1097792, + "source_peak_bytes": 393312, + "output_peak_bytes": 11312, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 2048000, + "elapsed_ns": 134580129, + "cpu_ns": 50901202, + "parse_call_ns": 26138215, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 1059072, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 7468.893211, + "output_byte_seconds": 924.833553, + "parser_byte_seconds": 10074.589742, + "source_allocations": 237, + "output_allocations": 99, + "parser_allocations": 260, + "reuses": 5794, + "budget_waits": 0, + "slot_waits": 603, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 84894241, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 46199.245, + "latency_p99_upper_ns": 147456 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5080295.214, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8082153.254, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "compact", + "repeat": 4, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2095936, + "source_peak_bytes": 2047296, + "output_peak_bytes": 3360, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 3768320, + "elapsed_ns": 330364653, + "cpu_ns": 56737666, + "parse_call_ns": 257390641, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 57344, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 542129.496495, + "output_byte_seconds": 342.3922, + "parser_byte_seconds": 10487.947668, + "source_allocations": 1626, + "output_allocations": 1018, + "parser_allocations": 584, + "reuses": 2669, + "budget_waits": 1234, + "slot_waits": 0, + "compacted": 1024, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 274961005, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 314000.227, + "latency_p99_upper_ns": 4718592 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 30, + "latency_mean_ns": 5359881.678, + "latency_p99_upper_ns": 10485760 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 49, + "latency_mean_ns": 8345470.393, + "latency_p99_upper_ns": 12582912 + } + ] + }, + { + "case": "mixed_tight", + "variant": "threshold2", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1097792, + "source_peak_bytes": 393312, + "output_peak_bytes": 72752, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 1884160, + "elapsed_ns": 134641407, + "cpu_ns": 51772899, + "parse_call_ns": 26303805, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 26814720, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 6823.249522, + "output_byte_seconds": 1222.425123, + "parser_byte_seconds": 10156.044791, + "source_allocations": 363, + "output_allocations": 239, + "parser_allocations": 367, + "reuses": 5952, + "budget_waits": 0, + "slot_waits": 584, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 83930889, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 47208.702, + "latency_p99_upper_ns": 131072 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5081715.549, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8082551.032, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "threshold8", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1097792, + "source_peak_bytes": 393312, + "output_peak_bytes": 11312, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 2048000, + "elapsed_ns": 134636889, + "cpu_ns": 51692325, + "parse_call_ns": 26232175, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 1059072, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 7604.090343, + "output_byte_seconds": 924.831397, + "parser_byte_seconds": 10109.160375, + "source_allocations": 237, + "output_allocations": 97, + "parser_allocations": 259, + "reuses": 5797, + "budget_waits": 0, + "slot_waits": 600, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 84203974, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 46850.104, + "latency_p99_upper_ns": 147456 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5081772.482, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8081990.295, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "borrow", + "repeat": 4, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 2097024, + "source_peak_bytes": 2047296, + "output_peak_bytes": 0, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 3719168, + "elapsed_ns": 516507633, + "cpu_ns": 56956626, + "parse_call_ns": 413462854, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 0, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 866066.604394, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 10498.181654, + "source_allocations": 1635, + "output_allocations": 0, + "parser_allocations": 588, + "reuses": 2650, + "budget_waits": 1258, + "slot_waits": 0, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 460890935, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 495819.875, + "latency_p99_upper_ns": 7864320 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 30, + "latency_mean_ns": 5527650.658, + "latency_p99_upper_ns": 12582912 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 30, + "latency_mean_ns": 8542682.03, + "latency_p99_upper_ns": 15728640 + } + ] + }, + { + "case": "mixed_tight", + "variant": "shared_copy", + "repeat": 4, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1097792, + "source_peak_bytes": 393312, + "output_peak_bytes": 72752, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 1884160, + "elapsed_ns": 134698503, + "cpu_ns": 52062419, + "parse_call_ns": 26232455, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 26814720, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 6807.634601, + "output_byte_seconds": 1226.698884, + "parser_byte_seconds": 10096.010075, + "source_allocations": 358, + "output_allocations": 229, + "parser_allocations": 363, + "reuses": 5971, + "budget_waits": 0, + "slot_waits": 573, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 1024, + "sleep_ns": 83820760, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 47338.287, + "latency_p99_upper_ns": 147456 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5082803.919, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8081430.476, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "copy_no_pool", + "repeat": 4, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 842368, + "source_peak_bytes": 393312, + "output_peak_bytes": 79920, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 1933312, + "elapsed_ns": 135617374, + "cpu_ns": 59370307, + "parse_call_ns": 27370335, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 26872064, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 8306.118105, + "output_byte_seconds": 1881.770411, + "parser_byte_seconds": 10193.350967, + "source_allocations": 3849, + "output_allocations": 3072, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 541, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 77447978, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 54118.737, + "latency_p99_upper_ns": 180224 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5093193.132, + "latency_p99_upper_ns": 5767168 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8094306.969, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "copy", + "repeat": 4, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1104736, + "source_peak_bytes": 393312, + "output_peak_bytes": 79920, + "parser_peak_bytes": 524336, + "rss_peak_bytes": 1884160, + "elapsed_ns": 135101765, + "cpu_ns": 53612089, + "parse_call_ns": 26369173, + "accepted": 1024, + "emitted": 3072, + "input_bytes": 49877076, + "selection_copy_bytes": 26872064, + "reader_copy_bytes": 114814580, + "parser_realloc_copy_bytes": 0, + "source_byte_seconds": 6944.794448, + "output_byte_seconds": 1822.831558, + "parser_byte_seconds": 10130.150831, + "source_allocations": 348, + "output_allocations": 886, + "parser_allocations": 368, + "reuses": 6343, + "budget_waits": 0, + "slot_waits": 561, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 82695691, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 1024, + "bytes": 26757376, + "peak_count": 1, + "latency_mean_ns": 48573.396, + "latency_p99_upper_ns": 147456 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 5083912.79, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 1024, + "bytes": 57344, + "peak_count": 64, + "latency_mean_ns": 8083831.809, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "copy_no_pool", + "repeat": 0, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 170672, + "source_peak_bytes": 24672, + "output_peak_bytes": 14896, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1835008, + "elapsed_ns": 66381179, + "cpu_ns": 14937944, + "parse_call_ns": 10634360, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 319488, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 191.835816, + "output_byte_seconds": 748.822762, + "parser_byte_seconds": 436.544508, + "source_allocations": 1273, + "output_allocations": 1536, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 200, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 51858352, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26502.654, + "latency_p99_upper_ns": 36864 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5055591.338, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8038187.436, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "borrow", + "repeat": 0, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1208192, + "source_peak_bytes": 1059888, + "output_peak_bytes": 0, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 2785280, + "elapsed_ns": 66395496, + "cpu_ns": 14949295, + "parse_call_ns": 10748920, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 0, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 67632.156584, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 441.340054, + "source_allocations": 70, + "output_allocations": 0, + "parser_allocations": 2, + "reuses": 2225, + "budget_waits": 0, + "slot_waits": 210, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 51867983, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26677.738, + "latency_p99_upper_ns": 40960 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5055635.91, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8040456.355, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "threshold8", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 180144, + "source_peak_bytes": 24672, + "output_peak_bytes": 7728, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1851392, + "elapsed_ns": 66344311, + "cpu_ns": 14626628, + "parse_call_ns": 10598197, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 290816, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 189.993439, + "output_byte_seconds": 460.282359, + "parser_byte_seconds": 437.832685, + "source_allocations": 6, + "output_allocations": 65, + "parser_allocations": 2, + "reuses": 3248, + "budget_waits": 0, + "slot_waits": 201, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 512, + "sleep_ns": 52108022, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26057.676, + "latency_p99_upper_ns": 30720 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5054707.516, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8038718.686, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "shared_copy", + "repeat": 0, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 180144, + "source_peak_bytes": 24672, + "output_peak_bytes": 7728, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1835008, + "elapsed_ns": 66360126, + "cpu_ns": 14610198, + "parse_call_ns": 10558947, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 290816, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 189.278595, + "output_byte_seconds": 460.358957, + "parser_byte_seconds": 433.475216, + "source_allocations": 6, + "output_allocations": 65, + "parser_allocations": 2, + "reuses": 3248, + "budget_waits": 0, + "slot_waits": 210, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 512, + "sleep_ns": 52155647, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26056.072, + "latency_p99_upper_ns": 30720 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5054720.746, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8039527.611, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "compact", + "repeat": 0, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1209200, + "source_peak_bytes": 1059888, + "output_peak_bytes": 7168, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 2899968, + "elapsed_ns": 66352515, + "cpu_ns": 15174956, + "parse_call_ns": 10767457, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 28672, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 42522.512719, + "output_byte_seconds": 170.992644, + "parser_byte_seconds": 444.338525, + "source_allocations": 462, + "output_allocations": 456, + "parser_allocations": 2, + "reuses": 1889, + "budget_waits": 0, + "slot_waits": 203, + "compacted": 512, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 51584350, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26833.023, + "latency_p99_upper_ns": 40960 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5055824.906, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8037818.045, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "copy", + "repeat": 0, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 187312, + "source_peak_bytes": 24672, + "output_peak_bytes": 14896, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1835008, + "elapsed_ns": 66358774, + "cpu_ns": 14704746, + "parse_call_ns": 10580140, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 319488, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 190.401936, + "output_byte_seconds": 748.797361, + "parser_byte_seconds": 434.190092, + "source_allocations": 6, + "output_allocations": 546, + "parser_allocations": 2, + "reuses": 3279, + "budget_waits": 0, + "slot_waits": 198, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 52055904, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26138.373, + "latency_p99_upper_ns": 32768 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5054837.756, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8038347.354, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "threshold2", + "repeat": 0, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 180144, + "source_peak_bytes": 24672, + "output_peak_bytes": 7728, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1851392, + "elapsed_ns": 66343256, + "cpu_ns": 14610428, + "parse_call_ns": 10601249, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 290816, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 190.005404, + "output_byte_seconds": 460.293238, + "parser_byte_seconds": 435.304664, + "source_allocations": 6, + "output_allocations": 65, + "parser_allocations": 2, + "reuses": 3248, + "budget_waits": 0, + "slot_waits": 199, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 512, + "sleep_ns": 52113330, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26103.785, + "latency_p99_upper_ns": 32768 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5054791.455, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8038668.434, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "threshold8", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 180144, + "source_peak_bytes": 24672, + "output_peak_bytes": 7728, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1835008, + "elapsed_ns": 66620533, + "cpu_ns": 15009658, + "parse_call_ns": 10599246, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 290816, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 190.711835, + "output_byte_seconds": 461.162485, + "parser_byte_seconds": 439.194778, + "source_allocations": 6, + "output_allocations": 67, + "parser_allocations": 2, + "reuses": 3246, + "budget_waits": 0, + "slot_waits": 195, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 512, + "sleep_ns": 52089340, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26514.744, + "latency_p99_upper_ns": 36864 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5059599.168, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8052646.494, + "latency_p99_upper_ns": 9437184 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "copy_no_pool", + "repeat": 1, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 170672, + "source_peak_bytes": 24672, + "output_peak_bytes": 14896, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1835008, + "elapsed_ns": 69246534, + "cpu_ns": 16610834, + "parse_call_ns": 11758115, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 319488, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 215.365911, + "output_byte_seconds": 778.347747, + "parser_byte_seconds": 481.501477, + "source_allocations": 1273, + "output_allocations": 1536, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 164, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 52395416, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 29861.328, + "latency_p99_upper_ns": 57344 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5481519.523, + "latency_p99_upper_ns": 10485760 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8132478.682, + "latency_p99_upper_ns": 10485760 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "shared_copy", + "repeat": 1, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 180144, + "source_peak_bytes": 24672, + "output_peak_bytes": 7728, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1835008, + "elapsed_ns": 67338922, + "cpu_ns": 15543047, + "parse_call_ns": 10965512, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 290816, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 198.833427, + "output_byte_seconds": 461.43294, + "parser_byte_seconds": 455.786835, + "source_allocations": 6, + "output_allocations": 88, + "parser_allocations": 2, + "reuses": 3225, + "budget_waits": 0, + "slot_waits": 170, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 512, + "sleep_ns": 52096250, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 27620.291, + "latency_p99_upper_ns": 53248 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5405312.287, + "latency_p99_upper_ns": 9437184 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8058747.33, + "latency_p99_upper_ns": 9437184 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "copy", + "repeat": 1, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 187312, + "source_peak_bytes": 24672, + "output_peak_bytes": 14896, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1835008, + "elapsed_ns": 66437867, + "cpu_ns": 14887131, + "parse_call_ns": 10719986, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 319488, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 192.97609, + "output_byte_seconds": 748.927344, + "parser_byte_seconds": 442.835871, + "source_allocations": 6, + "output_allocations": 546, + "parser_allocations": 2, + "reuses": 3279, + "budget_waits": 0, + "slot_waits": 206, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 51911693, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26502.299, + "latency_p99_upper_ns": 36864 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5055229.1, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8040517.863, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "threshold2", + "repeat": 1, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 180144, + "source_peak_bytes": 24672, + "output_peak_bytes": 7728, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1835008, + "elapsed_ns": 66341459, + "cpu_ns": 14573003, + "parse_call_ns": 10555283, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 290816, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 189.19959, + "output_byte_seconds": 460.262935, + "parser_byte_seconds": 433.563583, + "source_allocations": 6, + "output_allocations": 65, + "parser_allocations": 2, + "reuses": 3248, + "budget_waits": 0, + "slot_waits": 202, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 512, + "sleep_ns": 52150322, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26047.523, + "latency_p99_upper_ns": 30720 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5054844.742, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8037890.609, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "borrow", + "repeat": 1, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1208192, + "source_peak_bytes": 1059888, + "output_peak_bytes": 0, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 2801664, + "elapsed_ns": 66302663, + "cpu_ns": 14680433, + "parse_call_ns": 10680579, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 0, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 67603.216745, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 441.482243, + "source_allocations": 70, + "output_allocations": 0, + "parser_allocations": 2, + "reuses": 2225, + "budget_waits": 0, + "slot_waits": 203, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 52022749, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26241.209, + "latency_p99_upper_ns": 32768 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5054887.895, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8036938.547, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "compact", + "repeat": 1, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1209200, + "source_peak_bytes": 1059888, + "output_peak_bytes": 7168, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 2916352, + "elapsed_ns": 66647996, + "cpu_ns": 15645769, + "parse_call_ns": 10897093, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 28672, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 42531.184104, + "output_byte_seconds": 171.185155, + "parser_byte_seconds": 448.382215, + "source_allocations": 462, + "output_allocations": 456, + "parser_allocations": 2, + "reuses": 1889, + "budget_waits": 0, + "slot_waits": 208, + "compacted": 512, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 51484721, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 27363.605, + "latency_p99_upper_ns": 49152 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5056927.043, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8042303.346, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "shared_copy", + "repeat": 2, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 180144, + "source_peak_bytes": 24672, + "output_peak_bytes": 7728, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1835008, + "elapsed_ns": 66509552, + "cpu_ns": 15439851, + "parse_call_ns": 10723161, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 290816, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 194.692414, + "output_byte_seconds": 460.401472, + "parser_byte_seconds": 443.814792, + "source_allocations": 6, + "output_allocations": 65, + "parser_allocations": 2, + "reuses": 3248, + "budget_waits": 0, + "slot_waits": 188, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 512, + "sleep_ns": 51559999, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 27221.904, + "latency_p99_upper_ns": 40960 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5102159.828, + "latency_p99_upper_ns": 6291456 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8039936.652, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "threshold2", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 180144, + "source_peak_bytes": 24672, + "output_peak_bytes": 7728, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1851392, + "elapsed_ns": 66675868, + "cpu_ns": 15617313, + "parse_call_ns": 10794500, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 290816, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 196.368374, + "output_byte_seconds": 460.582208, + "parser_byte_seconds": 453.168708, + "source_allocations": 6, + "output_allocations": 72, + "parser_allocations": 2, + "reuses": 3241, + "budget_waits": 0, + "slot_waits": 206, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 512, + "sleep_ns": 51576007, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 27391.873, + "latency_p99_upper_ns": 45056 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5063401.098, + "latency_p99_upper_ns": 5767168 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8043009.266, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "threshold8", + "repeat": 2, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 180144, + "source_peak_bytes": 24672, + "output_peak_bytes": 7728, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1835008, + "elapsed_ns": 66346091, + "cpu_ns": 14749114, + "parse_call_ns": 10663838, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 290816, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 191.566293, + "output_byte_seconds": 460.387978, + "parser_byte_seconds": 441.272197, + "source_allocations": 6, + "output_allocations": 65, + "parser_allocations": 2, + "reuses": 3248, + "budget_waits": 0, + "slot_waits": 198, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 512, + "sleep_ns": 51956135, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26444.111, + "latency_p99_upper_ns": 40960 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5055009.982, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8040053.549, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "borrow", + "repeat": 2, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1208192, + "source_peak_bytes": 1059888, + "output_peak_bytes": 0, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 2768896, + "elapsed_ns": 66340906, + "cpu_ns": 14840713, + "parse_call_ns": 10710339, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 0, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 67628.848076, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 441.911742, + "source_allocations": 70, + "output_allocations": 0, + "parser_allocations": 2, + "reuses": 2225, + "budget_waits": 0, + "slot_waits": 214, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 51926596, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26533.881, + "latency_p99_upper_ns": 36864 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5055556.934, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8040046.408, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "copy_no_pool", + "repeat": 2, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 170672, + "source_peak_bytes": 24672, + "output_peak_bytes": 14896, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1851392, + "elapsed_ns": 66367572, + "cpu_ns": 14844612, + "parse_call_ns": 10626817, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 319488, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 191.787957, + "output_byte_seconds": 748.742987, + "parser_byte_seconds": 439.039763, + "source_allocations": 1273, + "output_allocations": 1536, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 202, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 51918865, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26443.496, + "latency_p99_upper_ns": 32768 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5055503.67, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8037164.848, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "compact", + "repeat": 2, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1209200, + "source_peak_bytes": 1059888, + "output_peak_bytes": 7168, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 2916352, + "elapsed_ns": 66456221, + "cpu_ns": 15237761, + "parse_call_ns": 10832907, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 28672, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 42524.965388, + "output_byte_seconds": 171.106633, + "parser_byte_seconds": 446.50427, + "source_allocations": 462, + "output_allocations": 456, + "parser_allocations": 2, + "reuses": 1889, + "budget_waits": 0, + "slot_waits": 211, + "compacted": 512, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 51628844, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26894.043, + "latency_p99_upper_ns": 36864 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5056115.033, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8040094.787, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "copy", + "repeat": 2, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 187312, + "source_peak_bytes": 24672, + "output_peak_bytes": 14896, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1818624, + "elapsed_ns": 66358054, + "cpu_ns": 14786258, + "parse_call_ns": 10588699, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 319488, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 190.767691, + "output_byte_seconds": 748.949984, + "parser_byte_seconds": 437.20655, + "source_allocations": 6, + "output_allocations": 546, + "parser_allocations": 2, + "reuses": 3279, + "budget_waits": 0, + "slot_waits": 202, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 51982953, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26290.178, + "latency_p99_upper_ns": 36864 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5055243.682, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8040476.592, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "shared_copy", + "repeat": 3, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 180144, + "source_peak_bytes": 24672, + "output_peak_bytes": 7728, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1835008, + "elapsed_ns": 66340017, + "cpu_ns": 14641398, + "parse_call_ns": 10583202, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 290816, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 189.850967, + "output_byte_seconds": 460.201756, + "parser_byte_seconds": 434.46664, + "source_allocations": 6, + "output_allocations": 65, + "parser_allocations": 2, + "reuses": 3248, + "budget_waits": 0, + "slot_waits": 200, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 512, + "sleep_ns": 52101474, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26126.43, + "latency_p99_upper_ns": 32768 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5054896.006, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8037126.236, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "borrow", + "repeat": 3, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1208192, + "source_peak_bytes": 1059888, + "output_peak_bytes": 0, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 2768896, + "elapsed_ns": 66397387, + "cpu_ns": 14926280, + "parse_call_ns": 10743184, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 0, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 67622.063537, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 442.942199, + "source_allocations": 70, + "output_allocations": 0, + "parser_allocations": 2, + "reuses": 2225, + "budget_waits": 0, + "slot_waits": 212, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 51935519, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26540.598, + "latency_p99_upper_ns": 36864 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5055706.689, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8039215.434, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "copy", + "repeat": 3, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 187312, + "source_peak_bytes": 24672, + "output_peak_bytes": 14896, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1835008, + "elapsed_ns": 66347591, + "cpu_ns": 14688841, + "parse_call_ns": 10558757, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 319488, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 190.237303, + "output_byte_seconds": 748.906445, + "parser_byte_seconds": 434.052077, + "source_allocations": 6, + "output_allocations": 546, + "parser_allocations": 2, + "reuses": 3279, + "budget_waits": 0, + "slot_waits": 201, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 52048363, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26185.322, + "latency_p99_upper_ns": 30720 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5054934.725, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8039957.693, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "compact", + "repeat": 3, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1209200, + "source_peak_bytes": 1059888, + "output_peak_bytes": 7168, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 2916352, + "elapsed_ns": 66425702, + "cpu_ns": 15126826, + "parse_call_ns": 10762572, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 28672, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 42518.234312, + "output_byte_seconds": 171.124375, + "parser_byte_seconds": 442.813559, + "source_allocations": 462, + "output_allocations": 456, + "parser_allocations": 2, + "reuses": 1889, + "budget_waits": 0, + "slot_waits": 207, + "compacted": 512, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 51722109, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26699.592, + "latency_p99_upper_ns": 36864 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5055311.875, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8039588.77, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "threshold8", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 180144, + "source_peak_bytes": 24672, + "output_peak_bytes": 7728, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1835008, + "elapsed_ns": 66342183, + "cpu_ns": 14624958, + "parse_call_ns": 10558072, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 290816, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 189.596919, + "output_byte_seconds": 460.250779, + "parser_byte_seconds": 436.103934, + "source_allocations": 6, + "output_allocations": 65, + "parser_allocations": 2, + "reuses": 3248, + "budget_waits": 0, + "slot_waits": 199, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 512, + "sleep_ns": 52113950, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26082.711, + "latency_p99_upper_ns": 32768 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5054439.891, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8037911.916, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "copy_no_pool", + "repeat": 3, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 170672, + "source_peak_bytes": 24672, + "output_peak_bytes": 14896, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1835008, + "elapsed_ns": 66421906, + "cpu_ns": 14924036, + "parse_call_ns": 10733514, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 319488, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 193.388376, + "output_byte_seconds": 748.846289, + "parser_byte_seconds": 443.059571, + "source_allocations": 1273, + "output_allocations": 1536, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 207, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 51871512, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26630.812, + "latency_p99_upper_ns": 40960 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5055263.076, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8039399.533, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "threshold2", + "repeat": 3, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 180144, + "source_peak_bytes": 24672, + "output_peak_bytes": 7728, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1835008, + "elapsed_ns": 66363184, + "cpu_ns": 14629240, + "parse_call_ns": 10568715, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 290816, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 189.501318, + "output_byte_seconds": 460.195707, + "parser_byte_seconds": 436.121559, + "source_allocations": 6, + "output_allocations": 65, + "parser_allocations": 2, + "reuses": 3248, + "budget_waits": 0, + "slot_waits": 199, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 512, + "sleep_ns": 52142767, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26129.004, + "latency_p99_upper_ns": 30720 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5054684.932, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8036606.693, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "threshold2", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 180144, + "source_peak_bytes": 24672, + "output_peak_bytes": 7728, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1835008, + "elapsed_ns": 66354498, + "cpu_ns": 14608671, + "parse_call_ns": 10552983, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 290816, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 189.286265, + "output_byte_seconds": 460.245208, + "parser_byte_seconds": 433.358809, + "source_allocations": 6, + "output_allocations": 65, + "parser_allocations": 2, + "reuses": 3248, + "budget_waits": 0, + "slot_waits": 197, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 512, + "sleep_ns": 52143565, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26044.074, + "latency_p99_upper_ns": 30720 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5054765.459, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8037717.471, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "copy_no_pool", + "repeat": 4, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 170672, + "source_peak_bytes": 24672, + "output_peak_bytes": 14896, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1851392, + "elapsed_ns": 66440315, + "cpu_ns": 15042208, + "parse_call_ns": 10714630, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 319488, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 193.34471, + "output_byte_seconds": 749.072578, + "parser_byte_seconds": 442.776453, + "source_allocations": 1273, + "output_allocations": 1536, + "parser_allocations": 1024, + "reuses": 0, + "budget_waits": 0, + "slot_waits": 203, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 51818059, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26719.596, + "latency_p99_upper_ns": 40960 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5055539.021, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8042928.75, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "shared_copy", + "repeat": 4, + "status": "ok", + "policy": "shared_copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 180144, + "source_peak_bytes": 24672, + "output_peak_bytes": 7728, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1835008, + "elapsed_ns": 66550686, + "cpu_ns": 14565611, + "parse_call_ns": 10569760, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 290816, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 189.196651, + "output_byte_seconds": 460.427963, + "parser_byte_seconds": 435.936714, + "source_allocations": 6, + "output_allocations": 70, + "parser_allocations": 2, + "reuses": 3243, + "budget_waits": 0, + "slot_waits": 199, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 512, + "sleep_ns": 52394259, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26054.17, + "latency_p99_upper_ns": 30720 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5054468.873, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8040821.889, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "compact", + "repeat": 4, + "status": "ok", + "policy": "compact", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1209200, + "source_peak_bytes": 1059888, + "output_peak_bytes": 7168, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 2932736, + "elapsed_ns": 66346982, + "cpu_ns": 15115580, + "parse_call_ns": 10730381, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 28672, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 42539.689103, + "output_byte_seconds": 170.963142, + "parser_byte_seconds": 440.137993, + "source_allocations": 462, + "output_allocations": 456, + "parser_allocations": 2, + "reuses": 1889, + "budget_waits": 0, + "slot_waits": 200, + "compacted": 512, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 51642878, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26772.898, + "latency_p99_upper_ns": 36864 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5057876.094, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8039346.365, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "threshold8", + "repeat": 4, + "status": "ok", + "policy": "threshold", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 180144, + "source_peak_bytes": 24672, + "output_peak_bytes": 7728, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1851392, + "elapsed_ns": 66367685, + "cpu_ns": 14678765, + "parse_call_ns": 10612300, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 290816, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 190.199351, + "output_byte_seconds": 460.290364, + "parser_byte_seconds": 438.024028, + "source_allocations": 6, + "output_allocations": 65, + "parser_allocations": 2, + "reuses": 3248, + "budget_waits": 0, + "slot_waits": 200, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 512, + "sleep_ns": 52099788, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26178.92, + "latency_p99_upper_ns": 36864 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5054797.43, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8038471.338, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "borrow", + "repeat": 4, + "status": "ok", + "policy": "borrow", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 1208192, + "source_peak_bytes": 1059888, + "output_peak_bytes": 0, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 2785280, + "elapsed_ns": 66395630, + "cpu_ns": 14769876, + "parse_call_ns": 10679603, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 0, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 67615.986637, + "output_byte_seconds": 0.0, + "parser_byte_seconds": 438.40001, + "source_allocations": 70, + "output_allocations": 0, + "parser_allocations": 2, + "reuses": 2225, + "budget_waits": 0, + "slot_waits": 207, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 52035492, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26350.551, + "latency_p99_upper_ns": 36864 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5054965.338, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8038469.066, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "copy", + "repeat": 4, + "status": "ok", + "policy": "copy", + "parser_version": "0.12.0", + "budget_bytes": 2097152, + "fixed_bytes": 41728, + "peak_reserved_bytes": 187312, + "source_peak_bytes": 24672, + "output_peak_bytes": 14896, + "parser_peak_bytes": 98400, + "rss_peak_bytes": 1835008, + "elapsed_ns": 66338315, + "cpu_ns": 14754424, + "parse_call_ns": 10609310, + "accepted": 512, + "emitted": 1536, + "input_bytes": 5259666, + "selection_copy_bytes": 319488, + "reader_copy_bytes": 6312628, + "parser_realloc_copy_bytes": 14086144, + "source_byte_seconds": 190.968242, + "output_byte_seconds": 748.772024, + "parser_byte_seconds": 435.574111, + "source_allocations": 6, + "output_allocations": 546, + "parser_allocations": 2, + "reuses": 3279, + "budget_waits": 0, + "slot_waits": 199, + "compacted": 0, + "compact_skipped": 0, + "dedup_hits": 0, + "sleep_ns": 51978025, + "live_at_stop_bytes": 0, + "unreleased_buffer_bytes": 0, + "queues": [ + { + "emitted": 512, + "bytes": 262144, + "peak_count": 1, + "latency_mean_ns": 26285.051, + "latency_p99_upper_ns": 36864 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 5055200.059, + "latency_p99_upper_ns": 5242880 + }, + { + "emitted": 512, + "bytes": 28672, + "peak_count": 64, + "latency_mean_ns": 8037468.172, + "latency_p99_upper_ns": 8388608 + } + ] + } +] diff --git a/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/sources/benchmark.c b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/sources/benchmark.c new file mode 100644 index 0000000..474bc7f --- /dev/null +++ b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/sources/benchmark.c @@ -0,0 +1,391 @@ +#define _POSIX_C_SOURCE 200809L +#include <assert.h> +#include <errno.h> +#include <inttypes.h> +#include <signal.h> +#include <stddef.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include <unistd.h> +#include "vendor/yyjson/yyjson.h" + +enum { BRANCHES=3, CACHE=16, READ_SIZE=16384, MAX_JSON=1024*1024, HIST=512 }; +enum { SOURCE, OUTPUT, PARSER, KINDS }; +typedef struct Item Item; +typedef struct Block { + size_t capacity, refs; + uint64_t since; + unsigned kind; + Item *views; + _Alignas(max_align_t) unsigned char data[]; +} Block; +struct Item { + Block *block; + Item *prev, *next; + size_t offset, length; + uint64_t sequence, start, ready; +}; +typedef struct Queue { + Item *items; + size_t head, count, peak; + const char *key; + uint64_t hold, service, last, emitted, bytes, latency_sum, histogram[HIST]; +} Queue; +typedef struct Engine { + Queue q[BRANCHES]; + Block *cache[CACHE]; + unsigned char read_buffer[READ_SIZE]; + size_t read_at, read_end; + size_t budget, fixed, slots, fanout, reserved, active, cached, peak; + size_t by_kind[KINDS], peak_kind[KINDS]; + long double byte_ns[KINDS]; + uint64_t allocations[KINDS], reuses, accepted, emitted, input_bytes; + uint64_t selection_copies, reader_copies, parser_copies, parse_ns; + uint64_t budget_waits, slot_waits, compacted, compact_skipped, dedup_hits; + uint64_t sleep_ns, elapsed_ns, cpu_ns, cancel_after; + unsigned ratio; + int pool; + const char *policy, *status; +} Engine; +static volatile sig_atomic_t stopped; +static void stop(int sig) { (void)sig; stopped=1; } +static uint64_t ns(clockid_t clock) { + struct timespec t; + if (clock_gettime(clock,&t)) abort(); + return (uint64_t)t.tv_sec*UINT64_C(1000000000)+(uint64_t)t.tv_nsec; +} +static size_t rounded(size_t n) { size_t c=64; while(c<n)c*=2; return c; } +static size_t charge(const Block *b) { return sizeof(*b)+b->capacity; } +static void check(Engine *e) { + assert(e->active+e->cached==e->reserved); + assert(e->by_kind[0]+e->by_kind[1]+e->by_kind[2]==e->active); + assert(e->fixed+e->reserved<=e->budget); + if(e->reserved>e->peak)e->peak=e->reserved; + for(unsigned k=0;k<KINDS;++k)if(e->by_kind[k]>e->peak_kind[k])e->peak_kind[k]=e->by_kind[k]; +} +static void evict(Engine *e,size_t i) { + Block *b=e->cache[i]; if(!b)return; + assert(!b->refs && !b->views); + e->reserved-=charge(b); e->cached-=charge(b); free(b); e->cache[i]=NULL; +} +static Block *take(Engine *e,size_t n,unsigned kind) { + size_t capacity=rounded(n),need=sizeof(Block)+capacity; + Block *b=NULL; + if(e->pool)for(size_t i=0;i<CACHE;++i)if(e->cache[i] && e->cache[i]->capacity==capacity) { + b=e->cache[i]; e->cache[i]=NULL; e->cached-=need; ++e->reuses; break; + } + if(!b) { + for(size_t i=0;i<CACHE && need>e->budget-e->fixed-e->reserved;++i)evict(e,i); + if(need>e->budget-e->fixed-e->reserved)return NULL; + b=malloc(need); + if(!b){e->status="allocation_failed";return NULL;} + b->capacity=capacity; e->reserved+=need; ++e->allocations[kind]; + } + b->kind=kind;b->refs=1;b->views=NULL;b->since=ns(CLOCK_MONOTONIC); + e->active+=need;e->by_kind[kind]+=need;check(e);return b; +} +static void drop(Engine *e,Block *b) { + if(!b)return; + assert(b->refs); + if(--b->refs)return; + assert(!b->views); + size_t bytes=charge(b); + e->byte_ns[b->kind]+=(long double)bytes*(ns(CLOCK_MONOTONIC)-b->since); + e->active-=bytes;e->by_kind[b->kind]-=bytes; + if(e->pool && bytes<=e->budget/4-e->cached)for(size_t i=0;i<CACHE;++i)if(!e->cache[i]) { + e->cache[i]=b;e->cached+=bytes;check(e);return; + } + e->reserved-=bytes;free(b);check(e); +} +static void attach(Item *item) { + Block *b=item->block; + item->prev=NULL;item->next=b->views; + if(b->views)b->views->prev=item; + b->views=item; +} +static void detach(Item *item) { + if(item->prev)item->prev->next=item->next;else item->block->views=item->next; + if(item->next)item->next->prev=item->prev; + item->prev=item->next=NULL; +} +static void compact(Engine *e,Block *source) { + if(strcmp(e->policy,"compact") || source->kind!=SOURCE || source->refs!=1 || !source->views)return; + Item *item=source->views; + assert(!item->next); + if(source->capacity/rounded(item->length)<e->ratio)return; + /* Opportunistic only: never block or recurse from a completion callback. */ + Block *small=take(e,item->length,OUTPUT); + if(!small){++e->compact_skipped;return;} + memcpy(small->data,source->data+item->offset,item->length); + e->selection_copies+=item->length;++e->compacted; + detach(item);item->block=small;item->offset=0;attach(item);drop(e,source); +} +static uint64_t deadline(Queue *q) { + uint64_t ready=q->items[q->head].ready; + return ready>q->last+q->service?ready:q->last+q->service; +} +static int next_queue(Engine *e) { + int selected=-1;uint64_t soon=UINT64_MAX; + for(size_t k=0;k<e->fanout;++k)if(e->q[k].count && deadline(&e->q[k])<soon) { + selected=(int)k;soon=deadline(&e->q[k]); + } + return selected; +} +static int sleep_to(Engine *e,uint64_t until) { + uint64_t start=ns(CLOCK_MONOTONIC),now=start; + while(now<until && !stopped) { + uint64_t left=until-now; + struct timespec t={(time_t)(left/1000000000),(long)(left%1000000000)}; + if(nanosleep(&t,NULL) && errno!=EINTR){e->status="sleep_failed";return 0;} + now=ns(CLOCK_MONOTONIC); + } + e->sleep_ns+=now-start;return !stopped; +} +static unsigned bucket(uint64_t n) { + unsigned k=0;for(uint64_t x=n;x>1;x>>=1)++k; + return k<3?(unsigned)n:k*8+(unsigned)((n-(UINT64_C(1)<<k))>>(k-3)); +} +static uint64_t upper(unsigned b) { + unsigned k=b/8; + if(b<24)return b+1; + if(k>=63)return UINT64_MAX; + return (UINT64_C(1)<<k)+(uint64_t)(b%8+1)*(UINT64_C(1)<<(k-3)); +} +static int write_all(Engine *e,const void *data,size_t n) { + const unsigned char *p=data; + while(n && !stopped) { + ssize_t w=write(STDOUT_FILENO,p,n); + if(w<0 && errno==EINTR)continue; + if(w<=0){e->status="output_failed";return 0;} + p+=w;n-=(size_t)w; + } + return !stopped; +} +static int emit(Engine *e) { + int k=next_queue(e);assert(k>=0); + Queue *q=&e->q[k];Item *item=&q->items[q->head]; + if(!sleep_to(e,deadline(q)))return 0; + unsigned char header[16]; + for(unsigned i=0;i<4;++i){header[i]=(unsigned char)((unsigned)k>>(8*i));header[4+i]=(unsigned char)(item->length>>(8*i));} + for(unsigned i=0;i<8;++i)header[8+i]=(unsigned char)(item->sequence>>(8*i)); + if(!write_all(e,header,16) || !write_all(e,item->block->data+item->offset,item->length))return 0; + uint64_t now=ns(CLOCK_MONOTONIC),latency=now-item->start; + q->last=now;q->latency_sum+=latency;++q->histogram[bucket(latency)]; + ++q->emitted;q->bytes+=item->length;++e->emitted; + Block *b=item->block;size_t old_refs=b->refs; + detach(item);drop(e,b);item->block=NULL; + q->head=(q->head+1)%e->slots;--q->count; + if(old_refs>1)compact(e,b); + if(e->cancel_after && e->emitted>=e->cancel_after){e->status="cancelled";return 0;} + return !strcmp(e->status,"ok"); +} +static Block *acquire(Engine *e,size_t n,unsigned kind) { + for(;;) { + Block *b=take(e,n,kind);if(b)return b; + if(strcmp(e->status,"ok"))return NULL; + if(next_queue(e)<0){e->status="budget_too_small";return NULL;} + ++e->budget_waits;if(!emit(e))return NULL; + } +} +static void *parser_alloc(void *ctx,size_t n) { + Block *b=acquire(ctx,n,PARSER);return b?b->data:NULL; +} +static Block *from_data(void *p) {return (Block *)((unsigned char *)p-sizeof(Block));} +static void parser_free(void *ctx,void *p) {if(p)drop(ctx,from_data(p));} +static void *parser_realloc(void *ctx,void *p,size_t old,size_t n) { + if(!p)return parser_alloc(ctx,n); + Block *b=from_data(p);assert(b->refs==1 && b->kind==PARSER && old<=b->capacity); + if(n<=b->capacity)return p; + void *fresh=parser_alloc(ctx,n);if(!fresh)return NULL; + memcpy(fresh,p,old);((Engine *)ctx)->parser_copies+=old;parser_free(ctx,p);return fresh; +} +/* Bounded NDJSON reader, accepting a final complete JSON without a newline. */ +static Block *read_record(Engine *e,size_t *length) { + Block *b=acquire(e,256,SOURCE);if(!b)return NULL; + *length=0; + for(;;) { + if(stopped){drop(e,b);return NULL;} + if(e->read_at==e->read_end) { + ssize_t got=read(STDIN_FILENO,e->read_buffer,READ_SIZE); + if(got<0 && errno==EINTR)continue; + if(got<0){e->status="input_failed";drop(e,b);return NULL;} + if(!got){if(*length)break;drop(e,b);return NULL;} + e->read_at=0;e->read_end=(size_t)got;e->input_bytes+=(uint64_t)got; + } + unsigned char *p=e->read_buffer+e->read_at; + size_t available=e->read_end-e->read_at; + unsigned char *newline=memchr(p,'\n',available); + size_t amount=newline?(size_t)(newline-p):available; + if(amount>MAX_JSON-*length){e->status="record_too_large";drop(e,b);return NULL;} + size_t need=*length+amount+YYJSON_PADDING_SIZE; + if(need>b->capacity) { + Block *larger=acquire(e,need,SOURCE); + if(!larger){drop(e,b);return NULL;} + memcpy(larger->data,b->data,*length);e->reader_copies+=*length; + drop(e,b);b=larger; + } + memcpy(b->data+*length,p,amount);e->reader_copies+=amount; + *length+=amount;e->read_at+=amount+(newline?1:0); + if(newline)break; + } + memset(b->data+*length,0,YYJSON_PADDING_SIZE);return b; +} +static int submit(Engine *e,Block *source,size_t length,uint64_t start) { + size_t offsets[BRANCHES]={0},lengths[BRANCHES]={0}; + yyjson_alc alc={parser_alloc,parser_realloc,parser_free,e}; + yyjson_read_err error; + uint64_t before=ns(CLOCK_MONOTONIC); + yyjson_doc *doc=yyjson_read_opts((char *)source->data,length,YYJSON_READ_INSITU,&alc,&error); + e->parse_ns+=ns(CLOCK_MONOTONIC)-before; + if(!doc){if(!strcmp(e->status,"ok"))e->status="invalid_json";drop(e,source);return 0;} + yyjson_val *root=yyjson_doc_get_root(doc); + int valid=yyjson_is_obj(root); + for(size_t k=0;valid && k<e->fanout;++k) { + yyjson_val *value=yyjson_obj_get(root,e->q[k].key); + const char *str=yyjson_get_str(value);size_t size=yyjson_get_len(value); + uintptr_t address=(uintptr_t)str,base=(uintptr_t)source->data; + if(!yyjson_is_str(value) || address<base || address-base>length || size>length-(address-base))valid=0; + else{offsets[k]=(size_t)(address-base);lengths[k]=size;} + } + /* Only decoded string offsets/lengths survive. No DOM nodes escape. */ + yyjson_doc_free(doc); + if(!valid){e->status="invalid_schema";drop(e,source);return 0;} + Item pending[BRANCHES]={{0}}; + for(size_t k=0;k<e->fanout;++k) { + int copy=!strcmp(e->policy,"copy") || !strcmp(e->policy,"shared_copy") || + (!strcmp(e->policy,"threshold") && source->capacity/rounded(lengths[k])>=e->ratio); + int reuse=copy && (!strcmp(e->policy,"shared_copy") || !strcmp(e->policy,"threshold")); + Block *b=NULL;size_t offset=offsets[k]; + if(reuse)for(size_t j=0;j<k;++j)if(offsets[j]==offsets[k] && lengths[j]==lengths[k] && pending[j].block!=source) { + b=pending[j].block;++b->refs;offset=0;++e->dedup_hits;break; + } + if(!b && copy) { + b=acquire(e,lengths[k],OUTPUT); + if(!b) { + for(size_t j=0;j<k;++j)drop(e,pending[j].block); + drop(e,source);return 0; + } + memcpy(b->data,source->data+offset,lengths[k]);e->selection_copies+=lengths[k];offset=0; + } else if(!b){b=source;++b->refs;} + pending[k]=(Item){.block=b,.offset=offset,.length=lengths[k],.sequence=e->accepted,.start=start}; + } + uint64_t now=ns(CLOCK_MONOTONIC); + for(size_t k=0;k<e->fanout;++k) { + Queue *q=&e->q[k];assert(q->count<e->slots); + Item *item=&q->items[(q->head+q->count)%e->slots]; + *item=pending[k];item->ready=now+q->hold;attach(item);++q->count; + if(q->count>q->peak)q->peak=q->count; + } + ++e->accepted;drop(e,source);return 1; +} +static void run(Engine *e) { + while(!stopped && !strcmp(e->status,"ok")) { + int k=next_queue(e); + if(k>=0 && deadline(&e->q[k])<=ns(CLOCK_MONOTONIC)){if(!emit(e))break;continue;} + int full=0;for(size_t j=0;j<e->fanout;++j)if(e->q[j].count==e->slots)full=1; + if(full){++e->slot_waits;if(!emit(e))break;continue;} + size_t length;uint64_t start=ns(CLOCK_MONOTONIC); + Block *source=read_record(e,&length); + if(!source) { + while(!stopped && !strcmp(e->status,"ok") && next_queue(e)>=0)if(!emit(e))break; + break; + } + if(!submit(e,source,length,start))break; + } + if(stopped)e->status="cancelled"; +} +static uint64_t number(const char *s,uint64_t max) { + char *end;errno=0;unsigned long long n=strtoull(s,&end,10); + if(!*s || *s=='-' || *end || errno || n>max){fprintf(stderr,"invalid number\n");exit(2);} + return n; +} +static uint64_t rss(void) { +#if defined(__linux__) + FILE *f=fopen("/proc/self/status","r");if(!f)return 0; + char line[256];unsigned long long kib=0; + while(fgets(line,sizeof(line),f))if(sscanf(line,"VmHWM: %llu kB",&kib)==1)break; + fclose(f);return (uint64_t)kib*1024; +#else + return 0; +#endif +} +int main(int argc,char **argv) { + _Static_assert(sizeof(Block)==offsetof(Block,data),"aligned block header"); + Engine storage={0},*e=&storage; + e->policy="borrow";e->status="ok";e->slots=64;e->fanout=3;e->budget=8*1024*1024;e->ratio=2;e->pool=1; + e->q[0].key="body";e->q[1].key=e->q[2].key="tag"; + e->q[1].hold=5000000;e->q[2].hold=8000000; + for(int i=1;i<argc;i+=2) { + if(i+1==argc){fprintf(stderr,"option needs value\n");return 2;} + const char *key=argv[i],*value=argv[i+1]; + if(!strcmp(key,"--policy"))e->policy=value; + else if(!strcmp(key,"--budget"))e->budget=(size_t)number(value,1073741824); + else if(!strcmp(key,"--slots"))e->slots=(size_t)number(value,4096); + else if(!strcmp(key,"--fanout"))e->fanout=(size_t)number(value,BRANCHES); + else if(!strcmp(key,"--ratio"))e->ratio=(unsigned)number(value,1024); + else if(!strcmp(key,"--pool"))e->pool=(int)number(value,1); + else if(!strcmp(key,"--cancel-after"))e->cancel_after=number(value,UINT64_MAX); + else { + int recognized=0; + for(size_t k=0;k<BRANCHES;++k) { + char option[32]; + snprintf(option,sizeof(option),"--key%zu",k); + if(!strcmp(key,option)){e->q[k].key=value;recognized=1;} + snprintf(option,sizeof(option),"--hold%zu-us",k); + if(!strcmp(key,option)){e->q[k].hold=number(value,10000000)*1000;recognized=1;} + snprintf(option,sizeof(option),"--service%zu-us",k); + if(!strcmp(key,option)){e->q[k].service=number(value,10000000)*1000;recognized=1;} + } + if(!recognized){fprintf(stderr,"unknown option\n");return 2;} + } + } + if(!e->slots || !e->fanout || e->ratio<2 || (strcmp(e->policy,"borrow") && strcmp(e->policy,"copy") && + strcmp(e->policy,"shared_copy") && strcmp(e->policy,"threshold") && strcmp(e->policy,"compact"))) { + fprintf(stderr,"invalid configuration\n");return 2; + } + e->fixed=sizeof(*e)+e->fanout*e->slots*sizeof(Item); + if(e->fixed>e->budget){fprintf(stderr,"budget below metadata\n");return 2;} + for(size_t k=0;k<e->fanout;++k) { + e->q[k].items=calloc(e->slots,sizeof(Item)); + if(!e->q[k].items){for(size_t j=0;j<k;++j)free(e->q[j].items);return 2;} + } + signal(SIGINT,stop);signal(SIGTERM,stop);signal(SIGPIPE,SIG_IGN); + uint64_t start=ns(CLOCK_MONOTONIC),cpu=ns(CLOCK_PROCESS_CPUTIME_ID); + run(e); + size_t live_at_stop=e->active; + for(size_t k=0;k<e->fanout;++k) { + Queue *q=&e->q[k]; + while(q->count){Item *item=&q->items[q->head];detach(item);drop(e,item->block);q->head=(q->head+1)%e->slots;--q->count;} + } + for(size_t i=0;i<CACHE;++i)evict(e,i); + assert(!e->active && !e->reserved); + e->elapsed_ns=ns(CLOCK_MONOTONIC)-start;e->cpu_ns=ns(CLOCK_PROCESS_CPUTIME_ID)-cpu; + fprintf(stderr,"{\"status\":\"%s\",\"policy\":\"%s\",\"parser_version\":\"%s\",\"budget_bytes\":%zu," + "\"fixed_bytes\":%zu,\"peak_reserved_bytes\":%zu,\"source_peak_bytes\":%zu,\"output_peak_bytes\":%zu," + "\"parser_peak_bytes\":%zu,\"rss_peak_bytes\":%" PRIu64 ",\"elapsed_ns\":%" PRIu64 ",\"cpu_ns\":%" PRIu64 "," + "\"parse_call_ns\":%" PRIu64 ",\"accepted\":%" PRIu64 ",\"emitted\":%" PRIu64 ",\"input_bytes\":%" PRIu64 "," + "\"selection_copy_bytes\":%" PRIu64 ",\"reader_copy_bytes\":%" PRIu64 ",\"parser_realloc_copy_bytes\":%" PRIu64 "," + "\"source_byte_seconds\":%.6Lf,\"output_byte_seconds\":%.6Lf,\"parser_byte_seconds\":%.6Lf," + "\"source_allocations\":%" PRIu64 ",\"output_allocations\":%" PRIu64 ",\"parser_allocations\":%" PRIu64 "," + "\"reuses\":%" PRIu64 ",\"budget_waits\":%" PRIu64 ",\"slot_waits\":%" PRIu64 "," + "\"compacted\":%" PRIu64 ",\"compact_skipped\":%" PRIu64 ",\"dedup_hits\":%" PRIu64 ",\"sleep_ns\":%" PRIu64 "," + "\"live_at_stop_bytes\":%zu,\"unreleased_buffer_bytes\":%zu,\"queues\":[", + e->status,e->policy,YYJSON_VERSION_STRING,e->budget,e->fixed,e->fixed+e->peak,e->peak_kind[SOURCE], + e->peak_kind[OUTPUT],e->peak_kind[PARSER],rss(),e->elapsed_ns,e->cpu_ns,e->parse_ns,e->accepted,e->emitted, + e->input_bytes,e->selection_copies,e->reader_copies,e->parser_copies,e->byte_ns[SOURCE]/1e9L, + e->byte_ns[OUTPUT]/1e9L,e->byte_ns[PARSER]/1e9L,e->allocations[SOURCE],e->allocations[OUTPUT], + e->allocations[PARSER],e->reuses,e->budget_waits,e->slot_waits,e->compacted,e->compact_skipped, + e->dedup_hits,e->sleep_ns,live_at_stop,e->reserved); + for(size_t k=0;k<e->fanout;++k) { + Queue *q=&e->q[k];uint64_t target=q->emitted-q->emitted/100,sum=0,p99=0; + for(unsigned b=0;q->emitted && b<HIST;++b){sum+=q->histogram[b];if(sum>=target){p99=upper(b);break;}} + fprintf(stderr,"%s{\"emitted\":%" PRIu64 ",\"bytes\":%" PRIu64 ",\"peak_count\":%zu," + "\"latency_mean_ns\":%.3f,\"latency_p99_upper_ns\":%" PRIu64 "}",k?",":"",q->emitted,q->bytes,q->peak, + q->emitted?(double)q->latency_sum/q->emitted:0,p99); + free(q->items); + } + fprintf(stderr,"]}\n");return !strcmp(e->status,"ok")?0:!strcmp(e->status,"cancelled")?3:2; +} diff --git a/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/sources/plan.json b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/sources/plan.json new file mode 100644 index 0000000..60c179b --- /dev/null +++ b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/sources/plan.json @@ -0,0 +1,32 @@ +{ + "version": 1, + "written_before_measurement": true, + "seed": 20260923, + "repeats": 5, + "policies": [ + {"name": "borrow", "policy": "borrow"}, + {"name": "copy", "policy": "copy"}, + {"name": "shared_copy", "policy": "shared_copy"}, + {"name": "threshold2", "policy": "threshold", "ratio": 2}, + {"name": "threshold8", "policy": "threshold", "ratio": 8}, + {"name": "compact", "policy": "compact", "ratio": 2}, + {"name": "copy_no_pool", "policy": "copy", "pool": 0} + ], + "cases": [ + {"name": "one_slow", "shape": "large", "records": 1024, "keys": ["tag"], "hold_us": [8000], "service_us": [0], "budget": 8388608, "slots": 64}, + {"name": "three_distinct_speeds", "shape": "large", "records": 1024, "keys": ["body", "tag", "tag"], "hold_us": [0, 5000, 8000], "service_us": [0, 0, 0], "budget": 8388608, "slots": 64}, + {"name": "same_large_field", "shape": "large", "records": 1024, "keys": ["body", "body", "body"], "hold_us": [0, 5000, 8000], "service_us": [0, 0, 0], "budget": 8388608, "slots": 64}, + {"name": "slow_large_field", "shape": "large", "records": 1024, "keys": ["tag", "tag", "body"], "hold_us": [0, 5000, 8000], "service_us": [0, 0, 0], "budget": 8388608, "slots": 64}, + {"name": "mixed_tight", "shape": "mixed", "records": 1024, "keys": ["body", "tag", "tag"], "hold_us": [0, 5000, 8000], "service_us": [0, 0, 0], "budget": 2097152, "slots": 64}, + {"name": "metadata_heavy", "shape": "metadata", "records": 512, "keys": ["body", "tag", "tag"], "hold_us": [0, 5000, 8000], "service_us": [0, 0, 0], "budget": 2097152, "slots": 64} + ], + "expectations": [ + "A slow small-field consumer can retain the input after a fast large-field consumer finishes.", + "Sharing identical compact copies can remove duplicate per-consumer copies without a new runtime.", + "Late compaction may save copied bytes or fail to beat early size-based copying; all remaining owners matter.", + "Parser temporary memory and reader growth must be charged, even when retained selections are small.", + "No novel-policy advantage or production service SLO is presumed." + ], + "comparison_rule": "Report all fixed presets; exploratory measurements, no trained/held-out policy or significance claim.", + "limits": "Real yyjson parser and actual bytes, but synthetic NDJSON corpus and sink delays, three synchronous consumers in one event loop, no open-loop arrivals, thread races, durable output, or independent parser comparison." +} diff --git a/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/sources/run.py b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/sources/run.py new file mode 100644 index 0000000..e4848bd --- /dev/null +++ b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/sources/run.py @@ -0,0 +1,351 @@ +#!/usr/bin/env python3 +"""Verify and measure yyjson parsing with bounded, differently paced consumers.""" +import argparse +import csv +import hashlib +import json +import os +from pathlib import Path +import platform +import random +import shlex +import signal +import statistics +import struct +import subprocess +import tempfile +import time + +ROOT = Path(__file__).resolve().parent +FLAGS = ["-std=c17", "-O2", "-g", "-Wall", "-Wextra", "-Wpedantic", "-Werror"] +FLAGS += ["-DYYJSON_DISABLE_WRITER=1", "-DYYJSON_DISABLE_UTILS=1", "-DYYJSON_DISABLE_INCR_READER=1"] +SOURCE_NAMES = ["benchmark.c", "run.py", "plan.json", "vendor/yyjson/UPSTREAM.json", + "vendor/yyjson/yyjson.c", "vendor/yyjson/yyjson.h", "vendor/yyjson/LICENSE"] + + +def digest(path): + with path.open("rb") as stream: + return hashlib.file_digest(stream, "sha256").hexdigest() + + +def dump(path, value): + path.write_text(json.dumps(value, indent=2, ensure_ascii=False) + "\n") + + +def first_members(pairs): + result = {} + for key, value in pairs: + result.setdefault(key, value) + return result + + +def reference(data, keys): + values = [[] for _ in keys] + for line in data.splitlines(): + row = json.loads(line, object_pairs_hook=first_members) + if not isinstance(row, dict): + raise ValueError("object required") + for k, key in enumerate(keys): + if not isinstance(row.get(key), str): + raise ValueError("string field required") + values[k].append(row[key].encode("utf-8")) + return values + + +def decode(data, keys, expected, partial=False): + at = 0 + found = [[] for _ in keys] + while at < len(data): + if len(data) - at < 16: + raise AssertionError("incomplete output header") + k, length, sequence = struct.unpack_from("<IIQ", data, at) + at += 16 + assert k < len(keys) and sequence == len(found[k]) + assert length <= len(data) - at + found[k].append(data[at:at + length]) + at += length + for k in range(len(keys)): + assert found[k] == (expected[k][:len(found[k])] if partial else expected[k]) + return [len(items) for items in found] + + +def build(cc, output, sanitizer=False): + command = [*cc, *FLAGS] + if sanitizer: + command += ["-O1", "-fsanitize=address,undefined", "-fno-omit-frame-pointer"] + command += [str(ROOT / "benchmark.c"), str(ROOT / "vendor/yyjson/yyjson.c"), "-o", str(output)] + start = time.monotonic_ns() + result = subprocess.run(command, capture_output=True, text=True, check=True) + return {"command": command, "stderr": result.stderr, "sha256": digest(output), + "size_bytes": output.stat().st_size, "build_wall_ns": time.monotonic_ns() - start} + + +def command(binary, case, policy, *extra): + keys = case.get("keys", ["body", "tag", "tag"]) + holds = case.get("hold_us", [0, 5000, 8000][:len(keys)]) + services = case.get("service_us", [0] * len(keys)) + result = [str(binary), "--policy", policy["policy"], "--fanout", str(len(keys)), + "--slots", str(case.get("slots", 64)), "--budget", str(case.get("budget", 8388608)), + "--pool", str(policy.get("pool", 1)), "--ratio", str(policy.get("ratio", 2))] + for k, key in enumerate(keys): + result += [f"--key{k}", key, f"--hold{k}-us", str(holds[k]), f"--service{k}-us", str(services[k])] + return result + list(extra) + + +def metrics(stderr): + try: + m = json.loads(stderr) + except (ValueError, UnicodeError) as exc: + raise AssertionError(f"Expected metrics only, got diagnostics: {stderr!r}") from exc + assert m["unreleased_buffer_bytes"] == 0 + assert m["peak_reserved_bytes"] <= m["budget_bytes"] + assert sum(q["emitted"] for q in m["queues"]) == m["emitted"] + assert m["parser_version"] == "0.12.0" + return m + + +def invoke(binary, case, policy, data, *extra): + proc = subprocess.run(command(binary, case, policy, *extra), input=data, + capture_output=True, timeout=20) + return proc, metrics(proc.stderr) + + +def verify(binary, policies, tmp): + checks = [] + rows = [{"body": "A" * 33000, "tag": "one"}, + {"body": "한글😀\n\x00\"\\", "tag": ""}, + {"body": "", "tag": "둘\t\r"}, + {"body": "z" * 66000, "tag": "three", "meta": [True, None, {"x": -3.5}]}] * 7 + data = b"".join(json.dumps(row, ensure_ascii=i % 2 == 0).encode() + b"\n" for i, row in enumerate(rows)) + for policy in policies: + for keys in [["tag"], ["body", "tag"], ["body", "tag", "tag"]]: + case = {"keys": keys, "hold_us": [500 * k for k in range(len(keys))], "slots": 3} + proc, m = invoke(binary, case, policy, data) + assert proc.returncode == 0 and m["status"] == "ok", proc.stderr + counts = decode(proc.stdout, keys, reference(data, keys)) + assert counts == [len(rows)] * len(keys) and m["accepted"] == len(rows) + assert m["live_at_stop_bytes"] == 0 + checks.append(f'{policy["name"]}: {len(keys)} consumer(s), UTF-8/escapes/NUL/empty, slot reuse') + keys = ["body", "tag", "tag"] + for sample in [b"", data.rstrip(b"\n"), b'{"body":"first","body":"second","tag":"x"}\n']: + proc, m = invoke(binary, {}, policy, sample) + assert proc.returncode == 0 and m["status"] == "ok" + decode(proc.stdout, keys, reference(sample, keys)) + checks.append(f'{policy["name"]}: empty input, final JSON without newline, first duplicate member') + malformed = [b'{"body":"x","tag":', b'{"body":"x","tag":"y","extra":[1,]}', + b'{"body":"x","tag":3}', b'{"body":"x"}', b'[]', + b'{"body":"\xff","tag":"x"}', b'\n', + b'{"body":"x","tag":"y"} true'] + for bad in malformed: + proc, m = invoke(binary, {"hold_us": [1000, 2000, 3000]}, policy, data[:data.index(b"\n") + 1] + bad) + assert proc.returncode == 2 and m["status"] in {"invalid_json", "invalid_schema"}, proc.stderr + checks.append(f'{policy["name"]}: eight invalid JSON/schema cases with retained owners') + proc, m = invoke(binary, {}, policy, data, "--cancel-after", "7") + assert proc.returncode == 3 and m["status"] == "cancelled" and m["emitted"] == 7 + counts = decode(proc.stdout, keys, reference(data, keys), partial=True) + assert sum(counts) == 7 + checks.append(f'{policy["name"]}: cancellation preserves each branch prefix and releases all shared owners') + # Source can fit; the many JSON nodes require more parser storage than the budget. + heavy = json.dumps({"body": "x", "tag": "y", "meta": [0] * 20000}).encode() + proc, m = invoke(binary, {"slots": 1, "budget": 160000}, policy, heavy) + assert proc.returncode == 2 and m["status"] == "budget_too_small", proc.stderr + assert m["accepted"] == 0 + checks.append(f'{policy["name"]}: parser allocation charged and refused within total budget') + # Same decoded field is shared after the document metadata has been freed. + sample = json.dumps({"body": "z" * 40000, "tag": "small"}).encode() + b"\n" + case = {"keys": ["tag", "tag", "tag"], "hold_us": [0, 1000, 2000]} + _, separate = invoke(binary, case, {"policy": "copy"}, sample) + proc, shared = invoke(binary, case, {"policy": "shared_copy"}, sample) + decode(proc.stdout, case["keys"], reference(sample, case["keys"])) + assert separate["selection_copy_bytes"] == 15 and shared["selection_copy_bytes"] == 5 + assert shared["dedup_hits"] == 2 + checks.append("identical selections copied once and live until the final consumer") + case = {"keys": ["body", "tag"], "hold_us": [0, 3000]} + proc, m = invoke(binary, case, {"policy": "compact"}, sample) + decode(proc.stdout, case["keys"], reference(sample, case["keys"])) + assert m["compacted"] == 1 and m["selection_copy_bytes"] == 5 + checks.append("last-owner compaction keeps the delayed decoded value valid") + proc, m = invoke(binary, {}, policies[0], b'x' * (1024 * 1024 + 1)) + assert proc.returncode == 2 and m["status"] == "record_too_large" + checks.append("overlong NDJSON record refused without leaked source") + if Path("/dev/full").exists(): + with open("/dev/full", "wb") as sink: + proc = subprocess.run(command(binary, {}, policies[0]), input=sample, + stdout=sink, stderr=subprocess.PIPE, timeout=10) + assert proc.returncode == 2 and metrics(proc.stderr)["status"] == "output_failed" + checks.append("actual /dev/full failure releases multiple owners") + source = tmp / "signal.ndjson" + source.write_bytes(sample * 20) + with source.open("rb") as inp, open(os.devnull, "wb") as sink: + proc = subprocess.Popen(command(binary, {"hold_us": [500000] * 3}, policies[0]), + stdin=inp, stdout=sink, stderr=subprocess.PIPE) + time.sleep(0.1) + proc.send_signal(signal.SIGTERM) + _, stderr = proc.communicate(timeout=5) + assert proc.returncode == 3 and metrics(stderr)["status"] == "cancelled" + checks.append("SIGTERM during delayed fan-out releases all owners") + return checks + + +def make_fixture(path, case, seed): + rng = random.Random(seed) + hashes = [hashlib.sha256() for _ in case["keys"]] + sizes = [0] * len(hashes) + with path.open("wb") as stream: + for seq in range(case["records"]): + if case["shape"] == "large": + body_size, padding = 32768, 8192 + elif case["shape"] == "mixed": + body_size, padding = rng.choice([(256, 1024), (4096, 16384), (32768, 8192), (65536, 65536)]) + elif case["shape"] == "metadata": + body_size, padding = 512, 512 + else: + raise ValueError(case["shape"]) + tile = rng.randbytes(128).hex() + body = (tile * ((body_size + 255) // 256))[:body_size] + tag = f'{seq:08x}-한글-"-\\-\n-\x00-' + tile[:32] + row = {"id": seq, "body": body, "tag": tag, "padding": "p" * padding, + "meta": list(range(2048)) if case["shape"] == "metadata" else {"ok": True, "n": seq}} + encoded = json.dumps(row, ensure_ascii=seq % 2 == 0, separators=(",", ":")).encode("utf-8") + stream.write(encoded + b"\n") + # Python's independent decoder defines the expected decoded UTF-8 output. + decoded = json.loads(encoded) + for k, key in enumerate(case["keys"]): + selected = decoded[key].encode("utf-8") + hashes[k].update(struct.pack("<QI", seq, len(selected)) + selected) + sizes[k] += len(selected) + return {"case": case["name"], "seed": seed, "records": case["records"], "input_bytes": path.stat().st_size, + "input_sha256": digest(path), "keys": case["keys"], "output_bytes_by_branch": sizes, + "output_sha256_by_branch": [h.hexdigest() for h in hashes]} + + +def verify_output(path, fixture): + count = [0] * len(fixture["keys"]) + hashes = [hashlib.sha256() for _ in count] + sizes = [0] * len(count) + with path.open("rb") as stream: + while header := stream.read(16): + assert len(header) == 16 + k, n, seq = struct.unpack("<IIQ", header) + assert k < len(count) and seq == count[k] and n <= 1024 * 1024 + data = stream.read(n) + assert len(data) == n + hashes[k].update(struct.pack("<QI", seq, n) + data) + count[k] += 1 + sizes[k] += n + assert count == [fixture["records"]] * len(count) + assert sizes == fixture["output_bytes_by_branch"] + assert [h.hexdigest() for h in hashes] == fixture["output_sha256_by_branch"] + + +def sample(binary, source, output, case, policy, fixture): + with source.open("rb") as inp, output.open("wb") as sink: + proc = subprocess.run(command(binary, case, policy), stdin=inp, stdout=sink, + stderr=subprocess.PIPE, timeout=30) + m = metrics(proc.stderr) + assert proc.returncode == 0 and m["status"] == "ok", proc.stderr + assert m["accepted"] == case["records"] and m["emitted"] == case["records"] * len(case["keys"]) + assert m["input_bytes"] == fixture["input_bytes"] + assert m["live_at_stop_bytes"] == 0 + verify_output(output, fixture) + return m + + +def summary(rows): + keys = ["peak_reserved_bytes", "source_peak_bytes", "output_peak_bytes", "parser_peak_bytes", + "rss_peak_bytes", "elapsed_ns", "cpu_ns", "parse_call_ns", "selection_copy_bytes", + "reader_copy_bytes", "parser_realloc_copy_bytes", "source_byte_seconds", "budget_waits", + "compacted", "dedup_hits"] + result = [] + for case, variant in sorted({(r["case"], r["variant"]) for r in rows}): + group = [r for r in rows if (r["case"], r["variant"]) == (case, variant)] + item = {"case": case, "variant": variant, "samples": len(group)} + for key in keys: + values = [r[key] for r in group] + item[key] = {"median": statistics.median(values), "min": min(values), "max": max(values)} + item["queues"] = [{key: statistics.median(r["queues"][k][key] for r in group) + for key in ["peak_count", "latency_mean_ns", "latency_p99_upper_ns"]} + for k in range(len(group[0]["queues"]))] + result.append(item) + return result + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--check-only", action="store_true") + parser.add_argument("--output", type=Path) + args = parser.parse_args() + if not args.check_only and args.output is None: + parser.error("provide --check-only or --output NEW_DIRECTORY") + if args.output: + args.output.mkdir(parents=True, exist_ok=False) + upstream = json.loads((ROOT / "vendor/yyjson/UPSTREAM.json").read_text()) + for name, item in upstream["files"].items(): + assert digest(ROOT / "vendor/yyjson" / name) == item["sha256"] + plan = json.loads((ROOT / "plan.json").read_text()) + cc = shlex.split(os.environ.get("CC", "cc")) + affinity = None + if hasattr(os, "sched_getaffinity"): + affinity = min(os.sched_getaffinity(0)) + os.sched_setaffinity(0, {affinity}) + with tempfile.TemporaryDirectory(prefix="pure-fanout-") as folder: + tmp = Path(folder) + binary, sanitizer = tmp / "benchmark", tmp / "benchmark-sanitized" + print("Building optimized parser and pipeline.", flush=True) + builds = [build(cc, binary)] + print("Building parser and pipeline with ASan/UBSan (-O1).", flush=True) + builds.append(build(cc, sanitizer, True)) + print("Checking native and instrumented builds.", flush=True) + checks = {"native": verify(binary, plan["policies"], tmp), + "asan_ubsan": verify(sanitizer, plan["policies"], tmp)} + print(f'Verified {sum(map(len, checks.values()))} scenario groups (native + ASan/UBSan).', flush=True) + if args.check_only: + return + sources = {name: digest(ROOT / name) for name in SOURCE_NAMES} + environment = {"platform": platform.platform(), "machine": platform.machine(), "python": platform.python_version(), + "compiler": subprocess.check_output([*cc, "--version"], text=True), "cpu_affinity": affinity, + "builds": builds, "source_sha256": sources, "upstream": upstream, + "timing": "I/O, parsing, selection, consumers, instrumentation, cleanup; excludes setup/build/verification", + "parse_call_ns": "wall duration inside yyjson_read_opts including allocator backpressure and serviced consumers", + "rss": "Linux current-image VmHWM approximate; zero means unavailable on other OSes", + "limits": "synthetic closed-loop arrivals/delays; one thread; uncontrolled thermals/power; cached file I/O; no fsync", + "started_utc": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())} + if Path("/proc/cpuinfo").exists(): + environment["cpuinfo"] = Path("/proc/cpuinfo").read_text() + dump(args.output / "environment.json", environment) + dump(args.output / "verification.json", checks) + dump(args.output / "plan.json", plan) + for name in sources: + destination = args.output / "sources" / name + destination.parent.mkdir(parents=True, exist_ok=True) + destination.write_bytes((ROOT / name).read_bytes()) + rng, rows, fixtures = random.Random(plan["seed"]), [], [] + for case in plan["cases"]: + source, output = tmp / "input.ndjson", tmp / "branches.bin" + info = make_fixture(source, case, plan["seed"]) + fixtures.append(info) + for policy in plan["policies"]: + sample(binary, source, output, case, policy, info) + for repeat in range(plan["repeats"]): + order = list(plan["policies"]) + rng.shuffle(order) + for policy in order: + value = sample(binary, source, output, case, policy, info) + rows.append({"case": case["name"], "variant": policy["name"], "repeat": repeat, **value}) + dump(args.output / "raw.json", rows) + dump(args.output / "fixtures.json", fixtures) + print(f'Completed {case["name"]}: {len(plan["policies"])} variants x {plan["repeats"]} trials.', flush=True) + dump(args.output / "summary.json", summary(rows)) + flat = [{**{k: v for k, v in row.items() if k != "queues"}, "queues": json.dumps(row["queues"])} for row in rows] + with (args.output / "raw.csv").open("w") as out: + writer = csv.DictWriter(out, fieldnames=list(flat[0])) + writer.writeheader() + writer.writerows(flat) + assert sources == {name: digest(ROOT / name) for name in SOURCE_NAMES} + dump(args.output / "complete.json", {"samples": len(rows), "all_branch_outputs_match": True, + "finished_utc": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())}) + print(args.output.resolve()) + + +if __name__ == "__main__": + main() diff --git a/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/sources/vendor/yyjson/LICENSE b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/sources/vendor/yyjson/LICENSE new file mode 100644 index 0000000..a09bff3 --- /dev/null +++ b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/sources/vendor/yyjson/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 YaoYuan <[email protected]> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/sources/vendor/yyjson/UPSTREAM.json b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/sources/vendor/yyjson/UPSTREAM.json new file mode 100644 index 0000000..7de2396 --- /dev/null +++ b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/sources/vendor/yyjson/UPSTREAM.json @@ -0,0 +1,23 @@ +{ + "project": "yyjson", + "version": "0.12.0", + "commit": "8b4a38dc994a110abaec8a400615567bd996105f", + "license": "MIT", + "files": { + "yyjson.c": { + "url": "https://raw.githubusercontent.com/ibireme/yyjson/8b4a38dc994a110abaec8a400615567bd996105f/src/yyjson.c", + "sha256": "ac2e9bbb2e2d9149d90878d40506a1d624fa0b33c979a11b61075c54782c6d6a", + "bytes": 410813 + }, + "yyjson.h": { + "url": "https://raw.githubusercontent.com/ibireme/yyjson/8b4a38dc994a110abaec8a400615567bd996105f/src/yyjson.h", + "sha256": "175867c5493a5df648cec566717fa1c29aa2f6096f5f0cf1efad0b65e1f6d7b3", + "bytes": 322407 + }, + "LICENSE": { + "url": "https://raw.githubusercontent.com/ibireme/yyjson/8b4a38dc994a110abaec8a400615567bd996105f/LICENSE", + "sha256": "45e384d3d52c73cba3a64d6e6c25d47cd738cd8a55c30629e3201046eda62947", + "bytes": 1084 + } + } +} diff --git a/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/sources/vendor/yyjson/yyjson.c b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/sources/vendor/yyjson/yyjson.c new file mode 100644 index 0000000..c16d925 --- /dev/null +++ b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/sources/vendor/yyjson/yyjson.c @@ -0,0 +1,11065 @@ +/*============================================================================== + Copyright (c) 2020 YaoYuan <[email protected]> + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + *============================================================================*/ + +#include "yyjson.h" +#include <math.h> /* for `HUGE_VAL/INFINIY/NAN` macros, no libm required */ + + + +/*============================================================================== + * MARK: - Warning Suppress (Private) + *============================================================================*/ + +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wunused-function" +# pragma clang diagnostic ignored "-Wunused-parameter" +# pragma clang diagnostic ignored "-Wunused-label" +# pragma clang diagnostic ignored "-Wunused-macros" +# pragma clang diagnostic ignored "-Wunused-variable" +#elif defined(__GNUC__) +# pragma GCC diagnostic ignored "-Wunused-function" +# pragma GCC diagnostic ignored "-Wunused-parameter" +# pragma GCC diagnostic ignored "-Wunused-label" +# pragma GCC diagnostic ignored "-Wunused-macros" +# pragma GCC diagnostic ignored "-Wunused-variable" +#elif defined(_MSC_VER) +# pragma warning(disable:4100) /* unreferenced formal parameter */ +# pragma warning(disable:4101) /* unreferenced variable */ +# pragma warning(disable:4102) /* unreferenced label */ +# pragma warning(disable:4127) /* conditional expression is constant */ +# pragma warning(disable:4706) /* assignment within conditional expression */ +#endif + + + +/*============================================================================== + * MARK: - Version (Public) + *============================================================================*/ + +uint32_t yyjson_version(void) { + return YYJSON_VERSION_HEX; +} + + + +/*============================================================================== + * MARK: - Flags (Private) + *============================================================================*/ + +/* msvc intrinsic */ +#if YYJSON_MSC_VER >= 1400 +# include <intrin.h> +# if defined(_M_AMD64) || defined(_M_ARM64) +# define MSC_HAS_BIT_SCAN_64 1 +# pragma intrinsic(_BitScanForward64) +# pragma intrinsic(_BitScanReverse64) +# else +# define MSC_HAS_BIT_SCAN_64 0 +# endif +# if defined(_M_AMD64) || defined(_M_ARM64) || \ + defined(_M_IX86) || defined(_M_ARM) +# define MSC_HAS_BIT_SCAN 1 +# pragma intrinsic(_BitScanForward) +# pragma intrinsic(_BitScanReverse) +# else +# define MSC_HAS_BIT_SCAN 0 +# endif +# if defined(_M_AMD64) +# define MSC_HAS_UMUL128 1 +# pragma intrinsic(_umul128) +# else +# define MSC_HAS_UMUL128 0 +# endif +#else +# define MSC_HAS_BIT_SCAN_64 0 +# define MSC_HAS_BIT_SCAN 0 +# define MSC_HAS_UMUL128 0 +#endif + +/* gcc builtin */ +#if yyjson_has_builtin(__builtin_clzll) || yyjson_gcc_available(3, 4, 0) +# define GCC_HAS_CLZLL 1 +#else +# define GCC_HAS_CLZLL 0 +#endif + +#if yyjson_has_builtin(__builtin_ctzll) || yyjson_gcc_available(3, 4, 0) +# define GCC_HAS_CTZLL 1 +#else +# define GCC_HAS_CTZLL 0 +#endif + +/* int128 type */ +#if defined(__SIZEOF_INT128__) && (__SIZEOF_INT128__ == 16) && \ + (defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)) +# define YYJSON_HAS_INT128 1 +#else +# define YYJSON_HAS_INT128 0 +#endif + +/* IEEE 754 floating-point binary representation */ +#if defined(__STDC_IEC_559__) || defined(__STDC_IEC_60559_BFP__) +# define YYJSON_HAS_IEEE_754 1 +#elif FLT_RADIX == 2 && \ + FLT_MANT_DIG == 24 && FLT_DIG == 6 && \ + FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128 && \ + FLT_MIN_10_EXP == -37 && FLT_MAX_10_EXP == 38 && \ + DBL_MANT_DIG == 53 && DBL_DIG == 15 && \ + DBL_MIN_EXP == -1021 && DBL_MAX_EXP == 1024 && \ + DBL_MIN_10_EXP == -307 && DBL_MAX_10_EXP == 308 +# define YYJSON_HAS_IEEE_754 1 +#else +# define YYJSON_HAS_IEEE_754 0 +# undef YYJSON_DISABLE_FAST_FP_CONV +# define YYJSON_DISABLE_FAST_FP_CONV 1 +#endif + +/* + Correct rounding in double number computations. + + On the x86 architecture, some compilers may use x87 FPU instructions for + floating-point arithmetic. The x87 FPU loads all floating point number as + 80-bit double-extended precision internally, then rounds the result to original + precision, which may produce inaccurate results. For a more detailed + explanation, see the paper: https://arxiv.org/abs/cs/0701192 + + Here are some examples of double precision calculation error: + + 2877.0 / 1e6 == 0.002877, but x87 returns 0.0028770000000000002 + 43683.0 * 1e21 == 4.3683e25, but x87 returns 4.3683000000000004e25 + + Here are some examples of compiler flags to generate x87 instructions on x86: + + clang -m32 -mno-sse + gcc/icc -m32 -mfpmath=387 + msvc /arch:SSE or /arch:IA32 + + If we are sure that there's no similar error described above, we can define the + YYJSON_DOUBLE_MATH_CORRECT as 1 to enable the fast path calculation. This is + not an accurate detection, it's just try to avoid the error at compile-time. + An accurate detection can be done at run-time: + + bool is_double_math_correct(void) { + volatile double r = 43683.0; + r *= 1e21; + return r == 4.3683e25; + } + + See also: utils.h in https://github.com/google/double-conversion/ + */ +#if !defined(FLT_EVAL_METHOD) && defined(__FLT_EVAL_METHOD__) +# define FLT_EVAL_METHOD __FLT_EVAL_METHOD__ +#endif + +#if defined(FLT_EVAL_METHOD) && FLT_EVAL_METHOD != 0 && FLT_EVAL_METHOD != 1 +# define YYJSON_DOUBLE_MATH_CORRECT 0 +#elif defined(i386) || defined(__i386) || defined(__i386__) || \ + defined(_X86_) || defined(__X86__) || defined(_M_IX86) || \ + defined(__I86__) || defined(__IA32__) || defined(__THW_INTEL) +# if (defined(_MSC_VER) && defined(_M_IX86_FP) && _M_IX86_FP == 2) || \ + (defined(__SSE2_MATH__) && __SSE2_MATH__) +# define YYJSON_DOUBLE_MATH_CORRECT 1 +# else +# define YYJSON_DOUBLE_MATH_CORRECT 0 +# endif +#elif defined(__mc68000__) || defined(__pnacl__) || defined(__native_client__) +# define YYJSON_DOUBLE_MATH_CORRECT 0 +#else +# define YYJSON_DOUBLE_MATH_CORRECT 1 +#endif + +/* + Detect the endianness at compile-time. + YYJSON_ENDIAN == YYJSON_BIG_ENDIAN + YYJSON_ENDIAN == YYJSON_LITTLE_ENDIAN + */ +#define YYJSON_BIG_ENDIAN 4321 +#define YYJSON_LITTLE_ENDIAN 1234 + +#if yyjson_has_include(<sys/types.h>) +# include <sys/types.h> /* POSIX */ +#endif +#if yyjson_has_include(<endian.h>) +# include <endian.h> /* Linux */ +#elif yyjson_has_include(<sys/endian.h>) +# include <sys/endian.h> /* BSD, Android */ +#elif yyjson_has_include(<machine/endian.h>) +# include <machine/endian.h> /* BSD, Darwin */ +#endif + +#if defined(BYTE_ORDER) && BYTE_ORDER +# if defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN) +# define YYJSON_ENDIAN YYJSON_BIG_ENDIAN +# elif defined(LITTLE_ENDIAN) && (BYTE_ORDER == LITTLE_ENDIAN) +# define YYJSON_ENDIAN YYJSON_LITTLE_ENDIAN +# endif +#elif defined(__BYTE_ORDER) && __BYTE_ORDER +# if defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN) +# define YYJSON_ENDIAN YYJSON_BIG_ENDIAN +# elif defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN) +# define YYJSON_ENDIAN YYJSON_LITTLE_ENDIAN +# endif +#elif defined(__BYTE_ORDER__) && __BYTE_ORDER__ +# if defined(__ORDER_BIG_ENDIAN__) && \ + (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) +# define YYJSON_ENDIAN YYJSON_BIG_ENDIAN +# elif defined(__ORDER_LITTLE_ENDIAN__) && \ + (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) +# define YYJSON_ENDIAN YYJSON_LITTLE_ENDIAN +# endif +#elif (defined(__LITTLE_ENDIAN__) && __LITTLE_ENDIAN__ == 1) || \ + defined(__i386) || defined(__i386__) || \ + defined(_X86_) || defined(__X86__) || \ + defined(_M_IX86) || defined(__THW_INTEL__) || \ + defined(__x86_64) || defined(__x86_64__) || \ + defined(__amd64) || defined(__amd64__) || \ + defined(_M_AMD64) || defined(_M_X64) || \ + defined(_M_ARM) || defined(_M_ARM64) || \ + defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || \ + defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) || \ + defined(__EMSCRIPTEN__) || defined(__wasm__) || \ + defined(__loongarch__) +# define YYJSON_ENDIAN YYJSON_LITTLE_ENDIAN +#elif (defined(__BIG_ENDIAN__) && __BIG_ENDIAN__ == 1) || \ + defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \ + defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__) || \ + defined(__or1k__) || defined(__OR1K__) +# define YYJSON_ENDIAN YYJSON_BIG_ENDIAN +#else +# define YYJSON_ENDIAN 0 /* unknown endian, detect at run-time */ +#endif + +/* + This macro controls how yyjson handles unaligned memory accesses. + + By default, yyjson uses `memcpy()` for memory copying. This allows the compiler + to optimize the code and emit unaligned memory access instructions when + supported by the target architecture. + + However, on some older compilers or architectures where `memcpy()` is not + well-optimized and may result in unnecessary function calls, defining this + macro as 1 may help. In such cases, yyjson switches to manual byte-by-byte + access, which can potentially improve performance. + + An example of the generated assembly code for ARM can be found here: + https://godbolt.org/z/334jjhxPT + + This flag is already enabled for common architectures in the following code, + so manual configuration is usually unnecessary. If unsure, you can check the + generated assembly or run benchmarks to make an informed decision. + */ +#ifndef YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS +# if defined(__ia64) || defined(_IA64) || defined(__IA64__) || \ + defined(__ia64__) || defined(_M_IA64) || defined(__itanium__) +# define YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS 1 /* Itanium */ +# elif (defined(__arm__) || defined(__arm64__) || defined(__aarch64__)) && \ + (defined(__GNUC__) || defined(__clang__)) && \ + (!defined(__ARM_FEATURE_UNALIGNED) || !__ARM_FEATURE_UNALIGNED) +# define YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS 1 /* ARM */ +# elif defined(__sparc) || defined(__sparc__) +# define YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS 1 /* SPARC */ +# elif defined(__mips) || defined(__mips__) || defined(__MIPS__) +# define YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS 1 /* MIPS */ +# elif defined(__m68k__) || defined(M68000) +# define YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS 1 /* M68K */ +# else +# define YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS 0 +# endif +#endif + +/* + Estimated initial ratio of the JSON data (data_size / value_count). + For example: + + data: {"id":12345678,"name":"Harry"} + data_size: 30 + value_count: 5 + ratio: 6 + + yyjson uses dynamic memory with a growth factor of 1.5 when reading and writing + JSON, the ratios below are used to determine the initial memory size. + + A too large ratio will waste memory, and a too small ratio will cause multiple + memory growths and degrade performance. Currently, these ratios are generated + with some commonly used JSON datasets. + */ +#define YYJSON_READER_ESTIMATED_PRETTY_RATIO 16 +#define YYJSON_READER_ESTIMATED_MINIFY_RATIO 6 +#define YYJSON_WRITER_ESTIMATED_PRETTY_RATIO 32 +#define YYJSON_WRITER_ESTIMATED_MINIFY_RATIO 18 + +/* The initial and maximum size of the memory pool's chunk in yyjson_mut_doc. */ +#define YYJSON_MUT_DOC_STR_POOL_INIT_SIZE 0x100 +#define YYJSON_MUT_DOC_STR_POOL_MAX_SIZE 0x10000000 +#define YYJSON_MUT_DOC_VAL_POOL_INIT_SIZE (0x10 * sizeof(yyjson_mut_val)) +#define YYJSON_MUT_DOC_VAL_POOL_MAX_SIZE (0x1000000 * sizeof(yyjson_mut_val)) + +/* The minimum size of the dynamic allocator's chunk. */ +#define YYJSON_ALC_DYN_MIN_SIZE 0x1000 + +/* Default value for compile-time options. */ +#ifndef YYJSON_DISABLE_READER +#define YYJSON_DISABLE_READER 0 +#endif +#ifndef YYJSON_DISABLE_WRITER +#define YYJSON_DISABLE_WRITER 0 +#endif +#ifndef YYJSON_DISABLE_INCR_READER +#define YYJSON_DISABLE_INCR_READER 0 +#endif +#ifndef YYJSON_DISABLE_UTILS +#define YYJSON_DISABLE_UTILS 0 +#endif +#ifndef YYJSON_DISABLE_FAST_FP_CONV +#define YYJSON_DISABLE_FAST_FP_CONV 0 +#endif +#ifndef YYJSON_DISABLE_NON_STANDARD +#define YYJSON_DISABLE_NON_STANDARD 0 +#endif +#ifndef YYJSON_DISABLE_UTF8_VALIDATION +#define YYJSON_DISABLE_UTF8_VALIDATION 0 +#endif + + + +/*============================================================================== + * MARK: - Macros (Private) + *============================================================================*/ + +/* Macros used for loop unrolling and other purpose. */ +#define repeat2(x) { x x } +#define repeat4(x) { x x x x } +#define repeat8(x) { x x x x x x x x } +#define repeat16(x) { x x x x x x x x x x x x x x x x } + +#define repeat2_incr(x) { x(0) x(1) } +#define repeat4_incr(x) { x(0) x(1) x(2) x(3) } +#define repeat8_incr(x) { x(0) x(1) x(2) x(3) x(4) x(5) x(6) x(7) } +#define repeat16_incr(x) { x(0) x(1) x(2) x(3) x(4) x(5) x(6) x(7) \ + x(8) x(9) x(10) x(11) x(12) x(13) x(14) x(15) } +#define repeat_in_1_18(x) { x(1) x(2) x(3) x(4) x(5) x(6) x(7) x(8) \ + x(9) x(10) x(11) x(12) x(13) x(14) x(15) x(16) \ + x(17) x(18) } + +/* Macros used to provide branch prediction information for compiler. */ +#undef likely +#define likely(x) yyjson_likely(x) +#undef unlikely +#define unlikely(x) yyjson_unlikely(x) + +/* Macros used to provide inline information for compiler. */ +#undef static_inline +#define static_inline static yyjson_inline +#undef static_noinline +#define static_noinline static yyjson_noinline + +/* Macros for min and max. */ +#undef yyjson_min +#define yyjson_min(x, y) ((x) < (y) ? (x) : (y)) +#undef yyjson_max +#define yyjson_max(x, y) ((x) > (y) ? (x) : (y)) + +/* Used to write u64 literal for C89 which doesn't support "ULL" suffix. */ +#undef U64 +#define U64(hi, lo) ((((u64)hi##UL) << 32U) + lo##UL) +#undef U32 +#define U32(hi) ((u32)(hi##UL)) + +/* Used to cast away (remove) const qualifier. */ +#define constcast(type) (type)(void *)(size_t)(const void *) + +/* + Compiler barriers for single variables. + + These macros inform GCC that a read or write access to the given memory + location will occur, preventing certain compiler optimizations or reordering + around the access to 'val'. They do not emit any actual instructions. + + This is useful when GCC's default optimization strategies are suboptimal and + precise control over memory access patterns is required. + These barriers are not needed when using Clang or MSVC. + */ +#if YYJSON_IS_REAL_GCC +# define gcc_load_barrier(val) __asm__ volatile(""::"m"(val)) +# define gcc_store_barrier(val) __asm__ volatile("":"=m"(val)) +# define gcc_full_barrier(val) __asm__ volatile("":"=m"(val):"m"(val)) +#else +# define gcc_load_barrier(val) +# define gcc_store_barrier(val) +# define gcc_full_barrier(val) +#endif + + + +/*============================================================================== + * MARK: - Constants (Private) + *============================================================================*/ + +/* Common error messages. */ +#define MSG_FOPEN "failed to open file" +#define MSG_FREAD "failed to read file" +#define MSG_FWRITE "failed to write file" +#define MSG_FCLOSE "failed to close file" +#define MSG_MALLOC "failed to allocate memory" +#define MSG_CHAR_T "invalid literal, expected 'true'" +#define MSG_CHAR_F "invalid literal, expected 'false'" +#define MSG_CHAR_N "invalid literal, expected 'null'" +#define MSG_CHAR "unexpected character, expected a JSON value" +#define MSG_ARR_END "unexpected character, expected ',' or ']'" +#define MSG_OBJ_KEY "unexpected character, expected a string key" +#define MSG_OBJ_SEP "unexpected character, expected ':' after key" +#define MSG_OBJ_END "unexpected character, expected ',' or '}'" +#define MSG_GARBAGE "unexpected content after document" +#define MSG_NOT_END "unexpected end of data" +#define MSG_COMMENT "unclosed multiline comment" +#define MSG_COMMA "trailing comma is not allowed" +#define MSG_NAN_INF "nan or inf number is not allowed" +#define MSG_ERR_TYPE "invalid JSON value type" +#define MSG_ERR_BOM "UTF-8 byte order mark (BOM) is not supported" +#define MSG_ERR_UTF8 "invalid utf-8 encoding in string" +#define MSG_ERR_UTF16 "UTF-16 encoding is not supported" +#define MSG_ERR_UTF32 "UTF-32 encoding is not supported" + +/* U64 constant values */ +#undef U64_MAX +#define U64_MAX U64(0xFFFFFFFF, 0xFFFFFFFF) +#undef I64_MAX +#define I64_MAX U64(0x7FFFFFFF, 0xFFFFFFFF) +#undef USIZE_MAX +#define USIZE_MAX ((usize)(~(usize)0)) + +/* Maximum number of digits for reading u32/u64/usize safety (not overflow). */ +#undef U32_SAFE_DIG +#define U32_SAFE_DIG 9 /* u32 max is 4294967295, 10 digits */ +#undef U64_SAFE_DIG +#define U64_SAFE_DIG 19 /* u64 max is 18446744073709551615, 20 digits */ +#undef USIZE_SAFE_DIG +#define USIZE_SAFE_DIG (sizeof(usize) == 8 ? U64_SAFE_DIG : U32_SAFE_DIG) + +/* Inf bits (positive) */ +#define F64_BITS_INF U64(0x7FF00000, 0x00000000) + +/* NaN bits (quiet NaN, no payload, no sign) */ +#if defined(__hppa__) || (defined(__mips__) && !defined(__mips_nan2008)) +#define F64_BITS_NAN U64(0x7FF7FFFF, 0xFFFFFFFF) +#else +#define F64_BITS_NAN U64(0x7FF80000, 0x00000000) +#endif + +/* maximum significant digits count in decimal when reading double number */ +#define F64_MAX_DEC_DIG 768 + +/* maximum decimal power of double number (1.7976931348623157e308) */ +#define F64_MAX_DEC_EXP 308 + +/* minimum decimal power of double number (4.9406564584124654e-324) */ +#define F64_MIN_DEC_EXP (-324) + +/* maximum binary power of double number */ +#define F64_MAX_BIN_EXP 1024 + +/* minimum binary power of double number */ +#define F64_MIN_BIN_EXP (-1021) + +/* float/double number bits */ +#define F32_BITS 32 +#define F64_BITS 64 + +/* float/double number exponent part bits */ +#define F32_EXP_BITS 8 +#define F64_EXP_BITS 11 + +/* float/double number significand part bits */ +#define F32_SIG_BITS 23 +#define F64_SIG_BITS 52 + +/* float/double number significand part bits (with 1 hidden bit) */ +#define F32_SIG_FULL_BITS 24 +#define F64_SIG_FULL_BITS 53 + +/* float/double number significand bit mask */ +#define F32_SIG_MASK U32(0x007FFFFF) +#define F64_SIG_MASK U64(0x000FFFFF, 0xFFFFFFFF) + +/* float/double number exponent bit mask */ +#define F32_EXP_MASK U32(0x7F800000) +#define F64_EXP_MASK U64(0x7FF00000, 0x00000000) + +/* float/double number exponent bias */ +#define F32_EXP_BIAS 127 +#define F64_EXP_BIAS 1023 + +/* float/double number significant digits count in decimal */ +#define F32_DEC_DIG 9 +#define F64_DEC_DIG 17 + +/* buffer length required for float/double number writer */ +#define FP_BUF_LEN 40 + +/* maximum length of a number in incremental parsing */ +#define INCR_NUM_MAX_LEN 1024 + + + +/*============================================================================== + * MARK: - Types (Private) + *============================================================================*/ + +/** Type define for primitive types. */ +typedef float f32; +typedef double f64; +typedef int8_t i8; +typedef uint8_t u8; +typedef int16_t i16; +typedef uint16_t u16; +typedef int32_t i32; +typedef uint32_t u32; +typedef int64_t i64; +typedef uint64_t u64; +typedef size_t usize; + +/** 128-bit integer, used by floating-point number reader and writer. */ +#if YYJSON_HAS_INT128 +__extension__ typedef __int128 i128; +__extension__ typedef unsigned __int128 u128; +#endif + +/** 16/32/64-bit vector */ +typedef struct v16 { char c[2]; } v16; +typedef struct v32 { char c[4]; } v32; +typedef struct v64 { char c[8]; } v64; + +/** 16/32/64-bit vector union */ +typedef union v16_uni { v16 v; u16 u; } v16_uni; +typedef union v32_uni { v32 v; u32 u; } v32_uni; +typedef union v64_uni { v64 v; u64 u; } v64_uni; + + + +/*============================================================================== + * MARK: - Load/Store Utils (Private) + *============================================================================*/ + +#define byte_move_idx(x) ((char *)dst)[x] = ((const char *)src)[x]; +#define byte_move_src(x) ((char *)tmp)[x] = ((const char *)src)[x]; +#define byte_move_dst(x) ((char *)dst)[x] = ((const char *)tmp)[x]; + +/** Same as `memcpy(dst, src, 2)`, no overlap. */ +static_inline void byte_copy_2(void *dst, const void *src) { +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + memcpy(dst, src, 2); +#else + repeat2_incr(byte_move_idx) +#endif +} + +/** Same as `memcpy(dst, src, 4)`, no overlap. */ +static_inline void byte_copy_4(void *dst, const void *src) { +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + memcpy(dst, src, 4); +#else + repeat4_incr(byte_move_idx) +#endif +} + +/** Same as `memcpy(dst, src, 8)`, no overlap. */ +static_inline void byte_copy_8(void *dst, const void *src) { +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + memcpy(dst, src, 8); +#else + repeat8_incr(byte_move_idx) +#endif +} + +/** Same as `memcpy(dst, src, 16)`, no overlap. */ +static_inline void byte_copy_16(void *dst, const void *src) { +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + memcpy(dst, src, 16); +#else + repeat16_incr(byte_move_idx) +#endif +} + +/** Same as `memmove(dst, src, 2)`, allows overlap. */ +static_inline void byte_move_2(void *dst, const void *src) { +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + u16 tmp; + memcpy(&tmp, src, 2); + memcpy(dst, &tmp, 2); +#else + char tmp[2]; + repeat2_incr(byte_move_src) + repeat2_incr(byte_move_dst) +#endif +} + +/** Same as `memmove(dst, src, 4)`, allows overlap. */ +static_inline void byte_move_4(void *dst, const void *src) { +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + u32 tmp; + memcpy(&tmp, src, 4); + memcpy(dst, &tmp, 4); +#else + char tmp[4]; + repeat4_incr(byte_move_src) + repeat4_incr(byte_move_dst) +#endif +} + +/** Same as `memmove(dst, src, 8)`, allows overlap. */ +static_inline void byte_move_8(void *dst, const void *src) { +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + u64 tmp; + memcpy(&tmp, src, 8); + memcpy(dst, &tmp, 8); +#else + char tmp[8]; + repeat8_incr(byte_move_src) + repeat8_incr(byte_move_dst) +#endif +} + +/** Same as `memmove(dst, src, 16)`, allows overlap. */ +static_inline void byte_move_16(void *dst, const void *src) { +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + char *pdst = (char *)dst; + const char *psrc = (const char *)src; + u64 tmp1, tmp2; + memcpy(&tmp1, psrc, 8); + memcpy(&tmp2, psrc + 8, 8); + memcpy(pdst, &tmp1, 8); + memcpy(pdst + 8, &tmp2, 8); +#else + char tmp[16]; + repeat16_incr(byte_move_src) + repeat16_incr(byte_move_dst) +#endif +} + +/** Same as `memmove(dst, src, n)`, but only `dst <= src` and `n <= 16`. */ +static_inline void byte_move_forward(void *dst, void *src, usize n) { + char *d = (char *)dst, *s = (char *)src; + n += (n % 2); /* round up to even */ + if (n == 16) { byte_move_16(d, s); return; } + if (n >= 8) { byte_move_8(d, s); n -= 8; d += 8; s += 8; } + if (n >= 4) { byte_move_4(d, s); n -= 4; d += 4; s += 4; } + if (n >= 2) { byte_move_2(d, s); } +} + +/** Same as `memcmp(buf, pat, 2) == 0`. */ +static_inline bool byte_match_2(void *buf, const char *pat) { +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + v16_uni u1, u2; + memcpy(&u1, buf, 2); + memcpy(&u2, pat, 2); + return u1.u == u2.u; +#else + return ((char *)buf)[0] == ((const char *)pat)[0] && + ((char *)buf)[1] == ((const char *)pat)[1]; +#endif +} + +/** Same as `memcmp(buf, pat, 4) == 0`. */ +static_inline bool byte_match_4(void *buf, const char *pat) { +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + v32_uni u1, u2; + memcpy(&u1, buf, 4); + memcpy(&u2, pat, 4); + return u1.u == u2.u; +#else + return ((char *)buf)[0] == ((const char *)pat)[0] && + ((char *)buf)[1] == ((const char *)pat)[1] && + ((char *)buf)[2] == ((const char *)pat)[2] && + ((char *)buf)[3] == ((const char *)pat)[3]; +#endif +} + +/** Loads 2 bytes from `src` as a u16 (native-endian). */ +static_inline u16 byte_load_2(const void *src) { + v16_uni uni; +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + memcpy(&uni, src, 2); +#else + uni.v.c[0] = ((const char *)src)[0]; + uni.v.c[1] = ((const char *)src)[1]; +#endif + return uni.u; +} + +/** Loads 3 bytes from `src` as a u32 (native-endian). */ +static_inline u32 byte_load_3(const void *src) { + v32_uni uni; +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + memcpy(&uni, src, 2); + uni.v.c[2] = ((const char *)src)[2]; + uni.v.c[3] = 0; +#else + uni.v.c[0] = ((const char *)src)[0]; + uni.v.c[1] = ((const char *)src)[1]; + uni.v.c[2] = ((const char *)src)[2]; + uni.v.c[3] = 0; +#endif + return uni.u; +} + +/** Loads 4 bytes from `src` as a u32 (native-endian). */ +static_inline u32 byte_load_4(const void *src) { + v32_uni uni; +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + memcpy(&uni, src, 4); +#else + uni.v.c[0] = ((const char *)src)[0]; + uni.v.c[1] = ((const char *)src)[1]; + uni.v.c[2] = ((const char *)src)[2]; + uni.v.c[3] = ((const char *)src)[3]; +#endif + return uni.u; +} + + + +/*============================================================================== + * MARK: - Character Utils (Private) + * These lookup tables were generated by `misc/make_tables.c`. + *============================================================================*/ + +/* char_table1 */ +#define CHAR_TYPE_ASCII (1 << 0) /* Except: ["\], [0x00-0x1F, 0x80-0xFF] */ +#define CHAR_TYPE_ASCII_SQ (1 << 1) /* Except: ['\], [0x00-0x1F, 0x80-0xFF] */ +#define CHAR_TYPE_SPACE (1 << 2) /* Whitespace: [ \t\n\r] */ +#define CHAR_TYPE_SPACE_EXT (1 << 3) /* Whitespace: [ \t\n\r\v\f], JSON5 */ +#define CHAR_TYPE_NUM (1 << 4) /* Number: [.-+0-9] */ +#define CHAR_TYPE_COMMENT (1 << 5) /* Comment: [/] */ + +/* char_table2 */ +#define CHAR_TYPE_EOL (1 << 0) /* End of line: [\r\n] */ +#define CHAR_TYPE_EOL_EXT (1 << 1) /* End of line: [\r\n], JSON5 */ +#define CHAR_TYPE_ID_START (1 << 2) /* ID start: [_$A-Za-z\], U+0080+ */ +#define CHAR_TYPE_ID_NEXT (1 << 3) /* ID next: [_$A-Za-z0-9\], U+0080+ */ +#define CHAR_TYPE_ID_ASCII (1 << 4) /* ID next ASCII: [_$A-Za-z0-9] */ + +/* char_table3 */ +#define CHAR_TYPE_SIGN (1 << 0) /* [-+] */ +#define CHAR_TYPE_DIGIT (1 << 1) /* [0-9] */ +#define CHAR_TYPE_NONZERO (1 << 2) /* [1-9] */ +#define CHAR_TYPE_EXP (1 << 3) /* [eE] */ +#define CHAR_TYPE_DOT (1 << 4) /* [.] */ + +static const u8 char_table1[256] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x0C, 0x0C, 0x08, 0x08, 0x0C, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0F, 0x03, 0x02, 0x03, 0x03, 0x03, 0x03, 0x01, + 0x03, 0x03, 0x03, 0x13, 0x03, 0x13, 0x13, 0x23, + 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, + 0x13, 0x13, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x00, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static const u8 char_table2[256] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, + 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, + 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, + 0x1C, 0x1C, 0x1C, 0x00, 0x0C, 0x00, 0x00, 0x1C, + 0x00, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, + 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, + 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, + 0x1C, 0x1C, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C +}; + +static const u8 char_table3[256] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x10, 0x00, + 0x02, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, + 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +/** Match a whitespace: [ \t\n\r]. */ +static_inline bool char_is_space(u8 c) { + return !!(char_table1[c] & CHAR_TYPE_SPACE); +} + +/** Match an extended whitespace: [ \t\n\r\\v\\f], JSON5 whitespace. */ +static_inline bool char_is_space_ext(u8 c) { + return !!(char_table1[c] & CHAR_TYPE_SPACE_EXT); +} + +/** Match a JSON number: [.-+0-9]. */ +static_inline bool char_is_num(u8 c) { + return !!(char_table1[c] & CHAR_TYPE_NUM); +} + +/** Match an ASCII character in string: ["\], [0x00-0x1F, 0x80-0xFF]. */ +static_inline bool char_is_ascii_skip(u8 c) { + return !!(char_table1[c] & CHAR_TYPE_ASCII); +} + +/** Match an ASCII character single-quoted: ['\], [0x00-0x1F, 0x80-0xFF]. */ +static_inline bool char_is_ascii_skip_sq(u8 c) { + return !!(char_table1[c] & CHAR_TYPE_ASCII_SQ); +} + +/** Match a trivia character: extended whitespace or comment. */ +static_inline bool char_is_trivia(u8 c) { + return !!(char_table1[c] & (CHAR_TYPE_SPACE_EXT | CHAR_TYPE_COMMENT)); +} + +/** Match a line end character: [\r\n]. */ +static_inline bool char_is_eol(u8 c) { + return !!(char_table2[c] & CHAR_TYPE_EOL); +} + +/** Match an extended line end character: [\r\n], JSON5 line terminator. */ +static_inline bool char_is_eol_ext(u8 c) { + return !!(char_table2[c] & CHAR_TYPE_EOL_EXT); +} + +/** Match an identifier name start: [_$A-Za-z\], U+0080+. */ +static_inline bool char_is_id_start(u8 c) { + return !!(char_table2[c] & CHAR_TYPE_ID_START); +} + +/** Match an identifier name next: [_$A-Za-z0-9\], U+0080+. */ +static_inline bool char_is_id_next(u8 c) { + return !!(char_table2[c] & CHAR_TYPE_ID_NEXT); +} + +/** Match an identifier name ASCII: [_$A-Za-z0-9]. */ +static_inline bool char_is_id_ascii(u8 c) { + return !!(char_table2[c] & CHAR_TYPE_ID_ASCII); +} + +/** Match a sign: [+-] */ +static_inline bool char_is_sign(u8 d) { + return !!(char_table3[d] & CHAR_TYPE_SIGN); +} + +/** Match a none-zero digit: [1-9] */ +static_inline bool char_is_nonzero(u8 d) { + return !!(char_table3[d] & CHAR_TYPE_NONZERO); +} + +/** Match a digit: [0-9] */ +static_inline bool char_is_digit(u8 d) { + return !!(char_table3[d] & CHAR_TYPE_DIGIT); +} + +/** Match an exponent sign: [eE]. */ +static_inline bool char_is_exp(u8 d) { + return !!(char_table3[d] & CHAR_TYPE_EXP); +} + +/** Match a floating point indicator: [.eE]. */ +static_inline bool char_is_fp(u8 d) { + return !!(char_table3[d] & (CHAR_TYPE_DOT | CHAR_TYPE_EXP)); +} + +/** Match a digit or floating point indicator: [0-9.eE]. */ +static_inline bool char_is_digit_or_fp(u8 d) { + return !!(char_table3[d] & (CHAR_TYPE_DIGIT | CHAR_TYPE_DOT | + CHAR_TYPE_EXP)); +} + +/** Match a JSON container: `{` or `[`. */ +static_inline bool char_is_ctn(u8 c) { + return (c & 0xDF) == 0x5B; /* '[': 0x5B, '{': 0x7B */ +} + +/** Convert ASCII letter to lowercase; valid only for [A-Za-z]. */ +static_inline u8 char_to_lower(u8 c) { + return c | 0x20; +} + +/** Match UTF-8 byte order mask. */ +static_inline bool is_utf8_bom(const u8 *cur) { + return byte_load_3(cur) == byte_load_3("\xEF\xBB\xBF"); +} + +/** Match UTF-16 byte order mask. */ +static_inline bool is_utf16_bom(const u8 *cur) { + return byte_load_2(cur) == byte_load_2("\xFE\xFF") || + byte_load_2(cur) == byte_load_2("\xFF\xFE"); +} + +/** Match UTF-32 byte order mask, need length check to avoid zero padding. */ +static_inline bool is_utf32_bom(const u8 *cur) { + return byte_load_4(cur) == byte_load_4("\x00\x00\xFE\xFF") || + byte_load_4(cur) == byte_load_4("\xFF\xFE\x00\x00"); +} + +/** Get the extended line end length. Used with `char_is_eol_ext`. */ +static_inline usize ext_eol_len(const u8 *cur) { + if (cur[0] < 0x80) return 1; + if (cur[1] == 0x80 && (cur[2] == 0xA8 || cur[2] == 0xA9)) return 3; + return 0; +} + +/** Get the extended whitespace length. Used with `char_is_space_ext`. */ +static_inline usize ext_space_len(const u8 *cur) { + if (cur[0] < 0x80) { + return 1; + } else if (byte_load_2(cur) == byte_load_2("\xC2\xA0")) { + return 2; + } else if (byte_load_2(cur) == byte_load_2("\xE2\x80")) { + if (cur[2] >= 0x80 && cur[2] <= 0x8A) return 3; + if (cur[2] == 0xA8 || cur[2] == 0xA9 || cur[2] == 0xAF) return 3; + } else { + u32 uni = byte_load_3(cur); + if (uni == byte_load_3("\xE1\x9A\x80") || + uni == byte_load_3("\xE2\x81\x9F") || + uni == byte_load_3("\xE3\x80\x80") || + uni == byte_load_3("\xEF\xBB\xBF")) return 3; + } + return 0; +} + + + +/*============================================================================== + * MARK: - Hex Character Reader (Private) + * This function is used by JSON reader to read escaped characters. + *============================================================================*/ + +/** + This table is used to convert 4 hex character sequence to a number. + A valid hex character [0-9A-Fa-f] will mapped to it's raw number [0x00, 0x0F], + an invalid hex character will mapped to [0xF0]. + (generate with misc/make_tables.c) + */ +static const u8 hex_conv_table[256] = { + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0 +}; + +/** Load 4 hex characters to `u16`, return true on valid input. */ +static_inline bool hex_load_4(const u8 *src, u16 *dst) { + u16 c0 = hex_conv_table[src[0]]; + u16 c1 = hex_conv_table[src[1]]; + u16 c2 = hex_conv_table[src[2]]; + u16 c3 = hex_conv_table[src[3]]; + u16 t0 = (u16)((c0 << 8) | c2); + u16 t1 = (u16)((c1 << 8) | c3); + *dst = (u16)((t0 << 4) | t1); + return ((t0 | t1) & (u16)0xF0F0) == 0; +} + +/** Load 2 hex characters to `u8`, return true on valid input. */ +static_inline bool hex_load_2(const u8 *src, u8 *dst) { + u8 c0 = hex_conv_table[src[0]]; + u8 c1 = hex_conv_table[src[1]]; + *dst = (u8)((c0 << 4) | c1); + return ((c0 | c1) & 0xF0) == 0; +} + +/** Match a hexadecimal numeric character: [0-9a-fA-F]. */ +static_inline bool char_is_hex(u8 c) { + return hex_conv_table[c] != 0xF0; +} + + + +/*============================================================================== + * MARK: - UTF8 Validation (Private) + * Each Unicode code point is encoded using 1 to 4 bytes in UTF-8. + * Validation is performed using a 4-byte mask and pattern-based approach, + * which requires the input data to be padded with four zero bytes at the end. + *============================================================================*/ + +/* Macro for concatenating four u8 into a u32 and keeping the byte order. */ +#if YYJSON_ENDIAN == YYJSON_LITTLE_ENDIAN +# define utf8_seq_def(name, a, b, c, d) \ + static const u32 utf8_seq_##name = 0x##d##c##b##a##UL; +# define utf8_seq(name) utf8_seq_##name +#elif YYJSON_ENDIAN == YYJSON_BIG_ENDIAN +# define utf8_seq_def(name, a, b, c, d) \ + static const u32 utf8_seq_##name = 0x##a##b##c##d##UL; +# define utf8_seq(name) utf8_seq_##name +#else +# define utf8_seq_def(name, a, b, c, d) \ + static const v32_uni utf8_uni_##name = {{ 0x##a, 0x##b, 0x##c, 0x##d }}; +# define utf8_seq(name) utf8_uni_##name.u +#endif + +/* + 1-byte sequence (U+0000 to U+007F) + bit min [.......0] (U+0000) + bit max [.1111111] (U+007F) + bit mask [x.......] (80) + bit pattern [0.......] (00) + */ +utf8_seq_def(b1_mask, 80, 00, 00, 00) +utf8_seq_def(b1_patt, 00, 00, 00, 00) +#define is_utf8_seq1(uni) ( \ + ((uni & utf8_seq(b1_mask)) == utf8_seq(b1_patt)) ) + +/* + 2-byte sequence (U+0080 to U+07FF) + bit min [......10 ..000000] (U+0080) + bit max [...11111 ..111111] (U+07FF) + bit mask [xxx..... xx......] (E0 C0) + bit pattern [110..... 10......] (C0 80) + bit require [...xxxx. ........] (1E 00) + */ +utf8_seq_def(b2_mask, E0, C0, 00, 00) +utf8_seq_def(b2_patt, C0, 80, 00, 00) +utf8_seq_def(b2_requ, 1E, 00, 00, 00) +#define is_utf8_seq2(uni) ( \ + ((uni & utf8_seq(b2_mask)) == utf8_seq(b2_patt)) && \ + ((uni & utf8_seq(b2_requ))) ) + +/* + 3-byte sequence (U+0800 to U+FFFF) + bit min [........ ..100000 ..000000] (U+0800) + bit max [....1111 ..111111 ..111111] (U+FFFF) + bit mask [xxxx.... xx...... xx......] (F0 C0 C0) + bit pattern [1110.... 10...... 10......] (E0 80 80) + bit require [....xxxx ..x..... ........] (0F 20 00) + + 3-byte invalid sequence, reserved for surrogate halves (U+D800 to U+DFFF) + bit min [....1101 ..100000 ..000000] (U+D800) + bit max [....1101 ..111111 ..111111] (U+DFFF) + bit mask [....xxxx ..x..... ........] (0F 20 00) + bit pattern [....1101 ..1..... ........] (0D 20 00) + */ +utf8_seq_def(b3_mask, F0, C0, C0, 00) +utf8_seq_def(b3_patt, E0, 80, 80, 00) +utf8_seq_def(b3_requ, 0F, 20, 00, 00) +utf8_seq_def(b3_erro, 0D, 20, 00, 00) +#define is_utf8_seq3(uni) ( \ + ((uni & utf8_seq(b3_mask)) == utf8_seq(b3_patt)) && \ + ((tmp = (uni & utf8_seq(b3_requ)))) && \ + ((tmp != utf8_seq(b3_erro))) ) + +/* + 4-byte sequence (U+10000 to U+10FFFF) + bit min [........ ...10000 ..000000 ..000000] (U+10000) + bit max [.....100 ..001111 ..111111 ..111111] (U+10FFFF) + bit mask [xxxxx... xx...... xx...... xx......] (F8 C0 C0 C0) + bit pattern [11110... 10...... 10...... 10......] (F0 80 80 80) + bit require [.....xxx ..xx.... ........ ........] (07 30 00 00) + bit require 1 [.....x.. ........ ........ ........] (04 00 00 00) + bit require 2 [......xx ..xx.... ........ ........] (03 30 00 00) + */ +utf8_seq_def(b4_mask, F8, C0, C0, C0) +utf8_seq_def(b4_patt, F0, 80, 80, 80) +utf8_seq_def(b4_requ, 07, 30, 00, 00) +utf8_seq_def(b4_req1, 04, 00, 00, 00) +utf8_seq_def(b4_req2, 03, 30, 00, 00) +#define is_utf8_seq4(uni) ( \ + ((uni & utf8_seq(b4_mask)) == utf8_seq(b4_patt)) && \ + ((tmp = (uni & utf8_seq(b4_requ)))) && \ + ((tmp & utf8_seq(b4_req1)) == 0 || (tmp & utf8_seq(b4_req2)) == 0) ) + + + +/*============================================================================== + * MARK: - Power10 Lookup Table (Private) + * These data are used by the floating-point number reader and writer. + *============================================================================*/ + +#if !YYJSON_DISABLE_FAST_FP_CONV + +/** Maximum pow10 exponent that can be represented exactly as a float64. */ +#define F64_POW10_MAX_EXACT_EXP 22 + +/** Cached pow10 table. */ +static const f64 f64_pow10_table[F64_POW10_MAX_EXACT_EXP + 1] = { + 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, + 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22 +}; + +/** Maximum pow10 exponent that can be represented exactly as a uint64. */ +#define U64_POW10_MAX_EXACT_EXP 19 + +/** Table: [ 10^0, ..., 10^19 ] (generate with misc/make_tables.c) */ +static const u64 u64_pow10_table[U64_POW10_MAX_EXACT_EXP + 1] = { + U64(0x00000000, 0x00000001), U64(0x00000000, 0x0000000A), + U64(0x00000000, 0x00000064), U64(0x00000000, 0x000003E8), + U64(0x00000000, 0x00002710), U64(0x00000000, 0x000186A0), + U64(0x00000000, 0x000F4240), U64(0x00000000, 0x00989680), + U64(0x00000000, 0x05F5E100), U64(0x00000000, 0x3B9ACA00), + U64(0x00000002, 0x540BE400), U64(0x00000017, 0x4876E800), + U64(0x000000E8, 0xD4A51000), U64(0x00000918, 0x4E72A000), + U64(0x00005AF3, 0x107A4000), U64(0x00038D7E, 0xA4C68000), + U64(0x002386F2, 0x6FC10000), U64(0x01634578, 0x5D8A0000), + U64(0x0DE0B6B3, 0xA7640000), U64(0x8AC72304, 0x89E80000) +}; + +/** Minimum decimal exponent in pow10_sig_table. */ +#define POW10_SIG_TABLE_MIN_EXP -343 + +/** Maximum decimal exponent in pow10_sig_table. */ +#define POW10_SIG_TABLE_MAX_EXP 324 + +/** Minimum exact decimal exponent in pow10_sig_table */ +#define POW10_SIG_TABLE_MIN_EXACT_EXP 0 + +/** Maximum exact decimal exponent in pow10_sig_table */ +#define POW10_SIG_TABLE_MAX_EXACT_EXP 55 + +/** Normalized significant 128 bits of pow10, no rounded up (size: 10.4KB). + This lookup table is used by both the double number reader and writer. + (generate with misc/make_tables.c) */ +static const u64 pow10_sig_table[] = { + U64(0xBF29DCAB, 0xA82FDEAE), U64(0x7432EE87, 0x3880FC33), /* ~= 10^-343 */ + U64(0xEEF453D6, 0x923BD65A), U64(0x113FAA29, 0x06A13B3F), /* ~= 10^-342 */ + U64(0x9558B466, 0x1B6565F8), U64(0x4AC7CA59, 0xA424C507), /* ~= 10^-341 */ + U64(0xBAAEE17F, 0xA23EBF76), U64(0x5D79BCF0, 0x0D2DF649), /* ~= 10^-340 */ + U64(0xE95A99DF, 0x8ACE6F53), U64(0xF4D82C2C, 0x107973DC), /* ~= 10^-339 */ + U64(0x91D8A02B, 0xB6C10594), U64(0x79071B9B, 0x8A4BE869), /* ~= 10^-338 */ + U64(0xB64EC836, 0xA47146F9), U64(0x9748E282, 0x6CDEE284), /* ~= 10^-337 */ + U64(0xE3E27A44, 0x4D8D98B7), U64(0xFD1B1B23, 0x08169B25), /* ~= 10^-336 */ + U64(0x8E6D8C6A, 0xB0787F72), U64(0xFE30F0F5, 0xE50E20F7), /* ~= 10^-335 */ + U64(0xB208EF85, 0x5C969F4F), U64(0xBDBD2D33, 0x5E51A935), /* ~= 10^-334 */ + U64(0xDE8B2B66, 0xB3BC4723), U64(0xAD2C7880, 0x35E61382), /* ~= 10^-333 */ + U64(0x8B16FB20, 0x3055AC76), U64(0x4C3BCB50, 0x21AFCC31), /* ~= 10^-332 */ + U64(0xADDCB9E8, 0x3C6B1793), U64(0xDF4ABE24, 0x2A1BBF3D), /* ~= 10^-331 */ + U64(0xD953E862, 0x4B85DD78), U64(0xD71D6DAD, 0x34A2AF0D), /* ~= 10^-330 */ + U64(0x87D4713D, 0x6F33AA6B), U64(0x8672648C, 0x40E5AD68), /* ~= 10^-329 */ + U64(0xA9C98D8C, 0xCB009506), U64(0x680EFDAF, 0x511F18C2), /* ~= 10^-328 */ + U64(0xD43BF0EF, 0xFDC0BA48), U64(0x0212BD1B, 0x2566DEF2), /* ~= 10^-327 */ + U64(0x84A57695, 0xFE98746D), U64(0x014BB630, 0xF7604B57), /* ~= 10^-326 */ + U64(0xA5CED43B, 0x7E3E9188), U64(0x419EA3BD, 0x35385E2D), /* ~= 10^-325 */ + U64(0xCF42894A, 0x5DCE35EA), U64(0x52064CAC, 0x828675B9), /* ~= 10^-324 */ + U64(0x818995CE, 0x7AA0E1B2), U64(0x7343EFEB, 0xD1940993), /* ~= 10^-323 */ + U64(0xA1EBFB42, 0x19491A1F), U64(0x1014EBE6, 0xC5F90BF8), /* ~= 10^-322 */ + U64(0xCA66FA12, 0x9F9B60A6), U64(0xD41A26E0, 0x77774EF6), /* ~= 10^-321 */ + U64(0xFD00B897, 0x478238D0), U64(0x8920B098, 0x955522B4), /* ~= 10^-320 */ + U64(0x9E20735E, 0x8CB16382), U64(0x55B46E5F, 0x5D5535B0), /* ~= 10^-319 */ + U64(0xC5A89036, 0x2FDDBC62), U64(0xEB2189F7, 0x34AA831D), /* ~= 10^-318 */ + U64(0xF712B443, 0xBBD52B7B), U64(0xA5E9EC75, 0x01D523E4), /* ~= 10^-317 */ + U64(0x9A6BB0AA, 0x55653B2D), U64(0x47B233C9, 0x2125366E), /* ~= 10^-316 */ + U64(0xC1069CD4, 0xEABE89F8), U64(0x999EC0BB, 0x696E840A), /* ~= 10^-315 */ + U64(0xF148440A, 0x256E2C76), U64(0xC00670EA, 0x43CA250D), /* ~= 10^-314 */ + U64(0x96CD2A86, 0x5764DBCA), U64(0x38040692, 0x6A5E5728), /* ~= 10^-313 */ + U64(0xBC807527, 0xED3E12BC), U64(0xC6050837, 0x04F5ECF2), /* ~= 10^-312 */ + U64(0xEBA09271, 0xE88D976B), U64(0xF7864A44, 0xC633682E), /* ~= 10^-311 */ + U64(0x93445B87, 0x31587EA3), U64(0x7AB3EE6A, 0xFBE0211D), /* ~= 10^-310 */ + U64(0xB8157268, 0xFDAE9E4C), U64(0x5960EA05, 0xBAD82964), /* ~= 10^-309 */ + U64(0xE61ACF03, 0x3D1A45DF), U64(0x6FB92487, 0x298E33BD), /* ~= 10^-308 */ + U64(0x8FD0C162, 0x06306BAB), U64(0xA5D3B6D4, 0x79F8E056), /* ~= 10^-307 */ + U64(0xB3C4F1BA, 0x87BC8696), U64(0x8F48A489, 0x9877186C), /* ~= 10^-306 */ + U64(0xE0B62E29, 0x29ABA83C), U64(0x331ACDAB, 0xFE94DE87), /* ~= 10^-305 */ + U64(0x8C71DCD9, 0xBA0B4925), U64(0x9FF0C08B, 0x7F1D0B14), /* ~= 10^-304 */ + U64(0xAF8E5410, 0x288E1B6F), U64(0x07ECF0AE, 0x5EE44DD9), /* ~= 10^-303 */ + U64(0xDB71E914, 0x32B1A24A), U64(0xC9E82CD9, 0xF69D6150), /* ~= 10^-302 */ + U64(0x892731AC, 0x9FAF056E), U64(0xBE311C08, 0x3A225CD2), /* ~= 10^-301 */ + U64(0xAB70FE17, 0xC79AC6CA), U64(0x6DBD630A, 0x48AAF406), /* ~= 10^-300 */ + U64(0xD64D3D9D, 0xB981787D), U64(0x092CBBCC, 0xDAD5B108), /* ~= 10^-299 */ + U64(0x85F04682, 0x93F0EB4E), U64(0x25BBF560, 0x08C58EA5), /* ~= 10^-298 */ + U64(0xA76C5823, 0x38ED2621), U64(0xAF2AF2B8, 0x0AF6F24E), /* ~= 10^-297 */ + U64(0xD1476E2C, 0x07286FAA), U64(0x1AF5AF66, 0x0DB4AEE1), /* ~= 10^-296 */ + U64(0x82CCA4DB, 0x847945CA), U64(0x50D98D9F, 0xC890ED4D), /* ~= 10^-295 */ + U64(0xA37FCE12, 0x6597973C), U64(0xE50FF107, 0xBAB528A0), /* ~= 10^-294 */ + U64(0xCC5FC196, 0xFEFD7D0C), U64(0x1E53ED49, 0xA96272C8), /* ~= 10^-293 */ + U64(0xFF77B1FC, 0xBEBCDC4F), U64(0x25E8E89C, 0x13BB0F7A), /* ~= 10^-292 */ + U64(0x9FAACF3D, 0xF73609B1), U64(0x77B19161, 0x8C54E9AC), /* ~= 10^-291 */ + U64(0xC795830D, 0x75038C1D), U64(0xD59DF5B9, 0xEF6A2417), /* ~= 10^-290 */ + U64(0xF97AE3D0, 0xD2446F25), U64(0x4B057328, 0x6B44AD1D), /* ~= 10^-289 */ + U64(0x9BECCE62, 0x836AC577), U64(0x4EE367F9, 0x430AEC32), /* ~= 10^-288 */ + U64(0xC2E801FB, 0x244576D5), U64(0x229C41F7, 0x93CDA73F), /* ~= 10^-287 */ + U64(0xF3A20279, 0xED56D48A), U64(0x6B435275, 0x78C1110F), /* ~= 10^-286 */ + U64(0x9845418C, 0x345644D6), U64(0x830A1389, 0x6B78AAA9), /* ~= 10^-285 */ + U64(0xBE5691EF, 0x416BD60C), U64(0x23CC986B, 0xC656D553), /* ~= 10^-284 */ + U64(0xEDEC366B, 0x11C6CB8F), U64(0x2CBFBE86, 0xB7EC8AA8), /* ~= 10^-283 */ + U64(0x94B3A202, 0xEB1C3F39), U64(0x7BF7D714, 0x32F3D6A9), /* ~= 10^-282 */ + U64(0xB9E08A83, 0xA5E34F07), U64(0xDAF5CCD9, 0x3FB0CC53), /* ~= 10^-281 */ + U64(0xE858AD24, 0x8F5C22C9), U64(0xD1B3400F, 0x8F9CFF68), /* ~= 10^-280 */ + U64(0x91376C36, 0xD99995BE), U64(0x23100809, 0xB9C21FA1), /* ~= 10^-279 */ + U64(0xB5854744, 0x8FFFFB2D), U64(0xABD40A0C, 0x2832A78A), /* ~= 10^-278 */ + U64(0xE2E69915, 0xB3FFF9F9), U64(0x16C90C8F, 0x323F516C), /* ~= 10^-277 */ + U64(0x8DD01FAD, 0x907FFC3B), U64(0xAE3DA7D9, 0x7F6792E3), /* ~= 10^-276 */ + U64(0xB1442798, 0xF49FFB4A), U64(0x99CD11CF, 0xDF41779C), /* ~= 10^-275 */ + U64(0xDD95317F, 0x31C7FA1D), U64(0x40405643, 0xD711D583), /* ~= 10^-274 */ + U64(0x8A7D3EEF, 0x7F1CFC52), U64(0x482835EA, 0x666B2572), /* ~= 10^-273 */ + U64(0xAD1C8EAB, 0x5EE43B66), U64(0xDA324365, 0x0005EECF), /* ~= 10^-272 */ + U64(0xD863B256, 0x369D4A40), U64(0x90BED43E, 0x40076A82), /* ~= 10^-271 */ + U64(0x873E4F75, 0xE2224E68), U64(0x5A7744A6, 0xE804A291), /* ~= 10^-270 */ + U64(0xA90DE353, 0x5AAAE202), U64(0x711515D0, 0xA205CB36), /* ~= 10^-269 */ + U64(0xD3515C28, 0x31559A83), U64(0x0D5A5B44, 0xCA873E03), /* ~= 10^-268 */ + U64(0x8412D999, 0x1ED58091), U64(0xE858790A, 0xFE9486C2), /* ~= 10^-267 */ + U64(0xA5178FFF, 0x668AE0B6), U64(0x626E974D, 0xBE39A872), /* ~= 10^-266 */ + U64(0xCE5D73FF, 0x402D98E3), U64(0xFB0A3D21, 0x2DC8128F), /* ~= 10^-265 */ + U64(0x80FA687F, 0x881C7F8E), U64(0x7CE66634, 0xBC9D0B99), /* ~= 10^-264 */ + U64(0xA139029F, 0x6A239F72), U64(0x1C1FFFC1, 0xEBC44E80), /* ~= 10^-263 */ + U64(0xC9874347, 0x44AC874E), U64(0xA327FFB2, 0x66B56220), /* ~= 10^-262 */ + U64(0xFBE91419, 0x15D7A922), U64(0x4BF1FF9F, 0x0062BAA8), /* ~= 10^-261 */ + U64(0x9D71AC8F, 0xADA6C9B5), U64(0x6F773FC3, 0x603DB4A9), /* ~= 10^-260 */ + U64(0xC4CE17B3, 0x99107C22), U64(0xCB550FB4, 0x384D21D3), /* ~= 10^-259 */ + U64(0xF6019DA0, 0x7F549B2B), U64(0x7E2A53A1, 0x46606A48), /* ~= 10^-258 */ + U64(0x99C10284, 0x4F94E0FB), U64(0x2EDA7444, 0xCBFC426D), /* ~= 10^-257 */ + U64(0xC0314325, 0x637A1939), U64(0xFA911155, 0xFEFB5308), /* ~= 10^-256 */ + U64(0xF03D93EE, 0xBC589F88), U64(0x793555AB, 0x7EBA27CA), /* ~= 10^-255 */ + U64(0x96267C75, 0x35B763B5), U64(0x4BC1558B, 0x2F3458DE), /* ~= 10^-254 */ + U64(0xBBB01B92, 0x83253CA2), U64(0x9EB1AAED, 0xFB016F16), /* ~= 10^-253 */ + U64(0xEA9C2277, 0x23EE8BCB), U64(0x465E15A9, 0x79C1CADC), /* ~= 10^-252 */ + U64(0x92A1958A, 0x7675175F), U64(0x0BFACD89, 0xEC191EC9), /* ~= 10^-251 */ + U64(0xB749FAED, 0x14125D36), U64(0xCEF980EC, 0x671F667B), /* ~= 10^-250 */ + U64(0xE51C79A8, 0x5916F484), U64(0x82B7E127, 0x80E7401A), /* ~= 10^-249 */ + U64(0x8F31CC09, 0x37AE58D2), U64(0xD1B2ECB8, 0xB0908810), /* ~= 10^-248 */ + U64(0xB2FE3F0B, 0x8599EF07), U64(0x861FA7E6, 0xDCB4AA15), /* ~= 10^-247 */ + U64(0xDFBDCECE, 0x67006AC9), U64(0x67A791E0, 0x93E1D49A), /* ~= 10^-246 */ + U64(0x8BD6A141, 0x006042BD), U64(0xE0C8BB2C, 0x5C6D24E0), /* ~= 10^-245 */ + U64(0xAECC4991, 0x4078536D), U64(0x58FAE9F7, 0x73886E18), /* ~= 10^-244 */ + U64(0xDA7F5BF5, 0x90966848), U64(0xAF39A475, 0x506A899E), /* ~= 10^-243 */ + U64(0x888F9979, 0x7A5E012D), U64(0x6D8406C9, 0x52429603), /* ~= 10^-242 */ + U64(0xAAB37FD7, 0xD8F58178), U64(0xC8E5087B, 0xA6D33B83), /* ~= 10^-241 */ + U64(0xD5605FCD, 0xCF32E1D6), U64(0xFB1E4A9A, 0x90880A64), /* ~= 10^-240 */ + U64(0x855C3BE0, 0xA17FCD26), U64(0x5CF2EEA0, 0x9A55067F), /* ~= 10^-239 */ + U64(0xA6B34AD8, 0xC9DFC06F), U64(0xF42FAA48, 0xC0EA481E), /* ~= 10^-238 */ + U64(0xD0601D8E, 0xFC57B08B), U64(0xF13B94DA, 0xF124DA26), /* ~= 10^-237 */ + U64(0x823C1279, 0x5DB6CE57), U64(0x76C53D08, 0xD6B70858), /* ~= 10^-236 */ + U64(0xA2CB1717, 0xB52481ED), U64(0x54768C4B, 0x0C64CA6E), /* ~= 10^-235 */ + U64(0xCB7DDCDD, 0xA26DA268), U64(0xA9942F5D, 0xCF7DFD09), /* ~= 10^-234 */ + U64(0xFE5D5415, 0x0B090B02), U64(0xD3F93B35, 0x435D7C4C), /* ~= 10^-233 */ + U64(0x9EFA548D, 0x26E5A6E1), U64(0xC47BC501, 0x4A1A6DAF), /* ~= 10^-232 */ + U64(0xC6B8E9B0, 0x709F109A), U64(0x359AB641, 0x9CA1091B), /* ~= 10^-231 */ + U64(0xF867241C, 0x8CC6D4C0), U64(0xC30163D2, 0x03C94B62), /* ~= 10^-230 */ + U64(0x9B407691, 0xD7FC44F8), U64(0x79E0DE63, 0x425DCF1D), /* ~= 10^-229 */ + U64(0xC2109436, 0x4DFB5636), U64(0x985915FC, 0x12F542E4), /* ~= 10^-228 */ + U64(0xF294B943, 0xE17A2BC4), U64(0x3E6F5B7B, 0x17B2939D), /* ~= 10^-227 */ + U64(0x979CF3CA, 0x6CEC5B5A), U64(0xA705992C, 0xEECF9C42), /* ~= 10^-226 */ + U64(0xBD8430BD, 0x08277231), U64(0x50C6FF78, 0x2A838353), /* ~= 10^-225 */ + U64(0xECE53CEC, 0x4A314EBD), U64(0xA4F8BF56, 0x35246428), /* ~= 10^-224 */ + U64(0x940F4613, 0xAE5ED136), U64(0x871B7795, 0xE136BE99), /* ~= 10^-223 */ + U64(0xB9131798, 0x99F68584), U64(0x28E2557B, 0x59846E3F), /* ~= 10^-222 */ + U64(0xE757DD7E, 0xC07426E5), U64(0x331AEADA, 0x2FE589CF), /* ~= 10^-221 */ + U64(0x9096EA6F, 0x3848984F), U64(0x3FF0D2C8, 0x5DEF7621), /* ~= 10^-220 */ + U64(0xB4BCA50B, 0x065ABE63), U64(0x0FED077A, 0x756B53A9), /* ~= 10^-219 */ + U64(0xE1EBCE4D, 0xC7F16DFB), U64(0xD3E84959, 0x12C62894), /* ~= 10^-218 */ + U64(0x8D3360F0, 0x9CF6E4BD), U64(0x64712DD7, 0xABBBD95C), /* ~= 10^-217 */ + U64(0xB080392C, 0xC4349DEC), U64(0xBD8D794D, 0x96AACFB3), /* ~= 10^-216 */ + U64(0xDCA04777, 0xF541C567), U64(0xECF0D7A0, 0xFC5583A0), /* ~= 10^-215 */ + U64(0x89E42CAA, 0xF9491B60), U64(0xF41686C4, 0x9DB57244), /* ~= 10^-214 */ + U64(0xAC5D37D5, 0xB79B6239), U64(0x311C2875, 0xC522CED5), /* ~= 10^-213 */ + U64(0xD77485CB, 0x25823AC7), U64(0x7D633293, 0x366B828B), /* ~= 10^-212 */ + U64(0x86A8D39E, 0xF77164BC), U64(0xAE5DFF9C, 0x02033197), /* ~= 10^-211 */ + U64(0xA8530886, 0xB54DBDEB), U64(0xD9F57F83, 0x0283FDFC), /* ~= 10^-210 */ + U64(0xD267CAA8, 0x62A12D66), U64(0xD072DF63, 0xC324FD7B), /* ~= 10^-209 */ + U64(0x8380DEA9, 0x3DA4BC60), U64(0x4247CB9E, 0x59F71E6D), /* ~= 10^-208 */ + U64(0xA4611653, 0x8D0DEB78), U64(0x52D9BE85, 0xF074E608), /* ~= 10^-207 */ + U64(0xCD795BE8, 0x70516656), U64(0x67902E27, 0x6C921F8B), /* ~= 10^-206 */ + U64(0x806BD971, 0x4632DFF6), U64(0x00BA1CD8, 0xA3DB53B6), /* ~= 10^-205 */ + U64(0xA086CFCD, 0x97BF97F3), U64(0x80E8A40E, 0xCCD228A4), /* ~= 10^-204 */ + U64(0xC8A883C0, 0xFDAF7DF0), U64(0x6122CD12, 0x8006B2CD), /* ~= 10^-203 */ + U64(0xFAD2A4B1, 0x3D1B5D6C), U64(0x796B8057, 0x20085F81), /* ~= 10^-202 */ + U64(0x9CC3A6EE, 0xC6311A63), U64(0xCBE33036, 0x74053BB0), /* ~= 10^-201 */ + U64(0xC3F490AA, 0x77BD60FC), U64(0xBEDBFC44, 0x11068A9C), /* ~= 10^-200 */ + U64(0xF4F1B4D5, 0x15ACB93B), U64(0xEE92FB55, 0x15482D44), /* ~= 10^-199 */ + U64(0x99171105, 0x2D8BF3C5), U64(0x751BDD15, 0x2D4D1C4A), /* ~= 10^-198 */ + U64(0xBF5CD546, 0x78EEF0B6), U64(0xD262D45A, 0x78A0635D), /* ~= 10^-197 */ + U64(0xEF340A98, 0x172AACE4), U64(0x86FB8971, 0x16C87C34), /* ~= 10^-196 */ + U64(0x9580869F, 0x0E7AAC0E), U64(0xD45D35E6, 0xAE3D4DA0), /* ~= 10^-195 */ + U64(0xBAE0A846, 0xD2195712), U64(0x89748360, 0x59CCA109), /* ~= 10^-194 */ + U64(0xE998D258, 0x869FACD7), U64(0x2BD1A438, 0x703FC94B), /* ~= 10^-193 */ + U64(0x91FF8377, 0x5423CC06), U64(0x7B6306A3, 0x4627DDCF), /* ~= 10^-192 */ + U64(0xB67F6455, 0x292CBF08), U64(0x1A3BC84C, 0x17B1D542), /* ~= 10^-191 */ + U64(0xE41F3D6A, 0x7377EECA), U64(0x20CABA5F, 0x1D9E4A93), /* ~= 10^-190 */ + U64(0x8E938662, 0x882AF53E), U64(0x547EB47B, 0x7282EE9C), /* ~= 10^-189 */ + U64(0xB23867FB, 0x2A35B28D), U64(0xE99E619A, 0x4F23AA43), /* ~= 10^-188 */ + U64(0xDEC681F9, 0xF4C31F31), U64(0x6405FA00, 0xE2EC94D4), /* ~= 10^-187 */ + U64(0x8B3C113C, 0x38F9F37E), U64(0xDE83BC40, 0x8DD3DD04), /* ~= 10^-186 */ + U64(0xAE0B158B, 0x4738705E), U64(0x9624AB50, 0xB148D445), /* ~= 10^-185 */ + U64(0xD98DDAEE, 0x19068C76), U64(0x3BADD624, 0xDD9B0957), /* ~= 10^-184 */ + U64(0x87F8A8D4, 0xCFA417C9), U64(0xE54CA5D7, 0x0A80E5D6), /* ~= 10^-183 */ + U64(0xA9F6D30A, 0x038D1DBC), U64(0x5E9FCF4C, 0xCD211F4C), /* ~= 10^-182 */ + U64(0xD47487CC, 0x8470652B), U64(0x7647C320, 0x0069671F), /* ~= 10^-181 */ + U64(0x84C8D4DF, 0xD2C63F3B), U64(0x29ECD9F4, 0x0041E073), /* ~= 10^-180 */ + U64(0xA5FB0A17, 0xC777CF09), U64(0xF4681071, 0x00525890), /* ~= 10^-179 */ + U64(0xCF79CC9D, 0xB955C2CC), U64(0x7182148D, 0x4066EEB4), /* ~= 10^-178 */ + U64(0x81AC1FE2, 0x93D599BF), U64(0xC6F14CD8, 0x48405530), /* ~= 10^-177 */ + U64(0xA21727DB, 0x38CB002F), U64(0xB8ADA00E, 0x5A506A7C), /* ~= 10^-176 */ + U64(0xCA9CF1D2, 0x06FDC03B), U64(0xA6D90811, 0xF0E4851C), /* ~= 10^-175 */ + U64(0xFD442E46, 0x88BD304A), U64(0x908F4A16, 0x6D1DA663), /* ~= 10^-174 */ + U64(0x9E4A9CEC, 0x15763E2E), U64(0x9A598E4E, 0x043287FE), /* ~= 10^-173 */ + U64(0xC5DD4427, 0x1AD3CDBA), U64(0x40EFF1E1, 0x853F29FD), /* ~= 10^-172 */ + U64(0xF7549530, 0xE188C128), U64(0xD12BEE59, 0xE68EF47C), /* ~= 10^-171 */ + U64(0x9A94DD3E, 0x8CF578B9), U64(0x82BB74F8, 0x301958CE), /* ~= 10^-170 */ + U64(0xC13A148E, 0x3032D6E7), U64(0xE36A5236, 0x3C1FAF01), /* ~= 10^-169 */ + U64(0xF18899B1, 0xBC3F8CA1), U64(0xDC44E6C3, 0xCB279AC1), /* ~= 10^-168 */ + U64(0x96F5600F, 0x15A7B7E5), U64(0x29AB103A, 0x5EF8C0B9), /* ~= 10^-167 */ + U64(0xBCB2B812, 0xDB11A5DE), U64(0x7415D448, 0xF6B6F0E7), /* ~= 10^-166 */ + U64(0xEBDF6617, 0x91D60F56), U64(0x111B495B, 0x3464AD21), /* ~= 10^-165 */ + U64(0x936B9FCE, 0xBB25C995), U64(0xCAB10DD9, 0x00BEEC34), /* ~= 10^-164 */ + U64(0xB84687C2, 0x69EF3BFB), U64(0x3D5D514F, 0x40EEA742), /* ~= 10^-163 */ + U64(0xE65829B3, 0x046B0AFA), U64(0x0CB4A5A3, 0x112A5112), /* ~= 10^-162 */ + U64(0x8FF71A0F, 0xE2C2E6DC), U64(0x47F0E785, 0xEABA72AB), /* ~= 10^-161 */ + U64(0xB3F4E093, 0xDB73A093), U64(0x59ED2167, 0x65690F56), /* ~= 10^-160 */ + U64(0xE0F218B8, 0xD25088B8), U64(0x306869C1, 0x3EC3532C), /* ~= 10^-159 */ + U64(0x8C974F73, 0x83725573), U64(0x1E414218, 0xC73A13FB), /* ~= 10^-158 */ + U64(0xAFBD2350, 0x644EEACF), U64(0xE5D1929E, 0xF90898FA), /* ~= 10^-157 */ + U64(0xDBAC6C24, 0x7D62A583), U64(0xDF45F746, 0xB74ABF39), /* ~= 10^-156 */ + U64(0x894BC396, 0xCE5DA772), U64(0x6B8BBA8C, 0x328EB783), /* ~= 10^-155 */ + U64(0xAB9EB47C, 0x81F5114F), U64(0x066EA92F, 0x3F326564), /* ~= 10^-154 */ + U64(0xD686619B, 0xA27255A2), U64(0xC80A537B, 0x0EFEFEBD), /* ~= 10^-153 */ + U64(0x8613FD01, 0x45877585), U64(0xBD06742C, 0xE95F5F36), /* ~= 10^-152 */ + U64(0xA798FC41, 0x96E952E7), U64(0x2C481138, 0x23B73704), /* ~= 10^-151 */ + U64(0xD17F3B51, 0xFCA3A7A0), U64(0xF75A1586, 0x2CA504C5), /* ~= 10^-150 */ + U64(0x82EF8513, 0x3DE648C4), U64(0x9A984D73, 0xDBE722FB), /* ~= 10^-149 */ + U64(0xA3AB6658, 0x0D5FDAF5), U64(0xC13E60D0, 0xD2E0EBBA), /* ~= 10^-148 */ + U64(0xCC963FEE, 0x10B7D1B3), U64(0x318DF905, 0x079926A8), /* ~= 10^-147 */ + U64(0xFFBBCFE9, 0x94E5C61F), U64(0xFDF17746, 0x497F7052), /* ~= 10^-146 */ + U64(0x9FD561F1, 0xFD0F9BD3), U64(0xFEB6EA8B, 0xEDEFA633), /* ~= 10^-145 */ + U64(0xC7CABA6E, 0x7C5382C8), U64(0xFE64A52E, 0xE96B8FC0), /* ~= 10^-144 */ + U64(0xF9BD690A, 0x1B68637B), U64(0x3DFDCE7A, 0xA3C673B0), /* ~= 10^-143 */ + U64(0x9C1661A6, 0x51213E2D), U64(0x06BEA10C, 0xA65C084E), /* ~= 10^-142 */ + U64(0xC31BFA0F, 0xE5698DB8), U64(0x486E494F, 0xCFF30A62), /* ~= 10^-141 */ + U64(0xF3E2F893, 0xDEC3F126), U64(0x5A89DBA3, 0xC3EFCCFA), /* ~= 10^-140 */ + U64(0x986DDB5C, 0x6B3A76B7), U64(0xF8962946, 0x5A75E01C), /* ~= 10^-139 */ + U64(0xBE895233, 0x86091465), U64(0xF6BBB397, 0xF1135823), /* ~= 10^-138 */ + U64(0xEE2BA6C0, 0x678B597F), U64(0x746AA07D, 0xED582E2C), /* ~= 10^-137 */ + U64(0x94DB4838, 0x40B717EF), U64(0xA8C2A44E, 0xB4571CDC), /* ~= 10^-136 */ + U64(0xBA121A46, 0x50E4DDEB), U64(0x92F34D62, 0x616CE413), /* ~= 10^-135 */ + U64(0xE896A0D7, 0xE51E1566), U64(0x77B020BA, 0xF9C81D17), /* ~= 10^-134 */ + U64(0x915E2486, 0xEF32CD60), U64(0x0ACE1474, 0xDC1D122E), /* ~= 10^-133 */ + U64(0xB5B5ADA8, 0xAAFF80B8), U64(0x0D819992, 0x132456BA), /* ~= 10^-132 */ + U64(0xE3231912, 0xD5BF60E6), U64(0x10E1FFF6, 0x97ED6C69), /* ~= 10^-131 */ + U64(0x8DF5EFAB, 0xC5979C8F), U64(0xCA8D3FFA, 0x1EF463C1), /* ~= 10^-130 */ + U64(0xB1736B96, 0xB6FD83B3), U64(0xBD308FF8, 0xA6B17CB2), /* ~= 10^-129 */ + U64(0xDDD0467C, 0x64BCE4A0), U64(0xAC7CB3F6, 0xD05DDBDE), /* ~= 10^-128 */ + U64(0x8AA22C0D, 0xBEF60EE4), U64(0x6BCDF07A, 0x423AA96B), /* ~= 10^-127 */ + U64(0xAD4AB711, 0x2EB3929D), U64(0x86C16C98, 0xD2C953C6), /* ~= 10^-126 */ + U64(0xD89D64D5, 0x7A607744), U64(0xE871C7BF, 0x077BA8B7), /* ~= 10^-125 */ + U64(0x87625F05, 0x6C7C4A8B), U64(0x11471CD7, 0x64AD4972), /* ~= 10^-124 */ + U64(0xA93AF6C6, 0xC79B5D2D), U64(0xD598E40D, 0x3DD89BCF), /* ~= 10^-123 */ + U64(0xD389B478, 0x79823479), U64(0x4AFF1D10, 0x8D4EC2C3), /* ~= 10^-122 */ + U64(0x843610CB, 0x4BF160CB), U64(0xCEDF722A, 0x585139BA), /* ~= 10^-121 */ + U64(0xA54394FE, 0x1EEDB8FE), U64(0xC2974EB4, 0xEE658828), /* ~= 10^-120 */ + U64(0xCE947A3D, 0xA6A9273E), U64(0x733D2262, 0x29FEEA32), /* ~= 10^-119 */ + U64(0x811CCC66, 0x8829B887), U64(0x0806357D, 0x5A3F525F), /* ~= 10^-118 */ + U64(0xA163FF80, 0x2A3426A8), U64(0xCA07C2DC, 0xB0CF26F7), /* ~= 10^-117 */ + U64(0xC9BCFF60, 0x34C13052), U64(0xFC89B393, 0xDD02F0B5), /* ~= 10^-116 */ + U64(0xFC2C3F38, 0x41F17C67), U64(0xBBAC2078, 0xD443ACE2), /* ~= 10^-115 */ + U64(0x9D9BA783, 0x2936EDC0), U64(0xD54B944B, 0x84AA4C0D), /* ~= 10^-114 */ + U64(0xC5029163, 0xF384A931), U64(0x0A9E795E, 0x65D4DF11), /* ~= 10^-113 */ + U64(0xF64335BC, 0xF065D37D), U64(0x4D4617B5, 0xFF4A16D5), /* ~= 10^-112 */ + U64(0x99EA0196, 0x163FA42E), U64(0x504BCED1, 0xBF8E4E45), /* ~= 10^-111 */ + U64(0xC06481FB, 0x9BCF8D39), U64(0xE45EC286, 0x2F71E1D6), /* ~= 10^-110 */ + U64(0xF07DA27A, 0x82C37088), U64(0x5D767327, 0xBB4E5A4C), /* ~= 10^-109 */ + U64(0x964E858C, 0x91BA2655), U64(0x3A6A07F8, 0xD510F86F), /* ~= 10^-108 */ + U64(0xBBE226EF, 0xB628AFEA), U64(0x890489F7, 0x0A55368B), /* ~= 10^-107 */ + U64(0xEADAB0AB, 0xA3B2DBE5), U64(0x2B45AC74, 0xCCEA842E), /* ~= 10^-106 */ + U64(0x92C8AE6B, 0x464FC96F), U64(0x3B0B8BC9, 0x0012929D), /* ~= 10^-105 */ + U64(0xB77ADA06, 0x17E3BBCB), U64(0x09CE6EBB, 0x40173744), /* ~= 10^-104 */ + U64(0xE5599087, 0x9DDCAABD), U64(0xCC420A6A, 0x101D0515), /* ~= 10^-103 */ + U64(0x8F57FA54, 0xC2A9EAB6), U64(0x9FA94682, 0x4A12232D), /* ~= 10^-102 */ + U64(0xB32DF8E9, 0xF3546564), U64(0x47939822, 0xDC96ABF9), /* ~= 10^-101 */ + U64(0xDFF97724, 0x70297EBD), U64(0x59787E2B, 0x93BC56F7), /* ~= 10^-100 */ + U64(0x8BFBEA76, 0xC619EF36), U64(0x57EB4EDB, 0x3C55B65A), /* ~= 10^-99 */ + U64(0xAEFAE514, 0x77A06B03), U64(0xEDE62292, 0x0B6B23F1), /* ~= 10^-98 */ + U64(0xDAB99E59, 0x958885C4), U64(0xE95FAB36, 0x8E45ECED), /* ~= 10^-97 */ + U64(0x88B402F7, 0xFD75539B), U64(0x11DBCB02, 0x18EBB414), /* ~= 10^-96 */ + U64(0xAAE103B5, 0xFCD2A881), U64(0xD652BDC2, 0x9F26A119), /* ~= 10^-95 */ + U64(0xD59944A3, 0x7C0752A2), U64(0x4BE76D33, 0x46F0495F), /* ~= 10^-94 */ + U64(0x857FCAE6, 0x2D8493A5), U64(0x6F70A440, 0x0C562DDB), /* ~= 10^-93 */ + U64(0xA6DFBD9F, 0xB8E5B88E), U64(0xCB4CCD50, 0x0F6BB952), /* ~= 10^-92 */ + U64(0xD097AD07, 0xA71F26B2), U64(0x7E2000A4, 0x1346A7A7), /* ~= 10^-91 */ + U64(0x825ECC24, 0xC873782F), U64(0x8ED40066, 0x8C0C28C8), /* ~= 10^-90 */ + U64(0xA2F67F2D, 0xFA90563B), U64(0x72890080, 0x2F0F32FA), /* ~= 10^-89 */ + U64(0xCBB41EF9, 0x79346BCA), U64(0x4F2B40A0, 0x3AD2FFB9), /* ~= 10^-88 */ + U64(0xFEA126B7, 0xD78186BC), U64(0xE2F610C8, 0x4987BFA8), /* ~= 10^-87 */ + U64(0x9F24B832, 0xE6B0F436), U64(0x0DD9CA7D, 0x2DF4D7C9), /* ~= 10^-86 */ + U64(0xC6EDE63F, 0xA05D3143), U64(0x91503D1C, 0x79720DBB), /* ~= 10^-85 */ + U64(0xF8A95FCF, 0x88747D94), U64(0x75A44C63, 0x97CE912A), /* ~= 10^-84 */ + U64(0x9B69DBE1, 0xB548CE7C), U64(0xC986AFBE, 0x3EE11ABA), /* ~= 10^-83 */ + U64(0xC24452DA, 0x229B021B), U64(0xFBE85BAD, 0xCE996168), /* ~= 10^-82 */ + U64(0xF2D56790, 0xAB41C2A2), U64(0xFAE27299, 0x423FB9C3), /* ~= 10^-81 */ + U64(0x97C560BA, 0x6B0919A5), U64(0xDCCD879F, 0xC967D41A), /* ~= 10^-80 */ + U64(0xBDB6B8E9, 0x05CB600F), U64(0x5400E987, 0xBBC1C920), /* ~= 10^-79 */ + U64(0xED246723, 0x473E3813), U64(0x290123E9, 0xAAB23B68), /* ~= 10^-78 */ + U64(0x9436C076, 0x0C86E30B), U64(0xF9A0B672, 0x0AAF6521), /* ~= 10^-77 */ + U64(0xB9447093, 0x8FA89BCE), U64(0xF808E40E, 0x8D5B3E69), /* ~= 10^-76 */ + U64(0xE7958CB8, 0x7392C2C2), U64(0xB60B1D12, 0x30B20E04), /* ~= 10^-75 */ + U64(0x90BD77F3, 0x483BB9B9), U64(0xB1C6F22B, 0x5E6F48C2), /* ~= 10^-74 */ + U64(0xB4ECD5F0, 0x1A4AA828), U64(0x1E38AEB6, 0x360B1AF3), /* ~= 10^-73 */ + U64(0xE2280B6C, 0x20DD5232), U64(0x25C6DA63, 0xC38DE1B0), /* ~= 10^-72 */ + U64(0x8D590723, 0x948A535F), U64(0x579C487E, 0x5A38AD0E), /* ~= 10^-71 */ + U64(0xB0AF48EC, 0x79ACE837), U64(0x2D835A9D, 0xF0C6D851), /* ~= 10^-70 */ + U64(0xDCDB1B27, 0x98182244), U64(0xF8E43145, 0x6CF88E65), /* ~= 10^-69 */ + U64(0x8A08F0F8, 0xBF0F156B), U64(0x1B8E9ECB, 0x641B58FF), /* ~= 10^-68 */ + U64(0xAC8B2D36, 0xEED2DAC5), U64(0xE272467E, 0x3D222F3F), /* ~= 10^-67 */ + U64(0xD7ADF884, 0xAA879177), U64(0x5B0ED81D, 0xCC6ABB0F), /* ~= 10^-66 */ + U64(0x86CCBB52, 0xEA94BAEA), U64(0x98E94712, 0x9FC2B4E9), /* ~= 10^-65 */ + U64(0xA87FEA27, 0xA539E9A5), U64(0x3F2398D7, 0x47B36224), /* ~= 10^-64 */ + U64(0xD29FE4B1, 0x8E88640E), U64(0x8EEC7F0D, 0x19A03AAD), /* ~= 10^-63 */ + U64(0x83A3EEEE, 0xF9153E89), U64(0x1953CF68, 0x300424AC), /* ~= 10^-62 */ + U64(0xA48CEAAA, 0xB75A8E2B), U64(0x5FA8C342, 0x3C052DD7), /* ~= 10^-61 */ + U64(0xCDB02555, 0x653131B6), U64(0x3792F412, 0xCB06794D), /* ~= 10^-60 */ + U64(0x808E1755, 0x5F3EBF11), U64(0xE2BBD88B, 0xBEE40BD0), /* ~= 10^-59 */ + U64(0xA0B19D2A, 0xB70E6ED6), U64(0x5B6ACEAE, 0xAE9D0EC4), /* ~= 10^-58 */ + U64(0xC8DE0475, 0x64D20A8B), U64(0xF245825A, 0x5A445275), /* ~= 10^-57 */ + U64(0xFB158592, 0xBE068D2E), U64(0xEED6E2F0, 0xF0D56712), /* ~= 10^-56 */ + U64(0x9CED737B, 0xB6C4183D), U64(0x55464DD6, 0x9685606B), /* ~= 10^-55 */ + U64(0xC428D05A, 0xA4751E4C), U64(0xAA97E14C, 0x3C26B886), /* ~= 10^-54 */ + U64(0xF5330471, 0x4D9265DF), U64(0xD53DD99F, 0x4B3066A8), /* ~= 10^-53 */ + U64(0x993FE2C6, 0xD07B7FAB), U64(0xE546A803, 0x8EFE4029), /* ~= 10^-52 */ + U64(0xBF8FDB78, 0x849A5F96), U64(0xDE985204, 0x72BDD033), /* ~= 10^-51 */ + U64(0xEF73D256, 0xA5C0F77C), U64(0x963E6685, 0x8F6D4440), /* ~= 10^-50 */ + U64(0x95A86376, 0x27989AAD), U64(0xDDE70013, 0x79A44AA8), /* ~= 10^-49 */ + U64(0xBB127C53, 0xB17EC159), U64(0x5560C018, 0x580D5D52), /* ~= 10^-48 */ + U64(0xE9D71B68, 0x9DDE71AF), U64(0xAAB8F01E, 0x6E10B4A6), /* ~= 10^-47 */ + U64(0x92267121, 0x62AB070D), U64(0xCAB39613, 0x04CA70E8), /* ~= 10^-46 */ + U64(0xB6B00D69, 0xBB55C8D1), U64(0x3D607B97, 0xC5FD0D22), /* ~= 10^-45 */ + U64(0xE45C10C4, 0x2A2B3B05), U64(0x8CB89A7D, 0xB77C506A), /* ~= 10^-44 */ + U64(0x8EB98A7A, 0x9A5B04E3), U64(0x77F3608E, 0x92ADB242), /* ~= 10^-43 */ + U64(0xB267ED19, 0x40F1C61C), U64(0x55F038B2, 0x37591ED3), /* ~= 10^-42 */ + U64(0xDF01E85F, 0x912E37A3), U64(0x6B6C46DE, 0xC52F6688), /* ~= 10^-41 */ + U64(0x8B61313B, 0xBABCE2C6), U64(0x2323AC4B, 0x3B3DA015), /* ~= 10^-40 */ + U64(0xAE397D8A, 0xA96C1B77), U64(0xABEC975E, 0x0A0D081A), /* ~= 10^-39 */ + U64(0xD9C7DCED, 0x53C72255), U64(0x96E7BD35, 0x8C904A21), /* ~= 10^-38 */ + U64(0x881CEA14, 0x545C7575), U64(0x7E50D641, 0x77DA2E54), /* ~= 10^-37 */ + U64(0xAA242499, 0x697392D2), U64(0xDDE50BD1, 0xD5D0B9E9), /* ~= 10^-36 */ + U64(0xD4AD2DBF, 0xC3D07787), U64(0x955E4EC6, 0x4B44E864), /* ~= 10^-35 */ + U64(0x84EC3C97, 0xDA624AB4), U64(0xBD5AF13B, 0xEF0B113E), /* ~= 10^-34 */ + U64(0xA6274BBD, 0xD0FADD61), U64(0xECB1AD8A, 0xEACDD58E), /* ~= 10^-33 */ + U64(0xCFB11EAD, 0x453994BA), U64(0x67DE18ED, 0xA5814AF2), /* ~= 10^-32 */ + U64(0x81CEB32C, 0x4B43FCF4), U64(0x80EACF94, 0x8770CED7), /* ~= 10^-31 */ + U64(0xA2425FF7, 0x5E14FC31), U64(0xA1258379, 0xA94D028D), /* ~= 10^-30 */ + U64(0xCAD2F7F5, 0x359A3B3E), U64(0x096EE458, 0x13A04330), /* ~= 10^-29 */ + U64(0xFD87B5F2, 0x8300CA0D), U64(0x8BCA9D6E, 0x188853FC), /* ~= 10^-28 */ + U64(0x9E74D1B7, 0x91E07E48), U64(0x775EA264, 0xCF55347D), /* ~= 10^-27 */ + U64(0xC6120625, 0x76589DDA), U64(0x95364AFE, 0x032A819D), /* ~= 10^-26 */ + U64(0xF79687AE, 0xD3EEC551), U64(0x3A83DDBD, 0x83F52204), /* ~= 10^-25 */ + U64(0x9ABE14CD, 0x44753B52), U64(0xC4926A96, 0x72793542), /* ~= 10^-24 */ + U64(0xC16D9A00, 0x95928A27), U64(0x75B7053C, 0x0F178293), /* ~= 10^-23 */ + U64(0xF1C90080, 0xBAF72CB1), U64(0x5324C68B, 0x12DD6338), /* ~= 10^-22 */ + U64(0x971DA050, 0x74DA7BEE), U64(0xD3F6FC16, 0xEBCA5E03), /* ~= 10^-21 */ + U64(0xBCE50864, 0x92111AEA), U64(0x88F4BB1C, 0xA6BCF584), /* ~= 10^-20 */ + U64(0xEC1E4A7D, 0xB69561A5), U64(0x2B31E9E3, 0xD06C32E5), /* ~= 10^-19 */ + U64(0x9392EE8E, 0x921D5D07), U64(0x3AFF322E, 0x62439FCF), /* ~= 10^-18 */ + U64(0xB877AA32, 0x36A4B449), U64(0x09BEFEB9, 0xFAD487C2), /* ~= 10^-17 */ + U64(0xE69594BE, 0xC44DE15B), U64(0x4C2EBE68, 0x7989A9B3), /* ~= 10^-16 */ + U64(0x901D7CF7, 0x3AB0ACD9), U64(0x0F9D3701, 0x4BF60A10), /* ~= 10^-15 */ + U64(0xB424DC35, 0x095CD80F), U64(0x538484C1, 0x9EF38C94), /* ~= 10^-14 */ + U64(0xE12E1342, 0x4BB40E13), U64(0x2865A5F2, 0x06B06FB9), /* ~= 10^-13 */ + U64(0x8CBCCC09, 0x6F5088CB), U64(0xF93F87B7, 0x442E45D3), /* ~= 10^-12 */ + U64(0xAFEBFF0B, 0xCB24AAFE), U64(0xF78F69A5, 0x1539D748), /* ~= 10^-11 */ + U64(0xDBE6FECE, 0xBDEDD5BE), U64(0xB573440E, 0x5A884D1B), /* ~= 10^-10 */ + U64(0x89705F41, 0x36B4A597), U64(0x31680A88, 0xF8953030), /* ~= 10^-9 */ + U64(0xABCC7711, 0x8461CEFC), U64(0xFDC20D2B, 0x36BA7C3D), /* ~= 10^-8 */ + U64(0xD6BF94D5, 0xE57A42BC), U64(0x3D329076, 0x04691B4C), /* ~= 10^-7 */ + U64(0x8637BD05, 0xAF6C69B5), U64(0xA63F9A49, 0xC2C1B10F), /* ~= 10^-6 */ + U64(0xA7C5AC47, 0x1B478423), U64(0x0FCF80DC, 0x33721D53), /* ~= 10^-5 */ + U64(0xD1B71758, 0xE219652B), U64(0xD3C36113, 0x404EA4A8), /* ~= 10^-4 */ + U64(0x83126E97, 0x8D4FDF3B), U64(0x645A1CAC, 0x083126E9), /* ~= 10^-3 */ + U64(0xA3D70A3D, 0x70A3D70A), U64(0x3D70A3D7, 0x0A3D70A3), /* ~= 10^-2 */ + U64(0xCCCCCCCC, 0xCCCCCCCC), U64(0xCCCCCCCC, 0xCCCCCCCC), /* ~= 10^-1 */ + U64(0x80000000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^0 */ + U64(0xA0000000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^1 */ + U64(0xC8000000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^2 */ + U64(0xFA000000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^3 */ + U64(0x9C400000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^4 */ + U64(0xC3500000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^5 */ + U64(0xF4240000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^6 */ + U64(0x98968000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^7 */ + U64(0xBEBC2000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^8 */ + U64(0xEE6B2800, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^9 */ + U64(0x9502F900, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^10 */ + U64(0xBA43B740, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^11 */ + U64(0xE8D4A510, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^12 */ + U64(0x9184E72A, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^13 */ + U64(0xB5E620F4, 0x80000000), U64(0x00000000, 0x00000000), /* == 10^14 */ + U64(0xE35FA931, 0xA0000000), U64(0x00000000, 0x00000000), /* == 10^15 */ + U64(0x8E1BC9BF, 0x04000000), U64(0x00000000, 0x00000000), /* == 10^16 */ + U64(0xB1A2BC2E, 0xC5000000), U64(0x00000000, 0x00000000), /* == 10^17 */ + U64(0xDE0B6B3A, 0x76400000), U64(0x00000000, 0x00000000), /* == 10^18 */ + U64(0x8AC72304, 0x89E80000), U64(0x00000000, 0x00000000), /* == 10^19 */ + U64(0xAD78EBC5, 0xAC620000), U64(0x00000000, 0x00000000), /* == 10^20 */ + U64(0xD8D726B7, 0x177A8000), U64(0x00000000, 0x00000000), /* == 10^21 */ + U64(0x87867832, 0x6EAC9000), U64(0x00000000, 0x00000000), /* == 10^22 */ + U64(0xA968163F, 0x0A57B400), U64(0x00000000, 0x00000000), /* == 10^23 */ + U64(0xD3C21BCE, 0xCCEDA100), U64(0x00000000, 0x00000000), /* == 10^24 */ + U64(0x84595161, 0x401484A0), U64(0x00000000, 0x00000000), /* == 10^25 */ + U64(0xA56FA5B9, 0x9019A5C8), U64(0x00000000, 0x00000000), /* == 10^26 */ + U64(0xCECB8F27, 0xF4200F3A), U64(0x00000000, 0x00000000), /* == 10^27 */ + U64(0x813F3978, 0xF8940984), U64(0x40000000, 0x00000000), /* == 10^28 */ + U64(0xA18F07D7, 0x36B90BE5), U64(0x50000000, 0x00000000), /* == 10^29 */ + U64(0xC9F2C9CD, 0x04674EDE), U64(0xA4000000, 0x00000000), /* == 10^30 */ + U64(0xFC6F7C40, 0x45812296), U64(0x4D000000, 0x00000000), /* == 10^31 */ + U64(0x9DC5ADA8, 0x2B70B59D), U64(0xF0200000, 0x00000000), /* == 10^32 */ + U64(0xC5371912, 0x364CE305), U64(0x6C280000, 0x00000000), /* == 10^33 */ + U64(0xF684DF56, 0xC3E01BC6), U64(0xC7320000, 0x00000000), /* == 10^34 */ + U64(0x9A130B96, 0x3A6C115C), U64(0x3C7F4000, 0x00000000), /* == 10^35 */ + U64(0xC097CE7B, 0xC90715B3), U64(0x4B9F1000, 0x00000000), /* == 10^36 */ + U64(0xF0BDC21A, 0xBB48DB20), U64(0x1E86D400, 0x00000000), /* == 10^37 */ + U64(0x96769950, 0xB50D88F4), U64(0x13144480, 0x00000000), /* == 10^38 */ + U64(0xBC143FA4, 0xE250EB31), U64(0x17D955A0, 0x00000000), /* == 10^39 */ + U64(0xEB194F8E, 0x1AE525FD), U64(0x5DCFAB08, 0x00000000), /* == 10^40 */ + U64(0x92EFD1B8, 0xD0CF37BE), U64(0x5AA1CAE5, 0x00000000), /* == 10^41 */ + U64(0xB7ABC627, 0x050305AD), U64(0xF14A3D9E, 0x40000000), /* == 10^42 */ + U64(0xE596B7B0, 0xC643C719), U64(0x6D9CCD05, 0xD0000000), /* == 10^43 */ + U64(0x8F7E32CE, 0x7BEA5C6F), U64(0xE4820023, 0xA2000000), /* == 10^44 */ + U64(0xB35DBF82, 0x1AE4F38B), U64(0xDDA2802C, 0x8A800000), /* == 10^45 */ + U64(0xE0352F62, 0xA19E306E), U64(0xD50B2037, 0xAD200000), /* == 10^46 */ + U64(0x8C213D9D, 0xA502DE45), U64(0x4526F422, 0xCC340000), /* == 10^47 */ + U64(0xAF298D05, 0x0E4395D6), U64(0x9670B12B, 0x7F410000), /* == 10^48 */ + U64(0xDAF3F046, 0x51D47B4C), U64(0x3C0CDD76, 0x5F114000), /* == 10^49 */ + U64(0x88D8762B, 0xF324CD0F), U64(0xA5880A69, 0xFB6AC800), /* == 10^50 */ + U64(0xAB0E93B6, 0xEFEE0053), U64(0x8EEA0D04, 0x7A457A00), /* == 10^51 */ + U64(0xD5D238A4, 0xABE98068), U64(0x72A49045, 0x98D6D880), /* == 10^52 */ + U64(0x85A36366, 0xEB71F041), U64(0x47A6DA2B, 0x7F864750), /* == 10^53 */ + U64(0xA70C3C40, 0xA64E6C51), U64(0x999090B6, 0x5F67D924), /* == 10^54 */ + U64(0xD0CF4B50, 0xCFE20765), U64(0xFFF4B4E3, 0xF741CF6D), /* == 10^55 */ + U64(0x82818F12, 0x81ED449F), U64(0xBFF8F10E, 0x7A8921A4), /* ~= 10^56 */ + U64(0xA321F2D7, 0x226895C7), U64(0xAFF72D52, 0x192B6A0D), /* ~= 10^57 */ + U64(0xCBEA6F8C, 0xEB02BB39), U64(0x9BF4F8A6, 0x9F764490), /* ~= 10^58 */ + U64(0xFEE50B70, 0x25C36A08), U64(0x02F236D0, 0x4753D5B4), /* ~= 10^59 */ + U64(0x9F4F2726, 0x179A2245), U64(0x01D76242, 0x2C946590), /* ~= 10^60 */ + U64(0xC722F0EF, 0x9D80AAD6), U64(0x424D3AD2, 0xB7B97EF5), /* ~= 10^61 */ + U64(0xF8EBAD2B, 0x84E0D58B), U64(0xD2E08987, 0x65A7DEB2), /* ~= 10^62 */ + U64(0x9B934C3B, 0x330C8577), U64(0x63CC55F4, 0x9F88EB2F), /* ~= 10^63 */ + U64(0xC2781F49, 0xFFCFA6D5), U64(0x3CBF6B71, 0xC76B25FB), /* ~= 10^64 */ + U64(0xF316271C, 0x7FC3908A), U64(0x8BEF464E, 0x3945EF7A), /* ~= 10^65 */ + U64(0x97EDD871, 0xCFDA3A56), U64(0x97758BF0, 0xE3CBB5AC), /* ~= 10^66 */ + U64(0xBDE94E8E, 0x43D0C8EC), U64(0x3D52EEED, 0x1CBEA317), /* ~= 10^67 */ + U64(0xED63A231, 0xD4C4FB27), U64(0x4CA7AAA8, 0x63EE4BDD), /* ~= 10^68 */ + U64(0x945E455F, 0x24FB1CF8), U64(0x8FE8CAA9, 0x3E74EF6A), /* ~= 10^69 */ + U64(0xB975D6B6, 0xEE39E436), U64(0xB3E2FD53, 0x8E122B44), /* ~= 10^70 */ + U64(0xE7D34C64, 0xA9C85D44), U64(0x60DBBCA8, 0x7196B616), /* ~= 10^71 */ + U64(0x90E40FBE, 0xEA1D3A4A), U64(0xBC8955E9, 0x46FE31CD), /* ~= 10^72 */ + U64(0xB51D13AE, 0xA4A488DD), U64(0x6BABAB63, 0x98BDBE41), /* ~= 10^73 */ + U64(0xE264589A, 0x4DCDAB14), U64(0xC696963C, 0x7EED2DD1), /* ~= 10^74 */ + U64(0x8D7EB760, 0x70A08AEC), U64(0xFC1E1DE5, 0xCF543CA2), /* ~= 10^75 */ + U64(0xB0DE6538, 0x8CC8ADA8), U64(0x3B25A55F, 0x43294BCB), /* ~= 10^76 */ + U64(0xDD15FE86, 0xAFFAD912), U64(0x49EF0EB7, 0x13F39EBE), /* ~= 10^77 */ + U64(0x8A2DBF14, 0x2DFCC7AB), U64(0x6E356932, 0x6C784337), /* ~= 10^78 */ + U64(0xACB92ED9, 0x397BF996), U64(0x49C2C37F, 0x07965404), /* ~= 10^79 */ + U64(0xD7E77A8F, 0x87DAF7FB), U64(0xDC33745E, 0xC97BE906), /* ~= 10^80 */ + U64(0x86F0AC99, 0xB4E8DAFD), U64(0x69A028BB, 0x3DED71A3), /* ~= 10^81 */ + U64(0xA8ACD7C0, 0x222311BC), U64(0xC40832EA, 0x0D68CE0C), /* ~= 10^82 */ + U64(0xD2D80DB0, 0x2AABD62B), U64(0xF50A3FA4, 0x90C30190), /* ~= 10^83 */ + U64(0x83C7088E, 0x1AAB65DB), U64(0x792667C6, 0xDA79E0FA), /* ~= 10^84 */ + U64(0xA4B8CAB1, 0xA1563F52), U64(0x577001B8, 0x91185938), /* ~= 10^85 */ + U64(0xCDE6FD5E, 0x09ABCF26), U64(0xED4C0226, 0xB55E6F86), /* ~= 10^86 */ + U64(0x80B05E5A, 0xC60B6178), U64(0x544F8158, 0x315B05B4), /* ~= 10^87 */ + U64(0xA0DC75F1, 0x778E39D6), U64(0x696361AE, 0x3DB1C721), /* ~= 10^88 */ + U64(0xC913936D, 0xD571C84C), U64(0x03BC3A19, 0xCD1E38E9), /* ~= 10^89 */ + U64(0xFB587849, 0x4ACE3A5F), U64(0x04AB48A0, 0x4065C723), /* ~= 10^90 */ + U64(0x9D174B2D, 0xCEC0E47B), U64(0x62EB0D64, 0x283F9C76), /* ~= 10^91 */ + U64(0xC45D1DF9, 0x42711D9A), U64(0x3BA5D0BD, 0x324F8394), /* ~= 10^92 */ + U64(0xF5746577, 0x930D6500), U64(0xCA8F44EC, 0x7EE36479), /* ~= 10^93 */ + U64(0x9968BF6A, 0xBBE85F20), U64(0x7E998B13, 0xCF4E1ECB), /* ~= 10^94 */ + U64(0xBFC2EF45, 0x6AE276E8), U64(0x9E3FEDD8, 0xC321A67E), /* ~= 10^95 */ + U64(0xEFB3AB16, 0xC59B14A2), U64(0xC5CFE94E, 0xF3EA101E), /* ~= 10^96 */ + U64(0x95D04AEE, 0x3B80ECE5), U64(0xBBA1F1D1, 0x58724A12), /* ~= 10^97 */ + U64(0xBB445DA9, 0xCA61281F), U64(0x2A8A6E45, 0xAE8EDC97), /* ~= 10^98 */ + U64(0xEA157514, 0x3CF97226), U64(0xF52D09D7, 0x1A3293BD), /* ~= 10^99 */ + U64(0x924D692C, 0xA61BE758), U64(0x593C2626, 0x705F9C56), /* ~= 10^100 */ + U64(0xB6E0C377, 0xCFA2E12E), U64(0x6F8B2FB0, 0x0C77836C), /* ~= 10^101 */ + U64(0xE498F455, 0xC38B997A), U64(0x0B6DFB9C, 0x0F956447), /* ~= 10^102 */ + U64(0x8EDF98B5, 0x9A373FEC), U64(0x4724BD41, 0x89BD5EAC), /* ~= 10^103 */ + U64(0xB2977EE3, 0x00C50FE7), U64(0x58EDEC91, 0xEC2CB657), /* ~= 10^104 */ + U64(0xDF3D5E9B, 0xC0F653E1), U64(0x2F2967B6, 0x6737E3ED), /* ~= 10^105 */ + U64(0x8B865B21, 0x5899F46C), U64(0xBD79E0D2, 0x0082EE74), /* ~= 10^106 */ + U64(0xAE67F1E9, 0xAEC07187), U64(0xECD85906, 0x80A3AA11), /* ~= 10^107 */ + U64(0xDA01EE64, 0x1A708DE9), U64(0xE80E6F48, 0x20CC9495), /* ~= 10^108 */ + U64(0x884134FE, 0x908658B2), U64(0x3109058D, 0x147FDCDD), /* ~= 10^109 */ + U64(0xAA51823E, 0x34A7EEDE), U64(0xBD4B46F0, 0x599FD415), /* ~= 10^110 */ + U64(0xD4E5E2CD, 0xC1D1EA96), U64(0x6C9E18AC, 0x7007C91A), /* ~= 10^111 */ + U64(0x850FADC0, 0x9923329E), U64(0x03E2CF6B, 0xC604DDB0), /* ~= 10^112 */ + U64(0xA6539930, 0xBF6BFF45), U64(0x84DB8346, 0xB786151C), /* ~= 10^113 */ + U64(0xCFE87F7C, 0xEF46FF16), U64(0xE6126418, 0x65679A63), /* ~= 10^114 */ + U64(0x81F14FAE, 0x158C5F6E), U64(0x4FCB7E8F, 0x3F60C07E), /* ~= 10^115 */ + U64(0xA26DA399, 0x9AEF7749), U64(0xE3BE5E33, 0x0F38F09D), /* ~= 10^116 */ + U64(0xCB090C80, 0x01AB551C), U64(0x5CADF5BF, 0xD3072CC5), /* ~= 10^117 */ + U64(0xFDCB4FA0, 0x02162A63), U64(0x73D9732F, 0xC7C8F7F6), /* ~= 10^118 */ + U64(0x9E9F11C4, 0x014DDA7E), U64(0x2867E7FD, 0xDCDD9AFA), /* ~= 10^119 */ + U64(0xC646D635, 0x01A1511D), U64(0xB281E1FD, 0x541501B8), /* ~= 10^120 */ + U64(0xF7D88BC2, 0x4209A565), U64(0x1F225A7C, 0xA91A4226), /* ~= 10^121 */ + U64(0x9AE75759, 0x6946075F), U64(0x3375788D, 0xE9B06958), /* ~= 10^122 */ + U64(0xC1A12D2F, 0xC3978937), U64(0x0052D6B1, 0x641C83AE), /* ~= 10^123 */ + U64(0xF209787B, 0xB47D6B84), U64(0xC0678C5D, 0xBD23A49A), /* ~= 10^124 */ + U64(0x9745EB4D, 0x50CE6332), U64(0xF840B7BA, 0x963646E0), /* ~= 10^125 */ + U64(0xBD176620, 0xA501FBFF), U64(0xB650E5A9, 0x3BC3D898), /* ~= 10^126 */ + U64(0xEC5D3FA8, 0xCE427AFF), U64(0xA3E51F13, 0x8AB4CEBE), /* ~= 10^127 */ + U64(0x93BA47C9, 0x80E98CDF), U64(0xC66F336C, 0x36B10137), /* ~= 10^128 */ + U64(0xB8A8D9BB, 0xE123F017), U64(0xB80B0047, 0x445D4184), /* ~= 10^129 */ + U64(0xE6D3102A, 0xD96CEC1D), U64(0xA60DC059, 0x157491E5), /* ~= 10^130 */ + U64(0x9043EA1A, 0xC7E41392), U64(0x87C89837, 0xAD68DB2F), /* ~= 10^131 */ + U64(0xB454E4A1, 0x79DD1877), U64(0x29BABE45, 0x98C311FB), /* ~= 10^132 */ + U64(0xE16A1DC9, 0xD8545E94), U64(0xF4296DD6, 0xFEF3D67A), /* ~= 10^133 */ + U64(0x8CE2529E, 0x2734BB1D), U64(0x1899E4A6, 0x5F58660C), /* ~= 10^134 */ + U64(0xB01AE745, 0xB101E9E4), U64(0x5EC05DCF, 0xF72E7F8F), /* ~= 10^135 */ + U64(0xDC21A117, 0x1D42645D), U64(0x76707543, 0xF4FA1F73), /* ~= 10^136 */ + U64(0x899504AE, 0x72497EBA), U64(0x6A06494A, 0x791C53A8), /* ~= 10^137 */ + U64(0xABFA45DA, 0x0EDBDE69), U64(0x0487DB9D, 0x17636892), /* ~= 10^138 */ + U64(0xD6F8D750, 0x9292D603), U64(0x45A9D284, 0x5D3C42B6), /* ~= 10^139 */ + U64(0x865B8692, 0x5B9BC5C2), U64(0x0B8A2392, 0xBA45A9B2), /* ~= 10^140 */ + U64(0xA7F26836, 0xF282B732), U64(0x8E6CAC77, 0x68D7141E), /* ~= 10^141 */ + U64(0xD1EF0244, 0xAF2364FF), U64(0x3207D795, 0x430CD926), /* ~= 10^142 */ + U64(0x8335616A, 0xED761F1F), U64(0x7F44E6BD, 0x49E807B8), /* ~= 10^143 */ + U64(0xA402B9C5, 0xA8D3A6E7), U64(0x5F16206C, 0x9C6209A6), /* ~= 10^144 */ + U64(0xCD036837, 0x130890A1), U64(0x36DBA887, 0xC37A8C0F), /* ~= 10^145 */ + U64(0x80222122, 0x6BE55A64), U64(0xC2494954, 0xDA2C9789), /* ~= 10^146 */ + U64(0xA02AA96B, 0x06DEB0FD), U64(0xF2DB9BAA, 0x10B7BD6C), /* ~= 10^147 */ + U64(0xC83553C5, 0xC8965D3D), U64(0x6F928294, 0x94E5ACC7), /* ~= 10^148 */ + U64(0xFA42A8B7, 0x3ABBF48C), U64(0xCB772339, 0xBA1F17F9), /* ~= 10^149 */ + U64(0x9C69A972, 0x84B578D7), U64(0xFF2A7604, 0x14536EFB), /* ~= 10^150 */ + U64(0xC38413CF, 0x25E2D70D), U64(0xFEF51385, 0x19684ABA), /* ~= 10^151 */ + U64(0xF46518C2, 0xEF5B8CD1), U64(0x7EB25866, 0x5FC25D69), /* ~= 10^152 */ + U64(0x98BF2F79, 0xD5993802), U64(0xEF2F773F, 0xFBD97A61), /* ~= 10^153 */ + U64(0xBEEEFB58, 0x4AFF8603), U64(0xAAFB550F, 0xFACFD8FA), /* ~= 10^154 */ + U64(0xEEAABA2E, 0x5DBF6784), U64(0x95BA2A53, 0xF983CF38), /* ~= 10^155 */ + U64(0x952AB45C, 0xFA97A0B2), U64(0xDD945A74, 0x7BF26183), /* ~= 10^156 */ + U64(0xBA756174, 0x393D88DF), U64(0x94F97111, 0x9AEEF9E4), /* ~= 10^157 */ + U64(0xE912B9D1, 0x478CEB17), U64(0x7A37CD56, 0x01AAB85D), /* ~= 10^158 */ + U64(0x91ABB422, 0xCCB812EE), U64(0xAC62E055, 0xC10AB33A), /* ~= 10^159 */ + U64(0xB616A12B, 0x7FE617AA), U64(0x577B986B, 0x314D6009), /* ~= 10^160 */ + U64(0xE39C4976, 0x5FDF9D94), U64(0xED5A7E85, 0xFDA0B80B), /* ~= 10^161 */ + U64(0x8E41ADE9, 0xFBEBC27D), U64(0x14588F13, 0xBE847307), /* ~= 10^162 */ + U64(0xB1D21964, 0x7AE6B31C), U64(0x596EB2D8, 0xAE258FC8), /* ~= 10^163 */ + U64(0xDE469FBD, 0x99A05FE3), U64(0x6FCA5F8E, 0xD9AEF3BB), /* ~= 10^164 */ + U64(0x8AEC23D6, 0x80043BEE), U64(0x25DE7BB9, 0x480D5854), /* ~= 10^165 */ + U64(0xADA72CCC, 0x20054AE9), U64(0xAF561AA7, 0x9A10AE6A), /* ~= 10^166 */ + U64(0xD910F7FF, 0x28069DA4), U64(0x1B2BA151, 0x8094DA04), /* ~= 10^167 */ + U64(0x87AA9AFF, 0x79042286), U64(0x90FB44D2, 0xF05D0842), /* ~= 10^168 */ + U64(0xA99541BF, 0x57452B28), U64(0x353A1607, 0xAC744A53), /* ~= 10^169 */ + U64(0xD3FA922F, 0x2D1675F2), U64(0x42889B89, 0x97915CE8), /* ~= 10^170 */ + U64(0x847C9B5D, 0x7C2E09B7), U64(0x69956135, 0xFEBADA11), /* ~= 10^171 */ + U64(0xA59BC234, 0xDB398C25), U64(0x43FAB983, 0x7E699095), /* ~= 10^172 */ + U64(0xCF02B2C2, 0x1207EF2E), U64(0x94F967E4, 0x5E03F4BB), /* ~= 10^173 */ + U64(0x8161AFB9, 0x4B44F57D), U64(0x1D1BE0EE, 0xBAC278F5), /* ~= 10^174 */ + U64(0xA1BA1BA7, 0x9E1632DC), U64(0x6462D92A, 0x69731732), /* ~= 10^175 */ + U64(0xCA28A291, 0x859BBF93), U64(0x7D7B8F75, 0x03CFDCFE), /* ~= 10^176 */ + U64(0xFCB2CB35, 0xE702AF78), U64(0x5CDA7352, 0x44C3D43E), /* ~= 10^177 */ + U64(0x9DEFBF01, 0xB061ADAB), U64(0x3A088813, 0x6AFA64A7), /* ~= 10^178 */ + U64(0xC56BAEC2, 0x1C7A1916), U64(0x088AAA18, 0x45B8FDD0), /* ~= 10^179 */ + U64(0xF6C69A72, 0xA3989F5B), U64(0x8AAD549E, 0x57273D45), /* ~= 10^180 */ + U64(0x9A3C2087, 0xA63F6399), U64(0x36AC54E2, 0xF678864B), /* ~= 10^181 */ + U64(0xC0CB28A9, 0x8FCF3C7F), U64(0x84576A1B, 0xB416A7DD), /* ~= 10^182 */ + U64(0xF0FDF2D3, 0xF3C30B9F), U64(0x656D44A2, 0xA11C51D5), /* ~= 10^183 */ + U64(0x969EB7C4, 0x7859E743), U64(0x9F644AE5, 0xA4B1B325), /* ~= 10^184 */ + U64(0xBC4665B5, 0x96706114), U64(0x873D5D9F, 0x0DDE1FEE), /* ~= 10^185 */ + U64(0xEB57FF22, 0xFC0C7959), U64(0xA90CB506, 0xD155A7EA), /* ~= 10^186 */ + U64(0x9316FF75, 0xDD87CBD8), U64(0x09A7F124, 0x42D588F2), /* ~= 10^187 */ + U64(0xB7DCBF53, 0x54E9BECE), U64(0x0C11ED6D, 0x538AEB2F), /* ~= 10^188 */ + U64(0xE5D3EF28, 0x2A242E81), U64(0x8F1668C8, 0xA86DA5FA), /* ~= 10^189 */ + U64(0x8FA47579, 0x1A569D10), U64(0xF96E017D, 0x694487BC), /* ~= 10^190 */ + U64(0xB38D92D7, 0x60EC4455), U64(0x37C981DC, 0xC395A9AC), /* ~= 10^191 */ + U64(0xE070F78D, 0x3927556A), U64(0x85BBE253, 0xF47B1417), /* ~= 10^192 */ + U64(0x8C469AB8, 0x43B89562), U64(0x93956D74, 0x78CCEC8E), /* ~= 10^193 */ + U64(0xAF584166, 0x54A6BABB), U64(0x387AC8D1, 0x970027B2), /* ~= 10^194 */ + U64(0xDB2E51BF, 0xE9D0696A), U64(0x06997B05, 0xFCC0319E), /* ~= 10^195 */ + U64(0x88FCF317, 0xF22241E2), U64(0x441FECE3, 0xBDF81F03), /* ~= 10^196 */ + U64(0xAB3C2FDD, 0xEEAAD25A), U64(0xD527E81C, 0xAD7626C3), /* ~= 10^197 */ + U64(0xD60B3BD5, 0x6A5586F1), U64(0x8A71E223, 0xD8D3B074), /* ~= 10^198 */ + U64(0x85C70565, 0x62757456), U64(0xF6872D56, 0x67844E49), /* ~= 10^199 */ + U64(0xA738C6BE, 0xBB12D16C), U64(0xB428F8AC, 0x016561DB), /* ~= 10^200 */ + U64(0xD106F86E, 0x69D785C7), U64(0xE13336D7, 0x01BEBA52), /* ~= 10^201 */ + U64(0x82A45B45, 0x0226B39C), U64(0xECC00246, 0x61173473), /* ~= 10^202 */ + U64(0xA34D7216, 0x42B06084), U64(0x27F002D7, 0xF95D0190), /* ~= 10^203 */ + U64(0xCC20CE9B, 0xD35C78A5), U64(0x31EC038D, 0xF7B441F4), /* ~= 10^204 */ + U64(0xFF290242, 0xC83396CE), U64(0x7E670471, 0x75A15271), /* ~= 10^205 */ + U64(0x9F79A169, 0xBD203E41), U64(0x0F0062C6, 0xE984D386), /* ~= 10^206 */ + U64(0xC75809C4, 0x2C684DD1), U64(0x52C07B78, 0xA3E60868), /* ~= 10^207 */ + U64(0xF92E0C35, 0x37826145), U64(0xA7709A56, 0xCCDF8A82), /* ~= 10^208 */ + U64(0x9BBCC7A1, 0x42B17CCB), U64(0x88A66076, 0x400BB691), /* ~= 10^209 */ + U64(0xC2ABF989, 0x935DDBFE), U64(0x6ACFF893, 0xD00EA435), /* ~= 10^210 */ + U64(0xF356F7EB, 0xF83552FE), U64(0x0583F6B8, 0xC4124D43), /* ~= 10^211 */ + U64(0x98165AF3, 0x7B2153DE), U64(0xC3727A33, 0x7A8B704A), /* ~= 10^212 */ + U64(0xBE1BF1B0, 0x59E9A8D6), U64(0x744F18C0, 0x592E4C5C), /* ~= 10^213 */ + U64(0xEDA2EE1C, 0x7064130C), U64(0x1162DEF0, 0x6F79DF73), /* ~= 10^214 */ + U64(0x9485D4D1, 0xC63E8BE7), U64(0x8ADDCB56, 0x45AC2BA8), /* ~= 10^215 */ + U64(0xB9A74A06, 0x37CE2EE1), U64(0x6D953E2B, 0xD7173692), /* ~= 10^216 */ + U64(0xE8111C87, 0xC5C1BA99), U64(0xC8FA8DB6, 0xCCDD0437), /* ~= 10^217 */ + U64(0x910AB1D4, 0xDB9914A0), U64(0x1D9C9892, 0x400A22A2), /* ~= 10^218 */ + U64(0xB54D5E4A, 0x127F59C8), U64(0x2503BEB6, 0xD00CAB4B), /* ~= 10^219 */ + U64(0xE2A0B5DC, 0x971F303A), U64(0x2E44AE64, 0x840FD61D), /* ~= 10^220 */ + U64(0x8DA471A9, 0xDE737E24), U64(0x5CEAECFE, 0xD289E5D2), /* ~= 10^221 */ + U64(0xB10D8E14, 0x56105DAD), U64(0x7425A83E, 0x872C5F47), /* ~= 10^222 */ + U64(0xDD50F199, 0x6B947518), U64(0xD12F124E, 0x28F77719), /* ~= 10^223 */ + U64(0x8A5296FF, 0xE33CC92F), U64(0x82BD6B70, 0xD99AAA6F), /* ~= 10^224 */ + U64(0xACE73CBF, 0xDC0BFB7B), U64(0x636CC64D, 0x1001550B), /* ~= 10^225 */ + U64(0xD8210BEF, 0xD30EFA5A), U64(0x3C47F7E0, 0x5401AA4E), /* ~= 10^226 */ + U64(0x8714A775, 0xE3E95C78), U64(0x65ACFAEC, 0x34810A71), /* ~= 10^227 */ + U64(0xA8D9D153, 0x5CE3B396), U64(0x7F1839A7, 0x41A14D0D), /* ~= 10^228 */ + U64(0xD31045A8, 0x341CA07C), U64(0x1EDE4811, 0x1209A050), /* ~= 10^229 */ + U64(0x83EA2B89, 0x2091E44D), U64(0x934AED0A, 0xAB460432), /* ~= 10^230 */ + U64(0xA4E4B66B, 0x68B65D60), U64(0xF81DA84D, 0x5617853F), /* ~= 10^231 */ + U64(0xCE1DE406, 0x42E3F4B9), U64(0x36251260, 0xAB9D668E), /* ~= 10^232 */ + U64(0x80D2AE83, 0xE9CE78F3), U64(0xC1D72B7C, 0x6B426019), /* ~= 10^233 */ + U64(0xA1075A24, 0xE4421730), U64(0xB24CF65B, 0x8612F81F), /* ~= 10^234 */ + U64(0xC94930AE, 0x1D529CFC), U64(0xDEE033F2, 0x6797B627), /* ~= 10^235 */ + U64(0xFB9B7CD9, 0xA4A7443C), U64(0x169840EF, 0x017DA3B1), /* ~= 10^236 */ + U64(0x9D412E08, 0x06E88AA5), U64(0x8E1F2895, 0x60EE864E), /* ~= 10^237 */ + U64(0xC491798A, 0x08A2AD4E), U64(0xF1A6F2BA, 0xB92A27E2), /* ~= 10^238 */ + U64(0xF5B5D7EC, 0x8ACB58A2), U64(0xAE10AF69, 0x6774B1DB), /* ~= 10^239 */ + U64(0x9991A6F3, 0xD6BF1765), U64(0xACCA6DA1, 0xE0A8EF29), /* ~= 10^240 */ + U64(0xBFF610B0, 0xCC6EDD3F), U64(0x17FD090A, 0x58D32AF3), /* ~= 10^241 */ + U64(0xEFF394DC, 0xFF8A948E), U64(0xDDFC4B4C, 0xEF07F5B0), /* ~= 10^242 */ + U64(0x95F83D0A, 0x1FB69CD9), U64(0x4ABDAF10, 0x1564F98E), /* ~= 10^243 */ + U64(0xBB764C4C, 0xA7A4440F), U64(0x9D6D1AD4, 0x1ABE37F1), /* ~= 10^244 */ + U64(0xEA53DF5F, 0xD18D5513), U64(0x84C86189, 0x216DC5ED), /* ~= 10^245 */ + U64(0x92746B9B, 0xE2F8552C), U64(0x32FD3CF5, 0xB4E49BB4), /* ~= 10^246 */ + U64(0xB7118682, 0xDBB66A77), U64(0x3FBC8C33, 0x221DC2A1), /* ~= 10^247 */ + U64(0xE4D5E823, 0x92A40515), U64(0x0FABAF3F, 0xEAA5334A), /* ~= 10^248 */ + U64(0x8F05B116, 0x3BA6832D), U64(0x29CB4D87, 0xF2A7400E), /* ~= 10^249 */ + U64(0xB2C71D5B, 0xCA9023F8), U64(0x743E20E9, 0xEF511012), /* ~= 10^250 */ + U64(0xDF78E4B2, 0xBD342CF6), U64(0x914DA924, 0x6B255416), /* ~= 10^251 */ + U64(0x8BAB8EEF, 0xB6409C1A), U64(0x1AD089B6, 0xC2F7548E), /* ~= 10^252 */ + U64(0xAE9672AB, 0xA3D0C320), U64(0xA184AC24, 0x73B529B1), /* ~= 10^253 */ + U64(0xDA3C0F56, 0x8CC4F3E8), U64(0xC9E5D72D, 0x90A2741E), /* ~= 10^254 */ + U64(0x88658996, 0x17FB1871), U64(0x7E2FA67C, 0x7A658892), /* ~= 10^255 */ + U64(0xAA7EEBFB, 0x9DF9DE8D), U64(0xDDBB901B, 0x98FEEAB7), /* ~= 10^256 */ + U64(0xD51EA6FA, 0x85785631), U64(0x552A7422, 0x7F3EA565), /* ~= 10^257 */ + U64(0x8533285C, 0x936B35DE), U64(0xD53A8895, 0x8F87275F), /* ~= 10^258 */ + U64(0xA67FF273, 0xB8460356), U64(0x8A892ABA, 0xF368F137), /* ~= 10^259 */ + U64(0xD01FEF10, 0xA657842C), U64(0x2D2B7569, 0xB0432D85), /* ~= 10^260 */ + U64(0x8213F56A, 0x67F6B29B), U64(0x9C3B2962, 0x0E29FC73), /* ~= 10^261 */ + U64(0xA298F2C5, 0x01F45F42), U64(0x8349F3BA, 0x91B47B8F), /* ~= 10^262 */ + U64(0xCB3F2F76, 0x42717713), U64(0x241C70A9, 0x36219A73), /* ~= 10^263 */ + U64(0xFE0EFB53, 0xD30DD4D7), U64(0xED238CD3, 0x83AA0110), /* ~= 10^264 */ + U64(0x9EC95D14, 0x63E8A506), U64(0xF4363804, 0x324A40AA), /* ~= 10^265 */ + U64(0xC67BB459, 0x7CE2CE48), U64(0xB143C605, 0x3EDCD0D5), /* ~= 10^266 */ + U64(0xF81AA16F, 0xDC1B81DA), U64(0xDD94B786, 0x8E94050A), /* ~= 10^267 */ + U64(0x9B10A4E5, 0xE9913128), U64(0xCA7CF2B4, 0x191C8326), /* ~= 10^268 */ + U64(0xC1D4CE1F, 0x63F57D72), U64(0xFD1C2F61, 0x1F63A3F0), /* ~= 10^269 */ + U64(0xF24A01A7, 0x3CF2DCCF), U64(0xBC633B39, 0x673C8CEC), /* ~= 10^270 */ + U64(0x976E4108, 0x8617CA01), U64(0xD5BE0503, 0xE085D813), /* ~= 10^271 */ + U64(0xBD49D14A, 0xA79DBC82), U64(0x4B2D8644, 0xD8A74E18), /* ~= 10^272 */ + U64(0xEC9C459D, 0x51852BA2), U64(0xDDF8E7D6, 0x0ED1219E), /* ~= 10^273 */ + U64(0x93E1AB82, 0x52F33B45), U64(0xCABB90E5, 0xC942B503), /* ~= 10^274 */ + U64(0xB8DA1662, 0xE7B00A17), U64(0x3D6A751F, 0x3B936243), /* ~= 10^275 */ + U64(0xE7109BFB, 0xA19C0C9D), U64(0x0CC51267, 0x0A783AD4), /* ~= 10^276 */ + U64(0x906A617D, 0x450187E2), U64(0x27FB2B80, 0x668B24C5), /* ~= 10^277 */ + U64(0xB484F9DC, 0x9641E9DA), U64(0xB1F9F660, 0x802DEDF6), /* ~= 10^278 */ + U64(0xE1A63853, 0xBBD26451), U64(0x5E7873F8, 0xA0396973), /* ~= 10^279 */ + U64(0x8D07E334, 0x55637EB2), U64(0xDB0B487B, 0x6423E1E8), /* ~= 10^280 */ + U64(0xB049DC01, 0x6ABC5E5F), U64(0x91CE1A9A, 0x3D2CDA62), /* ~= 10^281 */ + U64(0xDC5C5301, 0xC56B75F7), U64(0x7641A140, 0xCC7810FB), /* ~= 10^282 */ + U64(0x89B9B3E1, 0x1B6329BA), U64(0xA9E904C8, 0x7FCB0A9D), /* ~= 10^283 */ + U64(0xAC2820D9, 0x623BF429), U64(0x546345FA, 0x9FBDCD44), /* ~= 10^284 */ + U64(0xD732290F, 0xBACAF133), U64(0xA97C1779, 0x47AD4095), /* ~= 10^285 */ + U64(0x867F59A9, 0xD4BED6C0), U64(0x49ED8EAB, 0xCCCC485D), /* ~= 10^286 */ + U64(0xA81F3014, 0x49EE8C70), U64(0x5C68F256, 0xBFFF5A74), /* ~= 10^287 */ + U64(0xD226FC19, 0x5C6A2F8C), U64(0x73832EEC, 0x6FFF3111), /* ~= 10^288 */ + U64(0x83585D8F, 0xD9C25DB7), U64(0xC831FD53, 0xC5FF7EAB), /* ~= 10^289 */ + U64(0xA42E74F3, 0xD032F525), U64(0xBA3E7CA8, 0xB77F5E55), /* ~= 10^290 */ + U64(0xCD3A1230, 0xC43FB26F), U64(0x28CE1BD2, 0xE55F35EB), /* ~= 10^291 */ + U64(0x80444B5E, 0x7AA7CF85), U64(0x7980D163, 0xCF5B81B3), /* ~= 10^292 */ + U64(0xA0555E36, 0x1951C366), U64(0xD7E105BC, 0xC332621F), /* ~= 10^293 */ + U64(0xC86AB5C3, 0x9FA63440), U64(0x8DD9472B, 0xF3FEFAA7), /* ~= 10^294 */ + U64(0xFA856334, 0x878FC150), U64(0xB14F98F6, 0xF0FEB951), /* ~= 10^295 */ + U64(0x9C935E00, 0xD4B9D8D2), U64(0x6ED1BF9A, 0x569F33D3), /* ~= 10^296 */ + U64(0xC3B83581, 0x09E84F07), U64(0x0A862F80, 0xEC4700C8), /* ~= 10^297 */ + U64(0xF4A642E1, 0x4C6262C8), U64(0xCD27BB61, 0x2758C0FA), /* ~= 10^298 */ + U64(0x98E7E9CC, 0xCFBD7DBD), U64(0x8038D51C, 0xB897789C), /* ~= 10^299 */ + U64(0xBF21E440, 0x03ACDD2C), U64(0xE0470A63, 0xE6BD56C3), /* ~= 10^300 */ + U64(0xEEEA5D50, 0x04981478), U64(0x1858CCFC, 0xE06CAC74), /* ~= 10^301 */ + U64(0x95527A52, 0x02DF0CCB), U64(0x0F37801E, 0x0C43EBC8), /* ~= 10^302 */ + U64(0xBAA718E6, 0x8396CFFD), U64(0xD3056025, 0x8F54E6BA), /* ~= 10^303 */ + U64(0xE950DF20, 0x247C83FD), U64(0x47C6B82E, 0xF32A2069), /* ~= 10^304 */ + U64(0x91D28B74, 0x16CDD27E), U64(0x4CDC331D, 0x57FA5441), /* ~= 10^305 */ + U64(0xB6472E51, 0x1C81471D), U64(0xE0133FE4, 0xADF8E952), /* ~= 10^306 */ + U64(0xE3D8F9E5, 0x63A198E5), U64(0x58180FDD, 0xD97723A6), /* ~= 10^307 */ + U64(0x8E679C2F, 0x5E44FF8F), U64(0x570F09EA, 0xA7EA7648), /* ~= 10^308 */ + U64(0xB201833B, 0x35D63F73), U64(0x2CD2CC65, 0x51E513DA), /* ~= 10^309 */ + U64(0xDE81E40A, 0x034BCF4F), U64(0xF8077F7E, 0xA65E58D1), /* ~= 10^310 */ + U64(0x8B112E86, 0x420F6191), U64(0xFB04AFAF, 0x27FAF782), /* ~= 10^311 */ + U64(0xADD57A27, 0xD29339F6), U64(0x79C5DB9A, 0xF1F9B563), /* ~= 10^312 */ + U64(0xD94AD8B1, 0xC7380874), U64(0x18375281, 0xAE7822BC), /* ~= 10^313 */ + U64(0x87CEC76F, 0x1C830548), U64(0x8F229391, 0x0D0B15B5), /* ~= 10^314 */ + U64(0xA9C2794A, 0xE3A3C69A), U64(0xB2EB3875, 0x504DDB22), /* ~= 10^315 */ + U64(0xD433179D, 0x9C8CB841), U64(0x5FA60692, 0xA46151EB), /* ~= 10^316 */ + U64(0x849FEEC2, 0x81D7F328), U64(0xDBC7C41B, 0xA6BCD333), /* ~= 10^317 */ + U64(0xA5C7EA73, 0x224DEFF3), U64(0x12B9B522, 0x906C0800), /* ~= 10^318 */ + U64(0xCF39E50F, 0xEAE16BEF), U64(0xD768226B, 0x34870A00), /* ~= 10^319 */ + U64(0x81842F29, 0xF2CCE375), U64(0xE6A11583, 0x00D46640), /* ~= 10^320 */ + U64(0xA1E53AF4, 0x6F801C53), U64(0x60495AE3, 0xC1097FD0), /* ~= 10^321 */ + U64(0xCA5E89B1, 0x8B602368), U64(0x385BB19C, 0xB14BDFC4), /* ~= 10^322 */ + U64(0xFCF62C1D, 0xEE382C42), U64(0x46729E03, 0xDD9ED7B5), /* ~= 10^323 */ + U64(0x9E19DB92, 0xB4E31BA9), U64(0x6C07A2C2, 0x6A8346D1) /* ~= 10^324 */ +}; + +/** + Get the cached pow10 value from `pow10_sig_table`. + @param exp10 The exponent of pow(10, e). This value must in range + `POW10_SIG_TABLE_MIN_EXP` to `POW10_SIG_TABLE_MAX_EXP`. + @param hi The highest 64 bits of pow(10, e). + @param lo The lower 64 bits after `hi`. + */ +static_inline void pow10_table_get_sig(i32 exp10, u64 *hi, u64 *lo) { + i32 idx = exp10 - (POW10_SIG_TABLE_MIN_EXP); + *hi = pow10_sig_table[idx * 2]; + *lo = pow10_sig_table[idx * 2 + 1]; +} + +/** + Get the exponent (base 2) for highest 64 bits significand in `pow10_sig_table`. + */ +static_inline void pow10_table_get_exp(i32 exp10, i32 *exp2) { + /* e2 = floor(log2(pow(10, e))) - 64 + 1 */ + /* = floor(e * log2(10) - 63) */ + *exp2 = (exp10 * 217706 - 4128768) >> 16; +} + +#endif + + + +/*============================================================================== + * MARK: - Number and Bit Utils (Private) + *============================================================================*/ + +/** Convert bits to double. */ +static_inline f64 f64_from_bits(u64 u) { + f64 f; + memcpy(&f, &u, sizeof(u)); + return f; +} + +/** Convert double to bits. */ +static_inline u64 f64_to_bits(f64 f) { + u64 u; + memcpy(&u, &f, sizeof(u)); + return u; +} + +/** Convert double to bits. */ +static_inline u32 f32_to_bits(f32 f) { + u32 u; + memcpy(&u, &f, sizeof(u)); + return u; +} + +/** Get 'infinity' bits with sign. */ +static_inline u64 f64_bits_inf(bool sign) { +#if YYJSON_HAS_IEEE_754 + return F64_BITS_INF | ((u64)sign << 63); +#elif defined(INFINITY) + return f64_to_bits(sign ? -INFINITY : INFINITY); +#else + return f64_to_bits(sign ? -HUGE_VAL : HUGE_VAL); +#endif +} + +/** Get 'nan' bits with sign. */ +static_inline u64 f64_bits_nan(bool sign) { +#if YYJSON_HAS_IEEE_754 + return F64_BITS_NAN | ((u64)sign << 63); +#elif defined(NAN) + return f64_to_bits(sign ? (f64)-NAN : (f64)NAN); +#else + return f64_to_bits((sign ? -0.0 : 0.0) / 0.0); +#endif +} + +/** Casting double to float, allow overflow. */ +#if yyjson_has_attribute(no_sanitize) +__attribute__((no_sanitize("undefined"))) +#elif yyjson_gcc_available(4, 9, 0) +__attribute__((__no_sanitize_undefined__)) +#endif +static_inline f32 f64_to_f32(f64 val) { + return (f32)val; +} + +/** Returns the number of leading 0-bits in value (input should not be 0). */ +static_inline u32 u64_lz_bits(u64 v) { +#if GCC_HAS_CLZLL + return (u32)__builtin_clzll(v); +#elif MSC_HAS_BIT_SCAN_64 + unsigned long r; + _BitScanReverse64(&r, v); + return (u32)63 - (u32)r; +#elif MSC_HAS_BIT_SCAN + unsigned long hi, lo; + bool hi_set = _BitScanReverse(&hi, (u32)(v >> 32)) != 0; + _BitScanReverse(&lo, (u32)v); + hi |= 32; + return (u32)63 - (u32)(hi_set ? hi : lo); +#else + /* branchless, use De Bruijn sequence */ + /* see: https://www.chessprogramming.org/BitScan */ + const u8 table[64] = { + 63, 16, 62, 7, 15, 36, 61, 3, 6, 14, 22, 26, 35, 47, 60, 2, + 9, 5, 28, 11, 13, 21, 42, 19, 25, 31, 34, 40, 46, 52, 59, 1, + 17, 8, 37, 4, 23, 27, 48, 10, 29, 12, 43, 20, 32, 41, 53, 18, + 38, 24, 49, 30, 44, 33, 54, 39, 50, 45, 55, 51, 56, 57, 58, 0 + }; + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + v |= v >> 32; + return table[(v * U64(0x03F79D71, 0xB4CB0A89)) >> 58]; +#endif +} + +/** Returns the number of trailing 0-bits in value (input should not be 0). */ +static_inline u32 u64_tz_bits(u64 v) { +#if GCC_HAS_CTZLL + return (u32)__builtin_ctzll(v); +#elif MSC_HAS_BIT_SCAN_64 + unsigned long r; + _BitScanForward64(&r, v); + return (u32)r; +#elif MSC_HAS_BIT_SCAN + unsigned long lo, hi; + bool lo_set = _BitScanForward(&lo, (u32)(v)) != 0; + _BitScanForward(&hi, (u32)(v >> 32)); + hi += 32; + return lo_set ? lo : hi; +#else + /* branchless, use De Bruijn sequence */ + /* see: https://www.chessprogramming.org/BitScan */ + const u8 table[64] = { + 0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28, + 62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11, + 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10, + 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12 + }; + return table[((v & (~v + 1)) * U64(0x022FDD63, 0xCC95386D)) >> 58]; +#endif +} + +/** Multiplies two 64-bit unsigned integers (a * b), + returns the 128-bit result as 'hi' and 'lo'. */ +static_inline void u128_mul(u64 a, u64 b, u64 *hi, u64 *lo) { +#if YYJSON_HAS_INT128 + u128 m = (u128)a * b; + *hi = (u64)(m >> 64); + *lo = (u64)(m); +#elif MSC_HAS_UMUL128 + *lo = _umul128(a, b, hi); +#else + u32 a0 = (u32)(a), a1 = (u32)(a >> 32); + u32 b0 = (u32)(b), b1 = (u32)(b >> 32); + u64 p00 = (u64)a0 * b0, p01 = (u64)a0 * b1; + u64 p10 = (u64)a1 * b0, p11 = (u64)a1 * b1; + u64 m0 = p01 + (p00 >> 32); + u32 m00 = (u32)(m0), m01 = (u32)(m0 >> 32); + u64 m1 = p10 + m00; + u32 m10 = (u32)(m1), m11 = (u32)(m1 >> 32); + *hi = p11 + m01 + m11; + *lo = ((u64)m10 << 32) | (u32)p00; +#endif +} + +/** Multiplies two 64-bit unsigned integers and add a value (a * b + c), + returns the 128-bit result as 'hi' and 'lo'. */ +static_inline void u128_mul_add(u64 a, u64 b, u64 c, u64 *hi, u64 *lo) { +#if YYJSON_HAS_INT128 + u128 m = (u128)a * b + c; + *hi = (u64)(m >> 64); + *lo = (u64)(m); +#else + u64 h, l, t; + u128_mul(a, b, &h, &l); + t = l + c; + h += (u64)(((t < l) | (t < c))); + *hi = h; + *lo = t; +#endif +} + + + +/*============================================================================== + * MARK: - File Utils (Private) + * These functions are used to read and write JSON files. + *============================================================================*/ + +#define YYJSON_FOPEN_E +#if !defined(_MSC_VER) && defined(__GLIBC__) && defined(__GLIBC_PREREQ) +# if __GLIBC_PREREQ(2, 7) +# undef YYJSON_FOPEN_E +# define YYJSON_FOPEN_E "e" /* glibc extension to enable O_CLOEXEC */ +# endif +#endif + +static_inline FILE *fopen_safe(const char *path, const char *mode) { +#if YYJSON_MSC_VER >= 1400 + FILE *file = NULL; + if (fopen_s(&file, path, mode) != 0) return NULL; + return file; +#else + return fopen(path, mode); +#endif +} + +static_inline FILE *fopen_readonly(const char *path) { + return fopen_safe(path, "rb" YYJSON_FOPEN_E); +} + +static_inline FILE *fopen_writeonly(const char *path) { + return fopen_safe(path, "wb" YYJSON_FOPEN_E); +} + +static_inline usize fread_safe(void *buf, usize size, FILE *file) { +#if YYJSON_MSC_VER >= 1400 + return fread_s(buf, size, 1, size, file); +#else + return fread(buf, 1, size, file); +#endif +} + + + +/*============================================================================== + * MARK: - Size Utils (Private) + * These functions are used for memory allocation. + *============================================================================*/ + +/** Returns whether the size is overflow after increment. */ +static_inline bool size_add_is_overflow(usize size, usize add) { + return size > (size + add); +} + +/** Returns whether the size is power of 2 (size should not be 0). */ +static_inline bool size_is_pow2(usize size) { + return (size & (size - 1)) == 0; +} + +/** Align size upwards (may overflow). */ +static_inline usize size_align_up(usize size, usize align) { + if (size_is_pow2(align)) { + return (size + (align - 1)) & ~(align - 1); + } else { + return size + align - (size + align - 1) % align - 1; + } +} + +/** Align size downwards. */ +static_inline usize size_align_down(usize size, usize align) { + if (size_is_pow2(align)) { + return size & ~(align - 1); + } else { + return size - (size % align); + } +} + +/** Align address upwards (may overflow). */ +static_inline void *mem_align_up(void *mem, usize align) { + usize size; + memcpy(&size, &mem, sizeof(usize)); + size = size_align_up(size, align); + memcpy(&mem, &size, sizeof(usize)); + return mem; +} + + + +/*============================================================================== + * MARK: - Default Memory Allocator (Private) + * This is a simple libc memory allocator wrapper. + *============================================================================*/ + +static void *default_malloc(void *ctx, usize size) { + return malloc(size); +} + +static void *default_realloc(void *ctx, void *ptr, usize old_size, usize size) { + return realloc(ptr, size); +} + +static void default_free(void *ctx, void *ptr) { + free(ptr); +} + +static const yyjson_alc YYJSON_DEFAULT_ALC = { + default_malloc, default_realloc, default_free, NULL +}; + + + +/*============================================================================== + * MARK: - Null Memory Allocator (Private) + * This allocator is just a placeholder to ensure that the internal + * malloc/realloc/free function pointers are not null. + *============================================================================*/ + +static void *null_malloc(void *ctx, usize size) { + return NULL; +} + +static void *null_realloc(void *ctx, void *ptr, usize old_size, usize size) { + return NULL; +} + +static void null_free(void *ctx, void *ptr) { + return; +} + +static const yyjson_alc YYJSON_NULL_ALC = { + null_malloc, null_realloc, null_free, NULL +}; + + + +/*============================================================================== + * MARK: - Pool Memory Allocator (Public) + * This allocator is initialized with a fixed-size buffer. + * The buffer is split into multiple memory chunks for memory allocation. + *============================================================================*/ + +/** memory chunk header */ +typedef struct pool_chunk { + usize size; /* chunk memory size, include chunk header */ + struct pool_chunk *next; /* linked list, nullable */ + /* char mem[]; flexible array member */ +} pool_chunk; + +/** allocator ctx header */ +typedef struct pool_ctx { + usize size; /* total memory size, include ctx header */ + pool_chunk *free_list; /* linked list, nullable */ + /* pool_chunk chunks[]; flexible array member */ +} pool_ctx; + +/** align up the input size to chunk size */ +static_inline void pool_size_align(usize *size) { + *size = size_align_up(*size, sizeof(pool_chunk)) + sizeof(pool_chunk); +} + +static void *pool_malloc(void *ctx_ptr, usize size) { + /* assert(size != 0) */ + pool_ctx *ctx = (pool_ctx *)ctx_ptr; + pool_chunk *next, *prev = NULL, *cur = ctx->free_list; + + if (unlikely(size >= ctx->size)) return NULL; + pool_size_align(&size); + + while (cur) { + if (cur->size < size) { + /* not enough space, try next chunk */ + prev = cur; + cur = cur->next; + continue; + } + if (cur->size >= size + sizeof(pool_chunk) * 2) { + /* too much space, split this chunk */ + next = (pool_chunk *)(void *)((u8 *)cur + size); + next->size = cur->size - size; + next->next = cur->next; + cur->size = size; + } else { + /* just enough space, use whole chunk */ + next = cur->next; + } + if (prev) prev->next = next; + else ctx->free_list = next; + return (void *)(cur + 1); + } + return NULL; +} + +static void pool_free(void *ctx_ptr, void *ptr) { + /* assert(ptr != NULL) */ + pool_ctx *ctx = (pool_ctx *)ctx_ptr; + pool_chunk *cur = ((pool_chunk *)ptr) - 1; + pool_chunk *prev = NULL, *next = ctx->free_list; + + while (next && next < cur) { + prev = next; + next = next->next; + } + if (prev) prev->next = cur; + else ctx->free_list = cur; + cur->next = next; + + if (next && ((u8 *)cur + cur->size) == (u8 *)next) { + /* merge cur to higher chunk */ + cur->size += next->size; + cur->next = next->next; + } + if (prev && ((u8 *)prev + prev->size) == (u8 *)cur) { + /* merge cur to lower chunk */ + prev->size += cur->size; + prev->next = cur->next; + } +} + +static void *pool_realloc(void *ctx_ptr, void *ptr, + usize old_size, usize size) { + /* assert(ptr != NULL && size != 0 && old_size < size) */ + pool_ctx *ctx = (pool_ctx *)ctx_ptr; + pool_chunk *cur = ((pool_chunk *)ptr) - 1, *prev, *next, *tmp; + + /* check size */ + if (unlikely(size >= ctx->size)) return NULL; + pool_size_align(&old_size); + pool_size_align(&size); + if (unlikely(old_size == size)) return ptr; + + /* find next and prev chunk */ + prev = NULL; + next = ctx->free_list; + while (next && next < cur) { + prev = next; + next = next->next; + } + + if ((u8 *)cur + cur->size == (u8 *)next && cur->size + next->size >= size) { + /* merge to higher chunk if they are contiguous */ + usize free_size = cur->size + next->size - size; + if (free_size > sizeof(pool_chunk) * 2) { + tmp = (pool_chunk *)(void *)((u8 *)cur + size); + if (prev) prev->next = tmp; + else ctx->free_list = tmp; + tmp->next = next->next; + tmp->size = free_size; + cur->size = size; + } else { + if (prev) prev->next = next->next; + else ctx->free_list = next->next; + cur->size += next->size; + } + return ptr; + } else { + /* fallback to malloc and memcpy */ + void *new_ptr = pool_malloc(ctx_ptr, size - sizeof(pool_chunk)); + if (new_ptr) { + memcpy(new_ptr, ptr, cur->size - sizeof(pool_chunk)); + pool_free(ctx_ptr, ptr); + } + return new_ptr; + } +} + +bool yyjson_alc_pool_init(yyjson_alc *alc, void *buf, usize size) { + pool_chunk *chunk; + pool_ctx *ctx; + + if (unlikely(!alc)) return false; + *alc = YYJSON_NULL_ALC; + if (size < sizeof(pool_ctx) * 4) return false; + ctx = (pool_ctx *)mem_align_up(buf, sizeof(pool_ctx)); + if (unlikely(!ctx)) return false; + size -= (usize)((u8 *)ctx - (u8 *)buf); + size = size_align_down(size, sizeof(pool_ctx)); + + chunk = (pool_chunk *)(ctx + 1); + chunk->size = size - sizeof(pool_ctx); + chunk->next = NULL; + ctx->size = size; + ctx->free_list = chunk; + + alc->malloc = pool_malloc; + alc->realloc = pool_realloc; + alc->free = pool_free; + alc->ctx = (void *)ctx; + return true; +} + + + +/*============================================================================== + * MARK: - Dynamic Memory Allocator (Public) + * This allocator allocates memory on demand and does not immediately release + * unused memory. Instead, it places the unused memory into a freelist for + * potential reuse in the future. It is only when the entire allocator is + * destroyed that all previously allocated memory is released at once. + *============================================================================*/ + +/** memory chunk header */ +typedef struct dyn_chunk { + usize size; /* chunk size, include header */ + struct dyn_chunk *next; + /* char mem[]; flexible array member */ +} dyn_chunk; + +/** allocator ctx header */ +typedef struct { + dyn_chunk free_list; /* dummy header, sorted from small to large */ + dyn_chunk used_list; /* dummy header */ +} dyn_ctx; + +/** align up the input size to chunk size */ +static_inline bool dyn_size_align(usize *size) { + usize alc_size = *size + sizeof(dyn_chunk); + alc_size = size_align_up(alc_size, YYJSON_ALC_DYN_MIN_SIZE); + if (unlikely(alc_size < *size)) return false; /* overflow */ + *size = alc_size; + return true; +} + +/** remove a chunk from list (the chunk must already be in the list) */ +static_inline void dyn_chunk_list_remove(dyn_chunk *list, dyn_chunk *chunk) { + dyn_chunk *prev = list, *cur; + for (cur = prev->next; cur; cur = cur->next) { + if (cur == chunk) { + prev->next = cur->next; + cur->next = NULL; + return; + } + prev = cur; + } +} + +/** add a chunk to list header (the chunk must not be in the list) */ +static_inline void dyn_chunk_list_add(dyn_chunk *list, dyn_chunk *chunk) { + chunk->next = list->next; + list->next = chunk; +} + +static void *dyn_malloc(void *ctx_ptr, usize size) { + /* assert(size != 0) */ + const yyjson_alc def = YYJSON_DEFAULT_ALC; + dyn_ctx *ctx = (dyn_ctx *)ctx_ptr; + dyn_chunk *chunk, *prev; + if (unlikely(!dyn_size_align(&size))) return NULL; + + /* freelist is empty, create new chunk */ + if (!ctx->free_list.next) { + chunk = (dyn_chunk *)def.malloc(def.ctx, size); + if (unlikely(!chunk)) return NULL; + chunk->size = size; + chunk->next = NULL; + dyn_chunk_list_add(&ctx->used_list, chunk); + return (void *)(chunk + 1); + } + + /* find a large enough chunk, or resize the largest chunk */ + prev = &ctx->free_list; + while (true) { + chunk = prev->next; + if (chunk->size >= size) { /* enough size, reuse this chunk */ + prev->next = chunk->next; + dyn_chunk_list_add(&ctx->used_list, chunk); + return (void *)(chunk + 1); + } + if (!chunk->next) { /* resize the largest chunk */ + chunk = (dyn_chunk *)def.realloc(def.ctx, chunk, chunk->size, size); + if (unlikely(!chunk)) return NULL; + prev->next = NULL; + chunk->size = size; + dyn_chunk_list_add(&ctx->used_list, chunk); + return (void *)(chunk + 1); + } + prev = chunk; + } +} + +static void *dyn_realloc(void *ctx_ptr, void *ptr, + usize old_size, usize size) { + /* assert(ptr != NULL && size != 0 && old_size < size) */ + const yyjson_alc def = YYJSON_DEFAULT_ALC; + dyn_ctx *ctx = (dyn_ctx *)ctx_ptr; + dyn_chunk *new_chunk, *chunk = (dyn_chunk *)ptr - 1; + if (unlikely(!dyn_size_align(&size))) return NULL; + if (chunk->size >= size) return ptr; + + dyn_chunk_list_remove(&ctx->used_list, chunk); + new_chunk = (dyn_chunk *)def.realloc(def.ctx, chunk, chunk->size, size); + if (likely(new_chunk)) { + new_chunk->size = size; + chunk = new_chunk; + } + dyn_chunk_list_add(&ctx->used_list, chunk); + return new_chunk ? (void *)(new_chunk + 1) : NULL; +} + +static void dyn_free(void *ctx_ptr, void *ptr) { + /* assert(ptr != NULL) */ + dyn_ctx *ctx = (dyn_ctx *)ctx_ptr; + dyn_chunk *chunk = (dyn_chunk *)ptr - 1, *prev; + + dyn_chunk_list_remove(&ctx->used_list, chunk); + for (prev = &ctx->free_list; prev; prev = prev->next) { + if (!prev->next || prev->next->size >= chunk->size) { + chunk->next = prev->next; + prev->next = chunk; + break; + } + } +} + +yyjson_alc *yyjson_alc_dyn_new(void) { + const yyjson_alc def = YYJSON_DEFAULT_ALC; + usize hdr_len = sizeof(yyjson_alc) + sizeof(dyn_ctx); + yyjson_alc *alc = (yyjson_alc *)def.malloc(def.ctx, hdr_len); + dyn_ctx *ctx = (dyn_ctx *)(void *)(alc + 1); + if (unlikely(!alc)) return NULL; + alc->malloc = dyn_malloc; + alc->realloc = dyn_realloc; + alc->free = dyn_free; + alc->ctx = alc + 1; + memset(ctx, 0, sizeof(*ctx)); + return alc; +} + +void yyjson_alc_dyn_free(yyjson_alc *alc) { + const yyjson_alc def = YYJSON_DEFAULT_ALC; + dyn_ctx *ctx = (dyn_ctx *)(void *)(alc + 1); + dyn_chunk *chunk, *next; + if (unlikely(!alc)) return; + for (chunk = ctx->free_list.next; chunk; chunk = next) { + next = chunk->next; + def.free(def.ctx, chunk); + } + for (chunk = ctx->used_list.next; chunk; chunk = next) { + next = chunk->next; + def.free(def.ctx, chunk); + } + def.free(def.ctx, alc); +} + + + +/*============================================================================== + * MARK: - JSON Struct Utils (Public) + * These functions are used for creating, copying, releasing, and comparing + * JSON documents and values. They are widely used throughout this library. + *============================================================================*/ + +static_inline void unsafe_yyjson_str_pool_release(yyjson_str_pool *pool, + yyjson_alc *alc) { + yyjson_str_chunk *chunk = pool->chunks, *next; + while (chunk) { + next = chunk->next; + alc->free(alc->ctx, chunk); + chunk = next; + } +} + +static_inline void unsafe_yyjson_val_pool_release(yyjson_val_pool *pool, + yyjson_alc *alc) { + yyjson_val_chunk *chunk = pool->chunks, *next; + while (chunk) { + next = chunk->next; + alc->free(alc->ctx, chunk); + chunk = next; + } +} + +bool unsafe_yyjson_str_pool_grow(yyjson_str_pool *pool, + const yyjson_alc *alc, usize len) { + yyjson_str_chunk *chunk; + usize size, max_len; + + /* create a new chunk */ + max_len = USIZE_MAX - sizeof(yyjson_str_chunk); + if (unlikely(len > max_len)) return false; + size = len + sizeof(yyjson_str_chunk); + size = yyjson_max(pool->chunk_size, size); + chunk = (yyjson_str_chunk *)alc->malloc(alc->ctx, size); + if (unlikely(!chunk)) return false; + + /* insert the new chunk as the head of the linked list */ + chunk->next = pool->chunks; + chunk->chunk_size = size; + pool->chunks = chunk; + pool->cur = (char *)chunk + sizeof(yyjson_str_chunk); + pool->end = (char *)chunk + size; + + /* the next chunk is twice the size of the current one */ + size = yyjson_min(pool->chunk_size * 2, pool->chunk_size_max); + if (size < pool->chunk_size) size = pool->chunk_size_max; /* overflow */ + pool->chunk_size = size; + return true; +} + +bool unsafe_yyjson_val_pool_grow(yyjson_val_pool *pool, + const yyjson_alc *alc, usize count) { + yyjson_val_chunk *chunk; + usize size, max_count; + + /* create a new chunk */ + max_count = USIZE_MAX / sizeof(yyjson_mut_val) - 1; + if (unlikely(count > max_count)) return false; + size = (count + 1) * sizeof(yyjson_mut_val); + size = yyjson_max(pool->chunk_size, size); + chunk = (yyjson_val_chunk *)alc->malloc(alc->ctx, size); + if (unlikely(!chunk)) return false; + + /* insert the new chunk as the head of the linked list */ + chunk->next = pool->chunks; + chunk->chunk_size = size; + pool->chunks = chunk; + pool->cur = (yyjson_mut_val *)(void *)((u8 *)chunk) + 1; + pool->end = (yyjson_mut_val *)(void *)((u8 *)chunk + size); + + /* the next chunk is twice the size of the current one */ + size = yyjson_min(pool->chunk_size * 2, pool->chunk_size_max); + if (size < pool->chunk_size) size = pool->chunk_size_max; /* overflow */ + pool->chunk_size = size; + return true; +} + +bool yyjson_mut_doc_set_str_pool_size(yyjson_mut_doc *doc, size_t len) { + usize max_size = USIZE_MAX - sizeof(yyjson_str_chunk); + if (!doc || !len || len > max_size) return false; + doc->str_pool.chunk_size = len + sizeof(yyjson_str_chunk); + return true; +} + +bool yyjson_mut_doc_set_val_pool_size(yyjson_mut_doc *doc, size_t count) { + usize max_count = USIZE_MAX / sizeof(yyjson_mut_val) - 1; + if (!doc || !count || count > max_count) return false; + doc->val_pool.chunk_size = (count + 1) * sizeof(yyjson_mut_val); + return true; +} + +void yyjson_mut_doc_free(yyjson_mut_doc *doc) { + if (doc) { + yyjson_alc alc = doc->alc; + memset(&doc->alc, 0, sizeof(alc)); + unsafe_yyjson_str_pool_release(&doc->str_pool, &alc); + unsafe_yyjson_val_pool_release(&doc->val_pool, &alc); + alc.free(alc.ctx, doc); + } +} + +yyjson_mut_doc *yyjson_mut_doc_new(const yyjson_alc *alc) { + yyjson_mut_doc *doc; + if (!alc) alc = &YYJSON_DEFAULT_ALC; + doc = (yyjson_mut_doc *)alc->malloc(alc->ctx, sizeof(yyjson_mut_doc)); + if (!doc) return NULL; + memset(doc, 0, sizeof(yyjson_mut_doc)); + + doc->alc = *alc; + doc->str_pool.chunk_size = YYJSON_MUT_DOC_STR_POOL_INIT_SIZE; + doc->str_pool.chunk_size_max = YYJSON_MUT_DOC_STR_POOL_MAX_SIZE; + doc->val_pool.chunk_size = YYJSON_MUT_DOC_VAL_POOL_INIT_SIZE; + doc->val_pool.chunk_size_max = YYJSON_MUT_DOC_VAL_POOL_MAX_SIZE; + return doc; +} + +yyjson_mut_doc *yyjson_doc_mut_copy(yyjson_doc *doc, const yyjson_alc *alc) { + yyjson_mut_doc *m_doc; + yyjson_mut_val *m_val; + + if (!doc || !doc->root) return NULL; + m_doc = yyjson_mut_doc_new(alc); + if (!m_doc) return NULL; + m_val = yyjson_val_mut_copy(m_doc, doc->root); + if (!m_val) { + yyjson_mut_doc_free(m_doc); + return NULL; + } + yyjson_mut_doc_set_root(m_doc, m_val); + return m_doc; +} + +yyjson_mut_doc *yyjson_mut_doc_mut_copy(yyjson_mut_doc *doc, + const yyjson_alc *alc) { + yyjson_mut_doc *m_doc; + yyjson_mut_val *m_val; + + if (!doc) return NULL; + if (!doc->root) return yyjson_mut_doc_new(alc); + + m_doc = yyjson_mut_doc_new(alc); + if (!m_doc) return NULL; + m_val = yyjson_mut_val_mut_copy(m_doc, doc->root); + if (!m_val) { + yyjson_mut_doc_free(m_doc); + return NULL; + } + yyjson_mut_doc_set_root(m_doc, m_val); + return m_doc; +} + +yyjson_mut_val *yyjson_val_mut_copy(yyjson_mut_doc *m_doc, + yyjson_val *i_vals) { + /* + The immutable object or array stores all sub-values in a contiguous memory, + We copy them to another contiguous memory as mutable values, + then reconnect the mutable values with the original relationship. + */ + usize i_vals_len; + yyjson_mut_val *m_vals, *m_val; + yyjson_val *i_val, *i_end; + + if (!m_doc || !i_vals) return NULL; + i_end = unsafe_yyjson_get_next(i_vals); + i_vals_len = (usize)(unsafe_yyjson_get_next(i_vals) - i_vals); + m_vals = unsafe_yyjson_mut_val(m_doc, i_vals_len); + if (!m_vals) return NULL; + i_val = i_vals; + m_val = m_vals; + + for (; i_val < i_end; i_val++, m_val++) { + yyjson_type type = unsafe_yyjson_get_type(i_val); + m_val->tag = i_val->tag; + m_val->uni.u64 = i_val->uni.u64; + if (type == YYJSON_TYPE_STR || type == YYJSON_TYPE_RAW) { + const char *str = i_val->uni.str; + usize str_len = unsafe_yyjson_get_len(i_val); + m_val->uni.str = unsafe_yyjson_mut_strncpy(m_doc, str, str_len); + if (!m_val->uni.str) return NULL; + } else if (type == YYJSON_TYPE_ARR) { + usize len = unsafe_yyjson_get_len(i_val); + if (len > 0) { + yyjson_val *ii_val = i_val + 1, *ii_next; + yyjson_mut_val *mm_val = m_val + 1, *mm_ctn = m_val, *mm_next; + while (len-- > 1) { + ii_next = unsafe_yyjson_get_next(ii_val); + mm_next = mm_val + (ii_next - ii_val); + mm_val->next = mm_next; + ii_val = ii_next; + mm_val = mm_next; + } + mm_val->next = mm_ctn + 1; + mm_ctn->uni.ptr = mm_val; + } + } else if (type == YYJSON_TYPE_OBJ) { + usize len = unsafe_yyjson_get_len(i_val); + if (len > 0) { + yyjson_val *ii_key = i_val + 1, *ii_nextkey; + yyjson_mut_val *mm_key = m_val + 1, *mm_ctn = m_val; + yyjson_mut_val *mm_nextkey; + while (len-- > 1) { + ii_nextkey = unsafe_yyjson_get_next(ii_key + 1); + mm_nextkey = mm_key + (ii_nextkey - ii_key); + mm_key->next = mm_key + 1; + mm_key->next->next = mm_nextkey; + ii_key = ii_nextkey; + mm_key = mm_nextkey; + } + mm_key->next = mm_key + 1; + mm_key->next->next = mm_ctn + 1; + mm_ctn->uni.ptr = mm_key; + } + } + } + return m_vals; +} + +static yyjson_mut_val *unsafe_yyjson_mut_val_mut_copy(yyjson_mut_doc *m_doc, + yyjson_mut_val *m_vals) { + /* + The mutable object or array stores all sub-values in a circular linked + list, so we can traverse them in the same loop. The traversal starts from + the last item, continues with the first item in a list, and ends with the + second to last item, which needs to be linked to the last item to close the + circle. + */ + yyjson_mut_val *m_val = unsafe_yyjson_mut_val(m_doc, 1); + if (unlikely(!m_val)) return NULL; + m_val->tag = m_vals->tag; + + switch (unsafe_yyjson_get_type(m_vals)) { + case YYJSON_TYPE_OBJ: + case YYJSON_TYPE_ARR: + if (unsafe_yyjson_get_len(m_vals) > 0) { + yyjson_mut_val *last = (yyjson_mut_val *)m_vals->uni.ptr; + yyjson_mut_val *next = last->next, *prev; + prev = unsafe_yyjson_mut_val_mut_copy(m_doc, last); + if (!prev) return NULL; + m_val->uni.ptr = (void *)prev; + while (next != last) { + prev->next = unsafe_yyjson_mut_val_mut_copy(m_doc, next); + if (!prev->next) return NULL; + prev = prev->next; + next = next->next; + } + prev->next = (yyjson_mut_val *)m_val->uni.ptr; + } + break; + case YYJSON_TYPE_RAW: + case YYJSON_TYPE_STR: { + const char *str = m_vals->uni.str; + usize str_len = unsafe_yyjson_get_len(m_vals); + m_val->uni.str = unsafe_yyjson_mut_strncpy(m_doc, str, str_len); + if (!m_val->uni.str) return NULL; + break; + } + default: + m_val->uni = m_vals->uni; + break; + } + return m_val; +} + +yyjson_mut_val *yyjson_mut_val_mut_copy(yyjson_mut_doc *doc, + yyjson_mut_val *val) { + if (doc && val) return unsafe_yyjson_mut_val_mut_copy(doc, val); + return NULL; +} + +/* Count the number of values and the total length of the strings. */ +static void yyjson_mut_stat(yyjson_mut_val *val, + usize *val_sum, usize *str_sum) { + yyjson_type type = unsafe_yyjson_get_type(val); + *val_sum += 1; + if (type == YYJSON_TYPE_ARR || type == YYJSON_TYPE_OBJ) { + yyjson_mut_val *child = (yyjson_mut_val *)val->uni.ptr; + usize len = unsafe_yyjson_get_len(val), i; + len <<= (u8)(type == YYJSON_TYPE_OBJ); + *val_sum += len; + for (i = 0; i < len; i++) { + yyjson_type stype = unsafe_yyjson_get_type(child); + if (stype == YYJSON_TYPE_STR || stype == YYJSON_TYPE_RAW) { + *str_sum += unsafe_yyjson_get_len(child) + 1; + } else if (stype == YYJSON_TYPE_ARR || stype == YYJSON_TYPE_OBJ) { + yyjson_mut_stat(child, val_sum, str_sum); + *val_sum -= 1; + } + child = child->next; + } + } else if (type == YYJSON_TYPE_STR || type == YYJSON_TYPE_RAW) { + *str_sum += unsafe_yyjson_get_len(val) + 1; + } +} + +/* Copy mutable values to immutable value pool. */ +static usize yyjson_imut_copy(yyjson_val **val_ptr, char **buf_ptr, + yyjson_mut_val *mval) { + yyjson_val *val = *val_ptr; + yyjson_type type = unsafe_yyjson_get_type(mval); + if (type == YYJSON_TYPE_ARR || type == YYJSON_TYPE_OBJ) { + yyjson_mut_val *child = (yyjson_mut_val *)mval->uni.ptr; + usize len = unsafe_yyjson_get_len(mval), i; + usize val_sum = 1; + if (type == YYJSON_TYPE_OBJ) { + if (len) child = child->next->next; + len <<= 1; + } else { + if (len) child = child->next; + } + *val_ptr = val + 1; + for (i = 0; i < len; i++) { + val_sum += yyjson_imut_copy(val_ptr, buf_ptr, child); + child = child->next; + } + val->tag = mval->tag; + val->uni.ofs = val_sum * sizeof(yyjson_val); + return val_sum; + } else if (type == YYJSON_TYPE_STR || type == YYJSON_TYPE_RAW) { + char *buf = *buf_ptr; + usize len = unsafe_yyjson_get_len(mval); + memcpy((void *)buf, (const void *)mval->uni.str, len); + buf[len] = '\0'; + val->tag = mval->tag; + val->uni.str = buf; + *val_ptr = val + 1; + *buf_ptr = buf + len + 1; + return 1; + } else { + val->tag = mval->tag; + val->uni = mval->uni; + *val_ptr = val + 1; + return 1; + } +} + +yyjson_doc *yyjson_mut_doc_imut_copy(yyjson_mut_doc *mdoc, + const yyjson_alc *alc) { + if (!mdoc) return NULL; + return yyjson_mut_val_imut_copy(mdoc->root, alc); +} + +yyjson_doc *yyjson_mut_val_imut_copy(yyjson_mut_val *mval, + const yyjson_alc *alc) { + usize val_num = 0, str_sum = 0, hdr_size, buf_size; + yyjson_doc *doc = NULL; + yyjson_val *val_hdr = NULL; + + /* This value should be NULL here. Setting a non-null value suppresses + warning from the clang analyzer. */ + char *str_hdr = (char *)(void *)&str_sum; + if (!mval) return NULL; + if (!alc) alc = &YYJSON_DEFAULT_ALC; + + /* traverse the input value to get pool size */ + yyjson_mut_stat(mval, &val_num, &str_sum); + + /* create doc and val pool */ + hdr_size = size_align_up(sizeof(yyjson_doc), sizeof(yyjson_val)); + buf_size = hdr_size + val_num * sizeof(yyjson_val); + doc = (yyjson_doc *)alc->malloc(alc->ctx, buf_size); + if (!doc) return NULL; + memset(doc, 0, sizeof(yyjson_doc)); + val_hdr = (yyjson_val *)(void *)((char *)(void *)doc + hdr_size); + doc->root = val_hdr; + doc->alc = *alc; + + /* create str pool */ + if (str_sum > 0) { + str_hdr = (char *)alc->malloc(alc->ctx, str_sum); + doc->str_pool = str_hdr; + if (!str_hdr) { + alc->free(alc->ctx, (void *)doc); + return NULL; + } + } + + /* copy vals and strs */ + doc->val_read = yyjson_imut_copy(&val_hdr, &str_hdr, mval); + doc->dat_read = str_sum + 1; + return doc; +} + +static_inline bool unsafe_yyjson_num_equals(void *lhs, void *rhs) { + yyjson_val_uni *luni = &((yyjson_val *)lhs)->uni; + yyjson_val_uni *runi = &((yyjson_val *)rhs)->uni; + yyjson_subtype lt = unsafe_yyjson_get_subtype(lhs); + yyjson_subtype rt = unsafe_yyjson_get_subtype(rhs); + if (lt == rt) return luni->u64 == runi->u64; + if (lt == YYJSON_SUBTYPE_SINT && rt == YYJSON_SUBTYPE_UINT) { + return luni->i64 >= 0 && luni->u64 == runi->u64; + } + if (lt == YYJSON_SUBTYPE_UINT && rt == YYJSON_SUBTYPE_SINT) { + return runi->i64 >= 0 && luni->u64 == runi->u64; + } + return false; +} + +static_inline bool unsafe_yyjson_str_equals(void *lhs, void *rhs) { + usize len = unsafe_yyjson_get_len(lhs); + if (len != unsafe_yyjson_get_len(rhs)) return false; + return !memcmp(unsafe_yyjson_get_str(lhs), + unsafe_yyjson_get_str(rhs), len); +} + +bool unsafe_yyjson_equals(yyjson_val *lhs, yyjson_val *rhs) { + yyjson_type type = unsafe_yyjson_get_type(lhs); + if (type != unsafe_yyjson_get_type(rhs)) return false; + + switch (type) { + case YYJSON_TYPE_OBJ: { + usize len = unsafe_yyjson_get_len(lhs); + if (len != unsafe_yyjson_get_len(rhs)) return false; + if (len > 0) { + yyjson_obj_iter iter; + yyjson_obj_iter_init(rhs, &iter); + lhs = unsafe_yyjson_get_first(lhs); + while (len-- > 0) { + rhs = yyjson_obj_iter_getn(&iter, lhs->uni.str, + unsafe_yyjson_get_len(lhs)); + if (!rhs) return false; + if (!unsafe_yyjson_equals(lhs + 1, rhs)) return false; + lhs = unsafe_yyjson_get_next(lhs + 1); + } + } + /* yyjson allows duplicate keys, so the check may be inaccurate */ + return true; + } + + case YYJSON_TYPE_ARR: { + usize len = unsafe_yyjson_get_len(lhs); + if (len != unsafe_yyjson_get_len(rhs)) return false; + if (len > 0) { + lhs = unsafe_yyjson_get_first(lhs); + rhs = unsafe_yyjson_get_first(rhs); + while (len-- > 0) { + if (!unsafe_yyjson_equals(lhs, rhs)) return false; + lhs = unsafe_yyjson_get_next(lhs); + rhs = unsafe_yyjson_get_next(rhs); + } + } + return true; + } + + case YYJSON_TYPE_NUM: + return unsafe_yyjson_num_equals(lhs, rhs); + + case YYJSON_TYPE_RAW: + case YYJSON_TYPE_STR: + return unsafe_yyjson_str_equals(lhs, rhs); + + case YYJSON_TYPE_NULL: + case YYJSON_TYPE_BOOL: + return lhs->tag == rhs->tag; + + default: + return false; + } +} + +bool unsafe_yyjson_mut_equals(yyjson_mut_val *lhs, yyjson_mut_val *rhs) { + yyjson_type type = unsafe_yyjson_get_type(lhs); + if (type != unsafe_yyjson_get_type(rhs)) return false; + + switch (type) { + case YYJSON_TYPE_OBJ: { + usize len = unsafe_yyjson_get_len(lhs); + if (len != unsafe_yyjson_get_len(rhs)) return false; + if (len > 0) { + yyjson_mut_obj_iter iter; + yyjson_mut_obj_iter_init(rhs, &iter); + lhs = (yyjson_mut_val *)lhs->uni.ptr; + while (len-- > 0) { + rhs = yyjson_mut_obj_iter_getn(&iter, lhs->uni.str, + unsafe_yyjson_get_len(lhs)); + if (!rhs) return false; + if (!unsafe_yyjson_mut_equals(lhs->next, rhs)) return false; + lhs = lhs->next->next; + } + } + /* yyjson allows duplicate keys, so the check may be inaccurate */ + return true; + } + + case YYJSON_TYPE_ARR: { + usize len = unsafe_yyjson_get_len(lhs); + if (len != unsafe_yyjson_get_len(rhs)) return false; + if (len > 0) { + lhs = (yyjson_mut_val *)lhs->uni.ptr; + rhs = (yyjson_mut_val *)rhs->uni.ptr; + while (len-- > 0) { + if (!unsafe_yyjson_mut_equals(lhs, rhs)) return false; + lhs = lhs->next; + rhs = rhs->next; + } + } + return true; + } + + case YYJSON_TYPE_NUM: + return unsafe_yyjson_num_equals(lhs, rhs); + + case YYJSON_TYPE_RAW: + case YYJSON_TYPE_STR: + return unsafe_yyjson_str_equals(lhs, rhs); + + case YYJSON_TYPE_NULL: + case YYJSON_TYPE_BOOL: + return lhs->tag == rhs->tag; + + default: + return false; + } +} + +bool yyjson_locate_pos(const char *str, size_t len, size_t pos, + size_t *line, size_t *col, size_t *chr) { + usize line_sum = 0, line_pos = 0, chr_sum = 0; + const u8 *cur = (const u8 *)str; + const u8 *end = cur + pos; + + if (!str || pos > len) { + if (line) *line = 0; + if (col) *col = 0; + if (chr) *chr = 0; + return false; + } + + if (pos >= 3 && is_utf8_bom(cur)) cur += 3; /* don't count BOM */ + while (cur < end) { + u8 c = *cur; + chr_sum += 1; + if (likely(c < 0x80)) { /* 0xxxxxxx (0x00-0x7F) ASCII */ + if (c == '\n') { + line_sum += 1; + line_pos = chr_sum; + } + cur += 1; + } + else if (c < 0xC0) cur += 1; /* 10xxxxxx (0x80-0xBF) Invalid */ + else if (c < 0xE0) cur += 2; /* 110xxxxx (0xC0-0xDF) 2-byte UTF-8 */ + else if (c < 0xF0) cur += 3; /* 1110xxxx (0xE0-0xEF) 3-byte UTF-8 */ + else if (c < 0xF8) cur += 4; /* 11110xxx (0xF0-0xF7) 4-byte UTF-8 */ + else cur += 1; /* 11111xxx (0xF8-0xFF) Invalid */ + } + if (line) *line = line_sum + 1; + if (col) *col = chr_sum - line_pos + 1; + if (chr) *chr = chr_sum; + return true; +} + + + +#if !YYJSON_DISABLE_READER /* reader begin */ + +/* Check read flag, avoids `always false` warning when disabled. */ +#define has_flg(_flg) unlikely(has_rflag(flg, YYJSON_READ_##_flg, 0)) +#define has_allow(_flg) unlikely(has_rflag(flg, YYJSON_READ_ALLOW_##_flg, 1)) +#define YYJSON_READ_ALLOW_TRIVIA (YYJSON_READ_ALLOW_COMMENTS | \ + YYJSON_READ_ALLOW_EXT_WHITESPACE) +static_inline bool has_rflag(yyjson_read_flag flg, yyjson_read_flag chk, + bool non_standard) { +#if YYJSON_DISABLE_NON_STANDARD + if (non_standard) return false; +#endif + return (flg & chk) != 0; +} + + + +/*============================================================================== + * MARK: - JSON Reader Utils (Private) + * These functions are used by JSON reader to read literals and comments. + *============================================================================*/ + +/** Read `true` literal, `*ptr[0]` should be `t`. */ +static_inline bool read_true(u8 **ptr, yyjson_val *val) { + u8 *cur = *ptr; + if (likely(byte_match_4(cur, "true"))) { + val->tag = YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_TRUE; + *ptr = cur + 4; + return true; + } + return false; +} + +/** Read `false` literal, `*ptr[0]` should be `f`. */ +static_inline bool read_false(u8 **ptr, yyjson_val *val) { + u8 *cur = *ptr; + if (likely(byte_match_4(cur + 1, "alse"))) { + val->tag = YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_FALSE; + *ptr = cur + 5; + return true; + } + return false; +} + +/** Read `null` literal, `*ptr[0]` should be `n`. */ +static_inline bool read_null(u8 **ptr, yyjson_val *val) { + u8 *cur = *ptr; + if (likely(byte_match_4(cur, "null"))) { + val->tag = YYJSON_TYPE_NULL; + *ptr = cur + 4; + return true; + } + return false; +} + +/** Read `Inf` or `Infinity` literal (ignoring case). */ +static_inline bool read_inf(u8 **ptr, u8 **pre, + yyjson_read_flag flg, yyjson_val *val) { + u8 *hdr = *ptr; + u8 *cur = *ptr; + u8 **end = ptr; + bool sign = (*cur == '-'); + if (*cur == '+' && !has_allow(EXT_NUMBER)) return false; + cur += char_is_sign(*cur); + if (char_to_lower(cur[0]) == 'i' && + char_to_lower(cur[1]) == 'n' && + char_to_lower(cur[2]) == 'f') { + if (char_to_lower(cur[3]) == 'i') { + if (char_to_lower(cur[4]) == 'n' && + char_to_lower(cur[5]) == 'i' && + char_to_lower(cur[6]) == 't' && + char_to_lower(cur[7]) == 'y') { + cur += 8; + } else { + return false; + } + } else { + cur += 3; + } + *end = cur; + if (has_flg(NUMBER_AS_RAW)) { + **pre = '\0'; /* add null-terminator for previous raw string */ + *pre = cur; /* save end position for current raw string */ + val->tag = ((u64)(cur - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW; + val->uni.str = (const char *)hdr; + } else { + val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; + val->uni.u64 = f64_bits_inf(sign); + } + return true; + } + return false; +} + +/** Read `NaN` literal (ignoring case). */ +static_inline bool read_nan(u8 **ptr, u8 **pre, + yyjson_read_flag flg, yyjson_val *val) { + u8 *hdr = *ptr; + u8 *cur = *ptr; + u8 **end = ptr; + bool sign = (*cur == '-'); + if (*cur == '+' && !has_allow(EXT_NUMBER)) return false; + cur += char_is_sign(*cur); + if (char_to_lower(cur[0]) == 'n' && + char_to_lower(cur[1]) == 'a' && + char_to_lower(cur[2]) == 'n') { + cur += 3; + *end = cur; + if (has_flg(NUMBER_AS_RAW)) { + **pre = '\0'; /* add null-terminator for previous raw string */ + *pre = cur; /* save end position for current raw string */ + val->tag = ((u64)(cur - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW; + val->uni.str = (const char *)hdr; + } else { + val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; + val->uni.u64 = f64_bits_nan(sign); + } + return true; + } + return false; +} + +/** Read `Inf`, `Infinity` or `NaN` literal (ignoring case). */ +static_inline bool read_inf_or_nan(u8 **ptr, u8 **pre, + yyjson_read_flag flg, yyjson_val *val) { + if (read_inf(ptr, pre, flg, val)) return true; + if (read_nan(ptr, pre, flg, val)) return true; + return false; +} + +/** Read a JSON number as raw string. */ +static_noinline bool read_num_raw(u8 **ptr, u8 **pre, yyjson_read_flag flg, + yyjson_val *val, const char **msg) { +#define return_err(_pos, _msg) do { \ + *msg = _msg; *end = _pos; return false; \ +} while (false) + +#define return_raw() do { \ + val->tag = ((u64)(cur - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW; \ + val->uni.str = (const char *)hdr; \ + **pre = '\0'; *pre = cur; *end = cur; return true; \ +} while (false) + + u8 *hdr = *ptr; + u8 *cur = *ptr; + u8 **end = ptr; + + /* skip sign */ + cur += (*cur == '-'); + + /* read first digit, check leading zero */ + while (unlikely(!char_is_digit(*cur))) { + if (has_allow(EXT_NUMBER)) { + if (*cur == '+' && cur == hdr) { /* leading `+` sign */ + cur++; + continue; + } + if (*cur == '.' && char_is_digit(cur[1])) { /* e.g. '.123' */ + goto read_double; + } + } + if (has_allow(INF_AND_NAN)) { + if (read_inf_or_nan(ptr, pre, flg, val)) return true; + } + return_err(cur, "no digit after sign"); + } + + /* read integral part */ + if (*cur == '0') { + cur++; + if (unlikely(char_is_digit(*cur))) { + return_err(cur - 1, "number with leading zero is not allowed"); + } + if (!char_is_fp(*cur)) { + if (has_allow(EXT_NUMBER) && char_to_lower(*cur) == 'x') { /* hex */ + if (!char_is_hex(*++cur)) return_err(cur, "invalid hex number"); + while(char_is_hex(*cur)) cur++; + } + return_raw(); + } + } else { + while (char_is_digit(*cur)) cur++; + if (!char_is_fp(*cur)) return_raw(); + } + +read_double: + /* read fraction part */ + if (*cur == '.') { + cur++; + if (!char_is_digit(*cur)) { + if (has_allow(EXT_NUMBER)) { + if (!char_is_exp(*cur)) return_raw(); + } else { + return_err(cur, "no digit after decimal point"); + } + } + while (char_is_digit(*cur)) cur++; + } + + /* read exponent part */ + if (char_is_exp(*cur)) { + cur += 1 + char_is_sign(cur[1]); + if (!char_is_digit(*cur++)) { + return_err(cur, "no digit after exponent sign"); + } + while (char_is_digit(*cur)) cur++; + } + + return_raw(); + +#undef return_err +#undef return_raw +} + +/** Read a hex number. */ +static_noinline bool read_num_hex(u8 **ptr, u8 **pre, yyjson_read_flag flg, + yyjson_val *val, const char **msg) { + u8 *hdr = *ptr; + u8 *cur = *ptr; + u8 **end = ptr; + u64 sig = 0, i = 0; + bool sign; + + /* skip sign and '0x' */ + sign = (*cur == '-'); + cur += (*cur == '-' || *cur == '+') + 2; + + /* read hex */ + for(; i < 16; i++) { + u8 c = hex_conv_table[cur[i]]; + if (c == 0xF0) break; + sig <<= 4; + sig |= c; + } + + /* check error */ + if (unlikely(i == 0)) { + *msg = "invalid hex number"; + return false; + } + + /* check overflow */ + if (unlikely(i == 16)) { + if (char_is_hex(cur[16]) || (sign && sig > ((u64)1 << 63))) { + if (!has_flg(BIGNUM_AS_RAW)) { + *msg = "hex number overflow"; + return false; + } + cur += 16; + while (char_is_hex(*cur)) cur++; + **pre = '\0'; + val->tag = ((u64)(cur - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW; + val->uni.str = (const char *)hdr; + *pre = cur; *end = cur; + return true; + } + } + + val->tag = YYJSON_TYPE_NUM | (u64)((u8)sign << 3); + val->uni.u64 = (u64)(sign ? (u64)(~(sig) + 1) : (u64)(sig)); + *end = cur + i; + return true; +} + +/** + Skip trivia (whitespace and comments). + This function should be used only when `char_is_trivia()` returns true. + @param ptr (inout) Input current position, output end position. + @param eof JSON end position. + @param flg JSON read flags. + @return true if at least one character was skipped. + false if no characters were skipped, + or if a multi-line comment is unterminated; + in the latter case, `ptr` will be set to `eof`. + */ +static_noinline bool skip_trivia(u8 **ptr, u8 *eof, yyjson_read_flag flg) { + u8 *hdr = *ptr, *cur = *ptr; + usize len; + + while (cur < eof) { + u8 *loop_begin = cur; + + /* skip standard whitespace */ + while(char_is_space(*cur)) cur++; + + /* skip extended whitespace */ + if (has_allow(EXT_WHITESPACE)) { + while (char_is_space_ext(*cur)) { + cur += (len = ext_space_len(cur)); + if (!len) break; + } + } + + /* skip comment, do not validate encoding */ + if (has_allow(COMMENTS) && cur[0] == '/') { + if (cur[1] == '/') { /* single-line comment */ + cur += 2; + if (has_allow(EXT_WHITESPACE)) { + while (cur < eof) { + if (char_is_eol_ext(*cur)) { + cur += (len = ext_eol_len(cur)); + if (len) break; + } + cur++; + } + } else { + while (cur < eof && !char_is_eol(*cur)) cur++; + } + } else if (cur[1] == '*') { /* multi-line comment */ + cur += 2; + while (!byte_match_2(cur, "*/") && cur < eof) cur++; + if (cur == eof) { + *ptr = eof; + return false; /* unclosed comment */ + } + cur += 2; + } + } + if (cur == loop_begin) break; + } + *ptr = cur; + return cur > hdr; +} + +/** + Check truncated UTF-8 character. + Return true if `cur` starts a valid UTF-8 sequence that is truncated. + */ +static bool is_truncated_utf8(u8 *cur, u8 *eof) { + u8 c0, c1, c2; + usize len = (usize)(eof - cur); + if (cur >= eof || len >= 4) return false; + c0 = cur[0]; c1 = cur[1]; c2 = cur[2]; + /* 1-byte UTF-8, not truncated */ + if (c0 < 0x80) return false; + if (len == 1) { + /* 2-byte UTF-8, truncated */ + if ((c0 & 0xE0) == 0xC0 && (c0 & 0x1E) != 0x00) return true; + /* 3-byte UTF-8, truncated */ + if ((c0 & 0xF0) == 0xE0) return true; + /* 4-byte UTF-8, truncated */ + if ((c0 & 0xF8) == 0xF0 && (c0 & 0x07) <= 0x04) return true; + } else if (len == 2) { + /* 3-byte UTF-8, truncated */ + if ((c0 & 0xF0) == 0xE0 && (c1 & 0xC0) == 0x80) { + u8 t = (u8)(((c0 & 0x0F) << 1) | ((c1 & 0x20) >> 5)); + return 0x01 <= t && t != 0x1B; + } + /* 4-byte UTF-8, truncated */ + if ((c0 & 0xF8) == 0xF0 && (c1 & 0xC0) == 0x80) { + u8 t = (u8)(((c0 & 0x07) << 2) | ((c1 & 0x30) >> 4)); + return 0x01 <= t && t <= 0x10; + } + } else if (len == 3) { + /* 4 bytes UTF-8, truncated */ + if ((c0 & 0xF8) == 0xF0 && (c1 & 0xC0) == 0x80 && (c2 & 0xC0) == 0x80) { + u8 t = (u8)(((c0 & 0x07) << 2) | ((c1 & 0x30) >> 4)); + return 0x01 <= t && t <= 0x10; + } + } + return false; +} + +/** + Check truncated string. + Returns true if `cur` match `str` but is truncated. + The `str` should be lowercase ASCII letters. + */ +static bool is_truncated_str(u8 *cur, u8 *eof, const char *str, + bool case_sensitive) { + usize len = strlen(str); + if (cur + len <= eof || eof <= cur) return false; + if (case_sensitive) { + return memcmp(cur, str, (usize)(eof - cur)) == 0; + } + for (; cur < eof; cur++, str++) { + if (char_to_lower(*cur) != *(const u8 *)str) return false; + } + return true; +} + +/** + Check truncated JSON on parsing errors. + Returns true if the input is valid but truncated. + */ +static_noinline bool is_truncated_end(u8 *hdr, u8 *cur, u8 *eof, + yyjson_read_code code, + yyjson_read_flag flg) { + if (cur >= eof) return true; + if (code == YYJSON_READ_ERROR_LITERAL) { + if (is_truncated_str(cur, eof, "true", true) || + is_truncated_str(cur, eof, "false", true) || + is_truncated_str(cur, eof, "null", true)) { + return true; + } + } + if (code == YYJSON_READ_ERROR_UNEXPECTED_CHARACTER || + code == YYJSON_READ_ERROR_INVALID_NUMBER || + code == YYJSON_READ_ERROR_LITERAL) { + if (has_allow(INF_AND_NAN)) { + if (*cur == '-') cur++; + if (is_truncated_str(cur, eof, "infinity", false) || + is_truncated_str(cur, eof, "nan", false)) { + return true; + } + } + } + if (code == YYJSON_READ_ERROR_UNEXPECTED_CONTENT) { + if (has_allow(INF_AND_NAN)) { + if (hdr + 3 <= cur && + is_truncated_str(cur - 3, eof, "infinity", false)) { + return true; /* e.g. infin would be read as inf + in */ + } + } + } + if (code == YYJSON_READ_ERROR_INVALID_STRING) { + usize len = (usize)(eof - cur); + + /* unicode escape sequence */ + if (*cur == '\\') { + if (len == 1) return true; + if (len <= 5) { + if (*++cur != 'u') return false; + for (++cur; cur < eof; cur++) { + if (!char_is_hex(*cur)) return false; + } + return true; + } else if (len <= 11) { + /* incomplete surrogate pair? */ + u16 hi; + if (*++cur != 'u') return false; + if (!hex_load_4(++cur, &hi)) return false; + if ((hi & 0xF800) != 0xD800) return false; + cur += 4; + if (cur >= eof) return true; + /* valid low surrogate is DC00...DFFF */ + if (*cur != '\\') return false; + if (++cur >= eof) return true; + if (*cur != 'u') return false; + if (++cur >= eof) return true; + if (*cur != 'd' && *cur != 'D') return false; + if (++cur >= eof) return true; + if ((*cur < 'c' || *cur > 'f') && (*cur < 'C' || *cur > 'F')) + return false; + if (++cur >= eof) return true; + if (!char_is_hex(*cur)) return false; + return true; + } + return false; + } + + /* 2 to 4 bytes UTF-8 */ + if (is_truncated_utf8(cur, eof)) { + return true; + } + } + if (has_allow(COMMENTS)) { + if (code == YYJSON_READ_ERROR_INVALID_COMMENT) { + /* unclosed multiline comment */ + return true; + } + if (code == YYJSON_READ_ERROR_UNEXPECTED_CHARACTER && + *cur == '/' && cur + 1 == eof) { + /* truncated beginning of comment */ + return true; + } + } + if (code == YYJSON_READ_ERROR_UNEXPECTED_CHARACTER && + has_allow(BOM)) { + /* truncated UTF-8 BOM */ + usize len = (usize)(eof - cur); + if (cur == hdr && len < 3 && !memcmp(hdr, "\xEF\xBB\xBF", len)) { + return true; + } + } + return false; +} + + + +#if !YYJSON_DISABLE_FAST_FP_CONV /* FP_READER */ + +/*============================================================================== + * MARK: - BigInt For Floating Point Number Reader (Private) + * + * The bigint algorithm is used by floating-point number reader to get correctly + * rounded result for numbers with lots of digits. This part of code is rarely + * used for common numbers. + *============================================================================*/ + +/** Unsigned arbitrarily large integer */ +typedef struct bigint { + u32 used; /* used chunks count, should not be 0 */ + u64 bits[64]; /* chunks (58 is enough here) */ +} bigint; + +/** + Evaluate 'big += val'. + @param big A big number (can be 0). + @param val An unsigned integer (can be 0). + */ +static_inline void bigint_add_u64(bigint *big, u64 val) { + u32 idx, max; + u64 num = big->bits[0]; + u64 add = num + val; + big->bits[0] = add; + if (likely((add >= num) || (add >= val))) return; + for ((void)(idx = 1), max = big->used; idx < max; idx++) { + if (likely(big->bits[idx] != U64_MAX)) { + big->bits[idx] += 1; + return; + } + big->bits[idx] = 0; + } + big->bits[big->used++] = 1; +} + +/** + Evaluate 'big *= val'. + @param big A big number (can be 0). + @param val An unsigned integer (cannot be 0). + */ +static_inline void bigint_mul_u64(bigint *big, u64 val) { + u32 idx = 0, max = big->used; + u64 hi, lo, carry = 0; + for (; idx < max; idx++) { + if (big->bits[idx]) break; + } + for (; idx < max; idx++) { + u128_mul_add(big->bits[idx], val, carry, &hi, &lo); + big->bits[idx] = lo; + carry = hi; + } + if (carry) big->bits[big->used++] = carry; +} + +/** + Evaluate 'big *= 2^exp'. + @param big A big number (can be 0). + @param exp An exponent integer (can be 0). + */ +static_inline void bigint_mul_pow2(bigint *big, u32 exp) { + u32 shft = exp % 64; + u32 move = exp / 64; + u32 idx = big->used; + if (unlikely(shft == 0)) { + for (; idx > 0; idx--) { + big->bits[idx + move - 1] = big->bits[idx - 1]; + } + big->used += move; + while (move) big->bits[--move] = 0; + } else { + big->bits[idx] = 0; + for (; idx > 0; idx--) { + u64 num = big->bits[idx] << shft; + num |= big->bits[idx - 1] >> (64 - shft); + big->bits[idx + move] = num; + } + big->bits[move] = big->bits[0] << shft; + big->used += move + (big->bits[big->used + move] > 0); + while (move) big->bits[--move] = 0; + } +} + +/** + Evaluate 'big *= 10^exp'. + @param big A big number (can be 0). + @param exp An exponent integer (cannot be 0). + */ +static_inline void bigint_mul_pow10(bigint *big, i32 exp) { + for (; exp >= U64_POW10_MAX_EXACT_EXP; exp -= U64_POW10_MAX_EXACT_EXP) { + bigint_mul_u64(big, u64_pow10_table[U64_POW10_MAX_EXACT_EXP]); + } + if (exp) { + bigint_mul_u64(big, u64_pow10_table[exp]); + } +} + +/** + Compare two bigint. + @return -1 if 'a < b', +1 if 'a > b', 0 if 'a == b'. + */ +static_inline i32 bigint_cmp(bigint *a, bigint *b) { + u32 idx = a->used; + if (a->used < b->used) return -1; + if (a->used > b->used) return +1; + while (idx-- > 0) { + u64 av = a->bits[idx]; + u64 bv = b->bits[idx]; + if (av < bv) return -1; + if (av > bv) return +1; + } + return 0; +} + +/** + Evaluate 'big = val'. + @param big A big number (can be 0). + @param val An unsigned integer (can be 0). + */ +static_inline void bigint_set_u64(bigint *big, u64 val) { + big->used = 1; + big->bits[0] = val; +} + +/** Set a bigint with floating point number string. */ +static_noinline void bigint_set_buf(bigint *big, u64 sig, i32 *exp, + u8 *sig_cut, u8 *sig_end, u8 *dot_pos) { + + if (unlikely(!sig_cut)) { + /* no digit cut, set significant part only */ + bigint_set_u64(big, sig); + return; + + } else { + /* some digits were cut, read them from 'sig_cut' to 'sig_end' */ + u8 *hdr = sig_cut; + u8 *cur = hdr; + u32 len = 0; + u64 val = 0; + bool dig_big_cut = false; + bool has_dot = (hdr < dot_pos) & (dot_pos < sig_end); + u32 dig_len_total = U64_SAFE_DIG + (u32)(sig_end - hdr) - has_dot; + + sig -= (*sig_cut >= '5'); /* sig was rounded before */ + if (dig_len_total > F64_MAX_DEC_DIG) { + dig_big_cut = true; + sig_end -= dig_len_total - (F64_MAX_DEC_DIG + 1); + sig_end -= (dot_pos + 1 == sig_end); + dig_len_total = (F64_MAX_DEC_DIG + 1); + } + *exp -= (i32)dig_len_total - U64_SAFE_DIG; + + big->used = 1; + big->bits[0] = sig; + while (cur < sig_end) { + if (likely(cur != dot_pos)) { + val = val * 10 + (u8)(*cur++ - '0'); + len++; + if (unlikely(cur == sig_end && dig_big_cut)) { + /* The last digit must be non-zero, */ + /* set it to '1' for correct rounding. */ + val = val - (val % 10) + 1; + } + if (len == U64_SAFE_DIG || cur == sig_end) { + bigint_mul_pow10(big, (i32)len); + bigint_add_u64(big, val); + val = 0; + len = 0; + } + } else { + cur++; + } + } + } +} + + + +/*============================================================================== + * MARK: - Diy Floating Point (Private) + *============================================================================*/ + +/** "Do It Yourself Floating Point" struct. */ +typedef struct diy_fp { + u64 sig; /* significand */ + i32 exp; /* exponent, base 2 */ + i32 pad; /* padding, useless */ +} diy_fp; + +/** Get cached rounded diy_fp with pow(10, e) The input value must in range + [POW10_SIG_TABLE_MIN_EXP, POW10_SIG_TABLE_MAX_EXP]. */ +static_inline diy_fp diy_fp_get_cached_pow10(i32 exp10) { + diy_fp fp; + u64 sig_ext; + pow10_table_get_sig(exp10, &fp.sig, &sig_ext); + pow10_table_get_exp(exp10, &fp.exp); + fp.sig += (sig_ext >> 63); + return fp; +} + +/** Returns fp * fp2. */ +static_inline diy_fp diy_fp_mul(diy_fp fp, diy_fp fp2) { + u64 hi, lo; + u128_mul(fp.sig, fp2.sig, &hi, &lo); + fp.sig = hi + (lo >> 63); + fp.exp += fp2.exp + 64; + return fp; +} + +/** Convert diy_fp to IEEE-754 raw value. */ +static_inline u64 diy_fp_to_ieee_raw(diy_fp fp) { + u64 sig = fp.sig; + i32 exp = fp.exp; + u32 lz_bits; + if (unlikely(fp.sig == 0)) return 0; + + lz_bits = u64_lz_bits(sig); + sig <<= lz_bits; + sig >>= F64_BITS - F64_SIG_FULL_BITS; + exp -= (i32)lz_bits; + exp += F64_BITS - F64_SIG_FULL_BITS; + exp += F64_SIG_BITS; + + if (unlikely(exp >= F64_MAX_BIN_EXP)) { + /* overflow */ + return F64_BITS_INF; + } else if (likely(exp >= F64_MIN_BIN_EXP - 1)) { + /* normal */ + exp += F64_EXP_BIAS; + return ((u64)exp << F64_SIG_BITS) | (sig & F64_SIG_MASK); + } else if (likely(exp >= F64_MIN_BIN_EXP - F64_SIG_FULL_BITS)) { + /* subnormal */ + return sig >> (F64_MIN_BIN_EXP - exp - 1); + } else { + /* underflow */ + return 0; + } +} + + + +/*============================================================================== + * MARK: - Number Reader (Private) + *============================================================================*/ + +/** + Read a JSON number. + + 1. This function assume that the floating-point number is in IEEE-754 format. + 2. This function support uint64/int64/double number. If an integer number + cannot fit in uint64/int64, it will returns as a double number. If a double + number is infinite, the return value is based on flag. + 3. This function (with inline attribute) may generate a lot of instructions. + */ +static_inline bool read_num(u8 **ptr, u8 **pre, yyjson_read_flag flg, + yyjson_val *val, const char **msg) { +#define return_err(_pos, _msg) do { \ + *msg = _msg; \ + *end = _pos; \ + return false; \ +} while (false) + +#define return_0() do { \ + val->tag = YYJSON_TYPE_NUM | (u8)((u8)sign << 3); \ + val->uni.u64 = 0; \ + *end = cur; return true; \ +} while (false) + +#define return_i64(_v) do { \ + val->tag = YYJSON_TYPE_NUM | (u8)((u8)sign << 3); \ + val->uni.u64 = (u64)(sign ? (u64)(~(_v) + 1) : (u64)(_v)); \ + *end = cur; return true; \ +} while (false) + +#define return_f64(_v) do { \ + val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; \ + val->uni.f64 = sign ? -(f64)(_v) : (f64)(_v); \ + *end = cur; return true; \ +} while (false) + +#define return_f64_bin(_v) do { \ + val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; \ + val->uni.u64 = ((u64)sign << 63) | (u64)(_v); \ + *end = cur; return true; \ +} while (false) + +#define return_inf() do { \ + if (has_flg(BIGNUM_AS_RAW)) return_raw(); \ + if (has_allow(INF_AND_NAN)) return_f64_bin(F64_BITS_INF); \ + else return_err(hdr, "number is infinity when parsed as double"); \ +} while (false) + +#define return_raw() do { \ + **pre = '\0'; /* add null-terminator for previous raw string */ \ + val->tag = ((u64)(cur - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW; \ + val->uni.str = (const char *)hdr; \ + *pre = cur; *end = cur; return true; \ +} while (false) + + u8 *sig_cut = NULL; /* significant part cutting position for long number */ + u8 *sig_end = NULL; /* significant part ending position */ + u8 *dot_pos = NULL; /* decimal point position */ + + u64 sig = 0; /* significant part of the number */ + i32 exp = 0; /* exponent part of the number */ + + bool exp_sign; /* temporary exponent sign from literal part */ + i64 exp_sig = 0; /* temporary exponent number from significant part */ + i64 exp_lit = 0; /* temporary exponent number from exponent literal part */ + u64 num; /* temporary number for reading */ + u8 *tmp; /* temporary cursor for reading */ + + u8 *hdr = *ptr; + u8 *cur = *ptr; + u8 **end = ptr; + bool sign; + + /* read number as raw string if has `YYJSON_READ_NUMBER_AS_RAW` flag */ + if (has_flg(NUMBER_AS_RAW)) { + return read_num_raw(ptr, pre, flg, val, msg); + } + + sign = (*hdr == '-'); + cur += sign; + + /* begin with a leading zero or non-digit */ + while (unlikely(!char_is_nonzero(*cur))) { /* 0 or non-digit char */ + if (unlikely(*cur != '0')) { /* non-digit char */ + if (has_allow(EXT_NUMBER)) { + if (*cur == '+' && cur == hdr) { /* leading `+` sign */ + cur++; + continue; + } + if (*cur == '.' && char_is_digit(cur[1])) { /* e.g. '.123' */ + goto leading_dot; + } + } + if (has_allow(INF_AND_NAN)) { + if (read_inf_or_nan(ptr, pre, flg, val)) return true; + } + return_err(cur, "no digit after sign"); + } + /* begin with 0 */ + if (likely(!char_is_digit_or_fp(*++cur))) { + if (has_allow(EXT_NUMBER) && char_to_lower(*cur) == 'x') { /* hex */ + return read_num_hex(ptr, pre, flg, val, msg); + } + return_0(); + } + if (likely(*cur == '.')) { +leading_dot: + dot_pos = cur++; + if (unlikely(!char_is_digit(*cur))) { + if (has_allow(EXT_NUMBER)) { + if (char_is_exp(*cur)) { + goto digi_exp_more; + } else { + return_f64_bin(0); + } + } + return_err(cur, "no digit after decimal point"); + } + while (unlikely(*cur == '0')) cur++; + if (likely(char_is_digit(*cur))) { + /* first non-zero digit after decimal point */ + sig = (u64)(*cur - '0'); /* read first digit */ + cur--; + goto digi_frac_1; /* continue read fraction part */ + } + } + if (unlikely(char_is_digit(*cur))) { + return_err(cur - 1, "number with leading zero is not allowed"); + } + if (unlikely(char_is_exp(*cur))) { /* 0 with any exponent is still 0 */ + cur += (usize)1 + char_is_sign(cur[1]); + if (unlikely(!char_is_digit(*cur))) { + return_err(cur, "no digit after exponent sign"); + } + while (char_is_digit(*++cur)); + } + return_f64_bin(0); + } + + /* begin with non-zero digit */ + sig = (u64)(*cur - '0'); + + /* + Read integral part, same as the following code. + + for (int i = 1; i <= 18; i++) { + num = cur[i] - '0'; + if (num <= 9) sig = num + sig * 10; + else goto digi_sepr_i; + } + */ +#define expr_intg(i) \ + if (likely((num = (u64)(cur[i] - (u8)'0')) <= 9)) sig = num + sig * 10; \ + else { goto digi_sepr_##i; } + repeat_in_1_18(expr_intg) +#undef expr_intg + + + cur += 19; /* skip continuous 19 digits */ + if (!char_is_digit_or_fp(*cur)) { + /* this number is an integer consisting of 19 digits */ + if (sign && (sig > ((u64)1 << 63))) { /* overflow */ + if (has_flg(BIGNUM_AS_RAW)) return_raw(); + return_f64(unsafe_yyjson_u64_to_f64(sig)); + } + return_i64(sig); + } + goto digi_intg_more; /* read more digits in integral part */ + + + /* process first non-digit character */ +#define expr_sepr(i) \ + digi_sepr_##i: \ + if (likely(!char_is_fp(cur[i]))) { cur += i; return_i64(sig); } \ + dot_pos = cur + i; \ + if (likely(cur[i] == '.')) goto digi_frac_##i; \ + cur += i; sig_end = cur; goto digi_exp_more; + repeat_in_1_18(expr_sepr) +#undef expr_sepr + + + /* read fraction part */ +#define expr_frac(i) \ + digi_frac_##i: \ + if (likely((num = (u64)(cur[i + 1] - (u8)'0')) <= 9)) \ + sig = num + sig * 10; \ + else { goto digi_stop_##i; } + repeat_in_1_18(expr_frac) +#undef expr_frac + + cur += 20; /* skip 19 digits and 1 decimal point */ + if (!char_is_digit(*cur)) goto digi_frac_end; /* fraction part end */ + goto digi_frac_more; /* read more digits in fraction part */ + + + /* significant part end */ +#define expr_stop(i) \ + digi_stop_##i: \ + cur += i + 1; \ + goto digi_frac_end; + repeat_in_1_18(expr_stop) +#undef expr_stop + + + /* read more digits in integral part */ +digi_intg_more: + if (char_is_digit(*cur)) { + if (!char_is_digit_or_fp(cur[1])) { + /* this number is an integer consisting of 20 digits */ + num = (u64)(*cur - '0'); + if ((sig < (U64_MAX / 10)) || + (sig == (U64_MAX / 10) && num <= (U64_MAX % 10))) { + sig = num + sig * 10; + cur++; + /* convert to double if overflow */ + if (sign) { + if (has_flg(BIGNUM_AS_RAW)) return_raw(); + return_f64(unsafe_yyjson_u64_to_f64(sig)); + } + return_i64(sig); + } + } + } + + if (char_is_exp(*cur)) { + dot_pos = cur; + goto digi_exp_more; + } + + if (*cur == '.') { + dot_pos = cur++; + if (unlikely(!char_is_digit(*cur))) { + if (has_allow(EXT_NUMBER)) { + goto digi_frac_end; + } + return_err(cur, "no digit after decimal point"); + } + } + + + /* read more digits in fraction part */ +digi_frac_more: + sig_cut = cur; /* too large to fit in u64, excess digits need to be cut */ + sig += (*cur >= '5'); /* round */ + while (char_is_digit(*++cur)); + if (!dot_pos) { + if (!char_is_fp(*cur) && has_flg(BIGNUM_AS_RAW)) { + return_raw(); /* it's a large integer */ + } + dot_pos = cur; + if (*cur == '.') { + if (unlikely(!char_is_digit(*++cur))) { + if (!has_allow(EXT_NUMBER)) { + return_err(cur, "no digit after decimal point"); + } + } + while (char_is_digit(*cur)) cur++; + } + } + exp_sig = (i64)(dot_pos - sig_cut); + exp_sig += (dot_pos < sig_cut); + + /* ignore trailing zeros */ + tmp = cur - 1; + while ((*tmp == '0' || *tmp == '.') && tmp > hdr) tmp--; + if (tmp < sig_cut) { + sig_cut = NULL; + } else { + sig_end = cur; + } + + if (char_is_exp(*cur)) goto digi_exp_more; + goto digi_exp_finish; + + + /* fraction part end */ +digi_frac_end: + if (unlikely(dot_pos + 1 == cur)) { + if (!has_allow(EXT_NUMBER)) { + return_err(cur, "no digit after decimal point"); + } + } + sig_end = cur; + exp_sig = -(i64)((u64)(cur - dot_pos) - 1); + if (likely(!char_is_exp(*cur))) { + if (unlikely(exp_sig < F64_MIN_DEC_EXP - 19)) { + return_f64_bin(0); /* underflow */ + } + exp = (i32)exp_sig; + goto digi_finish; + } else { + goto digi_exp_more; + } + + + /* read exponent part */ +digi_exp_more: + exp_sign = (*++cur == '-'); + cur += char_is_sign(*cur); + if (unlikely(!char_is_digit(*cur))) { + return_err(cur, "no digit after exponent sign"); + } + while (*cur == '0') cur++; + + /* read exponent literal */ + tmp = cur; + while (char_is_digit(*cur)) { + exp_lit = (i64)((u8)(*cur++ - '0') + (u64)exp_lit * 10); + } + if (unlikely(cur - tmp >= U64_SAFE_DIG)) { + if (exp_sign) { + return_f64_bin(0); /* underflow */ + } else { + return_inf(); /* overflow */ + } + } + exp_sig += exp_sign ? -exp_lit : exp_lit; + + + /* validate exponent value */ +digi_exp_finish: + if (unlikely(exp_sig < F64_MIN_DEC_EXP - 19)) { + return_f64_bin(0); /* underflow */ + } + if (unlikely(exp_sig > F64_MAX_DEC_EXP)) { + return_inf(); /* overflow */ + } + exp = (i32)exp_sig; + + + /* all digit read finished */ +digi_finish: + + /* + Fast path 1: + + 1. The floating-point number calculation should be accurate, see the + comments of macro `YYJSON_DOUBLE_MATH_CORRECT`. + 2. Correct rounding should be performed (fegetround() == FE_TONEAREST). + 3. The input of floating point number calculation does not lose precision, + which means: 64 - leading_zero(input) - trailing_zero(input) < 53. + + We don't check all available inputs here, because that would make the code + more complicated, and not friendly to branch predictor. + */ +#if YYJSON_DOUBLE_MATH_CORRECT + if (sig < ((u64)1 << 53) && + exp >= -F64_POW10_MAX_EXACT_EXP && + exp <= +F64_POW10_MAX_EXACT_EXP) { + f64 dbl = (f64)sig; + if (exp < 0) { + dbl /= f64_pow10_table[-exp]; + } else { + dbl *= f64_pow10_table[+exp]; + } + return_f64(dbl); + } +#endif + + /* + Fast path 2: + + To keep it simple, we only accept normal number here, + let the slow path to handle subnormal and infinity number. + */ + if (likely(!sig_cut && + exp > -F64_MAX_DEC_EXP + 1 && + exp < +F64_MAX_DEC_EXP - 20)) { + /* + The result value is exactly equal to (sig * 10^exp), + the exponent part (10^exp) can be converted to (sig2 * 2^exp2). + + The sig2 can be an infinite length number, only the highest 128 bits + is cached in the pow10_sig_table. + + Now we have these bits: + sig1 (normalized 64bit) : aaaaaaaa + sig2 (higher 64bit) : bbbbbbbb + sig2_ext (lower 64bit) : cccccccc + sig2_cut (extra unknown bits) : dddddddddddd.... + + And the calculation process is: + ---------------------------------------- + aaaaaaaa * + bbbbbbbbccccccccdddddddddddd.... + ---------------------------------------- + abababababababab + + acacacacacacacac + + adadadadadadadadadad.... + ---------------------------------------- + [hi____][lo____] + + [hi2___][lo2___] + + [unknown___________....] + ---------------------------------------- + + The addition with carry may affect higher bits, but if there is a 0 + in higher bits, the bits higher than 0 will not be affected. + + `lo2` + `unknown` may get a carry bit and may affect `hi2`, the max + value of `hi2` is 0xFFFFFFFFFFFFFFFE, so `hi2` will not overflow. + + `lo` + `hi2` may also get a carry bit and may affect `hi`, but only + the highest significant 53 bits of `hi` is needed. If there is a 0 + in the lower bits of `hi`, then all the following bits can be dropped. + + To convert the result to IEEE-754 double number, we need to perform + correct rounding: + 1. if bit 54 is 0, round down, + 2. if bit 54 is 1 and any bit beyond bit 54 is 1, round up, + 3. if bit 54 is 1 and all bits beyond bit 54 are 0, round to even, + as the extra bits is unknown, this case will not be handled here. + */ + + u64 raw; + u64 sig1, sig2, sig2_ext, hi, lo, hi2, lo2, add, bits; + i32 exp2; + u32 lz; + bool exact = false, carry, round_up; + + /* convert (10^exp) to (sig2 * 2^exp2) */ + pow10_table_get_sig(exp, &sig2, &sig2_ext); + pow10_table_get_exp(exp, &exp2); + + /* normalize and multiply */ + lz = u64_lz_bits(sig); + sig1 = sig << lz; + exp2 -= (i32)lz; + u128_mul(sig1, sig2, &hi, &lo); + + /* + The `hi` is in range [0x4000000000000000, 0xFFFFFFFFFFFFFFFE], + To get normalized value, `hi` should be shifted to the left by 0 or 1. + + The highest significant 53 bits is used by IEEE-754 double number, + and the bit 54 is used to detect rounding direction. + + The lowest (64 - 54 - 1) bits is used to check whether it contains 0. + */ + bits = hi & (((u64)1 << (64 - 54 - 1)) - 1); + if (bits - 1 < (((u64)1 << (64 - 54 - 1)) - 2)) { + /* + (bits != 0 && bits != 0x1FF) => (bits - 1 < 0x1FF - 1) + The `bits` is not zero, so we don't need to check `round to even` + case. The `bits` contains bit `0`, so we can drop the extra bits + after `0`. + */ + exact = true; + + } else { + /* + (bits == 0 || bits == 0x1FF) + The `bits` is filled with all `0` or all `1`, so we need to check + lower bits with another 64-bit multiplication. + */ + u128_mul(sig1, sig2_ext, &hi2, &lo2); + + add = lo + hi2; + if (add + 1 > (u64)1) { + /* + (add != 0 && add != U64_MAX) => (add + 1 > 1) + The `add` is not zero, so we don't need to check `round to + even` case. The `add` contains bit `0`, so we can drop the + extra bits after `0`. The `hi` cannot be U64_MAX, so it will + not overflow. + */ + carry = add < lo || add < hi2; + hi += carry; + exact = true; + } + } + + if (exact) { + /* normalize */ + lz = hi < ((u64)1 << 63); + hi <<= lz; + exp2 -= (i32)lz; + exp2 += 64; + + /* test the bit 54 and get rounding direction */ + round_up = (hi & ((u64)1 << (64 - 54))) > (u64)0; + hi += (round_up ? ((u64)1 << (64 - 54)) : (u64)0); + + /* test overflow */ + if (hi < ((u64)1 << (64 - 54))) { + hi = ((u64)1 << 63); + exp2 += 1; + } + + /* This is a normal number, convert it to IEEE-754 format. */ + hi >>= F64_BITS - F64_SIG_FULL_BITS; + exp2 += F64_BITS - F64_SIG_FULL_BITS + F64_SIG_BITS; + exp2 += F64_EXP_BIAS; + raw = ((u64)exp2 << F64_SIG_BITS) | (hi & F64_SIG_MASK); + return_f64_bin(raw); + } + } + + /* + Slow path: read double number exactly with diyfp. + 1. Use cached diyfp to get an approximation value. + 2. Use bigcomp to check the approximation value if needed. + + This algorithm refers to google's double-conversion project: + https://github.com/google/double-conversion + */ + { + const i32 ERR_ULP_LOG = 3; + const i32 ERR_ULP = 1 << ERR_ULP_LOG; + const i32 ERR_CACHED_POW = ERR_ULP / 2; + const i32 ERR_MUL_FIXED = ERR_ULP / 2; + const i32 DIY_SIG_BITS = 64; + const i32 EXP_BIAS = F64_EXP_BIAS + F64_SIG_BITS; + const i32 EXP_SUBNORMAL = -EXP_BIAS + 1; + + u64 fp_err; + u32 bits; + i32 order_of_magnitude; + i32 effective_significand_size; + i32 precision_digits_count; + u64 precision_bits; + u64 half_way; + + u64 raw; + diy_fp fp, fp_upper; + bigint big_full, big_comp; + i32 cmp; + + fp.sig = sig; + fp.exp = 0; + fp_err = sig_cut ? (u64)(ERR_ULP / 2) : (u64)0; + + /* normalize */ + bits = u64_lz_bits(fp.sig); + fp.sig <<= bits; + fp.exp -= (i32)bits; + fp_err <<= bits; + + /* multiply and add error */ + fp = diy_fp_mul(fp, diy_fp_get_cached_pow10(exp)); + fp_err += (u64)ERR_CACHED_POW + (fp_err != 0) + (u64)ERR_MUL_FIXED; + + /* normalize */ + bits = u64_lz_bits(fp.sig); + fp.sig <<= bits; + fp.exp -= (i32)bits; + fp_err <<= bits; + + /* effective significand */ + order_of_magnitude = DIY_SIG_BITS + fp.exp; + if (likely(order_of_magnitude >= EXP_SUBNORMAL + F64_SIG_FULL_BITS)) { + effective_significand_size = F64_SIG_FULL_BITS; + } else if (order_of_magnitude <= EXP_SUBNORMAL) { + effective_significand_size = 0; + } else { + effective_significand_size = order_of_magnitude - EXP_SUBNORMAL; + } + + /* precision digits count */ + precision_digits_count = DIY_SIG_BITS - effective_significand_size; + if (unlikely(precision_digits_count + ERR_ULP_LOG >= DIY_SIG_BITS)) { + i32 shr = (precision_digits_count + ERR_ULP_LOG) - DIY_SIG_BITS + 1; + fp.sig >>= shr; + fp.exp += shr; + fp_err = (fp_err >> shr) + 1 + (u32)ERR_ULP; + precision_digits_count -= shr; + } + + /* half way */ + precision_bits = fp.sig & (((u64)1 << precision_digits_count) - 1); + precision_bits *= (u32)ERR_ULP; + half_way = (u64)1 << (precision_digits_count - 1); + half_way *= (u32)ERR_ULP; + + /* rounding */ + fp.sig >>= precision_digits_count; + fp.sig += (precision_bits >= half_way + fp_err); + fp.exp += precision_digits_count; + + /* get IEEE double raw value */ + raw = diy_fp_to_ieee_raw(fp); + if (unlikely(raw == F64_BITS_INF)) return_inf(); + if (likely(precision_bits <= half_way - fp_err || + precision_bits >= half_way + fp_err)) { + return_f64_bin(raw); /* number is accurate */ + } + /* now the number is the correct value, or the next lower value */ + + /* upper boundary */ + if (raw & F64_EXP_MASK) { + fp_upper.sig = (raw & F64_SIG_MASK) + ((u64)1 << F64_SIG_BITS); + fp_upper.exp = (i32)((raw & F64_EXP_MASK) >> F64_SIG_BITS); + } else { + fp_upper.sig = (raw & F64_SIG_MASK); + fp_upper.exp = 1; + } + fp_upper.exp -= F64_EXP_BIAS + F64_SIG_BITS; + fp_upper.sig <<= 1; + fp_upper.exp -= 1; + fp_upper.sig += 1; /* add half ulp */ + + /* compare with bigint */ + bigint_set_buf(&big_full, sig, &exp, sig_cut, sig_end, dot_pos); + bigint_set_u64(&big_comp, fp_upper.sig); + if (exp >= 0) { + bigint_mul_pow10(&big_full, +exp); + } else { + bigint_mul_pow10(&big_comp, -exp); + } + if (fp_upper.exp > 0) { + bigint_mul_pow2(&big_comp, (u32)+fp_upper.exp); + } else { + bigint_mul_pow2(&big_full, (u32)-fp_upper.exp); + } + cmp = bigint_cmp(&big_full, &big_comp); + if (likely(cmp != 0)) { + /* round down or round up */ + raw += (cmp > 0); + } else { + /* falls midway, round to even */ + raw += (raw & 1); + } + + if (unlikely(raw == F64_BITS_INF)) return_inf(); + return_f64_bin(raw); + } + +#undef return_err +#undef return_inf +#undef return_0 +#undef return_i64 +#undef return_f64 +#undef return_f64_bin +#undef return_raw +} + + + +#else /* FP_READER */ + +/** + Read a JSON number. + This is a fallback function if the custom number reader is disabled. + This function use libc's strtod() to read floating-point number. + */ +static_inline bool read_num(u8 **ptr, u8 **pre, yyjson_read_flag flg, + yyjson_val *val, const char **msg) { +#define return_err(_pos, _msg) do { \ + *msg = _msg; \ + *end = _pos; \ + return false; \ +} while (false) + +#define return_0() do { \ + val->tag = YYJSON_TYPE_NUM | (u64)((u8)sign << 3); \ + val->uni.u64 = 0; \ + *end = cur; return true; \ +} while (false) + +#define return_i64(_v) do { \ + val->tag = YYJSON_TYPE_NUM | (u64)((u8)sign << 3); \ + val->uni.u64 = (u64)(sign ? (u64)(~(_v) + 1) : (u64)(_v)); \ + *end = cur; return true; \ +} while (false) + +#define return_f64(_v) do { \ + val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; \ + val->uni.f64 = sign ? -(f64)(_v) : (f64)(_v); \ + *end = cur; return true; \ +} while (false) + +#define return_f64_bin(_v) do { \ + val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; \ + val->uni.u64 = ((u64)sign << 63) | (u64)(_v); \ + *end = cur; return true; \ +} while (false) + +#define return_inf() do { \ + if (has_flg(BIGNUM_AS_RAW)) return_raw(); \ + if (has_allow(INF_AND_NAN)) return_f64_bin(F64_BITS_INF); \ + else return_err(hdr, "number is infinity when parsed as double"); \ +} while (false) + +#define return_raw() do { \ + val->tag = ((u64)(cur - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW; \ + val->uni.str = (const char *)hdr; \ + **pre = '\0'; *pre = cur; *end = cur; return true; \ +} while (false) + + u64 sig, num; + u8 *hdr = *ptr; + u8 *cur = *ptr; + u8 **end = ptr; + u8 *dot = NULL; + u8 *f64_end = NULL; + bool sign; + + /* read number as raw string if has `YYJSON_READ_NUMBER_AS_RAW` flag */ + if (has_flg(NUMBER_AS_RAW)) { + return read_num_raw(ptr, pre, flg, val, msg); + } + + sign = (*hdr == '-'); + cur += sign; + sig = (u8)(*cur - '0'); + + /* read first digit, check leading zero */ + while (unlikely(!char_is_digit(*cur))) { + if (has_allow(EXT_NUMBER)) { + if (*cur == '+' && cur == hdr) { /* leading `+` sign */ + cur++; + sig = (u8)(*cur - '0'); + continue; + } + if (*cur == '.' && char_is_num(cur[1])) { /* no integer part */ + goto read_double; /* e.g. '.123' */ + } + } + if (has_allow(INF_AND_NAN)) { + if (read_inf_or_nan(ptr, pre, flg, val)) return true; + } + return_err(cur, "no digit after sign"); + } + if (*cur == '0') { + cur++; + if (unlikely(char_is_digit(*cur))) { + return_err(cur - 1, "number with leading zero is not allowed"); + } + if (!char_is_fp(*cur)) { + if (has_allow(EXT_NUMBER) && + (*cur == 'x' || *cur == 'X')) { /* hex integer */ + return read_num_hex(ptr, pre, flg, val, msg); + } + return_0(); + } + goto read_double; + } + + /* read continuous digits, up to 19 characters */ +#define expr_intg(i) \ + if (likely((num = (u64)(cur[i] - (u8)'0')) <= 9)) sig = num + sig * 10; \ + else { cur += i; goto intg_end; } + repeat_in_1_18(expr_intg) +#undef expr_intg + + /* here are 19 continuous digits, skip them */ + cur += 19; + if (char_is_digit(cur[0]) && !char_is_digit_or_fp(cur[1])) { + /* this number is an integer consisting of 20 digits */ + num = (u8)(*cur - '0'); + if ((sig < (U64_MAX / 10)) || + (sig == (U64_MAX / 10) && num <= (U64_MAX % 10))) { + sig = num + sig * 10; + cur++; + if (sign) { + if (has_flg(BIGNUM_AS_RAW)) return_raw(); + return_f64(unsafe_yyjson_u64_to_f64(sig)); + } + return_i64(sig); + } + } + +intg_end: + /* continuous digits ended */ + if (!char_is_digit_or_fp(*cur)) { + /* this number is an integer consisting of 1 to 19 digits */ + if (sign && (sig > ((u64)1 << 63))) { + if (has_flg(BIGNUM_AS_RAW)) return_raw(); + return_f64(unsafe_yyjson_u64_to_f64(sig)); + } + return_i64(sig); + } + +read_double: + /* this number should be read as double */ + while (char_is_digit(*cur)) cur++; + if (!char_is_fp(*cur) && has_flg(BIGNUM_AS_RAW)) { + return_raw(); /* it's a large integer */ + } + while (*cur == '.') { + /* skip fraction part */ + dot = cur; + cur++; + if (!char_is_digit(*cur)) { + if (has_allow(EXT_NUMBER)) { + break; + } else { + return_err(cur, "no digit after decimal point"); + } + } + cur++; + while (char_is_digit(*cur)) cur++; + break; + } + if (char_is_exp(*cur)) { + /* skip exponent part */ + cur += 1 + char_is_sign(cur[1]); + if (!char_is_digit(*cur)) { + return_err(cur, "no digit after exponent sign"); + } + cur++; + while (char_is_digit(*cur)) cur++; + } + + /* + libc's strtod() is used to parse the floating-point number. + + Note that the decimal point character used by strtod() is locale-dependent, + and the rounding direction may affected by fesetround(). + + For currently known locales, (en, zh, ja, ko, am, he, hi) use '.' as the + decimal point, while other locales use ',' as the decimal point. + + Here strtod() is called twice for different locales, but if another thread + happens calls setlocale() between two strtod(), parsing may still fail. + */ + val->uni.f64 = strtod((const char *)hdr, (char **)&f64_end); + if (unlikely(f64_end != cur)) { + /* replace '.' with ',' for locale */ + bool cut = (*cur == ','); + if (cut) *cur = ' '; + if (dot) *dot = ','; + val->uni.f64 = strtod((const char *)hdr, (char **)&f64_end); + /* restore ',' to '.' */ + if (cut) *cur = ','; + if (dot) *dot = '.'; + if (unlikely(f64_end != cur)) { + return_err(hdr, "strtod() failed to parse the number"); + } + } + if (unlikely(val->uni.f64 >= HUGE_VAL || val->uni.f64 <= -HUGE_VAL)) { + return_inf(); + } + val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; + *end = cur; + return true; + +#undef return_err +#undef return_0 +#undef return_i64 +#undef return_f64 +#undef return_f64_bin +#undef return_inf +#undef return_raw +} + +#endif /* FP_READER */ + + + +/*============================================================================== + * MARK: - String Reader (Private) + *============================================================================*/ + +/** Read unicode escape sequence. */ +static_inline bool read_uni_esc(u8 **src_ptr, u8 **dst_ptr, const char **msg) { +#define return_err(_end, _msg) *msg = _msg; *src_ptr = _end; return false + + u8 *src = *src_ptr; + u8 *dst = *dst_ptr; + u16 hi, lo; + u32 uni; + + src += 2; /* skip `\u` */ + if (unlikely(!hex_load_4(src, &hi))) { + return_err(src - 2, "invalid escaped sequence in string"); + } + src += 4; /* skip hex */ + if (likely((hi & 0xF800) != 0xD800)) { + /* a BMP character */ + if (hi >= 0x800) { + *dst++ = (u8)(0xE0 | (hi >> 12)); + *dst++ = (u8)(0x80 | ((hi >> 6) & 0x3F)); + *dst++ = (u8)(0x80 | (hi & 0x3F)); + } else if (hi >= 0x80) { + *dst++ = (u8)(0xC0 | (hi >> 6)); + *dst++ = (u8)(0x80 | (hi & 0x3F)); + } else { + *dst++ = (u8)hi; + } + } else { + /* a non-BMP character, represented as a surrogate pair */ + if (unlikely((hi & 0xFC00) != 0xD800)) { + return_err(src - 6, "invalid high surrogate in string"); + } + if (unlikely(!byte_match_2(src, "\\u"))) { + return_err(src - 6, "no low surrogate in string"); + } + if (unlikely(!hex_load_4(src + 2, &lo))) { + return_err(src - 6, "invalid escape in string"); + } + if (unlikely((lo & 0xFC00) != 0xDC00)) { + return_err(src - 6, "invalid low surrogate in string"); + } + uni = ((((u32)hi - 0xD800) << 10) | + ((u32)lo - 0xDC00)) + 0x10000; + *dst++ = (u8)(0xF0 | (uni >> 18)); + *dst++ = (u8)(0x80 | ((uni >> 12) & 0x3F)); + *dst++ = (u8)(0x80 | ((uni >> 6) & 0x3F)); + *dst++ = (u8)(0x80 | (uni & 0x3F)); + src += 6; + } + *src_ptr = src; + *dst_ptr = dst; + return true; +#undef return_err +} + +/** + Read a JSON string. + @param quo The quote character (single quote or double quote). + @param ptr The head pointer of string before quote (inout). + @param eof JSON end position. + @param flg JSON read flag. + @param val The string value to be written. + @param msg The error message pointer. + @param con Continuation for incremental parsing. + @return Whether success. + */ +static_inline bool read_str_opt(u8 quo, u8 **ptr, u8 *eof, yyjson_read_flag flg, + yyjson_val *val, const char **msg, u8 *con[2]) { + /* + GCC may sometimes load variables into registers too early, causing + unnecessary instructions and performance degradation. This inline assembly + serves as a hint to GCC: 'This variable will be modified, so avoid loading + it too early.' Other compilers like MSVC, Clang, and ICC can generate the + expected instructions without needing this hint. + + Check out this example: https://godbolt.org/z/YG6a5W5Ec + */ +#define return_err(_end, _msg) do { \ + *msg = _msg; \ + *end = _end; \ + if (con) { con[0] = _end; con[1] = dst; } \ + return false; \ +} while (false) + + u8 *hdr = *ptr + 1; + u8 **end = ptr; + u8 *src = hdr, *dst = NULL, *pos; + u16 hi, lo; + u32 uni, tmp; + + /* Resume incremental parsing. */ + if (con && unlikely(con[0])) { + src = con[0]; + dst = con[1]; + if (dst) goto copy_ascii; + } + +skip_ascii: + /* + Most strings have no escaped characters, so we can jump them quickly. + + We want to make loop unrolling, as shown in the following code. Some + compiler may not generate instructions as expected, so we rewrite it with + explicit goto statements. We hope the compiler can generate instructions + like this: https://godbolt.org/z/8vjsYq + + while (true) repeat16({ + if (likely((char_is_ascii_skip(*src)))) src++; + else break; + }) + */ + if (quo == '"') { +#define expr_jump(i) \ + if (likely(char_is_ascii_skip(src[i]))) {} \ + else goto skip_ascii_stop##i; + +#define expr_stop(i) \ + skip_ascii_stop##i: \ + src += i; \ + goto skip_ascii_end; + + repeat16_incr(expr_jump) + src += 16; + goto skip_ascii; + repeat16_incr(expr_stop) + +#undef expr_jump +#undef expr_stop + } else { +#define expr_jump(i) \ + if (likely(char_is_ascii_skip_sq(src[i]))) {} \ + else goto skip_ascii_stop_sq##i; + +#define expr_stop(i) \ + skip_ascii_stop_sq##i: \ + src += i; \ + goto skip_ascii_end; + + repeat16_incr(expr_jump) + src += 16; + goto skip_ascii; + repeat16_incr(expr_stop) + +#undef expr_jump +#undef expr_stop + } + +skip_ascii_end: + gcc_store_barrier(*src); + if (likely(*src == quo)) { + val->tag = ((u64)(src - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_STR | + (quo == '"' ? YYJSON_SUBTYPE_NOESC : 0); + val->uni.str = (const char *)hdr; + *src = '\0'; + *end = src + 1; + if (con) con[0] = con[1] = NULL; + return true; + } + +skip_utf8: + if (*src & 0x80) { /* non-ASCII character */ + /* + Non-ASCII character appears here, which means that the text is likely + to be written in non-English or emoticons. According to some common + data set statistics, byte sequences of the same length may appear + consecutively. We process the byte sequences of the same length in each + loop, which is more friendly to branch prediction. + */ + pos = src; +#if YYJSON_DISABLE_UTF8_VALIDATION + while (true) repeat8({ + if (likely((*src & 0xF0) == 0xE0)) src += 3; + else break; + }) + if (*src < 0x80) goto skip_ascii; + while (true) repeat8({ + if (likely((*src & 0xE0) == 0xC0)) src += 2; + else break; + }) + while (true) repeat8({ + if (likely((*src & 0xF8) == 0xF0)) src += 4; + else break; + }) +#else + uni = byte_load_4(src); + while (is_utf8_seq3(uni)) { + src += 3; + uni = byte_load_4(src); + } + if (is_utf8_seq1(uni)) goto skip_ascii; + while (is_utf8_seq2(uni)) { + src += 2; + uni = byte_load_4(src); + } + while (is_utf8_seq4(uni)) { + src += 4; + uni = byte_load_4(src); + } +#endif + if (unlikely(pos == src)) { + if (has_allow(INVALID_UNICODE)) ++src; + else return_err(src, "invalid UTF-8 encoding in string"); + } + goto skip_ascii; + } + + /* The escape character appears, we need to copy it. */ + dst = src; +copy_escape: + if (likely(*src == '\\')) { + switch (*++src) { + case '"': *dst++ = '"'; src++; break; + case '\\': *dst++ = '\\'; src++; break; + case '/': *dst++ = '/'; src++; break; + case 'b': *dst++ = '\b'; src++; break; + case 'f': *dst++ = '\f'; src++; break; + case 'n': *dst++ = '\n'; src++; break; + case 'r': *dst++ = '\r'; src++; break; + case 't': *dst++ = '\t'; src++; break; + case 'u': + src--; + if (!read_uni_esc(&src, &dst, msg)) return_err(src, *msg); + break; + default: { + if (has_allow(EXT_ESCAPE)) { + /* read extended escape (non-standard) */ + switch (*src) { + case '\'': *dst++ = '\''; src++; break; + case 'a': *dst++ = '\a'; src++; break; + case 'v': *dst++ = '\v'; src++; break; + case '?': *dst++ = '\?'; src++; break; + case 'e': *dst++ = 0x1B; src++; break; + case '0': + if (!char_is_digit(src[1])) { + *dst++ = '\0'; src++; break; + } + return_err(src - 1, "octal escape is not allowed"); + case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + return_err(src - 1, "invalid number escape"); + case 'x': { + u8 c; + if (hex_load_2(src + 1, &c)) { + src += 3; + if (c <= 0x7F) { /* 1-byte ASCII */ + *dst++ = c; + } else { /* 2-byte UTF-8 */ + *dst++ = (u8)(0xC0 | (c >> 6)); + *dst++ = (u8)(0x80 | (c & 0x3F)); + } + break; + } + return_err(src - 1, "invalid hex escape"); + } + case '\n': src++; break; + case '\r': src++; src += (*src == '\n'); break; + case 0xE2: /* Line terminator: U+2028, U+2029 */ + if ((src[1] == 0x80 && src[2] == 0xA8) || + (src[1] == 0x80 && src[2] == 0xA9)) { + src += 3; + } + break; + default: + break; /* skip */ + } + } else if (quo == '\'' && *src == '\'') { + *dst++ = '\''; src++; break; + } else { + return_err(src - 1, "invalid escaped sequence in string"); + } + } + } + } else if (likely(*src == quo)) { + val->tag = ((u64)(dst - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; + val->uni.str = (const char *)hdr; + *dst = '\0'; + *end = src + 1; + if (con) con[0] = con[1] = NULL; + return true; + } else { + if (!has_allow(INVALID_UNICODE)) { + return_err(src, "unexpected control character in string"); + } + if (src >= eof) return_err(src, "unclosed string"); + *dst++ = *src++; + } + +copy_ascii: + /* + Copy continuous ASCII, loop unrolling, same as the following code: + + while (true) repeat16({ + if (char_is_ascii_skip(*src)) *dst++ = *src++; + else break; + }) + */ + if (quo == '"') { +#define expr_jump(i) \ + if (likely((char_is_ascii_skip(src[i])))) {} \ + else { gcc_store_barrier(src[i]); goto copy_ascii_stop_##i; } + repeat16_incr(expr_jump) +#undef expr_jump + } else { +#define expr_jump(i) \ + if (likely((char_is_ascii_skip_sq(src[i])))) {} \ + else { gcc_store_barrier(src[i]); goto copy_ascii_stop_##i; } + repeat16_incr(expr_jump) +#undef expr_jump + } + + byte_move_16(dst, src); + dst += 16; src += 16; + goto copy_ascii; + + /* + The memory is copied forward since `dst < src`. + So it's safe to move one extra byte to reduce instruction count. + */ +#define expr_jump(i) \ + copy_ascii_stop_##i: \ + byte_move_forward(dst, src, i); \ + dst += i; src += i; \ + goto copy_utf8; + repeat16_incr(expr_jump) +#undef expr_jump + +copy_utf8: + if (*src & 0x80) { /* non-ASCII character */ + pos = src; + uni = byte_load_4(src); +#if YYJSON_DISABLE_UTF8_VALIDATION + while (true) repeat4({ + if ((uni & utf8_seq(b3_mask)) == utf8_seq(b3_patt)) { + byte_copy_4(dst, &uni); + dst += 3; src += 3; + uni = byte_load_4(src); + } else break; + }) + if ((uni & utf8_seq(b1_mask)) == utf8_seq(b1_patt)) goto copy_ascii; + while (true) repeat4({ + if ((uni & utf8_seq(b2_mask)) == utf8_seq(b2_patt)) { + byte_copy_2(dst, &uni); + dst += 2; src += 2; + uni = byte_load_4(src); + } else break; + }) + while (true) repeat4({ + if ((uni & utf8_seq(b4_mask)) == utf8_seq(b4_patt)) { + byte_copy_4(dst, &uni); + dst += 4; src += 4; + uni = byte_load_4(src); + } else break; + }) +#else + while (is_utf8_seq3(uni)) { + byte_copy_4(dst, &uni); + dst += 3; src += 3; + uni = byte_load_4(src); + } + if (is_utf8_seq1(uni)) goto copy_ascii; + while (is_utf8_seq2(uni)) { + byte_copy_2(dst, &uni); + dst += 2; src += 2; + uni = byte_load_4(src); + } + while (is_utf8_seq4(uni)) { + byte_copy_4(dst, &uni); + dst += 4; src += 4; + uni = byte_load_4(src); + } +#endif + if (unlikely(pos == src)) { + if (!has_allow(INVALID_UNICODE)) { + return_err(src, MSG_ERR_UTF8); + } + goto copy_ascii_stop_1; + } + goto copy_ascii; + } + goto copy_escape; + +#undef return_err +} + +static_inline bool read_str(u8 **ptr, u8 *eof, yyjson_read_flag flg, + yyjson_val *val, const char **msg) { + return read_str_opt('\"', ptr, eof, flg, val, msg, NULL); +} + +static_inline bool read_str_con(u8 **ptr, u8 *eof, yyjson_read_flag flg, + yyjson_val *val, const char **msg, u8 **con) { + return read_str_opt('\"', ptr, eof, flg, val, msg, con); +} + +static_noinline bool read_str_sq(u8 **ptr, u8 *eof, yyjson_read_flag flg, + yyjson_val *val, const char **msg) { + return read_str_opt('\'', ptr, eof, flg, val, msg, NULL); +} + +/** Read unquoted key (identifier name). */ +static_noinline bool read_str_id(u8 **ptr, u8 *eof, yyjson_read_flag flg, + u8 **pre, yyjson_val *val, const char **msg) { +#define return_err(_end, _msg) do { \ + *msg = _msg; \ + *end = _end; \ + return false; \ +} while (false) + +#define return_suc(_str_end, _cur_end) do { \ + val->tag = ((u64)(_str_end - hdr) << YYJSON_TAG_BIT) | \ + (u64)(YYJSON_TYPE_STR); \ + val->uni.str = (const char *)hdr; \ + *pre = _str_end; *end = _cur_end; \ + return true; \ +} while (false) + + u8 *hdr = *ptr; + u8 **end = ptr; + u8 *src = hdr, *dst = NULL; + u16 hi, lo; + u32 uni, tmp; + + /* add null-terminator for previous raw string */ + **pre = '\0'; + +skip_ascii: +#define expr_jump(i) \ + if (likely(char_is_id_ascii(src[i]))) {} \ + else goto skip_ascii_stop##i; + +#define expr_stop(i) \ + skip_ascii_stop##i: \ + src += i; \ + goto skip_ascii_end; + + repeat16_incr(expr_jump) + src += 16; + goto skip_ascii; + repeat16_incr(expr_stop) + +#undef expr_jump +#undef expr_stop + +skip_ascii_end: + gcc_store_barrier(*src); + if (likely(!char_is_id_next(*src))) { + return_suc(src, src); + } + +skip_utf8: + while (*src >= 0x80) { + if (has_allow(EXT_WHITESPACE)) { + if (char_is_space_ext(*src) && ext_space_len(src)) { + return_suc(src, src); + } + } + uni = byte_load_4(src); + if (is_utf8_seq2(uni)) { + src += 2; + } else if (is_utf8_seq3(uni)) { + src += 3; + } else if (is_utf8_seq4(uni)) { + src += 4; + } else { +#if !YYJSON_DISABLE_UTF8_VALIDATION + if (!has_allow(INVALID_UNICODE)) return_err(src, MSG_ERR_UTF8); +#endif + src += 1; + } + } + if (char_is_id_ascii(*src)) goto skip_ascii; + + /* The escape character appears, we need to copy it. */ + dst = src; +copy_escape: + if (byte_match_2(src, "\\u")) { + if (!read_uni_esc(&src, &dst, msg)) return_err(src, *msg); + } else { + if (!char_is_id_next(*src)) return_suc(dst, src); + return_err(src, "unexpected character in key"); + } + +copy_ascii: + /* + Copy continuous ASCII, loop unrolling, same as the following code: + + while (true) repeat16({ + if (char_is_ascii_skip(*src)) *dst++ = *src++; + else break; + }) + */ +#define expr_jump(i) \ + if (likely((char_is_id_ascii(src[i])))) {} \ + else { gcc_store_barrier(src[i]); goto copy_ascii_stop_##i; } + repeat16_incr(expr_jump) +#undef expr_jump + + byte_move_16(dst, src); + dst += 16; src += 16; + goto copy_ascii; + +#define expr_jump(i) \ + copy_ascii_stop_##i: \ + byte_move_forward(dst, src, i); \ + dst += i; src += i; \ + goto copy_utf8; + repeat16_incr(expr_jump) +#undef expr_jump + +copy_utf8: + while (*src >= 0x80) { /* non-ASCII character */ + if (has_allow(EXT_WHITESPACE)) { + if (char_is_space_ext(*src) && ext_space_len(src)) { + return_suc(dst, src); + } + } + uni = byte_load_4(src); + if (is_utf8_seq2(uni)) { + byte_copy_2(dst, &uni); + dst += 2; src += 2; + } else if (is_utf8_seq3(uni)) { + byte_copy_4(dst, &uni); + dst += 3; src += 3; + } else if (is_utf8_seq4(uni)) { + byte_copy_4(dst, &uni); + dst += 4; src += 4; + } else { +#if !YYJSON_DISABLE_UTF8_VALIDATION + if (!has_allow(INVALID_UNICODE)) return_err(src, MSG_ERR_UTF8); +#endif + *dst = *src; + dst += 1; src += 1; + } + } + if (char_is_id_ascii(*src)) goto copy_ascii; + goto copy_escape; + +#undef return_err +#undef return_suc +} + + + +/*============================================================================== + * MARK: - JSON Reader Implementation (Private) + * + * We use goto statements to build the finite state machine (FSM). + * The FSM's state was held by program counter (PC) and the 'goto' make the + * state transitions. + *============================================================================*/ + +/** Read single value JSON document. */ +static_noinline yyjson_doc *read_root_single(u8 *hdr, u8 *cur, u8 *eof, + yyjson_alc alc, + yyjson_read_flag flg, + yyjson_read_err *err) { +#define return_err(_pos, _code, _msg) do { \ + if (is_truncated_end(hdr, _pos, eof, YYJSON_READ_ERROR_##_code, flg)) { \ + err->pos = (usize)(eof - hdr); \ + err->code = YYJSON_READ_ERROR_UNEXPECTED_END; \ + err->msg = MSG_NOT_END; \ + } else { \ + err->pos = (usize)(_pos - hdr); \ + err->code = YYJSON_READ_ERROR_##_code; \ + err->msg = _msg; \ + } \ + if (val_hdr) alc.free(alc.ctx, val_hdr); \ + return NULL; \ +} while (false) + + usize hdr_len; /* value count used by doc */ + usize alc_num; /* value count capacity */ + yyjson_val *val_hdr; /* the head of allocated values */ + yyjson_val *val; /* current value */ + yyjson_doc *doc; /* the JSON document, equals to val_hdr */ + const char *msg; /* error message */ + + u8 raw_end[1]; /* raw end for null-terminator */ + u8 *raw_ptr = raw_end; + u8 **pre = &raw_ptr; /* previous raw end pointer */ + + hdr_len = sizeof(yyjson_doc) / sizeof(yyjson_val); + hdr_len += (sizeof(yyjson_doc) % sizeof(yyjson_val)) > 0; + alc_num = hdr_len + 1; /* single value */ + + val_hdr = (yyjson_val *)alc.malloc(alc.ctx, alc_num * sizeof(yyjson_val)); + if (unlikely(!val_hdr)) goto fail_alloc; + val = val_hdr + hdr_len; + + if (char_is_num(*cur)) { + if (likely(read_num(&cur, pre, flg, val, &msg))) goto doc_end; + goto fail_number; + } + if (*cur == '"') { + if (likely(read_str(&cur, eof, flg, val, &msg))) goto doc_end; + goto fail_string; + } + if (*cur == 't') { + if (likely(read_true(&cur, val))) goto doc_end; + goto fail_literal_true; + } + if (*cur == 'f') { + if (likely(read_false(&cur, val))) goto doc_end; + goto fail_literal_false; + } + if (*cur == 'n') { + if (likely(read_null(&cur, val))) goto doc_end; + if (has_allow(INF_AND_NAN)) { + if (read_nan(&cur, pre, flg, val)) goto doc_end; + } + goto fail_literal_null; + } + if (has_allow(INF_AND_NAN)) { + if (read_inf_or_nan(&cur, pre, flg, val)) goto doc_end; + } + if (has_allow(SINGLE_QUOTED_STR) && *cur == '\'') { + if (likely(read_str_sq(&cur, eof, flg, val, &msg))) goto doc_end; + goto fail_string; + } + goto fail_character; + +doc_end: + /* check invalid contents after json document */ + if (unlikely(cur < eof) && !has_flg(STOP_WHEN_DONE)) { + while (char_is_space(*cur)) cur++; + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (!skip_trivia(&cur, eof, flg) && cur == eof) { + goto fail_comment; + } + } + if (unlikely(cur < eof)) goto fail_garbage; + } + + **pre = '\0'; + doc = (yyjson_doc *)val_hdr; + doc->root = val_hdr + hdr_len; + doc->alc = alc; + doc->dat_read = (usize)(cur - hdr); + doc->val_read = 1; + doc->str_pool = has_flg(INSITU) ? NULL : (char *)hdr; + return doc; + +fail_string: return_err(cur, INVALID_STRING, msg); +fail_number: return_err(cur, INVALID_NUMBER, msg); +fail_alloc: return_err(cur, MEMORY_ALLOCATION, MSG_MALLOC); +fail_literal_true: return_err(cur, LITERAL, MSG_CHAR_T); +fail_literal_false: return_err(cur, LITERAL, MSG_CHAR_F); +fail_literal_null: return_err(cur, LITERAL, MSG_CHAR_N); +fail_character: return_err(cur, UNEXPECTED_CHARACTER, MSG_CHAR); +fail_comment: return_err(cur, INVALID_COMMENT, MSG_COMMENT); +fail_garbage: return_err(cur, UNEXPECTED_CONTENT, MSG_GARBAGE); + +#undef return_err +} + +/** Read JSON document (accept all style, but optimized for minify). */ +static_inline yyjson_doc *read_root_minify(u8 *hdr, u8 *cur, u8 *eof, + yyjson_alc alc, + yyjson_read_flag flg, + yyjson_read_err *err) { +#define return_err(_pos, _code, _msg) do { \ + if (is_truncated_end(hdr, _pos, eof, YYJSON_READ_ERROR_##_code, flg)) { \ + err->pos = (usize)(eof - hdr); \ + err->code = YYJSON_READ_ERROR_UNEXPECTED_END; \ + err->msg = MSG_NOT_END; \ + } else { \ + err->pos = (usize)(_pos - hdr); \ + err->code = YYJSON_READ_ERROR_##_code; \ + err->msg = _msg; \ + } \ + if (val_hdr) alc.free(alc.ctx, val_hdr); \ + return NULL; \ +} while (false) + +#define val_incr() do { \ + val++; \ + if (unlikely(val >= val_end)) { \ + usize alc_old = alc_len; \ + usize val_ofs = (usize)(val - val_hdr); \ + usize ctn_ofs = (usize)(ctn - val_hdr); \ + alc_len += alc_len / 2; \ + if ((sizeof(usize) < 8) && (alc_len >= alc_max)) goto fail_alloc; \ + val_tmp = (yyjson_val *)alc.realloc(alc.ctx, (void *)val_hdr, \ + alc_old * sizeof(yyjson_val), \ + alc_len * sizeof(yyjson_val)); \ + if ((!val_tmp)) goto fail_alloc; \ + val = val_tmp + val_ofs; \ + ctn = val_tmp + ctn_ofs; \ + val_hdr = val_tmp; \ + val_end = val_tmp + (alc_len - 2); \ + } \ +} while (false) + + usize dat_len; /* data length in bytes, hint for allocator */ + usize hdr_len; /* value count used by yyjson_doc */ + usize alc_len; /* value count allocated */ + usize alc_max; /* maximum value count for allocator */ + usize ctn_len; /* the number of elements in current container */ + yyjson_val *val_hdr; /* the head of allocated values */ + yyjson_val *val_end; /* the end of allocated values */ + yyjson_val *val_tmp; /* temporary pointer for realloc */ + yyjson_val *val; /* current JSON value */ + yyjson_val *ctn; /* current container */ + yyjson_val *ctn_parent; /* parent of current container */ + yyjson_doc *doc; /* the JSON document, equals to val_hdr */ + const char *msg; /* error message */ + + u8 raw_end[1]; /* raw end for null-terminator */ + u8 *raw_ptr = raw_end; + u8 **pre = &raw_ptr; /* previous raw end pointer */ + + dat_len = has_flg(STOP_WHEN_DONE) ? 256 : (usize)(eof - cur); + hdr_len = sizeof(yyjson_doc) / sizeof(yyjson_val); + hdr_len += (sizeof(yyjson_doc) % sizeof(yyjson_val)) > 0; + alc_max = USIZE_MAX / sizeof(yyjson_val); + alc_len = hdr_len + (dat_len / YYJSON_READER_ESTIMATED_MINIFY_RATIO) + 4; + alc_len = yyjson_min(alc_len, alc_max); + + val_hdr = (yyjson_val *)alc.malloc(alc.ctx, alc_len * sizeof(yyjson_val)); + if (unlikely(!val_hdr)) goto fail_alloc; + val_end = val_hdr + (alc_len - 2); /* padding for key-value pair reading */ + val = val_hdr + hdr_len; + ctn = val; + ctn_len = 0; + + if (*cur++ == '{') { + ctn->tag = YYJSON_TYPE_OBJ; + ctn->uni.ofs = 0; + goto obj_key_begin; + } else { + ctn->tag = YYJSON_TYPE_ARR; + ctn->uni.ofs = 0; + goto arr_val_begin; + } + +arr_begin: + /* save current container */ + ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) | + (ctn->tag & YYJSON_TAG_MASK); + + /* create a new array value, save parent container offset */ + val_incr(); + val->tag = YYJSON_TYPE_ARR; + val->uni.ofs = (usize)((u8 *)val - (u8 *)ctn); + + /* push the new array value as current container */ + ctn = val; + ctn_len = 0; + +arr_val_begin: + if (*cur == '{') { + cur++; + goto obj_begin; + } + if (*cur == '[') { + cur++; + goto arr_begin; + } + if (char_is_num(*cur)) { + val_incr(); + ctn_len++; + if (likely(read_num(&cur, pre, flg, val, &msg))) goto arr_val_end; + goto fail_number; + } + if (*cur == '"') { + val_incr(); + ctn_len++; + if (likely(read_str(&cur, eof, flg, val, &msg))) goto arr_val_end; + goto fail_string; + } + if (*cur == 't') { + val_incr(); + ctn_len++; + if (likely(read_true(&cur, val))) goto arr_val_end; + goto fail_literal_true; + } + if (*cur == 'f') { + val_incr(); + ctn_len++; + if (likely(read_false(&cur, val))) goto arr_val_end; + goto fail_literal_false; + } + if (*cur == 'n') { + val_incr(); + ctn_len++; + if (likely(read_null(&cur, val))) goto arr_val_end; + if (has_allow(INF_AND_NAN)) { + if (read_nan(&cur, pre, flg, val)) goto arr_val_end; + } + goto fail_literal_null; + } + if (*cur == ']') { + cur++; + if (likely(ctn_len == 0)) goto arr_end; + if (has_allow(TRAILING_COMMAS)) goto arr_end; + while (*cur != ',') cur--; + goto fail_trailing_comma; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto arr_val_begin; + } + if (has_allow(INF_AND_NAN) && + (*cur == 'i' || *cur == 'I' || *cur == 'N')) { + val_incr(); + ctn_len++; + if (read_inf_or_nan(&cur, pre, flg, val)) goto arr_val_end; + goto fail_character_val; + } + if (has_allow(SINGLE_QUOTED_STR) && *cur == '\'') { + val_incr(); + ctn_len++; + if (likely(read_str_sq(&cur, eof, flg, val, &msg))) goto arr_val_end; + goto fail_string; + } + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (skip_trivia(&cur, eof, flg)) goto arr_val_begin; + if (cur == eof) goto fail_comment; + } + goto fail_character_val; + +arr_val_end: + if (*cur == ',') { + cur++; + goto arr_val_begin; + } + if (*cur == ']') { + cur++; + goto arr_end; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto arr_val_end; + } + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (skip_trivia(&cur, eof, flg)) goto arr_val_end; + if (cur == eof) goto fail_comment; + } + goto fail_character_arr_end; + +arr_end: + /* get parent container */ + ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs); + + /* save the next sibling value offset */ + ctn->uni.ofs = (usize)((u8 *)val - (u8 *)ctn) + sizeof(yyjson_val); + ctn->tag = ((ctn_len) << YYJSON_TAG_BIT) | YYJSON_TYPE_ARR; + if (unlikely(ctn == ctn_parent)) goto doc_end; + + /* pop parent as current container */ + ctn = ctn_parent; + ctn_len = (usize)(ctn->tag >> YYJSON_TAG_BIT); + if ((ctn->tag & YYJSON_TYPE_MASK) == YYJSON_TYPE_OBJ) { + goto obj_val_end; + } else { + goto arr_val_end; + } + +obj_begin: + /* push container */ + ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) | + (ctn->tag & YYJSON_TAG_MASK); + val_incr(); + val->tag = YYJSON_TYPE_OBJ; + /* offset to the parent */ + val->uni.ofs = (usize)((u8 *)val - (u8 *)ctn); + ctn = val; + ctn_len = 0; + +obj_key_begin: + if (likely(*cur == '"')) { + val_incr(); + ctn_len++; + if (likely(read_str(&cur, eof, flg, val, &msg))) goto obj_key_end; + goto fail_string; + } + if (likely(*cur == '}')) { + cur++; + if (likely(ctn_len == 0)) goto obj_end; + if (has_allow(TRAILING_COMMAS)) goto obj_end; + while (*cur != ',') cur--; + goto fail_trailing_comma; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto obj_key_begin; + } + if (has_allow(SINGLE_QUOTED_STR) && *cur == '\'') { + val_incr(); + ctn_len++; + if (likely(read_str_sq(&cur, eof, flg, val, &msg))) goto obj_key_end; + goto fail_string; + } + if (has_allow(UNQUOTED_KEY) && char_is_id_start(*cur)) { + val_incr(); + ctn_len++; + if (read_str_id(&cur, eof, flg, pre, val, &msg)) goto obj_key_end; + goto fail_string; + } + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (skip_trivia(&cur, eof, flg)) goto obj_key_begin; + if (cur == eof) goto fail_comment; + } + goto fail_character_obj_key; + +obj_key_end: + if (*cur == ':') { + cur++; + goto obj_val_begin; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto obj_key_end; + } + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (skip_trivia(&cur, eof, flg)) goto obj_key_end; + if (cur == eof) goto fail_comment; + } + goto fail_character_obj_sep; + +obj_val_begin: + if (*cur == '"') { + val++; + ctn_len++; + if (likely(read_str(&cur, eof, flg, val, &msg))) goto obj_val_end; + goto fail_string; + } + if (char_is_num(*cur)) { + val++; + ctn_len++; + if (likely(read_num(&cur, pre, flg, val, &msg))) goto obj_val_end; + goto fail_number; + } + if (*cur == '{') { + cur++; + goto obj_begin; + } + if (*cur == '[') { + cur++; + goto arr_begin; + } + if (*cur == 't') { + val++; + ctn_len++; + if (likely(read_true(&cur, val))) goto obj_val_end; + goto fail_literal_true; + } + if (*cur == 'f') { + val++; + ctn_len++; + if (likely(read_false(&cur, val))) goto obj_val_end; + goto fail_literal_false; + } + if (*cur == 'n') { + val++; + ctn_len++; + if (likely(read_null(&cur, val))) goto obj_val_end; + if (has_allow(INF_AND_NAN)) { + if (read_nan(&cur, pre, flg, val)) goto obj_val_end; + } + goto fail_literal_null; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto obj_val_begin; + } + if (has_allow(INF_AND_NAN) && + (*cur == 'i' || *cur == 'I' || *cur == 'N')) { + val++; + ctn_len++; + if (read_inf_or_nan(&cur, pre, flg, val)) goto obj_val_end; + goto fail_character_val; + } + if (has_allow(SINGLE_QUOTED_STR) && *cur == '\'') { + val++; + ctn_len++; + if (likely(read_str_sq(&cur, eof, flg, val, &msg))) goto obj_val_end; + goto fail_string; + } + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (skip_trivia(&cur, eof, flg)) goto obj_val_begin; + if (cur == eof) goto fail_comment; + } + goto fail_character_val; + +obj_val_end: + if (likely(*cur == ',')) { + cur++; + goto obj_key_begin; + } + if (likely(*cur == '}')) { + cur++; + goto obj_end; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto obj_val_end; + } + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (skip_trivia(&cur, eof, flg)) goto obj_val_end; + if (cur == eof) goto fail_comment; + } + goto fail_character_obj_end; + +obj_end: + /* pop container */ + ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs); + /* point to the next value */ + ctn->uni.ofs = (usize)((u8 *)val - (u8 *)ctn) + sizeof(yyjson_val); + ctn->tag = (ctn_len << (YYJSON_TAG_BIT - 1)) | YYJSON_TYPE_OBJ; + if (unlikely(ctn == ctn_parent)) goto doc_end; + ctn = ctn_parent; + ctn_len = (usize)(ctn->tag >> YYJSON_TAG_BIT); + if ((ctn->tag & YYJSON_TYPE_MASK) == YYJSON_TYPE_OBJ) { + goto obj_val_end; + } else { + goto arr_val_end; + } + +doc_end: + /* check invalid contents after json document */ + if (unlikely(cur < eof) && !has_flg(STOP_WHEN_DONE)) { + while (char_is_space(*cur)) cur++; + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (!skip_trivia(&cur, eof, flg) && cur == eof) { + goto fail_comment; + } + } + if (unlikely(cur < eof)) goto fail_garbage; + } + + **pre = '\0'; + doc = (yyjson_doc *)val_hdr; + doc->root = val_hdr + hdr_len; + doc->alc = alc; + doc->dat_read = (usize)(cur - hdr); + doc->val_read = (usize)((val - doc->root) + 1); + doc->str_pool = has_flg(INSITU) ? NULL : (char *)hdr; + return doc; + +fail_string: return_err(cur, INVALID_STRING, msg); +fail_number: return_err(cur, INVALID_NUMBER, msg); +fail_alloc: return_err(cur, MEMORY_ALLOCATION, MSG_MALLOC); +fail_trailing_comma: return_err(cur, JSON_STRUCTURE, MSG_COMMA); +fail_literal_true: return_err(cur, LITERAL, MSG_CHAR_T); +fail_literal_false: return_err(cur, LITERAL, MSG_CHAR_F); +fail_literal_null: return_err(cur, LITERAL, MSG_CHAR_N); +fail_character_val: return_err(cur, UNEXPECTED_CHARACTER, MSG_CHAR); +fail_character_arr_end: return_err(cur, UNEXPECTED_CHARACTER, MSG_ARR_END); +fail_character_obj_key: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_KEY); +fail_character_obj_sep: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_SEP); +fail_character_obj_end: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_END); +fail_comment: return_err(cur, INVALID_COMMENT, MSG_COMMENT); +fail_garbage: return_err(cur, UNEXPECTED_CONTENT, MSG_GARBAGE); + +#undef val_incr +#undef return_err +} + +/** Read JSON document (accept all style, but optimized for pretty). */ +static_inline yyjson_doc *read_root_pretty(u8 *hdr, u8 *cur, u8 *eof, + yyjson_alc alc, + yyjson_read_flag flg, + yyjson_read_err *err) { +#define return_err(_pos, _code, _msg) do { \ + if (is_truncated_end(hdr, _pos, eof, YYJSON_READ_ERROR_##_code, flg)) { \ + err->pos = (usize)(eof - hdr); \ + err->code = YYJSON_READ_ERROR_UNEXPECTED_END; \ + err->msg = MSG_NOT_END; \ + } else { \ + err->pos = (usize)(_pos - hdr); \ + err->code = YYJSON_READ_ERROR_##_code; \ + err->msg = _msg; \ + } \ + if (val_hdr) alc.free(alc.ctx, val_hdr); \ + return NULL; \ +} while (false) + +#define val_incr() do { \ + val++; \ + if (unlikely(val >= val_end)) { \ + usize alc_old = alc_len; \ + usize val_ofs = (usize)(val - val_hdr); \ + usize ctn_ofs = (usize)(ctn - val_hdr); \ + alc_len += alc_len / 2; \ + if ((sizeof(usize) < 8) && (alc_len >= alc_max)) goto fail_alloc; \ + val_tmp = (yyjson_val *)alc.realloc(alc.ctx, (void *)val_hdr, \ + alc_old * sizeof(yyjson_val), \ + alc_len * sizeof(yyjson_val)); \ + if ((!val_tmp)) goto fail_alloc; \ + val = val_tmp + val_ofs; \ + ctn = val_tmp + ctn_ofs; \ + val_hdr = val_tmp; \ + val_end = val_tmp + (alc_len - 2); \ + } \ +} while (false) + + usize dat_len; /* data length in bytes, hint for allocator */ + usize hdr_len; /* value count used by yyjson_doc */ + usize alc_len; /* value count allocated */ + usize alc_max; /* maximum value count for allocator */ + usize ctn_len; /* the number of elements in current container */ + yyjson_val *val_hdr; /* the head of allocated values */ + yyjson_val *val_end; /* the end of allocated values */ + yyjson_val *val_tmp; /* temporary pointer for realloc */ + yyjson_val *val; /* current JSON value */ + yyjson_val *ctn; /* current container */ + yyjson_val *ctn_parent; /* parent of current container */ + yyjson_doc *doc; /* the JSON document, equals to val_hdr */ + const char *msg; /* error message */ + + u8 raw_end[1]; /* raw end for null-terminator */ + u8 *raw_ptr = raw_end; + u8 **pre = &raw_ptr; /* previous raw end pointer */ + + dat_len = has_flg(STOP_WHEN_DONE) ? 256 : (usize)(eof - cur); + hdr_len = sizeof(yyjson_doc) / sizeof(yyjson_val); + hdr_len += (sizeof(yyjson_doc) % sizeof(yyjson_val)) > 0; + alc_max = USIZE_MAX / sizeof(yyjson_val); + alc_len = hdr_len + (dat_len / YYJSON_READER_ESTIMATED_PRETTY_RATIO) + 4; + alc_len = yyjson_min(alc_len, alc_max); + + val_hdr = (yyjson_val *)alc.malloc(alc.ctx, alc_len * sizeof(yyjson_val)); + if (unlikely(!val_hdr)) goto fail_alloc; + val_end = val_hdr + (alc_len - 2); /* padding for key-value pair reading */ + val = val_hdr + hdr_len; + ctn = val; + ctn_len = 0; + + if (*cur++ == '{') { + ctn->tag = YYJSON_TYPE_OBJ; + ctn->uni.ofs = 0; + if (*cur == '\n') cur++; + goto obj_key_begin; + } else { + ctn->tag = YYJSON_TYPE_ARR; + ctn->uni.ofs = 0; + if (*cur == '\n') cur++; + goto arr_val_begin; + } + +arr_begin: + /* save current container */ + ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) | + (ctn->tag & YYJSON_TAG_MASK); + + /* create a new array value, save parent container offset */ + val_incr(); + val->tag = YYJSON_TYPE_ARR; + val->uni.ofs = (usize)((u8 *)val - (u8 *)ctn); + + /* push the new array value as current container */ + ctn = val; + ctn_len = 0; + if (*cur == '\n') cur++; + +arr_val_begin: +#if YYJSON_IS_REAL_GCC + while (true) repeat16({ + if (byte_match_2(cur, " ")) cur += 2; + else break; + }) +#else + while (true) repeat16({ + if (likely(byte_match_2(cur, " "))) cur += 2; + else break; + }) +#endif + + if (*cur == '{') { + cur++; + goto obj_begin; + } + if (*cur == '[') { + cur++; + goto arr_begin; + } + if (char_is_num(*cur)) { + val_incr(); + ctn_len++; + if (likely(read_num(&cur, pre, flg, val, &msg))) goto arr_val_end; + goto fail_number; + } + if (*cur == '"') { + val_incr(); + ctn_len++; + if (likely(read_str(&cur, eof, flg, val, &msg))) goto arr_val_end; + goto fail_string; + } + if (*cur == 't') { + val_incr(); + ctn_len++; + if (likely(read_true(&cur, val))) goto arr_val_end; + goto fail_literal_true; + } + if (*cur == 'f') { + val_incr(); + ctn_len++; + if (likely(read_false(&cur, val))) goto arr_val_end; + goto fail_literal_false; + } + if (*cur == 'n') { + val_incr(); + ctn_len++; + if (likely(read_null(&cur, val))) goto arr_val_end; + if (has_allow(INF_AND_NAN)) { + if (read_nan(&cur, pre, flg, val)) goto arr_val_end; + } + goto fail_literal_null; + } + if (*cur == ']') { + cur++; + if (likely(ctn_len == 0)) goto arr_end; + if (has_allow(TRAILING_COMMAS)) goto arr_end; + while (*cur != ',') cur--; + goto fail_trailing_comma; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto arr_val_begin; + } + if (has_allow(INF_AND_NAN) && + (*cur == 'i' || *cur == 'I' || *cur == 'N')) { + val_incr(); + ctn_len++; + if (read_inf_or_nan(&cur, pre, flg, val)) goto arr_val_end; + goto fail_character_val; + } + if (has_allow(SINGLE_QUOTED_STR) && *cur == '\'') { + val_incr(); + ctn_len++; + if (likely(read_str_sq(&cur, eof, flg, val, &msg))) goto arr_val_end; + goto fail_string; + } + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (skip_trivia(&cur, eof, flg)) goto arr_val_begin; + if (cur == eof) goto fail_comment; + } + goto fail_character_val; + +arr_val_end: + if (byte_match_2(cur, ",\n")) { + cur += 2; + goto arr_val_begin; + } + if (*cur == ',') { + cur++; + goto arr_val_begin; + } + if (*cur == ']') { + cur++; + goto arr_end; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto arr_val_end; + } + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (skip_trivia(&cur, eof, flg)) goto arr_val_end; + if (cur == eof) goto fail_comment; + } + goto fail_character_arr_end; + +arr_end: + /* get parent container */ + ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs); + + /* save the next sibling value offset */ + ctn->uni.ofs = (usize)((u8 *)val - (u8 *)ctn) + sizeof(yyjson_val); + ctn->tag = ((ctn_len) << YYJSON_TAG_BIT) | YYJSON_TYPE_ARR; + if (unlikely(ctn == ctn_parent)) goto doc_end; + + /* pop parent as current container */ + ctn = ctn_parent; + ctn_len = (usize)(ctn->tag >> YYJSON_TAG_BIT); + if (*cur == '\n') cur++; + if ((ctn->tag & YYJSON_TYPE_MASK) == YYJSON_TYPE_OBJ) { + goto obj_val_end; + } else { + goto arr_val_end; + } + +obj_begin: + /* push container */ + ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) | + (ctn->tag & YYJSON_TAG_MASK); + val_incr(); + val->tag = YYJSON_TYPE_OBJ; + /* offset to the parent */ + val->uni.ofs = (usize)((u8 *)val - (u8 *)ctn); + ctn = val; + ctn_len = 0; + if (*cur == '\n') cur++; + +obj_key_begin: +#if YYJSON_IS_REAL_GCC + while (true) repeat16({ + if (byte_match_2(cur, " ")) cur += 2; + else break; + }) +#else + while (true) repeat16({ + if (likely(byte_match_2(cur, " "))) cur += 2; + else break; + }) +#endif + if (likely(*cur == '"')) { + val_incr(); + ctn_len++; + if (likely(read_str(&cur, eof, flg, val, &msg))) goto obj_key_end; + goto fail_string; + } + if (likely(*cur == '}')) { + cur++; + if (likely(ctn_len == 0)) goto obj_end; + if (has_allow(TRAILING_COMMAS)) goto obj_end; + while (*cur != ',') cur--; + goto fail_trailing_comma; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto obj_key_begin; + } + if (has_allow(SINGLE_QUOTED_STR) && *cur == '\'') { + val_incr(); + ctn_len++; + if (likely(read_str_sq(&cur, eof, flg, val, &msg))) goto obj_key_end; + goto fail_string; + } + if (has_allow(UNQUOTED_KEY) && char_is_id_start(*cur)) { + val_incr(); + ctn_len++; + if (read_str_id(&cur, eof, flg, pre, val, &msg)) goto obj_key_end; + goto fail_string; + } + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (skip_trivia(&cur, eof, flg)) goto obj_key_begin; + if (cur == eof) goto fail_comment; + } + goto fail_character_obj_key; + +obj_key_end: + if (byte_match_2(cur, ": ")) { + cur += 2; + goto obj_val_begin; + } + if (*cur == ':') { + cur++; + goto obj_val_begin; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto obj_key_end; + } + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (skip_trivia(&cur, eof, flg)) goto obj_key_end; + if (cur == eof) goto fail_comment; + } + goto fail_character_obj_sep; + +obj_val_begin: + if (*cur == '"') { + val++; + ctn_len++; + if (likely(read_str(&cur, eof, flg, val, &msg))) goto obj_val_end; + goto fail_string; + } + if (char_is_num(*cur)) { + val++; + ctn_len++; + if (likely(read_num(&cur, pre, flg, val, &msg))) goto obj_val_end; + goto fail_number; + } + if (*cur == '{') { + cur++; + goto obj_begin; + } + if (*cur == '[') { + cur++; + goto arr_begin; + } + if (*cur == 't') { + val++; + ctn_len++; + if (likely(read_true(&cur, val))) goto obj_val_end; + goto fail_literal_true; + } + if (*cur == 'f') { + val++; + ctn_len++; + if (likely(read_false(&cur, val))) goto obj_val_end; + goto fail_literal_false; + } + if (*cur == 'n') { + val++; + ctn_len++; + if (likely(read_null(&cur, val))) goto obj_val_end; + if (has_allow(INF_AND_NAN)) { + if (read_nan(&cur, pre, flg, val)) goto obj_val_end; + } + goto fail_literal_null; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto obj_val_begin; + } + if (has_allow(INF_AND_NAN) && + (*cur == 'i' || *cur == 'I' || *cur == 'N')) { + val++; + ctn_len++; + if (read_inf_or_nan(&cur, pre, flg, val)) goto obj_val_end; + goto fail_character_val; + } + if (has_allow(SINGLE_QUOTED_STR) && *cur == '\'') { + val++; + ctn_len++; + if (likely(read_str_sq(&cur, eof, flg, val, &msg))) goto obj_val_end; + goto fail_string; + } + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (skip_trivia(&cur, eof, flg)) goto obj_val_begin; + if (cur == eof) goto fail_comment; + } + goto fail_character_val; + +obj_val_end: + if (byte_match_2(cur, ",\n")) { + cur += 2; + goto obj_key_begin; + } + if (likely(*cur == ',')) { + cur++; + goto obj_key_begin; + } + if (likely(*cur == '}')) { + cur++; + goto obj_end; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto obj_val_end; + } + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (skip_trivia(&cur, eof, flg)) goto obj_val_end; + if (cur == eof) goto fail_comment; + } + goto fail_character_obj_end; + +obj_end: + /* pop container */ + ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs); + /* point to the next value */ + ctn->uni.ofs = (usize)((u8 *)val - (u8 *)ctn) + sizeof(yyjson_val); + ctn->tag = (ctn_len << (YYJSON_TAG_BIT - 1)) | YYJSON_TYPE_OBJ; + if (unlikely(ctn == ctn_parent)) goto doc_end; + ctn = ctn_parent; + ctn_len = (usize)(ctn->tag >> YYJSON_TAG_BIT); + if (*cur == '\n') cur++; + if ((ctn->tag & YYJSON_TYPE_MASK) == YYJSON_TYPE_OBJ) { + goto obj_val_end; + } else { + goto arr_val_end; + } + +doc_end: + /* check invalid contents after json document */ + if (unlikely(cur < eof) && !has_flg(STOP_WHEN_DONE)) { + while (char_is_space(*cur)) cur++; + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (!skip_trivia(&cur, eof, flg) && cur == eof) { + goto fail_comment; + } + } + if (unlikely(cur < eof)) goto fail_garbage; + } + + **pre = '\0'; + doc = (yyjson_doc *)val_hdr; + doc->root = val_hdr + hdr_len; + doc->alc = alc; + doc->dat_read = (usize)(cur - hdr); + doc->val_read = (usize)((val - doc->root) + 1); + doc->str_pool = has_flg(INSITU) ? NULL : (char *)hdr; + return doc; + +fail_string: return_err(cur, INVALID_STRING, msg); +fail_number: return_err(cur, INVALID_NUMBER, msg); +fail_alloc: return_err(cur, MEMORY_ALLOCATION, MSG_MALLOC); +fail_trailing_comma: return_err(cur, JSON_STRUCTURE, MSG_COMMA); +fail_literal_true: return_err(cur, LITERAL, MSG_CHAR_T); +fail_literal_false: return_err(cur, LITERAL, MSG_CHAR_F); +fail_literal_null: return_err(cur, LITERAL, MSG_CHAR_N); +fail_character_val: return_err(cur, UNEXPECTED_CHARACTER, MSG_CHAR); +fail_character_arr_end: return_err(cur, UNEXPECTED_CHARACTER, MSG_ARR_END); +fail_character_obj_key: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_KEY); +fail_character_obj_sep: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_SEP); +fail_character_obj_end: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_END); +fail_comment: return_err(cur, INVALID_COMMENT, MSG_COMMENT); +fail_garbage: return_err(cur, UNEXPECTED_CONTENT, MSG_GARBAGE); + +#undef val_incr +#undef return_err +} + + + +/*============================================================================== + * MARK: - JSON Reader (Public) + *============================================================================*/ + +yyjson_doc *yyjson_read_opts(char *dat, usize len, + yyjson_read_flag flg, + const yyjson_alc *alc_ptr, + yyjson_read_err *err) { +#define return_err(_pos, _code, _msg) do { \ + err->pos = (usize)(_pos); \ + err->msg = _msg; \ + err->code = YYJSON_READ_ERROR_##_code; \ + if (!has_flg(INSITU) && hdr) alc.free(alc.ctx, (void *)hdr); \ + return NULL; \ +} while (false) + + yyjson_read_err tmp_err; + yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC; + yyjson_doc *doc; + u8 *hdr = NULL, *eof, *cur; + + /* validate input parameters */ + if (!err) err = &tmp_err; + if (unlikely(!dat)) return_err(0, INVALID_PARAMETER, "input data is NULL"); + if (unlikely(!len)) return_err(0, INVALID_PARAMETER, "input length is 0"); + + /* add 4-byte zero padding for input data if necessary */ + if (has_flg(INSITU)) { + hdr = (u8 *)dat; + eof = (u8 *)dat + len; + cur = (u8 *)dat; + } else { + if (unlikely(len >= USIZE_MAX - YYJSON_PADDING_SIZE)) { + return_err(0, MEMORY_ALLOCATION, MSG_MALLOC); + } + hdr = (u8 *)alc.malloc(alc.ctx, len + YYJSON_PADDING_SIZE); + if (unlikely(!hdr)) { + return_err(0, MEMORY_ALLOCATION, MSG_MALLOC); + } + eof = hdr + len; + cur = hdr; + memcpy(hdr, dat, len); + } + memset(eof, 0, YYJSON_PADDING_SIZE); + + if (has_allow(BOM)) { + if (len >= 3 && is_utf8_bom(cur)) cur += 3; + } + + /* skip empty contents before json document */ + if (unlikely(!char_is_ctn(*cur))) { + while (char_is_space(*cur)) cur++; + if (unlikely(!char_is_ctn(*cur))) { + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (!skip_trivia(&cur, eof, flg) && cur == eof) { + return_err(cur - hdr, INVALID_COMMENT, MSG_COMMENT); + } + } + } + if (unlikely(cur >= eof)) { + return_err(0, EMPTY_CONTENT, "input data is empty"); + } + } + + /* read json document */ + if (likely(char_is_ctn(*cur))) { + if (char_is_space(cur[1]) && char_is_space(cur[2])) { + doc = read_root_pretty(hdr, cur, eof, alc, flg, err); + } else { + doc = read_root_minify(hdr, cur, eof, alc, flg, err); + } + } else { + doc = read_root_single(hdr, cur, eof, alc, flg, err); + } + + /* check result */ + if (likely(doc)) { + memset(err, 0, sizeof(yyjson_read_err)); + } else { + /* RFC 8259: JSON text MUST be encoded using UTF-8 */ + if (err->pos == 0 && err->code != YYJSON_READ_ERROR_MEMORY_ALLOCATION) { + if (is_utf8_bom(hdr)) err->msg = MSG_ERR_BOM; + else if (len >= 4 && is_utf32_bom(hdr)) err->msg = MSG_ERR_UTF32; + else if (len >= 2 && is_utf16_bom(hdr)) err->msg = MSG_ERR_UTF16; + } + if (!has_flg(INSITU)) alc.free(alc.ctx, hdr); + } + return doc; + +#undef return_err +} + +yyjson_doc *yyjson_read_file(const char *path, + yyjson_read_flag flg, + const yyjson_alc *alc_ptr, + yyjson_read_err *err) { +#define return_err(_code, _msg) do { \ + err->pos = 0; \ + err->msg = _msg; \ + err->code = YYJSON_READ_ERROR_##_code; \ + return NULL; \ +} while (false) + + yyjson_read_err tmp_err; + yyjson_doc *doc; + FILE *file; + + if (!err) err = &tmp_err; + if (unlikely(!path)) return_err(INVALID_PARAMETER, "input path is NULL"); + + file = fopen_readonly(path); + if (unlikely(!file)) return_err(FILE_OPEN, MSG_FREAD); + + doc = yyjson_read_fp(file, flg, alc_ptr, err); + fclose(file); + return doc; + +#undef return_err +} + +yyjson_doc *yyjson_read_fp(FILE *file, + yyjson_read_flag flg, + const yyjson_alc *alc_ptr, + yyjson_read_err *err) { +#define return_err(_code, _msg) do { \ + err->pos = 0; \ + err->msg = _msg; \ + err->code = YYJSON_READ_ERROR_##_code; \ + if (buf) alc.free(alc.ctx, buf); \ + return NULL; \ +} while (false) + + yyjson_read_err tmp_err; + yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC; + yyjson_doc *doc; + + long file_size = 0, file_pos; + void *buf = NULL; + usize buf_size = 0; + + /* validate input parameters */ + if (!err) err = &tmp_err; + if (unlikely(!file)) return_err(INVALID_PARAMETER, "input file is NULL"); + + /* get current position */ + file_pos = ftell(file); + if (file_pos != -1) { + /* get total file size, may fail */ + if (fseek(file, 0, SEEK_END) == 0) file_size = ftell(file); + /* reset to original position, may fail */ + if (fseek(file, file_pos, SEEK_SET) != 0) file_size = 0; + /* get file size from current postion to end */ + if (file_size > 0) file_size -= file_pos; + } + + /* read file */ + if (file_size > 0) { + /* read the entire file in one call */ + buf_size = (usize)file_size + YYJSON_PADDING_SIZE; + buf = alc.malloc(alc.ctx, buf_size); + if (buf == NULL) { + return_err(MEMORY_ALLOCATION, MSG_MALLOC); + } + if (fread_safe(buf, (usize)file_size, file) != (usize)file_size) { + return_err(FILE_READ, MSG_FREAD); + } + } else { + /* failed to get file size, read it as a stream */ + usize chunk_min = (usize)64; + usize chunk_max = (usize)512 * 1024 * 1024; + usize chunk_now = chunk_min; + usize read_size; + void *tmp; + + buf_size = YYJSON_PADDING_SIZE; + while (true) { + if (buf_size + chunk_now < buf_size) { /* overflow */ + return_err(MEMORY_ALLOCATION, MSG_MALLOC); + } + buf_size += chunk_now; + if (!buf) { + buf = alc.malloc(alc.ctx, buf_size); + if (!buf) return_err(MEMORY_ALLOCATION, MSG_MALLOC); + } else { + tmp = alc.realloc(alc.ctx, buf, buf_size - chunk_now, buf_size); + if (!tmp) return_err(MEMORY_ALLOCATION, MSG_MALLOC); + buf = tmp; + } + tmp = ((u8 *)buf) + buf_size - YYJSON_PADDING_SIZE - chunk_now; + read_size = fread_safe(tmp, chunk_now, file); + file_size += (long)read_size; + if (read_size != chunk_now) break; + + chunk_now *= 2; + if (chunk_now > chunk_max) chunk_now = chunk_max; + } + } + + /* read JSON */ + memset((u8 *)buf + file_size, 0, YYJSON_PADDING_SIZE); + flg |= YYJSON_READ_INSITU; + doc = yyjson_read_opts((char *)buf, (usize)file_size, flg, &alc, err); + if (doc) { + doc->str_pool = (char *)buf; + return doc; + } else { + alc.free(alc.ctx, buf); + return NULL; + } + +#undef return_err +} + +const char *yyjson_read_number(const char *dat, + yyjson_val *val, + yyjson_read_flag flg, + const yyjson_alc *alc, + yyjson_read_err *err) { +#define return_err(_pos, _code, _msg) do { \ + err->pos = _pos > hdr ? (usize)(_pos - hdr) : 0; \ + err->msg = _msg; \ + err->code = YYJSON_READ_ERROR_##_code; \ + return NULL; \ +} while (false) + + u8 *hdr = constcast(u8 *)dat, *cur = hdr; + u8 raw_end[1]; /* raw end for null-terminator */ + u8 *raw_ptr = raw_end; + u8 **pre = &raw_ptr; /* previous raw end pointer */ + const char *msg; + yyjson_read_err tmp_err; + +#if YYJSON_DISABLE_FAST_FP_CONV + u8 buf[128]; + usize dat_len; +#endif + + if (!err) err = &tmp_err; + if (unlikely(!dat)) { + return_err(cur, INVALID_PARAMETER, "input data is NULL"); + } + if (unlikely(!val)) { + return_err(cur, INVALID_PARAMETER, "output value is NULL"); + } + +#if YYJSON_DISABLE_FAST_FP_CONV + if (!alc) alc = &YYJSON_DEFAULT_ALC; + dat_len = strlen(dat); + if (dat_len < sizeof(buf)) { + memcpy(buf, dat, dat_len + 1); + hdr = buf; + cur = hdr; + } else { + hdr = (u8 *)alc->malloc(alc->ctx, dat_len + 1); + cur = hdr; + if (unlikely(!hdr)) { + return_err(cur, MEMORY_ALLOCATION, MSG_MALLOC); + } + memcpy(hdr, dat, dat_len + 1); + } + hdr[dat_len] = 0; +#endif + +#if YYJSON_DISABLE_FAST_FP_CONV + if (!read_num(&cur, pre, flg, val, &msg)) { + if (dat_len >= sizeof(buf)) alc->free(alc->ctx, hdr); + return_err(cur, INVALID_NUMBER, msg); + } + if (dat_len >= sizeof(buf)) alc->free(alc->ctx, hdr); + if (yyjson_is_raw(val)) val->uni.str = dat; + return dat + (cur - hdr); +#else + if (!read_num(&cur, pre, flg, val, &msg)) { + return_err(cur, INVALID_NUMBER, msg); + } + return (const char *)cur; +#endif + +#undef return_err +} + + + +/*============================================================================== + * MARK: - Incremental JSON Reader (Public) + *============================================================================*/ + +#if !YYJSON_DISABLE_INCR_READER + +/* labels within yyjson_incr_read() to resume incremental parsing */ +#define LABEL_doc_begin 0 +#define LABEL_arr_val_begin 1 +#define LABEL_arr_val_end 2 +#define LABEL_obj_key_begin 3 +#define LABEL_obj_key_end 4 +#define LABEL_obj_val_begin 5 +#define LABEL_obj_val_end 6 +#define LABEL_doc_end 7 + +/** State for incremental JSON reader, opaque in the API. */ +struct yyjson_incr_state { + u32 label; /* current parser goto label */ + yyjson_alc alc; /* allocator */ + yyjson_read_flag flg; /* read flags */ + u8 *hdr; /* JSON data header */ + u8 *cur; /* current position in JSON data */ + usize buf_len; /* total buffer length (without padding) */ + usize hdr_len; /* value count used by yyjson_doc */ + usize alc_len; /* value count allocated */ + usize ctn_len; /* the number of elements in current container */ + yyjson_val *val_hdr; /* the head of allocated values */ + yyjson_val *val_end; /* the end of allocated values */ + yyjson_val *val; /* current JSON value */ + yyjson_val *ctn; /* current container */ + u8 *str_con[2]; /* string parser incremental state */ +}; + +yyjson_incr_state *yyjson_incr_new(char *buf, size_t buf_len, + yyjson_read_flag flg, + const yyjson_alc *alc_ptr) { + yyjson_incr_state *state = NULL; + yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC; + + /* remove non-standard flags */ + flg &= ~YYJSON_READ_JSON5; + flg &= ~YYJSON_READ_ALLOW_BOM; + flg &= ~YYJSON_READ_ALLOW_INVALID_UNICODE; + + if (unlikely(!buf)) return NULL; + if (unlikely(buf_len >= USIZE_MAX - YYJSON_PADDING_SIZE)) return NULL; + state = (yyjson_incr_state *)alc.malloc(alc.ctx, sizeof(*state)); + if (!state) return NULL; + memset(state, 0, sizeof(yyjson_incr_state)); + state->alc = alc; + state->flg = flg; + state->buf_len = buf_len; + + /* add 4-byte zero padding for input data if necessary */ + if (has_flg(INSITU)) { + state->hdr = (u8 *)buf; + } else { + state->hdr = (u8 *)alc.malloc(alc.ctx, buf_len + YYJSON_PADDING_SIZE); + if (unlikely(!state->hdr)) { + alc.free(alc.ctx, state); + return NULL; + } + memcpy(state->hdr, buf, buf_len); + } + memset(state->hdr + buf_len, 0, YYJSON_PADDING_SIZE); + state->cur = state->hdr; + state->label = LABEL_doc_begin; + return state; +} + +void yyjson_incr_free(yyjson_incr_state *state) { + if (state) { + yyjson_alc alc = state->alc; + memset(&state->alc, 0, sizeof(alc)); + if (state->val_hdr) { + alc.free(alc.ctx, (void *)state->val_hdr); + } + if (state->hdr && !(state->flg & YYJSON_READ_INSITU)) { + alc.free(alc.ctx, state->hdr); + } + alc.free(alc.ctx, state); + } +} + +yyjson_doc *yyjson_incr_read(yyjson_incr_state *state, size_t len, + yyjson_read_err *err) { +#define return_err_inv_param(_msg) do { \ + err->pos = 0; \ + err->msg = _msg; \ + err->code = YYJSON_READ_ERROR_INVALID_PARAMETER; \ + return NULL; \ +} while (false) + +#define return_err(_pos, _code, _msg) do { \ + if (is_truncated_end(hdr, _pos, end, YYJSON_READ_ERROR_##_code, flg)) { \ + goto unexpected_end; \ + } else { \ + err->pos = (usize)(_pos - hdr); \ + err->code = YYJSON_READ_ERROR_##_code; \ + err->msg = _msg; \ + } \ + return NULL; \ +} while (false) + +#define val_incr() do { \ + val++; \ + if (unlikely(val >= val_end)) { \ + usize alc_old = alc_len; \ + alc_len += alc_len / 2; \ + if ((sizeof(usize) < 8) && (alc_len >= alc_max)) goto fail_alloc; \ + val_tmp = (yyjson_val *)alc.realloc(alc.ctx, (void *)val_hdr, \ + alc_old * sizeof(yyjson_val), \ + alc_len * sizeof(yyjson_val)); \ + if ((!val_tmp)) goto fail_alloc; \ + val = val_tmp + (usize)(val - val_hdr); \ + ctn = val_tmp + (usize)(ctn - val_hdr); \ + state->val = val_tmp + (usize)(state->val - val_hdr); \ + state->val_hdr = val_hdr = val_tmp; \ + val_end = val_tmp + (alc_len - 2); \ + state->val_end = val_end; \ + } \ +} while (false) + + /* save position where it's possible to resume incremental parsing */ +#define save_incr_state(_label) do { \ + state->label = LABEL_##_label; \ + state->cur = cur; \ + state->val = val; \ + state->ctn_len = ctn_len; \ + state->hdr_len = hdr_len; \ + if (unlikely(cur >= end)) goto unexpected_end; \ +} while (false) + +#define check_maybe_truncated_number() do { \ + if (unlikely(cur >= end)) { \ + if (unlikely(cur > state->cur + INCR_NUM_MAX_LEN)) { \ + msg = "number too long"; \ + goto fail_number; \ + } \ + goto unexpected_end; \ + } \ +} while (false) + + u8 *hdr = NULL, *end = NULL, *cur = NULL; + yyjson_read_flag flg; + yyjson_alc alc; + usize dat_len; /* data length in bytes, hint for allocator */ + usize hdr_len; /* value count used by yyjson_doc */ + usize alc_len; /* value count allocated */ + usize alc_max; /* maximum value count for allocator */ + usize ctn_len; /* the number of elements in current container */ + yyjson_val *val_hdr; /* the head of allocated values */ + yyjson_val *val_end; /* the end of allocated values */ + yyjson_val *val_tmp; /* temporary pointer for realloc */ + yyjson_val *val; /* current JSON value */ + yyjson_val *ctn; /* current container */ + yyjson_val *ctn_parent; /* parent of current container */ + yyjson_doc *doc; /* the JSON document, equals to val_hdr */ + const char *msg; /* error message */ + + yyjson_read_err tmp_err; + u8 raw_end[1]; /* raw end for null-terminator */ + u8 *raw_ptr = raw_end; + u8 **pre = &raw_ptr; /* previous raw end pointer */ + u8 **con = NULL; /* for incremental string parsing */ + u8 saved_end = '\0'; /* saved end char */ + + /* validate input parameters */ + if (!err) err = &tmp_err; + if (unlikely(!state)) { + return_err_inv_param("input state is NULL"); + } + if (unlikely(!len)) { + return_err_inv_param("input length is 0"); + } + if (unlikely(len > state->buf_len)) { + return_err_inv_param("length is greater than total input length"); + } + + /* restore state saved from the previous call */ + hdr = state->hdr; + end = state->hdr + len; + cur = state->cur; + flg = state->flg; + alc = state->alc; + ctn_len = state->ctn_len; + hdr_len = state->hdr_len; + alc_len = state->alc_len; + val = state->val; + val_hdr = state->val_hdr; + val_end = state->val_end; + ctn = state->ctn; + con = state->str_con; + alc_max = USIZE_MAX / sizeof(yyjson_val); + + /* insert null terminator to make us stop at the specified end, even if + the data contains more valid JSON */ + saved_end = *end; + *end = '\0'; + + /* resume parsing from the last save point */ + switch (state->label) { + case LABEL_doc_begin: goto doc_begin; + case LABEL_arr_val_begin: goto arr_val_begin; + case LABEL_arr_val_end: goto arr_val_end; + case LABEL_obj_key_begin: goto obj_key_begin; + case LABEL_obj_key_end: goto obj_key_end; + case LABEL_obj_val_begin: goto obj_val_begin; + case LABEL_obj_val_end: goto obj_val_end; + case LABEL_doc_end: goto doc_end; + default: return_err_inv_param("invalid incremental state"); + } + +doc_begin: + /* skip empty contents before json document */ + if (unlikely(!char_is_ctn(*cur))) { + while (char_is_space(*cur)) cur++; + if (unlikely(cur >= end)) goto unexpected_end; /* input data is empty */ + } + + /* allocate memory for document */ + if (!val_hdr) { + hdr_len = sizeof(yyjson_doc) / sizeof(yyjson_val); + hdr_len += (sizeof(yyjson_doc) % sizeof(yyjson_val)) > 0; + if (likely(char_is_ctn(*cur))) { + dat_len = has_flg(STOP_WHEN_DONE) ? 256 : state->buf_len; + alc_len = hdr_len + + (dat_len / YYJSON_READER_ESTIMATED_MINIFY_RATIO) + 4; + alc_len = yyjson_min(alc_len, alc_max); + } else { + alc_len = hdr_len + 1; /* single value */ + } + val_hdr = (yyjson_val *)alc.malloc(alc.ctx, + alc_len * sizeof(yyjson_val)); + if (unlikely(!val_hdr)) goto fail_alloc; + val_end = val_hdr + (alc_len - 2); /* padding for kv pair reading */ + val = val_hdr + hdr_len; + ctn = val; + ctn_len = 0; + state->val_hdr = val_hdr; + state->val_end = val_end; + save_incr_state(doc_begin); + } + + /* read json document */ + if (*cur == '{') { + cur++; + ctn->tag = YYJSON_TYPE_OBJ; + ctn->uni.ofs = 0; + goto obj_key_begin; + } + if (*cur == '[') { + cur++; + ctn->tag = YYJSON_TYPE_ARR; + ctn->uni.ofs = 0; + goto arr_val_begin; + } + if (char_is_num(*cur)) { + if (likely(read_num(&cur, pre, flg, val, &msg))) goto doc_end; + goto fail_number; + } + if (*cur == '"') { + if (likely(read_str_con(&cur, end, flg, val, &msg, con))) goto doc_end; + goto fail_string; + } + if (*cur == 't') { + if (likely(read_true(&cur, val))) goto doc_end; + goto fail_literal_true; + } + if (*cur == 'f') { + if (likely(read_false(&cur, val))) goto doc_end; + goto fail_literal_false; + } + if (*cur == 'n') { + if (likely(read_null(&cur, val))) goto doc_end; + goto fail_literal_null; + } + + msg = "unexpected character, expected a valid root value"; + if (cur == hdr) { + /* RFC 8259: JSON text MUST be encoded using UTF-8 */ + if (is_utf8_bom(hdr)) msg = MSG_ERR_BOM; + else if (len >= 4 && is_utf32_bom(hdr)) msg = MSG_ERR_UTF32; + else if (len >= 2 && is_utf16_bom(hdr)) msg = MSG_ERR_UTF16; + } + return_err(cur, UNEXPECTED_CHARACTER, msg); + +arr_begin: + /* save current container */ + ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) | + (ctn->tag & YYJSON_TAG_MASK); + + /* create a new array value, save parent container offset */ + val_incr(); + val->tag = YYJSON_TYPE_ARR; + val->uni.ofs = (usize)((u8 *)val - (u8 *)ctn); + + /* push the new array value as current container */ + ctn = val; + ctn_len = 0; + +arr_val_begin: + save_incr_state(arr_val_begin); +arr_val_continue: + if (*cur == '{') { + cur++; + goto obj_begin; + } + if (*cur == '[') { + cur++; + goto arr_begin; + } + if (char_is_num(*cur)) { + val_incr(); + ctn_len++; + if (likely(read_num(&cur, pre, flg, val, &msg))) goto arr_val_maybe_end; + goto fail_number; + } + if (*cur == '"') { + val_incr(); + ctn_len++; + if (likely(read_str_con(&cur, end, flg, val, &msg, con))) + goto arr_val_end; + goto fail_string; + } + if (*cur == 't') { + val_incr(); + ctn_len++; + if (likely(read_true(&cur, val))) goto arr_val_end; + goto fail_literal_true; + } + if (*cur == 'f') { + val_incr(); + ctn_len++; + if (likely(read_false(&cur, val))) goto arr_val_end; + goto fail_literal_false; + } + if (*cur == 'n') { + val_incr(); + ctn_len++; + if (likely(read_null(&cur, val))) goto arr_val_end; + goto fail_literal_null; + } + if (*cur == ']') { + cur++; + if (likely(ctn_len == 0)) goto arr_end; + while (*cur != ',') cur--; + goto fail_trailing_comma; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto arr_val_continue; + } + goto fail_character_val; + +arr_val_maybe_end: + /* if incremental parsing stops in the middle of a number, it may continue + with more digits, so arr val maybe didn't end yet */ + check_maybe_truncated_number(); + +arr_val_end: + save_incr_state(arr_val_end); + if (*cur == ',') { + cur++; + goto arr_val_begin; + } + if (*cur == ']') { + cur++; + goto arr_end; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto arr_val_end; + } + goto fail_character_arr_end; + +arr_end: + /* get parent container */ + ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs); + + /* save the next sibling value offset */ + ctn->uni.ofs = (usize)((u8 *)val - (u8 *)ctn) + sizeof(yyjson_val); + ctn->tag = ((ctn_len) << YYJSON_TAG_BIT) | YYJSON_TYPE_ARR; + if (unlikely(ctn == ctn_parent)) goto doc_end; + + /* pop parent as current container */ + ctn = ctn_parent; + ctn_len = (usize)(ctn->tag >> YYJSON_TAG_BIT); + if ((ctn->tag & YYJSON_TYPE_MASK) == YYJSON_TYPE_OBJ) { + goto obj_val_end; + } else { + goto arr_val_end; + } + +obj_begin: + /* push container */ + ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) | + (ctn->tag & YYJSON_TAG_MASK); + val_incr(); + val->tag = YYJSON_TYPE_OBJ; + /* offset to the parent */ + val->uni.ofs = (usize)((u8 *)val - (u8 *)ctn); + ctn = val; + ctn_len = 0; + +obj_key_begin: + save_incr_state(obj_key_begin); +obj_key_continue: + if (likely(*cur == '"')) { + val_incr(); + ctn_len++; + if (likely(read_str_con(&cur, end, flg, val, &msg, con))) + goto obj_key_end; + goto fail_string; + } + if (likely(*cur == '}')) { + cur++; + if (likely(ctn_len == 0)) goto obj_end; + while (*cur != ',') cur--; + goto fail_trailing_comma; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto obj_key_continue; + } + goto fail_character_obj_key; + +obj_key_end: + save_incr_state(obj_key_end); + if (*cur == ':') { + cur++; + goto obj_val_begin; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto obj_key_end; + } + goto fail_character_obj_sep; + +obj_val_begin: + save_incr_state(obj_val_begin); +obj_val_continue: + if (*cur == '"') { + val++; + ctn_len++; + if (likely(read_str_con(&cur, end, flg, val, &msg, con))) + goto obj_val_end; + goto fail_string; + } + if (char_is_num(*cur)) { + val++; + ctn_len++; + if (likely(read_num(&cur, pre, flg, val, &msg))) goto obj_val_maybe_end; + goto fail_number; + } + if (*cur == '{') { + cur++; + goto obj_begin; + } + if (*cur == '[') { + cur++; + goto arr_begin; + } + if (*cur == 't') { + val++; + ctn_len++; + if (likely(read_true(&cur, val))) goto obj_val_end; + goto fail_literal_true; + } + if (*cur == 'f') { + val++; + ctn_len++; + if (likely(read_false(&cur, val))) goto obj_val_end; + goto fail_literal_false; + } + if (*cur == 'n') { + val++; + ctn_len++; + if (likely(read_null(&cur, val))) goto obj_val_end; + goto fail_literal_null; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto obj_val_continue; + } + goto fail_character_val; + +obj_val_maybe_end: + /* if incremental parsing stops in the middle of a number, it may continue + with more digits, so obj val maybe didn't end yet */ + check_maybe_truncated_number(); + +obj_val_end: + save_incr_state(obj_val_end); + if (likely(*cur == ',')) { + cur++; + goto obj_key_begin; + } + if (likely(*cur == '}')) { + cur++; + goto obj_end; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto obj_val_end; + } + goto fail_character_obj_end; + +obj_end: + /* pop container */ + ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs); + /* point to the next value */ + ctn->uni.ofs = (usize)((u8 *)val - (u8 *)ctn) + sizeof(yyjson_val); + ctn->tag = (ctn_len << (YYJSON_TAG_BIT - 1)) | YYJSON_TYPE_OBJ; + if (unlikely(ctn == ctn_parent)) goto doc_end; + ctn = ctn_parent; + ctn_len = (usize)(ctn->tag >> YYJSON_TAG_BIT); + if ((ctn->tag & YYJSON_TYPE_MASK) == YYJSON_TYPE_OBJ) { + goto obj_val_end; + } else { + goto arr_val_end; + } + +doc_end: + /* check invalid contents after json document */ + if (unlikely(cur < end) && !has_flg(STOP_WHEN_DONE)) { + save_incr_state(doc_end); + while (char_is_space(*cur)) cur++; + if (unlikely(cur < end)) goto fail_garbage; + } + + **pre = '\0'; + doc = (yyjson_doc *)val_hdr; + doc->root = val_hdr + hdr_len; + doc->alc = alc; + doc->dat_read = (usize)(cur - hdr); + doc->val_read = (usize)((val - doc->root) + 1); + doc->str_pool = has_flg(INSITU) ? NULL : (char *)hdr; + state->hdr = NULL; + state->val_hdr = NULL; + memset(err, 0, sizeof(yyjson_read_err)); + return doc; + +unexpected_end: + err->pos = len; + /* if no nore data, stop the incr read */ + if (unlikely(len >= state->buf_len)) { + err->code = YYJSON_READ_ERROR_UNEXPECTED_END; + err->msg = MSG_NOT_END; + return NULL; + } + /* save parser state in extended error struct, in addition to what was + * stored in the last save_incr_state */ + err->code = YYJSON_READ_ERROR_MORE; + err->msg = "need more data"; + state->val_end = val_end; + state->ctn = ctn; + state->alc_len = alc_len; + /* restore the end where we've inserted a null terminator */ + *end = saved_end; + return NULL; + +fail_string: return_err(cur, INVALID_STRING, msg); +fail_number: return_err(cur, INVALID_NUMBER, msg); +fail_alloc: return_err(cur, MEMORY_ALLOCATION, MSG_MALLOC); +fail_trailing_comma: return_err(cur, JSON_STRUCTURE, MSG_COMMA); +fail_literal_true: return_err(cur, LITERAL, MSG_CHAR_T); +fail_literal_false: return_err(cur, LITERAL, MSG_CHAR_F); +fail_literal_null: return_err(cur, LITERAL, MSG_CHAR_N); +fail_character_val: return_err(cur, UNEXPECTED_CHARACTER, MSG_CHAR); +fail_character_arr_end: return_err(cur, UNEXPECTED_CHARACTER, MSG_ARR_END); +fail_character_obj_key: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_KEY); +fail_character_obj_sep: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_SEP); +fail_character_obj_end: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_END); +fail_garbage: return_err(cur, UNEXPECTED_CONTENT, MSG_GARBAGE); + +#undef val_incr +#undef return_err +#undef return_err_inv_param +#undef save_incr_state +#undef check_maybe_truncated_number +} + +#endif /* YYJSON_DISABLE_INCR_READER */ + +#undef has_flg +#undef has_allow +#endif /* YYJSON_DISABLE_READER */ + + + +#if !YYJSON_DISABLE_WRITER /* writer begin */ + +/* Check write flag, avoids `always false` warning when disabled. */ +#define has_flg(_flg) unlikely(has_wflag(flg, YYJSON_WRITE_##_flg, 0)) +#define has_allow(_flg) unlikely(has_wflag(flg, YYJSON_WRITE_ALLOW_##_flg, 1)) +static_inline bool has_wflag(yyjson_write_flag flg, yyjson_write_flag chk, + bool non_standard) { +#if YYJSON_DISABLE_NON_STANDARD + if (non_standard) return false; +#endif + return (flg & chk) != 0; +} + +/*============================================================================== + * MARK: - Integer Writer (Private) + * + * The maximum value of uint32_t is 4294967295 (10 digits), + * these digits are named as 'aabbccddee' here. + * + * Although most compilers may convert the "division by constant value" into + * "multiply and shift", manual conversion can still help some compilers + * generate fewer and better instructions. + * + * Reference: + * Division by Invariant Integers using Multiplication, 1994. + * https://gmplib.org/~tege/divcnst-pldi94.pdf + * Improved division by invariant integers, 2011. + * https://gmplib.org/~tege/division-paper.pdf + *============================================================================*/ + +/** Digit table from 00 to 99. */ +yyjson_align(2) +static const char digit_table[200] = { + '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', + '0', '5', '0', '6', '0', '7', '0', '8', '0', '9', + '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', + '1', '5', '1', '6', '1', '7', '1', '8', '1', '9', + '2', '0', '2', '1', '2', '2', '2', '3', '2', '4', + '2', '5', '2', '6', '2', '7', '2', '8', '2', '9', + '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', + '3', '5', '3', '6', '3', '7', '3', '8', '3', '9', + '4', '0', '4', '1', '4', '2', '4', '3', '4', '4', + '4', '5', '4', '6', '4', '7', '4', '8', '4', '9', + '5', '0', '5', '1', '5', '2', '5', '3', '5', '4', + '5', '5', '5', '6', '5', '7', '5', '8', '5', '9', + '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', + '6', '5', '6', '6', '6', '7', '6', '8', '6', '9', + '7', '0', '7', '1', '7', '2', '7', '3', '7', '4', + '7', '5', '7', '6', '7', '7', '7', '8', '7', '9', + '8', '0', '8', '1', '8', '2', '8', '3', '8', '4', + '8', '5', '8', '6', '8', '7', '8', '8', '8', '9', + '9', '0', '9', '1', '9', '2', '9', '3', '9', '4', + '9', '5', '9', '6', '9', '7', '9', '8', '9', '9' +}; + +static_inline u8 *write_u32_len_8(u32 val, u8 *buf) { + u32 aa, bb, cc, dd, aabb, ccdd; /* 8 digits: aabbccdd */ + aabb = (u32)(((u64)val * 109951163) >> 40); /* (val / 10000) */ + ccdd = val - aabb * 10000; /* (val % 10000) */ + aa = (aabb * 5243) >> 19; /* (aabb / 100) */ + cc = (ccdd * 5243) >> 19; /* (ccdd / 100) */ + bb = aabb - aa * 100; /* (aabb % 100) */ + dd = ccdd - cc * 100; /* (ccdd % 100) */ + byte_copy_2(buf + 0, digit_table + aa * 2); + byte_copy_2(buf + 2, digit_table + bb * 2); + byte_copy_2(buf + 4, digit_table + cc * 2); + byte_copy_2(buf + 6, digit_table + dd * 2); + return buf + 8; +} + +static_inline u8 *write_u32_len_4(u32 val, u8 *buf) { + u32 aa, bb; /* 4 digits: aabb */ + aa = (val * 5243) >> 19; /* (val / 100) */ + bb = val - aa * 100; /* (val % 100) */ + byte_copy_2(buf + 0, digit_table + aa * 2); + byte_copy_2(buf + 2, digit_table + bb * 2); + return buf + 4; +} + +static_inline u8 *write_u32_len_1_to_8(u32 val, u8 *buf) { + u32 aa, bb, cc, dd, aabb, bbcc, ccdd, lz; + + if (val < 100) { /* 1-2 digits: aa */ + lz = val < 10; /* leading zero: 0 or 1 */ + byte_copy_2(buf + 0, digit_table + val * 2 + lz); + buf -= lz; + return buf + 2; + + } else if (val < 10000) { /* 3-4 digits: aabb */ + aa = (val * 5243) >> 19; /* (val / 100) */ + bb = val - aa * 100; /* (val % 100) */ + lz = aa < 10; /* leading zero: 0 or 1 */ + byte_copy_2(buf + 0, digit_table + aa * 2 + lz); + buf -= lz; + byte_copy_2(buf + 2, digit_table + bb * 2); + return buf + 4; + + } else if (val < 1000000) { /* 5-6 digits: aabbcc */ + aa = (u32)(((u64)val * 429497) >> 32); /* (val / 10000) */ + bbcc = val - aa * 10000; /* (val % 10000) */ + bb = (bbcc * 5243) >> 19; /* (bbcc / 100) */ + cc = bbcc - bb * 100; /* (bbcc % 100) */ + lz = aa < 10; /* leading zero: 0 or 1 */ + byte_copy_2(buf + 0, digit_table + aa * 2 + lz); + buf -= lz; + byte_copy_2(buf + 2, digit_table + bb * 2); + byte_copy_2(buf + 4, digit_table + cc * 2); + return buf + 6; + + } else { /* 7-8 digits: aabbccdd */ + aabb = (u32)(((u64)val * 109951163) >> 40); /* (val / 10000) */ + ccdd = val - aabb * 10000; /* (val % 10000) */ + aa = (aabb * 5243) >> 19; /* (aabb / 100) */ + cc = (ccdd * 5243) >> 19; /* (ccdd / 100) */ + bb = aabb - aa * 100; /* (aabb % 100) */ + dd = ccdd - cc * 100; /* (ccdd % 100) */ + lz = aa < 10; /* leading zero: 0 or 1 */ + byte_copy_2(buf + 0, digit_table + aa * 2 + lz); + buf -= lz; + byte_copy_2(buf + 2, digit_table + bb * 2); + byte_copy_2(buf + 4, digit_table + cc * 2); + byte_copy_2(buf + 6, digit_table + dd * 2); + return buf + 8; + } +} + +static_inline u8 *write_u32_len_5_to_8(u32 val, u8 *buf) { + u32 aa, bb, cc, dd, aabb, bbcc, ccdd, lz; + + if (val < 1000000) { /* 5-6 digits: aabbcc */ + aa = (u32)(((u64)val * 429497) >> 32); /* (val / 10000) */ + bbcc = val - aa * 10000; /* (val % 10000) */ + bb = (bbcc * 5243) >> 19; /* (bbcc / 100) */ + cc = bbcc - bb * 100; /* (bbcc % 100) */ + lz = aa < 10; /* leading zero: 0 or 1 */ + byte_copy_2(buf + 0, digit_table + aa * 2 + lz); + buf -= lz; + byte_copy_2(buf + 2, digit_table + bb * 2); + byte_copy_2(buf + 4, digit_table + cc * 2); + return buf + 6; + + } else { /* 7-8 digits: aabbccdd */ + aabb = (u32)(((u64)val * 109951163) >> 40); /* (val / 10000) */ + ccdd = val - aabb * 10000; /* (val % 10000) */ + aa = (aabb * 5243) >> 19; /* (aabb / 100) */ + cc = (ccdd * 5243) >> 19; /* (ccdd / 100) */ + bb = aabb - aa * 100; /* (aabb % 100) */ + dd = ccdd - cc * 100; /* (ccdd % 100) */ + lz = aa < 10; /* leading zero: 0 or 1 */ + byte_copy_2(buf + 0, digit_table + aa * 2 + lz); + buf -= lz; + byte_copy_2(buf + 2, digit_table + bb * 2); + byte_copy_2(buf + 4, digit_table + cc * 2); + byte_copy_2(buf + 6, digit_table + dd * 2); + return buf + 8; + } +} + +static_inline u8 *write_u64(u64 val, u8 *buf) { + u64 tmp, hgh; + u32 mid, low; + + if (val < 100000000) { /* 1-8 digits */ + buf = write_u32_len_1_to_8((u32)val, buf); + return buf; + + } else if (val < (u64)100000000 * 100000000) { /* 9-16 digits */ + hgh = val / 100000000; /* (val / 100000000) */ + low = (u32)(val - hgh * 100000000); /* (val % 100000000) */ + buf = write_u32_len_1_to_8((u32)hgh, buf); + buf = write_u32_len_8(low, buf); + return buf; + + } else { /* 17-20 digits */ + tmp = val / 100000000; /* (val / 100000000) */ + low = (u32)(val - tmp * 100000000); /* (val % 100000000) */ + hgh = (u32)(tmp / 10000); /* (tmp / 10000) */ + mid = (u32)(tmp - hgh * 10000); /* (tmp % 10000) */ + buf = write_u32_len_5_to_8((u32)hgh, buf); + buf = write_u32_len_4(mid, buf); + buf = write_u32_len_8(low, buf); + return buf; + } +} + + + +/*============================================================================== + * MARK: - Number Writer (Private) + *============================================================================*/ + +#if !YYJSON_DISABLE_FAST_FP_CONV /* FP_WRITER */ + +/** Trailing zero count table for number 0 to 99. + (generate with misc/make_tables.c) */ +static const u8 dec_trailing_zero_table[] = { + 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +static_inline u8 *write_u64_len_1_to_16(u64 val, u8 *buf) { + u64 hgh; + u32 low; + if (val < 100000000) { /* 1-8 digits */ + buf = write_u32_len_1_to_8((u32)val, buf); + return buf; + } else { /* 9-16 digits */ + hgh = val / 100000000; /* (val / 100000000) */ + low = (u32)(val - hgh * 100000000); /* (val % 100000000) */ + buf = write_u32_len_1_to_8((u32)hgh, buf); + buf = write_u32_len_8(low, buf); + return buf; + } +} + +static_inline u8 *write_u64_len_1_to_17(u64 val, u8 *buf) { + u64 hgh; + u32 mid, low, one; + if (val >= (u64)100000000 * 10000000) { /* len: 16 to 17 */ + hgh = val / 100000000; /* (val / 100000000) */ + low = (u32)(val - hgh * 100000000); /* (val % 100000000) */ + one = (u32)(hgh / 100000000); /* (hgh / 100000000) */ + mid = (u32)(hgh - (u64)one * 100000000); /* (hgh % 100000000) */ + *buf = (u8)((u8)one + (u8)'0'); + buf += one > 0; + buf = write_u32_len_8(mid, buf); + buf = write_u32_len_8(low, buf); + return buf; + } else if (val >= (u64)100000000){ /* len: 9 to 15 */ + hgh = val / 100000000; /* (val / 100000000) */ + low = (u32)(val - hgh * 100000000); /* (val % 100000000) */ + buf = write_u32_len_1_to_8((u32)hgh, buf); + buf = write_u32_len_8(low, buf); + return buf; + } else { /* len: 1 to 8 */ + buf = write_u32_len_1_to_8((u32)val, buf); + return buf; + } +} + +/** + Write an unsigned integer with a length of 7 to 9 with trailing zero trimmed. + These digits are named as "abbccddee" here. + For example, input 123456000, output "123456". + */ +static_inline u8 *write_u32_len_7_to_9_trim(u32 val, u8 *buf) { + bool lz; + u32 tz, tz1, tz2; + + u32 abbcc = val / 10000; /* (abbccddee / 10000) */ + u32 ddee = val - abbcc * 10000; /* (abbccddee % 10000) */ + u32 abb = (u32)(((u64)abbcc * 167773) >> 24); /* (abbcc / 100) */ + u32 a = (abb * 41) >> 12; /* (abb / 100) */ + u32 bb = abb - a * 100; /* (abb % 100) */ + u32 cc = abbcc - abb * 100; /* (abbcc % 100) */ + + /* write abbcc */ + buf[0] = (u8)(a + '0'); + buf += a > 0; + lz = bb < 10 && a == 0; + byte_copy_2(buf + 0, digit_table + bb * 2 + lz); + buf -= lz; + byte_copy_2(buf + 2, digit_table + cc * 2); + + if (ddee) { + u32 dd = (ddee * 5243) >> 19; /* (ddee / 100) */ + u32 ee = ddee - dd * 100; /* (ddee % 100) */ + byte_copy_2(buf + 4, digit_table + dd * 2); + byte_copy_2(buf + 6, digit_table + ee * 2); + tz1 = dec_trailing_zero_table[dd]; + tz2 = dec_trailing_zero_table[ee]; + tz = ee ? tz2 : (tz1 + 2); + buf += 8 - tz; + return buf; + } else { + tz1 = dec_trailing_zero_table[bb]; + tz2 = dec_trailing_zero_table[cc]; + tz = cc ? tz2 : (tz1 + tz2); + buf += 4 - tz; + return buf; + } +} + +/** + Write an unsigned integer with a length of 16 or 17 with trailing zero trimmed. + These digits are named as "abbccddeeffgghhii" here. + For example, input 1234567890123000, output "1234567890123". + */ +static_inline u8 *write_u64_len_16_to_17_trim(u64 val, u8 *buf) { + u32 tz, tz1, tz2; + + u32 abbccddee = (u32)(val / 100000000); + u32 ffgghhii = (u32)(val - (u64)abbccddee * 100000000); + u32 abbcc = abbccddee / 10000; + u32 ddee = abbccddee - abbcc * 10000; + u32 abb = (u32)(((u64)abbcc * 167773) >> 24); /* (abbcc / 100) */ + u32 a = (abb * 41) >> 12; /* (abb / 100) */ + u32 bb = abb - a * 100; /* (abb % 100) */ + u32 cc = abbcc - abb * 100; /* (abbcc % 100) */ + buf[0] = (u8)(a + '0'); + buf += a > 0; + byte_copy_2(buf + 0, digit_table + bb * 2); + byte_copy_2(buf + 2, digit_table + cc * 2); + + if (ffgghhii) { + u32 dd = (ddee * 5243) >> 19; /* (ddee / 100) */ + u32 ee = ddee - dd * 100; /* (ddee % 100) */ + u32 ffgg = (u32)(((u64)ffgghhii * 109951163) >> 40); /* (val / 10000) */ + u32 hhii = ffgghhii - ffgg * 10000; /* (val % 10000) */ + u32 ff = (ffgg * 5243) >> 19; /* (aabb / 100) */ + u32 gg = ffgg - ff * 100; /* (aabb % 100) */ + byte_copy_2(buf + 4, digit_table + dd * 2); + byte_copy_2(buf + 6, digit_table + ee * 2); + byte_copy_2(buf + 8, digit_table + ff * 2); + byte_copy_2(buf + 10, digit_table + gg * 2); + if (hhii) { + u32 hh = (hhii * 5243) >> 19; /* (ccdd / 100) */ + u32 ii = hhii - hh * 100; /* (ccdd % 100) */ + byte_copy_2(buf + 12, digit_table + hh * 2); + byte_copy_2(buf + 14, digit_table + ii * 2); + tz1 = dec_trailing_zero_table[hh]; + tz2 = dec_trailing_zero_table[ii]; + tz = ii ? tz2 : (tz1 + 2); + return buf + 16 - tz; + } else { + tz1 = dec_trailing_zero_table[ff]; + tz2 = dec_trailing_zero_table[gg]; + tz = gg ? tz2 : (tz1 + 2); + return buf + 12 - tz; + } + } else { + if (ddee) { + u32 dd = (ddee * 5243) >> 19; /* (ddee / 100) */ + u32 ee = ddee - dd * 100; /* (ddee % 100) */ + byte_copy_2(buf + 4, digit_table + dd * 2); + byte_copy_2(buf + 6, digit_table + ee * 2); + tz1 = dec_trailing_zero_table[dd]; + tz2 = dec_trailing_zero_table[ee]; + tz = ee ? tz2 : (tz1 + 2); + return buf + 8 - tz; + } else { + tz1 = dec_trailing_zero_table[bb]; + tz2 = dec_trailing_zero_table[cc]; + tz = cc ? tz2 : (tz1 + tz2); + return buf + 4 - tz; + } + } +} + +/** Write exponent part in range `e-45` to `e38`. */ +static_inline u8 *write_f32_exp(i32 exp, u8 *buf) { + bool lz; + byte_copy_2(buf, "e-"); + buf += 2 - (exp >= 0); + exp = exp < 0 ? -exp : exp; + lz = exp < 10; + byte_copy_2(buf + 0, digit_table + (u32)exp * 2 + lz); + return buf + 2 - lz; +} + +/** Write exponent part in range `e-324` to `e308`. */ +static_inline u8 *write_f64_exp(i32 exp, u8 *buf) { + byte_copy_2(buf, "e-"); + buf += 2 - (exp >= 0); + exp = exp < 0 ? -exp : exp; + if (exp < 100) { + bool lz = exp < 10; + byte_copy_2(buf + 0, digit_table + (u32)exp * 2 + lz); + return buf + 2 - lz; + } else { + u32 hi = ((u32)exp * 656) >> 16; /* exp / 100 */ + u32 lo = (u32)exp - hi * 100; /* exp % 100 */ + buf[0] = (u8)((u8)hi + (u8)'0'); + byte_copy_2(buf + 1, digit_table + lo * 2); + return buf + 3; + } +} + +/** Magic number for fast `divide by power of 10`. */ +typedef struct { + u64 p10, mul; + u32 shr1, shr2; +} div_pow10_magic; + +/** Generated with llvm, see https://github.com/llvm/llvm-project/ + blob/main/llvm/lib/Support/DivisionByConstantInfo.cpp */ +static const div_pow10_magic div_pow10_table[] = { + { U64(0x00000000, 0x00000001), U64(0x00000000, 0x00000000), 0, 0 }, + { U64(0x00000000, 0x0000000A), U64(0xCCCCCCCC, 0xCCCCCCCD), 0, 3 }, + { U64(0x00000000, 0x00000064), U64(0x28F5C28F, 0x5C28F5C3), 2, 2 }, + { U64(0x00000000, 0x000003E8), U64(0x20C49BA5, 0xE353F7CF), 3, 4 }, + { U64(0x00000000, 0x00002710), U64(0x346DC5D6, 0x3886594B), 0, 11 }, + { U64(0x00000000, 0x000186A0), U64(0x0A7C5AC4, 0x71B47843), 5, 7 }, + { U64(0x00000000, 0x000F4240), U64(0x431BDE82, 0xD7B634DB), 0, 18 }, + { U64(0x00000000, 0x00989680), U64(0xD6BF94D5, 0xE57A42BD), 0, 23 }, + { U64(0x00000000, 0x05F5E100), U64(0xABCC7711, 0x8461CEFD), 0, 26 }, + { U64(0x00000000, 0x3B9ACA00), U64(0x0044B82F, 0xA09B5A53), 9, 11 }, + { U64(0x00000002, 0x540BE400), U64(0xDBE6FECE, 0xBDEDD5BF), 0, 33 }, + { U64(0x00000017, 0x4876E800), U64(0xAFEBFF0B, 0xCB24AAFF), 0, 36 }, + { U64(0x000000E8, 0xD4A51000), U64(0x232F3302, 0x5BD42233), 0, 37 }, + { U64(0x00000918, 0x4E72A000), U64(0x384B84D0, 0x92ED0385), 0, 41 }, + { U64(0x00005AF3, 0x107A4000), U64(0x0B424DC3, 0x5095CD81), 0, 42 }, + { U64(0x00038D7E, 0xA4C68000), U64(0x00024075, 0xF3DCEAC3), 15, 20 }, + { U64(0x002386F2, 0x6FC10000), U64(0x39A5652F, 0xB1137857), 0, 51 }, + { U64(0x01634578, 0x5D8A0000), U64(0x00005C3B, 0xD5191B53), 17, 22 }, + { U64(0x0DE0B6B3, 0xA7640000), U64(0x000049C9, 0x7747490F), 18, 24 }, + { U64(0x8AC72304, 0x89E80000), U64(0x760F253E, 0xDB4AB0d3), 0, 62 }, +}; + +/** Divide a number by power of 10. */ +static_inline void div_pow10(u64 num, u32 exp, u64 *div, u64 *mod, u64 *p10) { + u64 hi, lo; + div_pow10_magic m = div_pow10_table[exp]; + u128_mul(num >> m.shr1, m.mul, &hi, &lo); + *div = hi >> m.shr2; + *mod = num - (*div * m.p10); + *p10 = m.p10; +} + +/** Multiplies 64-bit integer and returns highest 64-bit rounded value. */ +static_inline u32 u64_round_to_odd(u64 u, u32 cp) { + u64 hi, lo; + u32 y_hi, y_lo; + u128_mul(cp, u, &hi, &lo); + y_hi = (u32)hi; + y_lo = (u32)(lo >> 32); + return y_hi | (y_lo > 1); +} + +/** Multiplies 128-bit integer and returns highest 64-bit rounded value. */ +static_inline u64 u128_round_to_odd(u64 hi, u64 lo, u64 cp) { + u64 x_hi, x_lo, y_hi, y_lo; + u128_mul(cp, lo, &x_hi, &x_lo); + u128_mul_add(cp, hi, x_hi, &y_hi, &y_lo); + return y_hi | (y_lo > 1); +} + +/** Convert f32 from binary to decimal (shortest but may have trailing zeros). + The input should not be 0, inf or nan. */ +static_inline void f32_bin_to_dec(u32 sig_raw, u32 exp_raw, + u32 sig_bin, i32 exp_bin, + u32 *sig_dec, i32 *exp_dec) { + + bool is_even, irregular, round_up, trim; + bool u0_inside, u1_inside, w0_inside, w1_inside; + u64 p10_hi, p10_lo, hi, lo; + u32 s, sp, cb, cbl, cbr, vb, vbl, vbr, upper, lower, mid; + i32 k, h; + + /* Fast path, see f64_bin_to_dec(). */ + while (likely(sig_raw)) { + u32 mod, dec, add_1, add_10, s_hi, s_lo; + u32 c, half_ulp, t0, t1; + + /* k = floor(exp_bin * log10(2)); */ + /* h = exp_bin + floor(log2(10) * -k); (h = 0/1/2/3) */ + k = (i32)(exp_bin * 315653) >> 20; + h = exp_bin + ((-k * 217707) >> 16); + pow10_table_get_sig(-k, &p10_hi, &p10_lo); + + /* sig_bin << (1/2/3/4) */ + cb = sig_bin << (h + 1); + u128_mul(cb, p10_hi, &hi, &lo); + s_hi = (u32)(hi); + s_lo = (u32)(lo >> 32); + mod = s_hi % 10; + dec = s_hi - mod; + + /* right shift 4 to fit in u32 */ + c = (mod << (32 - 4)) | (s_lo >> 4); + half_ulp = (u32)(p10_hi >> (32 + 4 - h)); + + /* check w1, u0, w0 range */ + w1_inside = (s_lo >= ((u32)1 << 31)); + if (unlikely(s_lo == ((u32)1 << 31))) break; + u0_inside = (half_ulp >= c); + if (unlikely(half_ulp == c)) break; + t0 = (u32)10 << (32 - 4); + t1 = c + half_ulp; + w0_inside = (t1 >= t0); + if (unlikely(t0 - t1 <= (u32)1)) break; + + trim = (u0_inside | w0_inside); + add_10 = (w0_inside ? 10 : 0); + add_1 = mod + w1_inside; + *sig_dec = dec + (trim ? add_10 : add_1); + *exp_dec = k; + return; + } + + /* Schubfach algorithm, see f64_bin_to_dec(). */ + irregular = (sig_raw == 0 && exp_raw > 1); + is_even = !(sig_bin & 1); + cbl = 4 * sig_bin - 2 + irregular; + cb = 4 * sig_bin; + cbr = 4 * sig_bin + 2; + + /* k = floor(exp_bin * log10(2) + (irregular ? log10(3.0 / 4.0) : 0)); */ + /* h = exp_bin + floor(log2(10) * -k) + 1; (h = 1/2/3/4) */ + k = (i32)(exp_bin * 315653 - (irregular ? 131237 : 0)) >> 20; + h = exp_bin + ((-k * 217707) >> 16) + 1; + pow10_table_get_sig(-k, &p10_hi, &p10_lo); + p10_hi += 1; + + vbl = u64_round_to_odd(p10_hi, cbl << h); + vb = u64_round_to_odd(p10_hi, cb << h); + vbr = u64_round_to_odd(p10_hi, cbr << h); + lower = vbl + !is_even; + upper = vbr - !is_even; + + s = vb / 4; + if (s >= 10) { + sp = s / 10; + u0_inside = (lower <= 40 * sp); + w0_inside = (upper >= 40 * sp + 40); + if (u0_inside != w0_inside) { + *sig_dec = sp * 10 + (w0_inside ? 10 : 0); + *exp_dec = k; + return; + } + } + u1_inside = (lower <= 4 * s); + w1_inside = (upper >= 4 * s + 4); + mid = 4 * s + 2; + round_up = (vb > mid) || (vb == mid && (s & 1) != 0); + *sig_dec = s + ((u1_inside != w1_inside) ? w1_inside : round_up); + *exp_dec = k; +} + +/** Convert f64 from binary to decimal (shortest but may have trailing zeros). + The input should not be 0, inf or nan. */ +static_inline void f64_bin_to_dec(u64 sig_raw, u32 exp_raw, + u64 sig_bin, i32 exp_bin, + u64 *sig_dec, i32 *exp_dec) { + + bool is_even, irregular, round_up, trim; + bool u0_inside, u1_inside, w0_inside, w1_inside; + u64 s, sp, cb, cbl, cbr, vb, vbl, vbr, p10_hi, p10_lo, upper, lower, mid; + i32 k, h; + + /* + Fast path: + For regular spacing significand 'c', there are 4 candidates: + + u0 u1 c w1 w0 + ----|----|----|----|----|-*--|----|----|----|----|----|----|----|---- + 9 0 1 2 3 4 5 6 7 8 9 0 1 + |___________________|___________________| + 1ulp + + The `1ulp` is in the range [1.0, 10.0). + If (c - 0.5ulp < u0), trim the last digit and round down. + If (c + 0.5ulp > w0), trim the last digit and round up. + If (c - 0.5ulp < u1), round down. + If (c + 0.5ulp > w1), round up. + */ + while (likely(sig_raw)) { + u64 mod, dec, add_1, add_10, s_hi, s_lo; + u64 c, half_ulp, t0, t1; + + /* k = floor(exp_bin * log10(2)); */ + /* h = exp_bin + floor(log2(10) * -k); (h = 0/1/2/3) */ + k = (i32)(exp_bin * 315653) >> 20; + h = exp_bin + ((-k * 217707) >> 16); + pow10_table_get_sig(-k, &p10_hi, &p10_lo); + + /* sig_bin << (1/2/3/4) */ + cb = sig_bin << (h + 1); + u128_mul(cb, p10_lo, &s_hi, &s_lo); + u128_mul_add(cb, p10_hi, s_hi, &s_hi, &s_lo); + mod = s_hi % 10; + dec = s_hi - mod; + + /* right shift 4 to fit in u64 */ + c = (mod << (64 - 4)) | (s_lo >> 4); + half_ulp = p10_hi >> (4 - h); + + /* check w1, u0, w0 range */ + w1_inside = (s_lo >= ((u64)1 << 63)); + if (unlikely(s_lo == ((u64)1 << 63))) break; + u0_inside = (half_ulp >= c); + if (unlikely(half_ulp == c)) break; + t0 = ((u64)10 << (64 - 4)); + t1 = c + half_ulp; + w0_inside = (t1 >= t0); + if (unlikely(t0 - t1 <= (u64)1)) break; + + trim = (u0_inside | w0_inside); + add_10 = (w0_inside ? 10 : 0); + add_1 = mod + w1_inside; + *sig_dec = dec + (trim ? add_10 : add_1); + *exp_dec = k; + return; + } + + /* + Schubfach algorithm: + Raffaello Giulietti, The Schubfach way to render doubles, 2022. + https://drive.google.com/file/d/1gp5xv4CAa78SVgCeWfGqqI4FfYYYuNFb (Paper) + https://github.com/openjdk/jdk/pull/3402 (Java implementation) + https://github.com/abolz/Drachennest (C++ implementation) + */ + irregular = (sig_raw == 0 && exp_raw > 1); + is_even = !(sig_bin & 1); + cbl = 4 * sig_bin - 2 + irregular; + cb = 4 * sig_bin; + cbr = 4 * sig_bin + 2; + + /* k = floor(exp_bin * log10(2) + (irregular ? log10(3.0 / 4.0) : 0)); */ + /* h = exp_bin + floor(log2(10) * -k) + 1; (h = 1/2/3/4) */ + k = (i32)(exp_bin * 315653 - (irregular ? 131237 : 0)) >> 20; + h = exp_bin + ((-k * 217707) >> 16) + 1; + pow10_table_get_sig(-k, &p10_hi, &p10_lo); + p10_lo += 1; + + vbl = u128_round_to_odd(p10_hi, p10_lo, cbl << h); + vb = u128_round_to_odd(p10_hi, p10_lo, cb << h); + vbr = u128_round_to_odd(p10_hi, p10_lo, cbr << h); + lower = vbl + !is_even; + upper = vbr - !is_even; + + s = vb / 4; + if (s >= 10) { + sp = s / 10; + u0_inside = (lower <= 40 * sp); + w0_inside = (upper >= 40 * sp + 40); + if (u0_inside != w0_inside) { + *sig_dec = sp * 10 + (w0_inside ? 10 : 0); + *exp_dec = k; + return; + } + } + u1_inside = (lower <= 4 * s); + w1_inside = (upper >= 4 * s + 4); + mid = 4 * s + 2; + round_up = (vb > mid) || (vb == mid && (s & 1) != 0); + *sig_dec = s + ((u1_inside != w1_inside) ? w1_inside : round_up); + *exp_dec = k; +} + +/** Convert f64 from binary to decimal (fast but not the shortest). + The input should not be 0, inf, nan. */ +static_inline void f64_bin_to_dec_fast(u64 sig_raw, u32 exp_raw, + u64 sig_bin, i32 exp_bin, + u64 *sig_dec, i32 *exp_dec, + bool *round_up) { + u64 cb, p10_hi, p10_lo, s_hi, s_lo; + i32 k, h; + bool irregular, u; + + irregular = (sig_raw == 0 && exp_raw > 1); + + /* k = floor(exp_bin * log10(2) + (irregular ? log10(3.0 / 4.0) : 0)); */ + /* h = exp_bin + floor(log2(10) * -k) + 1; (h = 1/2/3/4) */ + k = (i32)(exp_bin * 315653 - (irregular ? 131237 : 0)) >> 20; + h = exp_bin + ((-k * 217707) >> 16); + pow10_table_get_sig(-k, &p10_hi, &p10_lo); + + /* sig_bin << (1/2/3/4) */ + cb = sig_bin << (h + 1); + u128_mul(cb, p10_lo, &s_hi, &s_lo); + u128_mul_add(cb, p10_hi, s_hi, &s_hi, &s_lo); + + /* round up */ + u = s_lo >= (irregular ? U64(0x55555555, 0x55555555) : ((u64)1 << 63)); + + *sig_dec = s_hi + u; + *exp_dec = k; + *round_up = u; + return; +} + +/** Write inf/nan if allowed. */ +static_inline u8 *write_inf_or_nan(u8 *buf, yyjson_write_flag flg, + u64 sig_raw, bool sign) { + if (has_flg(INF_AND_NAN_AS_NULL)) { + byte_copy_4(buf, "null"); + return buf + 4; + } + if (has_allow(INF_AND_NAN)) { + if (sig_raw == 0) { + buf[0] = '-'; + buf += sign; + byte_copy_8(buf, "Infinity"); + return buf + 8; + } else { + byte_copy_4(buf, "NaN"); + return buf + 3; + } + } + return NULL; +} + +/** + Write a float number (requires 40 bytes buffer). + We follow the ECMAScript specification for printing floating-point numbers, + similar to `Number.prototype.toString()`, but with the following changes: + 1. Keep the negative sign of `-0.0` to preserve input information. + 2. Keep decimal point to indicate the number is floating point. + 3. Remove positive sign in the exponent part. + */ +static_noinline u8 *write_f32_raw(u8 *buf, u64 raw_f64, + yyjson_write_flag flg) { + u32 sig_bin, sig_dec, sig_raw; + i32 exp_bin, exp_dec, sig_len, dot_ofs; + u32 exp_raw, raw; + u8 *end; + bool sign; + + /* cast double to float */ + raw = f32_to_bits(f64_to_f32(f64_from_bits(raw_f64))); + + /* decode raw bytes from IEEE-754 double format. */ + sign = (bool)(raw >> (F32_BITS - 1)); + sig_raw = raw & F32_SIG_MASK; + exp_raw = (raw & F32_EXP_MASK) >> F32_SIG_BITS; + + /* return inf or nan */ + if (unlikely(exp_raw == ((u32)1 << F32_EXP_BITS) - 1)) { + return write_inf_or_nan(buf, flg, sig_raw, sign); + } + + /* add sign for all finite number */ + buf[0] = '-'; + buf += sign; + + /* return zero */ + if ((raw << 1) == 0) { + byte_copy_4(buf, "0.0"); + return buf + 3; + } + + if (likely(exp_raw != 0)) { + /* normal number */ + sig_bin = sig_raw | ((u32)1 << F32_SIG_BITS); + exp_bin = (i32)exp_raw - F32_EXP_BIAS - F32_SIG_BITS; + + /* fast path for small integer number without fraction */ + if ((-F32_SIG_BITS <= exp_bin && exp_bin <= 0) && + (u64_tz_bits(sig_bin) >= (u32)-exp_bin)) { + sig_dec = sig_bin >> -exp_bin; /* range: [1, 0xFFFFFF] */ + buf = write_u32_len_1_to_8(sig_dec, buf); + byte_copy_2(buf, ".0"); + return buf + 2; + } + + /* binary to decimal */ + f32_bin_to_dec(sig_raw, exp_raw, sig_bin, exp_bin, &sig_dec, &exp_dec); + + /* the sig length is 7 or 9 */ + sig_len = 7 + (sig_dec >= (u32)10000000) + (sig_dec >= (u32)100000000); + + /* the decimal point offset relative to the first digit */ + dot_ofs = sig_len + exp_dec; + + if (-6 < dot_ofs && dot_ofs <= 21) { + i32 num_sep_pos, dot_set_pos, pre_ofs; + u8 *num_hdr, *num_end, *num_sep, *dot_end; + bool no_pre_zero; + + /* fill zeros */ + memset(buf, '0', 32); + + /* not prefixed with zero, e.g. 1.234, 1234.0 */ + no_pre_zero = (dot_ofs > 0); + + /* write the number as digits */ + pre_ofs = no_pre_zero ? 0 : (2 - dot_ofs); + num_hdr = buf + pre_ofs; + num_end = write_u32_len_7_to_9_trim(sig_dec, num_hdr); + + /* seperate these digits to leave a space for dot */ + num_sep_pos = no_pre_zero ? dot_ofs : 0; + num_sep = num_hdr + num_sep_pos; + byte_move_8(num_sep + no_pre_zero, num_sep); + num_end += no_pre_zero; + + /* write the dot */ + dot_set_pos = yyjson_max(dot_ofs, 1); + buf[dot_set_pos] = '.'; + + /* return the ending */ + dot_end = buf + dot_ofs + 2; + return yyjson_max(dot_end, num_end); + + } else { + /* write with scientific notation, e.g. 1.234e56 */ + end = write_u32_len_7_to_9_trim(sig_dec, buf + 1); + end -= (end == buf + 2); /* remove '.0', e.g. 2.0e34 -> 2e34 */ + exp_dec += sig_len - 1; + buf[0] = buf[1]; + buf[1] = '.'; + return write_f32_exp(exp_dec, end); + } + + } else { + /* subnormal number */ + sig_bin = sig_raw; + exp_bin = 1 - F32_EXP_BIAS - F32_SIG_BITS; + + /* binary to decimal */ + f32_bin_to_dec(sig_raw, exp_raw, sig_bin, exp_bin, &sig_dec, &exp_dec); + + /* write significand part */ + end = write_u32_len_1_to_8(sig_dec, buf + 1); + buf[0] = buf[1]; + buf[1] = '.'; + exp_dec += (i32)(end - buf) - 2; + + /* trim trailing zeros */ + end -= *(end - 1) == '0'; /* branchless for last zero */ + end -= *(end - 1) == '0'; /* branchless for second last zero */ + while (*(end - 1) == '0') end--; /* for unlikely more zeros */ + end -= *(end - 1) == '.'; /* remove dot, e.g. 2.e-321 -> 2e-321 */ + + /* write exponent part */ + return write_f32_exp(exp_dec, end); + } +} + +/** + Write a double number (requires 40 bytes buffer). + We follow the ECMAScript specification for printing floating-point numbers, + similar to `Number.prototype.toString()`, but with the following changes: + 1. Keep the negative sign of `-0.0` to preserve input information. + 2. Keep decimal point to indicate the number is floating point. + 3. Remove positive sign in the exponent part. + */ +static_noinline u8 *write_f64_raw(u8 *buf, u64 raw, yyjson_write_flag flg) { + u64 sig_bin, sig_dec, sig_raw; + i32 exp_bin, exp_dec, sig_len, dot_ofs; + u32 exp_raw; + u8 *end; + bool sign; + + /* decode raw bytes from IEEE-754 double format. */ + sign = (bool)(raw >> (F64_BITS - 1)); + sig_raw = raw & F64_SIG_MASK; + exp_raw = (u32)((raw & F64_EXP_MASK) >> F64_SIG_BITS); + + /* return inf or nan */ + if (unlikely(exp_raw == ((u32)1 << F64_EXP_BITS) - 1)) { + return write_inf_or_nan(buf, flg, sig_raw, sign); + } + + /* add sign for all finite number */ + buf[0] = '-'; + buf += sign; + + /* return zero */ + if ((raw << 1) == 0) { + byte_copy_4(buf, "0.0"); + return buf + 3; + } + + if (likely(exp_raw != 0)) { + /* normal number */ + sig_bin = sig_raw | ((u64)1 << F64_SIG_BITS); + exp_bin = (i32)exp_raw - F64_EXP_BIAS - F64_SIG_BITS; + + /* fast path for small integer number without fraction */ + if ((-F64_SIG_BITS <= exp_bin && exp_bin <= 0) && + (u64_tz_bits(sig_bin) >= (u32)-exp_bin)) { + sig_dec = sig_bin >> -exp_bin; /* range: [1, 0x1FFFFFFFFFFFFF] */ + buf = write_u64_len_1_to_16(sig_dec, buf); + byte_copy_2(buf, ".0"); + return buf + 2; + } + + /* binary to decimal */ + f64_bin_to_dec(sig_raw, exp_raw, sig_bin, exp_bin, &sig_dec, &exp_dec); + + /* the sig length is 16 or 17 */ + sig_len = 16 + (sig_dec >= (u64)100000000 * 100000000); + + /* the decimal point offset relative to the first digit */ + dot_ofs = sig_len + exp_dec; + + if (-6 < dot_ofs && dot_ofs <= 21) { + i32 num_sep_pos, dot_set_pos, pre_ofs; + u8 *num_hdr, *num_end, *num_sep, *dot_end; + bool no_pre_zero; + + /* fill zeros */ + memset(buf, '0', 32); + + /* not prefixed with zero, e.g. 1.234, 1234.0 */ + no_pre_zero = (dot_ofs > 0); + + /* write the number as digits */ + pre_ofs = no_pre_zero ? 0 : (2 - dot_ofs); + num_hdr = buf + pre_ofs; + num_end = write_u64_len_16_to_17_trim(sig_dec, num_hdr); + + /* seperate these digits to leave a space for dot */ + num_sep_pos = no_pre_zero ? dot_ofs : 0; + num_sep = num_hdr + num_sep_pos; + byte_move_16(num_sep + no_pre_zero, num_sep); + num_end += no_pre_zero; + + /* write the dot */ + dot_set_pos = yyjson_max(dot_ofs, 1); + buf[dot_set_pos] = '.'; + + /* return the ending */ + dot_end = buf + dot_ofs + 2; + return yyjson_max(dot_end, num_end); + + } else { + /* write with scientific notation, e.g. 1.234e56 */ + end = write_u64_len_16_to_17_trim(sig_dec, buf + 1); + end -= (end == buf + 2); /* remove '.0', e.g. 2.0e34 -> 2e34 */ + exp_dec += sig_len - 1; + buf[0] = buf[1]; + buf[1] = '.'; + return write_f64_exp(exp_dec, end); + } + + } else { + /* subnormal number */ + sig_bin = sig_raw; + exp_bin = 1 - F64_EXP_BIAS - F64_SIG_BITS; + + /* binary to decimal */ + f64_bin_to_dec(sig_raw, exp_raw, sig_bin, exp_bin, &sig_dec, &exp_dec); + + /* write significand part */ + end = write_u64_len_1_to_17(sig_dec, buf + 1); + buf[0] = buf[1]; + buf[1] = '.'; + exp_dec += (i32)(end - buf) - 2; + + /* trim trailing zeros */ + end -= *(end - 1) == '0'; /* branchless for last zero */ + end -= *(end - 1) == '0'; /* branchless for second last zero */ + while (*(end - 1) == '0') end--; /* for unlikely more zeros */ + end -= *(end - 1) == '.'; /* remove dot, e.g. 2.e-321 -> 2e-321 */ + + /* write exponent part */ + return write_f64_exp(exp_dec, end); + } +} + +/** + Write a double number using fixed-point notation (requires 40 bytes buffer). + + We follow the ECMAScript specification for printing floating-point numbers, + similar to `Number.prototype.toFixed(prec)`, but with the following changes: + 1. Keep the negative sign of `-0.0` to preserve input information. + 2. Keep decimal point to indicate the number is floating point. + 3. Remove positive sign in the exponent part. + 4. Remove trailing zeros and reduce unnecessary precision. + */ +static_noinline u8 *write_f64_raw_fixed(u8 *buf, u64 raw, yyjson_write_flag flg, + u32 prec) { + u64 sig_bin, sig_dec, sig_raw; + i32 exp_bin, exp_dec, sig_len, dot_ofs; + u32 exp_raw; + u8 *end; + bool sign; + + /* decode raw bytes from IEEE-754 double format. */ + sign = (bool)(raw >> (F64_BITS - 1)); + sig_raw = raw & F64_SIG_MASK; + exp_raw = (u32)((raw & F64_EXP_MASK) >> F64_SIG_BITS); + + /* return inf or nan */ + if (unlikely(exp_raw == ((u32)1 << F64_EXP_BITS) - 1)) { + return write_inf_or_nan(buf, flg, sig_raw, sign); + } + + /* add sign for all finite number */ + buf[0] = '-'; + buf += sign; + + /* return zero */ + if ((raw << 1) == 0) { + byte_copy_4(buf, "0.0"); + return buf + 3; + } + + if (likely(exp_raw != 0)) { + /* normal number */ + sig_bin = sig_raw | ((u64)1 << F64_SIG_BITS); + exp_bin = (i32)exp_raw - F64_EXP_BIAS - F64_SIG_BITS; + + /* fast path for small integer number without fraction */ + if ((-F64_SIG_BITS <= exp_bin && exp_bin <= 0) && + (u64_tz_bits(sig_bin) >= (u32)-exp_bin)) { + sig_dec = sig_bin >> -exp_bin; /* range: [1, 0x1FFFFFFFFFFFFF] */ + buf = write_u64_len_1_to_16(sig_dec, buf); + byte_copy_2(buf, ".0"); + return buf + 2; + } + + /* only `fabs(num) < 1e21` are processed here. */ + if ((raw << 1) < (U64(0x444B1AE4, 0xD6E2EF50) << 1)) { + i32 num_sep_pos, dot_set_pos, pre_ofs; + u8 *num_hdr, *num_end, *num_sep; + bool round_up, no_pre_zero; + + /* binary to decimal */ + f64_bin_to_dec_fast(sig_raw, exp_raw, sig_bin, exp_bin, + &sig_dec, &exp_dec, &round_up); + + /* the sig length is 16 or 17 */ + sig_len = 16 + (sig_dec >= (u64)100000000 * 100000000); + + /* limit the length of digits after the decimal point */ + if (exp_dec < -1) { + i32 sig_len_cut = -exp_dec - (i32)prec; + if (sig_len_cut > sig_len) { + byte_copy_4(buf, "0.0"); + return buf + 3; + } + if (sig_len_cut > 0) { + u64 div, mod, p10; + + /* remove round up */ + sig_dec -= round_up; + sig_len = 16 + (sig_dec >= (u64)100000000 * 100000000); + + /* cut off some digits */ + div_pow10(sig_dec, (u32)sig_len_cut, &div, &mod, &p10); + + /* add round up */ + sig_dec = div + (mod >= p10 / 2); + + /* update exp and sig length */ + exp_dec += sig_len_cut; + sig_len -= sig_len_cut; + sig_len += (sig_len >= 0) && + (sig_dec >= div_pow10_table[sig_len].p10); + } + if (sig_len <= 0) { + byte_copy_4(buf, "0.0"); + return buf + 3; + } + } + + /* fill zeros */ + memset(buf, '0', 32); + + /* the decimal point offset relative to the first digit */ + dot_ofs = sig_len + exp_dec; + + /* not prefixed with zero, e.g. 1.234, 1234.0 */ + no_pre_zero = (dot_ofs > 0); + + /* write the number as digits */ + pre_ofs = no_pre_zero ? 0 : (1 - dot_ofs); + num_hdr = buf + pre_ofs; + num_end = write_u64_len_1_to_17(sig_dec, num_hdr); + + /* seperate these digits to leave a space for dot */ + num_sep_pos = no_pre_zero ? dot_ofs : -dot_ofs; + num_sep = buf + num_sep_pos; + byte_move_16(num_sep + 1, num_sep); + num_end += (exp_dec < 0); + + /* write the dot */ + dot_set_pos = yyjson_max(dot_ofs, 1); + buf[dot_set_pos] = '.'; + + /* remove trailing zeros */ + buf += dot_set_pos + 2; + buf = yyjson_max(buf, num_end); + buf -= *(buf - 1) == '0'; /* branchless for last zero */ + buf -= *(buf - 1) == '0'; /* branchless for second last zero */ + while (*(buf - 1) == '0') buf--; /* for unlikely more zeros */ + buf += *(buf - 1) == '.'; /* keep a zero after dot */ + return buf; + + } else { + /* binary to decimal */ + f64_bin_to_dec(sig_raw, exp_raw, sig_bin, exp_bin, + &sig_dec, &exp_dec); + + /* the sig length is 16 or 17 */ + sig_len = 16 + (sig_dec >= (u64)100000000 * 100000000); + + /* write with scientific notation, e.g. 1.234e56 */ + end = write_u64_len_16_to_17_trim(sig_dec, buf + 1); + end -= (end == buf + 2); /* remove '.0', e.g. 2.0e34 -> 2e34 */ + exp_dec += sig_len - 1; + buf[0] = buf[1]; + buf[1] = '.'; + return write_f64_exp(exp_dec, end); + } + } else { + /* subnormal number */ + byte_copy_4(buf, "0.0"); + return buf + 3; + } +} + +#else /* FP_WRITER */ + +#if YYJSON_MSC_VER >= 1400 +#define snprintf_num(buf, len, fmt, dig, val) \ + sprintf_s((char *)buf, len, fmt, dig, val) +#elif defined(snprintf) || (YYJSON_STDC_VER >= 199901L) +#define snprintf_num(buf, len, fmt, dig, val) \ + snprintf((char *)buf, len, fmt, dig, val) +#else +#define snprintf_num(buf, len, fmt, dig, val) \ + sprintf((char *)buf, fmt, dig, val) +#endif + +static_noinline u8 *write_fp_reformat(u8 *buf, int len, + yyjson_write_flag flg, bool fixed) { + u8 *cur = buf; + if (unlikely(len < 1)) return NULL; + cur += (*cur == '-'); + if (unlikely(!char_is_digit(*cur))) { + /* nan, inf, or bad output */ + if (has_flg(INF_AND_NAN_AS_NULL)) { + byte_copy_4(buf, "null"); + return buf + 4; + } else if (has_allow(INF_AND_NAN)) { + if (*cur == 'i') { + byte_copy_8(cur, "Infinity"); + return cur + 8; + } else if (*cur == 'n') { + byte_copy_4(buf, "NaN"); + return buf + 3; + } + } + return NULL; + } else { + /* finite number */ + u8 *end = buf + len, *dot = NULL, *exp = NULL; + + /* + The snprintf() function is locale-dependent. For currently known + locales, (en, zh, ja, ko, am, he, hi) use '.' as the decimal point, + while other locales use ',' as the decimal point. we need to replace + ',' with '.' to avoid the locale setting. + */ + for (; cur < end; cur++) { + switch (*cur) { + case ',': *cur = '.'; /* fallthrough */ + case '.': dot = cur; break; + case 'e': exp = cur; break; + default: break; + } + } + if (fixed) { + /* remove trailing zeros */ + while (*(end - 1) == '0') end--; + end += *(end - 1) == '.'; + } else { + if (!dot && !exp) { + /* add decimal point, e.g. 123 -> 123.0 */ + byte_copy_2(end, ".0"); + end += 2; + } else if (exp) { + cur = exp + 1; + /* remove positive sign in the exponent part */ + if (*cur == '+') { + memmove(cur, cur + 1, (usize)(end - cur - 1)); + end--; + } + cur += (*cur == '-'); + /* remove leading zeros in the exponent part */ + if (*cur == '0') { + u8 *hdr = cur++; + while (*cur == '0') cur++; + memmove(hdr, cur, (usize)(end - cur)); + end -= (usize)(cur - hdr); + } + } + } + return end; + } +} + +/** Write a double number (requires 40 bytes buffer). */ +static_noinline u8 *write_f64_raw(u8 *buf, u64 raw, yyjson_write_flag flg) { +#if defined(DBL_DECIMAL_DIG) && DBL_DECIMAL_DIG < F64_DEC_DIG + int dig = DBL_DECIMAL_DIG; +#else + int dig = F64_DEC_DIG; +#endif + f64 val = f64_from_bits(raw); + int len = snprintf_num(buf, FP_BUF_LEN, "%.*g", dig, val); + return write_fp_reformat(buf, len, flg, false); +} + +/** Write a double number (requires 40 bytes buffer). */ +static_noinline u8 *write_f32_raw(u8 *buf, u64 raw, yyjson_write_flag flg) { +#if defined(FLT_DECIMAL_DIG) && FLT_DECIMAL_DIG < F32_DEC_DIG + int dig = FLT_DECIMAL_DIG; +#else + int dig = F32_DEC_DIG; +#endif + f64 val = (f64)f64_to_f32(f64_from_bits(raw)); + int len = snprintf_num(buf, FP_BUF_LEN, "%.*g", dig, val); + return write_fp_reformat(buf, len, flg, false); +} + +/** Write a double number (requires 40 bytes buffer). */ +static_noinline u8 *write_f64_raw_fixed(u8 *buf, u64 raw, + yyjson_write_flag flg, u32 prec) { + f64 val = (f64)f64_from_bits(raw); + if (-1e21 < val && val < 1e21) { + int len = snprintf_num(buf, FP_BUF_LEN, "%.*f", (int)prec, val); + return write_fp_reformat(buf, len, flg, true); + } else { + return write_f64_raw(buf, raw, flg); + } +} + +#endif /* FP_WRITER */ + +/** Write a JSON number (requires 40 bytes buffer). */ +static_inline u8 *write_num(u8 *cur, yyjson_val *val, yyjson_write_flag flg) { + if (!(val->tag & YYJSON_SUBTYPE_REAL)) { + u64 pos = val->uni.u64; + u64 neg = ~pos + 1; + usize sign = ((val->tag & YYJSON_SUBTYPE_SINT) > 0) & ((i64)pos < 0); + *cur = '-'; + return write_u64(sign ? neg : pos, cur + sign); + } else { + u64 raw = val->uni.u64; + u32 val_fmt = (u32)(val->tag >> 32); + u32 all_fmt = flg; + u32 fmt = val_fmt | all_fmt; + if (likely(!(fmt >> (32 - YYJSON_WRITE_FP_FLAG_BITS)))) { + /* double to shortest */ + return write_f64_raw(cur, raw, flg); + } else if (fmt >> (32 - YYJSON_WRITE_FP_PREC_BITS)) { + /* double to fixed */ + u32 val_prec = val_fmt >> (32 - YYJSON_WRITE_FP_PREC_BITS); + u32 all_prec = all_fmt >> (32 - YYJSON_WRITE_FP_PREC_BITS); + u32 prec = val_prec ? val_prec : all_prec; + return write_f64_raw_fixed(cur, raw, flg, prec); + } else { + if (fmt & YYJSON_WRITE_FP_TO_FLOAT) { + /* float to shortest */ + return write_f32_raw(cur, raw, flg); + } else { + /* double to shortest */ + return write_f64_raw(cur, raw, flg); + } + } + } +} + +char *yyjson_write_number(const yyjson_val *val, char *buf) { + if (unlikely(!val || !buf)) return NULL; + switch (val->tag & YYJSON_TAG_MASK) { + case YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT: { + buf = (char *)write_u64(val->uni.u64, (u8 *)buf); + *buf = '\0'; + return buf; + } + case YYJSON_TYPE_NUM | YYJSON_SUBTYPE_SINT: { + u64 pos = val->uni.u64; + u64 neg = ~pos + 1; + usize sign = ((i64)pos < 0); + *buf = '-'; + buf = (char *)write_u64(sign ? neg : pos, (u8 *)buf + sign); + *buf = '\0'; + return buf; + } + case YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL: { + u64 raw = val->uni.u64; + u32 fmt = (u32)(val->tag >> 32); + u32 flg = YYJSON_WRITE_ALLOW_INF_AND_NAN; + if (likely(!(fmt >> (32 - YYJSON_WRITE_FP_FLAG_BITS)))) { + buf = (char *)write_f64_raw((u8 *)buf, raw, flg); + } else if (fmt >> (32 - YYJSON_WRITE_FP_PREC_BITS)) { + u32 prec = fmt >> (32 - YYJSON_WRITE_FP_PREC_BITS); + buf = (char *)write_f64_raw_fixed((u8 *)buf, raw, flg, prec); + } else { + if (fmt & YYJSON_WRITE_FP_TO_FLOAT) { + buf = (char *)write_f32_raw((u8 *)buf, raw, flg); + } else { + buf = (char *)write_f64_raw((u8 *)buf, raw, flg); + } + } + if (buf) *buf = '\0'; + return buf; + } + default: return NULL; + } +} + + + +/*============================================================================== + * MARK: - String Writer (Private) + *============================================================================*/ + +/** Character encode type, if (type > CHAR_ENC_ERR_1) bytes = type / 2; */ +typedef u8 char_enc_type; +#define CHAR_ENC_CPY_1 0 /* 1-byte UTF-8, copy. */ +#define CHAR_ENC_ERR_1 1 /* 1-byte UTF-8, error. */ +#define CHAR_ENC_ESC_A 2 /* 1-byte ASCII, escaped as '\x'. */ +#define CHAR_ENC_ESC_1 3 /* 1-byte UTF-8, escaped as '\uXXXX'. */ +#define CHAR_ENC_CPY_2 4 /* 2-byte UTF-8, copy. */ +#define CHAR_ENC_ESC_2 5 /* 2-byte UTF-8, escaped as '\uXXXX'. */ +#define CHAR_ENC_CPY_3 6 /* 3-byte UTF-8, copy. */ +#define CHAR_ENC_ESC_3 7 /* 3-byte UTF-8, escaped as '\uXXXX'. */ +#define CHAR_ENC_CPY_4 8 /* 4-byte UTF-8, copy. */ +#define CHAR_ENC_ESC_4 9 /* 4-byte UTF-8, escaped as '\uXXXX\uXXXX'. */ + +/** Character encode type table: don't escape unicode, don't escape '/'. + (generate with misc/make_tables.c) */ +static const char_enc_type enc_table_cpy[256] = { + 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 3, 2, 2, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 8, 8, 8, 8, 8, 8, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1 +}; + +/** Character encode type table: don't escape unicode, escape '/'. + (generate with misc/make_tables.c) */ +static const char_enc_type enc_table_cpy_slash[256] = { + 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 3, 2, 2, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 8, 8, 8, 8, 8, 8, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1 +}; + +/** Character encode type table: escape unicode, don't escape '/'. + (generate with misc/make_tables.c) */ +static const char_enc_type enc_table_esc[256] = { + 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 3, 2, 2, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 9, 9, 9, 9, 9, 9, 9, 9, 1, 1, 1, 1, 1, 1, 1, 1 +}; + +/** Character encode type table: escape unicode, escape '/'. + (generate with misc/make_tables.c) */ +static const char_enc_type enc_table_esc_slash[256] = { + 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 3, 2, 2, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 9, 9, 9, 9, 9, 9, 9, 9, 1, 1, 1, 1, 1, 1, 1, 1 +}; + +/** Escaped hex character table: ["00" "01" "02" ... "FD" "FE" "FF"]. + (generate with misc/make_tables.c) */ +yyjson_align(2) +static const u8 esc_hex_char_table[512] = { + '0', '0', '0', '1', '0', '2', '0', '3', + '0', '4', '0', '5', '0', '6', '0', '7', + '0', '8', '0', '9', '0', 'A', '0', 'B', + '0', 'C', '0', 'D', '0', 'E', '0', 'F', + '1', '0', '1', '1', '1', '2', '1', '3', + '1', '4', '1', '5', '1', '6', '1', '7', + '1', '8', '1', '9', '1', 'A', '1', 'B', + '1', 'C', '1', 'D', '1', 'E', '1', 'F', + '2', '0', '2', '1', '2', '2', '2', '3', + '2', '4', '2', '5', '2', '6', '2', '7', + '2', '8', '2', '9', '2', 'A', '2', 'B', + '2', 'C', '2', 'D', '2', 'E', '2', 'F', + '3', '0', '3', '1', '3', '2', '3', '3', + '3', '4', '3', '5', '3', '6', '3', '7', + '3', '8', '3', '9', '3', 'A', '3', 'B', + '3', 'C', '3', 'D', '3', 'E', '3', 'F', + '4', '0', '4', '1', '4', '2', '4', '3', + '4', '4', '4', '5', '4', '6', '4', '7', + '4', '8', '4', '9', '4', 'A', '4', 'B', + '4', 'C', '4', 'D', '4', 'E', '4', 'F', + '5', '0', '5', '1', '5', '2', '5', '3', + '5', '4', '5', '5', '5', '6', '5', '7', + '5', '8', '5', '9', '5', 'A', '5', 'B', + '5', 'C', '5', 'D', '5', 'E', '5', 'F', + '6', '0', '6', '1', '6', '2', '6', '3', + '6', '4', '6', '5', '6', '6', '6', '7', + '6', '8', '6', '9', '6', 'A', '6', 'B', + '6', 'C', '6', 'D', '6', 'E', '6', 'F', + '7', '0', '7', '1', '7', '2', '7', '3', + '7', '4', '7', '5', '7', '6', '7', '7', + '7', '8', '7', '9', '7', 'A', '7', 'B', + '7', 'C', '7', 'D', '7', 'E', '7', 'F', + '8', '0', '8', '1', '8', '2', '8', '3', + '8', '4', '8', '5', '8', '6', '8', '7', + '8', '8', '8', '9', '8', 'A', '8', 'B', + '8', 'C', '8', 'D', '8', 'E', '8', 'F', + '9', '0', '9', '1', '9', '2', '9', '3', + '9', '4', '9', '5', '9', '6', '9', '7', + '9', '8', '9', '9', '9', 'A', '9', 'B', + '9', 'C', '9', 'D', '9', 'E', '9', 'F', + 'A', '0', 'A', '1', 'A', '2', 'A', '3', + 'A', '4', 'A', '5', 'A', '6', 'A', '7', + 'A', '8', 'A', '9', 'A', 'A', 'A', 'B', + 'A', 'C', 'A', 'D', 'A', 'E', 'A', 'F', + 'B', '0', 'B', '1', 'B', '2', 'B', '3', + 'B', '4', 'B', '5', 'B', '6', 'B', '7', + 'B', '8', 'B', '9', 'B', 'A', 'B', 'B', + 'B', 'C', 'B', 'D', 'B', 'E', 'B', 'F', + 'C', '0', 'C', '1', 'C', '2', 'C', '3', + 'C', '4', 'C', '5', 'C', '6', 'C', '7', + 'C', '8', 'C', '9', 'C', 'A', 'C', 'B', + 'C', 'C', 'C', 'D', 'C', 'E', 'C', 'F', + 'D', '0', 'D', '1', 'D', '2', 'D', '3', + 'D', '4', 'D', '5', 'D', '6', 'D', '7', + 'D', '8', 'D', '9', 'D', 'A', 'D', 'B', + 'D', 'C', 'D', 'D', 'D', 'E', 'D', 'F', + 'E', '0', 'E', '1', 'E', '2', 'E', '3', + 'E', '4', 'E', '5', 'E', '6', 'E', '7', + 'E', '8', 'E', '9', 'E', 'A', 'E', 'B', + 'E', 'C', 'E', 'D', 'E', 'E', 'E', 'F', + 'F', '0', 'F', '1', 'F', '2', 'F', '3', + 'F', '4', 'F', '5', 'F', '6', 'F', '7', + 'F', '8', 'F', '9', 'F', 'A', 'F', 'B', + 'F', 'C', 'F', 'D', 'F', 'E', 'F', 'F' +}; + +/** Escaped single character table. (generate with misc/make_tables.c) */ +yyjson_align(2) +static const u8 esc_single_char_table[512] = { + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + '\\', 'b', '\\', 't', '\\', 'n', ' ', ' ', + '\\', 'f', '\\', 'r', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', '\\', '"', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', '\\', '/', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + '\\', '\\', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' +}; + +/** Returns the encode table with options. */ +static_inline const char_enc_type *get_enc_table_with_flag( + yyjson_write_flag flg) { + if (has_flg(ESCAPE_UNICODE)) { + if (has_flg(ESCAPE_SLASHES)) { + return enc_table_esc_slash; + } else { + return enc_table_esc; + } + } else { + if (has_flg(ESCAPE_SLASHES)) { + return enc_table_cpy_slash; + } else { + return enc_table_cpy; + } + } +} + +/** Write raw string. */ +static_inline u8 *write_raw(u8 *cur, const u8 *raw, usize raw_len) { + memcpy(cur, raw, raw_len); + return cur + raw_len; +} + +/** + Write string no-escape. + @param cur Buffer cursor. + @param str A UTF-8 string, null-terminator is not required. + @param str_len Length of string in bytes. + @return The buffer cursor after string. + */ +static_inline u8 *write_str_noesc(u8 *cur, const u8 *str, usize str_len) { + *cur++ = '"'; + while (str_len >= 16) { + byte_copy_16(cur, str); + cur += 16; + str += 16; + str_len -= 16; + } + while (str_len >= 4) { + byte_copy_4(cur, str); + cur += 4; + str += 4; + str_len -= 4; + } + while (str_len) { + *cur++ = *str++; + str_len -= 1; + } + *cur++ = '"'; + return cur; +} + +/** + Write UTF-8 string (requires len * 6 + 2 bytes buffer). + @param cur Buffer cursor. + @param esc Escape unicode. + @param inv Allow invalid unicode. + @param str A UTF-8 string, null-terminator is not required. + @param str_len Length of string in bytes. + @param enc_table Encode type table for character. + @return The buffer cursor after string, or NULL on invalid unicode. + */ +static_inline u8 *write_str(u8 *cur, bool esc, bool inv, + const u8 *str, usize str_len, + const char_enc_type *enc_table) { + /* The replacement character U+FFFD, used to indicate invalid character. */ + const v32 rep = {{ 'F', 'F', 'F', 'D' }}; + const v32 pre = {{ '\\', 'u', '0', '0' }}; + + const u8 *src = str; + const u8 *end = str + str_len; + *cur++ = '"'; + +copy_ascii: + /* + Copy continuous ASCII, loop unrolling, same as the following code: + + while (end > src) ( + if (unlikely(enc_table[*src])) break; + *cur++ = *src++; + ); + */ +#define expr_jump(i) \ + if (unlikely(enc_table[src[i]])) goto stop_char_##i; + +#define expr_stop(i) \ + stop_char_##i: \ + memcpy(cur, src, i); \ + cur += i; src += i; goto copy_utf8; + + while (end - src >= 16) { + repeat16_incr(expr_jump) + byte_copy_16(cur, src); + cur += 16; src += 16; + } + + while (end - src >= 4) { + repeat4_incr(expr_jump) + byte_copy_4(cur, src); + cur += 4; src += 4; + } + + while (end > src) { + expr_jump(0) + *cur++ = *src++; + } + + *cur++ = '"'; + return cur; + + repeat16_incr(expr_stop) + +#undef expr_jump +#undef expr_stop + +copy_utf8: + if (unlikely(src + 4 > end)) { + if (end == src) goto copy_end; + if (end - src < enc_table[*src] / 2) goto err_one; + } + switch (enc_table[*src]) { + case CHAR_ENC_CPY_1: { + *cur++ = *src++; + goto copy_ascii; + } + case CHAR_ENC_CPY_2: { +#if YYJSON_DISABLE_UTF8_VALIDATION + byte_copy_2(cur, src); +#else + u32 uni = 0; + byte_copy_2(&uni, src); + if (unlikely(!is_utf8_seq2(uni))) goto err_cpy; + byte_copy_2(cur, &uni); +#endif + cur += 2; + src += 2; + goto copy_utf8; + } + case CHAR_ENC_CPY_3: { +#if YYJSON_DISABLE_UTF8_VALIDATION + if (likely(src + 4 <= end)) { + byte_copy_4(cur, src); + } else { + byte_copy_2(cur, src); + cur[2] = src[2]; + } +#else + u32 uni, tmp; + if (likely(src + 4 <= end)) { + uni = byte_load_4(src); + if (unlikely(!is_utf8_seq3(uni))) goto err_cpy; + byte_copy_4(cur, src); + } else { + uni = byte_load_3(src); + if (unlikely(!is_utf8_seq3(uni))) goto err_cpy; + byte_copy_4(cur, &uni); + } +#endif + cur += 3; + src += 3; + goto copy_utf8; + } + case CHAR_ENC_CPY_4: { +#if YYJSON_DISABLE_UTF8_VALIDATION + byte_copy_4(cur, src); +#else + u32 uni, tmp; + uni = byte_load_4(src); + if (unlikely(!is_utf8_seq4(uni))) goto err_cpy; + byte_copy_4(cur, src); +#endif + cur += 4; + src += 4; + goto copy_utf8; + } + case CHAR_ENC_ESC_A: { + byte_copy_2(cur, &esc_single_char_table[*src * 2]); + cur += 2; + src += 1; + goto copy_utf8; + } + case CHAR_ENC_ESC_1: { + byte_copy_4(cur + 0, &pre); + byte_copy_2(cur + 4, &esc_hex_char_table[*src * 2]); + cur += 6; + src += 1; + goto copy_utf8; + } + case CHAR_ENC_ESC_2: { + u16 u; +#if !YYJSON_DISABLE_UTF8_VALIDATION + u32 v4 = 0; + u16 v2 = byte_load_2(src); + byte_copy_2(&v4, &v2); + if (unlikely(!is_utf8_seq2(v4))) goto err_esc; +#endif + u = (u16)(((u16)(src[0] & 0x1F) << 6) | + ((u16)(src[1] & 0x3F) << 0)); + byte_copy_2(cur + 0, &pre); + byte_copy_2(cur + 2, &esc_hex_char_table[(u >> 8) * 2]); + byte_copy_2(cur + 4, &esc_hex_char_table[(u & 0xFF) * 2]); + cur += 6; + src += 2; + goto copy_utf8; + } + case CHAR_ENC_ESC_3: { + u16 u; + u32 v, tmp; +#if !YYJSON_DISABLE_UTF8_VALIDATION + v = byte_load_3(src); + if (unlikely(!is_utf8_seq3(v))) goto err_esc; +#endif + u = (u16)(((u16)(src[0] & 0x0F) << 12) | + ((u16)(src[1] & 0x3F) << 6) | + ((u16)(src[2] & 0x3F) << 0)); + byte_copy_2(cur + 0, &pre); + byte_copy_2(cur + 2, &esc_hex_char_table[(u >> 8) * 2]); + byte_copy_2(cur + 4, &esc_hex_char_table[(u & 0xFF) * 2]); + cur += 6; + src += 3; + goto copy_utf8; + } + case CHAR_ENC_ESC_4: { + u32 hi, lo, u, v, tmp; +#if !YYJSON_DISABLE_UTF8_VALIDATION + v = byte_load_4(src); + if (unlikely(!is_utf8_seq4(v))) goto err_esc; +#endif + u = ((u32)(src[0] & 0x07) << 18) | + ((u32)(src[1] & 0x3F) << 12) | + ((u32)(src[2] & 0x3F) << 6) | + ((u32)(src[3] & 0x3F) << 0); + u -= 0x10000; + hi = (u >> 10) + 0xD800; + lo = (u & 0x3FF) + 0xDC00; + byte_copy_2(cur + 0, &pre); + byte_copy_2(cur + 2, &esc_hex_char_table[(hi >> 8) * 2]); + byte_copy_2(cur + 4, &esc_hex_char_table[(hi & 0xFF) * 2]); + byte_copy_2(cur + 6, &pre); + byte_copy_2(cur + 8, &esc_hex_char_table[(lo >> 8) * 2]); + byte_copy_2(cur + 10, &esc_hex_char_table[(lo & 0xFF) * 2]); + cur += 12; + src += 4; + goto copy_utf8; + } + case CHAR_ENC_ERR_1: { + goto err_one; + } + default: break; /* unreachable */ + } + +copy_end: + *cur++ = '"'; + return cur; + +err_one: + if (esc) goto err_esc; + else goto err_cpy; + +err_cpy: + if (!inv) return NULL; + *cur++ = *src++; + goto copy_utf8; + +err_esc: + if (!inv) return NULL; + byte_copy_2(cur + 0, &pre); + byte_copy_4(cur + 2, &rep); + cur += 6; + src += 1; + goto copy_utf8; +} + + + +/*============================================================================== + * MARK: - JSON Writer Utilities (Private) + *============================================================================*/ + +/** Write null (requires 8 bytes buffer). */ +static_inline u8 *write_null(u8 *cur) { + v64 v = {{ 'n', 'u', 'l', 'l', ',', '\n', 0, 0 }}; + byte_copy_8(cur, &v); + return cur + 4; +} + +/** Write bool (requires 8 bytes buffer). */ +static_inline u8 *write_bool(u8 *cur, bool val) { + v64 v0 = {{ 'f', 'a', 'l', 's', 'e', ',', '\n', 0 }}; + v64 v1 = {{ 't', 'r', 'u', 'e', ',', '\n', 0, 0 }}; + if (val) { + byte_copy_8(cur, &v1); + } else { + byte_copy_8(cur, &v0); + } + return cur + 5 - val; +} + +/** Write indent (requires level x 4 bytes buffer). + Param spaces should not larger than 4. */ +static_inline u8 *write_indent(u8 *cur, usize level, usize spaces) { + while (level-- > 0) { + byte_copy_4(cur, " "); + cur += spaces; + } + return cur; +} + +/** Write data to file pointer. */ +static bool write_dat_to_fp(FILE *fp, u8 *dat, usize len, + yyjson_write_err *err) { + if (fwrite(dat, len, 1, fp) != 1) { + err->msg = "file writing failed"; + err->code = YYJSON_WRITE_ERROR_FILE_WRITE; + return false; + } + return true; +} + +/** Write data to file. */ +static bool write_dat_to_file(const char *path, u8 *dat, usize len, + yyjson_write_err *err) { +#define return_err(_code, _msg) do { \ + err->msg = _msg; \ + err->code = YYJSON_WRITE_ERROR_##_code; \ + if (file) fclose(file); \ + return false; \ +} while (false) + + FILE *file = fopen_writeonly(path); + if (file == NULL) { + return_err(FILE_OPEN, MSG_FOPEN); + } + if (fwrite(dat, len, 1, file) != 1) { + return_err(FILE_WRITE, MSG_FWRITE); + } + if (fclose(file) != 0) { + file = NULL; + return_err(FILE_WRITE, MSG_FCLOSE); + } + return true; + +#undef return_err +} + + + +/*============================================================================== + * MARK: - JSON Writer Implementation (Private) + *============================================================================*/ + +typedef struct yyjson_write_ctx { + usize tag; +} yyjson_write_ctx; + +static_inline void yyjson_write_ctx_set(yyjson_write_ctx *ctx, + usize size, bool is_obj) { + ctx->tag = (size << 1) | (usize)is_obj; +} + +static_inline void yyjson_write_ctx_get(yyjson_write_ctx *ctx, + usize *size, bool *is_obj) { + usize tag = ctx->tag; + *size = tag >> 1; + *is_obj = (bool)(tag & 1); +} + +/** Write single JSON value. */ +static_inline u8 *yyjson_write_single(yyjson_val *val, + yyjson_write_flag flg, + yyjson_alc alc, + usize *dat_len, + yyjson_write_err *err) { +#define return_err(_code, _msg) do { \ + if (hdr) alc.free(alc.ctx, (void *)hdr); \ + *dat_len = 0; \ + err->code = YYJSON_WRITE_ERROR_##_code; \ + err->msg = _msg; \ + return NULL; \ +} while (false) + +#define incr_len(_len) do { \ + hdr = (u8 *)alc.malloc(alc.ctx, _len); \ + if (!hdr) goto fail_alloc; \ + cur = hdr; \ +} while (false) + +#define check_str_len(_len) do { \ + if ((sizeof(usize) < 8) && (_len >= (USIZE_MAX - 16) / 6)) \ + goto fail_alloc; \ +} while (false) + + u8 *hdr = NULL, *cur; + usize str_len; + const u8 *str_ptr; + const char_enc_type *enc_table = get_enc_table_with_flag(flg); + bool cpy = (enc_table == enc_table_cpy); + bool esc = has_flg(ESCAPE_UNICODE) != 0; + bool inv = has_allow(INVALID_UNICODE) != 0; + bool newline = has_flg(NEWLINE_AT_END) != 0; + const usize end_len = 2; /* '\n' and '\0' */ + + switch (unsafe_yyjson_get_type(val)) { + case YYJSON_TYPE_RAW: + str_len = unsafe_yyjson_get_len(val); + str_ptr = (const u8 *)unsafe_yyjson_get_str(val); + check_str_len(str_len); + incr_len(str_len + end_len); + cur = write_raw(cur, str_ptr, str_len); + break; + + case YYJSON_TYPE_STR: + str_len = unsafe_yyjson_get_len(val); + str_ptr = (const u8 *)unsafe_yyjson_get_str(val); + check_str_len(str_len); + incr_len(str_len * 6 + 2 + end_len); + if (likely(cpy) && unsafe_yyjson_get_subtype(val)) { + cur = write_str_noesc(cur, str_ptr, str_len); + } else { + cur = write_str(cur, esc, inv, str_ptr, str_len, enc_table); + if (unlikely(!cur)) goto fail_str; + } + break; + + case YYJSON_TYPE_NUM: + incr_len(FP_BUF_LEN + end_len); + cur = write_num(cur, val, flg); + if (unlikely(!cur)) goto fail_num; + break; + + case YYJSON_TYPE_BOOL: + incr_len(8); + cur = write_bool(cur, unsafe_yyjson_get_bool(val)); + break; + + case YYJSON_TYPE_NULL: + incr_len(8); + cur = write_null(cur); + break; + + case YYJSON_TYPE_ARR: + incr_len(2 + end_len); + byte_copy_2(cur, "[]"); + cur += 2; + break; + + case YYJSON_TYPE_OBJ: + incr_len(2 + end_len); + byte_copy_2(cur, "{}"); + cur += 2; + break; + + default: + goto fail_type; + } + + if (newline) *cur++ = '\n'; + *cur = '\0'; + *dat_len = (usize)(cur - hdr); + memset(err, 0, sizeof(yyjson_write_err)); + return hdr; + +fail_alloc: return_err(MEMORY_ALLOCATION, MSG_MALLOC); +fail_type: return_err(INVALID_VALUE_TYPE, MSG_ERR_TYPE); +fail_num: return_err(NAN_OR_INF, MSG_NAN_INF); +fail_str: return_err(INVALID_STRING, MSG_ERR_UTF8); + +#undef return_err +#undef check_str_len +#undef incr_len +} + +/** Write JSON document minify. + The root of this document should be a non-empty container. */ +static_inline u8 *yyjson_write_minify(const yyjson_val *root, + const yyjson_write_flag flg, + const yyjson_alc alc, + usize *dat_len, + yyjson_write_err *err) { +#define return_err(_code, _msg) do { \ + *dat_len = 0; \ + err->code = YYJSON_WRITE_ERROR_##_code; \ + err->msg = _msg; \ + if (hdr) alc.free(alc.ctx, hdr); \ + return NULL; \ +} while (false) + +#define incr_len(_len) do { \ + ext_len = (usize)(_len); \ + if (unlikely((u8 *)(cur + ext_len) >= (u8 *)ctx)) { \ + usize ctx_pos = (usize)((u8 *)ctx - hdr); \ + usize cur_pos = (usize)(cur - hdr); \ + ctx_len = (usize)(end - (u8 *)ctx); \ + alc_inc = yyjson_max(alc_len / 2, ext_len); \ + alc_inc = size_align_up(alc_inc, sizeof(yyjson_write_ctx)); \ + if ((sizeof(usize) < 8) && size_add_is_overflow(alc_len, alc_inc)) \ + goto fail_alloc; \ + alc_len += alc_inc; \ + tmp = (u8 *)alc.realloc(alc.ctx, hdr, alc_len - alc_inc, alc_len); \ + if (unlikely(!tmp)) goto fail_alloc; \ + ctx_tmp = (yyjson_write_ctx *)(void *)(tmp + (alc_len - ctx_len)); \ + memmove((void *)ctx_tmp, (void *)(tmp + ctx_pos), ctx_len); \ + ctx = ctx_tmp; \ + cur = tmp + cur_pos; \ + end = tmp + alc_len; \ + hdr = tmp; \ + } \ +} while (false) + +#define check_str_len(_len) do { \ + if ((sizeof(usize) < 8) && (_len >= (USIZE_MAX - 16) / 6)) \ + goto fail_alloc; \ +} while (false) + + yyjson_val *val; + yyjson_type val_type; + usize ctn_len, ctn_len_tmp; + bool ctn_obj, ctn_obj_tmp, is_key; + u8 *hdr, *cur, *end, *tmp; + yyjson_write_ctx *ctx, *ctx_tmp; + usize alc_len, alc_inc, ctx_len, ext_len, str_len; + const u8 *str_ptr; + const char_enc_type *enc_table = get_enc_table_with_flag(flg); + bool cpy = (enc_table == enc_table_cpy); + bool esc = has_flg(ESCAPE_UNICODE) != 0; + bool inv = has_allow(INVALID_UNICODE) != 0; + bool newline = has_flg(NEWLINE_AT_END) != 0; + + alc_len = root->uni.ofs / sizeof(yyjson_val); + alc_len = alc_len * YYJSON_WRITER_ESTIMATED_MINIFY_RATIO + 64; + alc_len = size_align_up(alc_len, sizeof(yyjson_write_ctx)); + hdr = (u8 *)alc.malloc(alc.ctx, alc_len); + if (!hdr) goto fail_alloc; + cur = hdr; + end = hdr + alc_len; + ctx = (yyjson_write_ctx *)(void *)end; + +doc_begin: + val = constcast(yyjson_val *)root; + val_type = unsafe_yyjson_get_type(val); + ctn_obj = (val_type == YYJSON_TYPE_OBJ); + ctn_len = unsafe_yyjson_get_len(val) << (u8)ctn_obj; + *cur++ = (u8)('[' | ((u8)ctn_obj << 5)); + val++; + +val_begin: + val_type = unsafe_yyjson_get_type(val); + if (val_type == YYJSON_TYPE_STR) { + is_key = ((u8)ctn_obj & (u8)~ctn_len); + str_len = unsafe_yyjson_get_len(val); + str_ptr = (const u8 *)unsafe_yyjson_get_str(val); + check_str_len(str_len); + incr_len(str_len * 6 + 16); + if (likely(cpy) && unsafe_yyjson_get_subtype(val)) { + cur = write_str_noesc(cur, str_ptr, str_len); + } else { + cur = write_str(cur, esc, inv, str_ptr, str_len, enc_table); + if (unlikely(!cur)) goto fail_str; + } + *cur++ = is_key ? ':' : ','; + goto val_end; + } + if (val_type == YYJSON_TYPE_NUM) { + incr_len(FP_BUF_LEN); + cur = write_num(cur, val, flg); + if (unlikely(!cur)) goto fail_num; + *cur++ = ','; + goto val_end; + } + if ((val_type & (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) == + (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) { + ctn_len_tmp = unsafe_yyjson_get_len(val); + ctn_obj_tmp = (val_type == YYJSON_TYPE_OBJ); + incr_len(16); + if (unlikely(ctn_len_tmp == 0)) { + /* write empty container */ + *cur++ = (u8)('[' | ((u8)ctn_obj_tmp << 5)); + *cur++ = (u8)(']' | ((u8)ctn_obj_tmp << 5)); + *cur++ = ','; + goto val_end; + } else { + /* push context, setup new container */ + yyjson_write_ctx_set(--ctx, ctn_len, ctn_obj); + ctn_len = ctn_len_tmp << (u8)ctn_obj_tmp; + ctn_obj = ctn_obj_tmp; + *cur++ = (u8)('[' | ((u8)ctn_obj << 5)); + val++; + goto val_begin; + } + } + if (val_type == YYJSON_TYPE_BOOL) { + incr_len(16); + cur = write_bool(cur, unsafe_yyjson_get_bool(val)); + cur++; + goto val_end; + } + if (val_type == YYJSON_TYPE_NULL) { + incr_len(16); + cur = write_null(cur); + cur++; + goto val_end; + } + if (val_type == YYJSON_TYPE_RAW) { + str_len = unsafe_yyjson_get_len(val); + str_ptr = (const u8 *)unsafe_yyjson_get_str(val); + check_str_len(str_len); + incr_len(str_len + 2); + cur = write_raw(cur, str_ptr, str_len); + *cur++ = ','; + goto val_end; + } + goto fail_type; + +val_end: + val++; + ctn_len--; + if (unlikely(ctn_len == 0)) goto ctn_end; + goto val_begin; + +ctn_end: + cur--; + *cur++ = (u8)(']' | ((u8)ctn_obj << 5)); + *cur++ = ','; + if (unlikely((u8 *)ctx >= end)) goto doc_end; + yyjson_write_ctx_get(ctx++, &ctn_len, &ctn_obj); + ctn_len--; + if (likely(ctn_len > 0)) { + goto val_begin; + } else { + goto ctn_end; + } + +doc_end: + if (newline) { + incr_len(2); + *(cur - 1) = '\n'; + cur++; + } + *--cur = '\0'; + *dat_len = (usize)(cur - hdr); + memset(err, 0, sizeof(yyjson_write_err)); + return hdr; + +fail_alloc: return_err(MEMORY_ALLOCATION, MSG_MALLOC); +fail_type: return_err(INVALID_VALUE_TYPE, MSG_ERR_TYPE); +fail_num: return_err(NAN_OR_INF, MSG_NAN_INF); +fail_str: return_err(INVALID_STRING, MSG_ERR_UTF8); + +#undef return_err +#undef incr_len +#undef check_str_len +} + +/** Write JSON document pretty. + The root of this document should be a non-empty container. */ +static_inline u8 *yyjson_write_pretty(const yyjson_val *root, + const yyjson_write_flag flg, + const yyjson_alc alc, + usize *dat_len, + yyjson_write_err *err) { +#define return_err(_code, _msg) do { \ + *dat_len = 0; \ + err->code = YYJSON_WRITE_ERROR_##_code; \ + err->msg = _msg; \ + if (hdr) alc.free(alc.ctx, hdr); \ + return NULL; \ +} while (false) + +#define incr_len(_len) do { \ + ext_len = (usize)(_len); \ + if (unlikely((u8 *)(cur + ext_len) >= (u8 *)ctx)) { \ + usize ctx_pos = (usize)((u8 *)ctx - hdr); \ + usize cur_pos = (usize)(cur - hdr); \ + ctx_len = (usize)(end - (u8 *)ctx); \ + alc_inc = yyjson_max(alc_len / 2, ext_len); \ + alc_inc = size_align_up(alc_inc, sizeof(yyjson_write_ctx)); \ + if ((sizeof(usize) < 8) && size_add_is_overflow(alc_len, alc_inc)) \ + goto fail_alloc; \ + alc_len += alc_inc; \ + tmp = (u8 *)alc.realloc(alc.ctx, hdr, alc_len - alc_inc, alc_len); \ + if (unlikely(!tmp)) goto fail_alloc; \ + ctx_tmp = (yyjson_write_ctx *)(void *)(tmp + (alc_len - ctx_len)); \ + memmove((void *)ctx_tmp, (void *)(tmp + ctx_pos), ctx_len); \ + ctx = ctx_tmp; \ + cur = tmp + cur_pos; \ + end = tmp + alc_len; \ + hdr = tmp; \ + } \ +} while (false) + +#define check_str_len(_len) do { \ + if ((sizeof(usize) < 8) && (_len >= (USIZE_MAX - 16) / 6)) \ + goto fail_alloc; \ +} while (false) + + yyjson_val *val; + yyjson_type val_type; + usize ctn_len, ctn_len_tmp; + bool ctn_obj, ctn_obj_tmp, is_key, no_indent; + u8 *hdr, *cur, *end, *tmp; + yyjson_write_ctx *ctx, *ctx_tmp; + usize alc_len, alc_inc, ctx_len, ext_len, str_len, level; + const u8 *str_ptr; + const char_enc_type *enc_table = get_enc_table_with_flag(flg); + bool cpy = (enc_table == enc_table_cpy); + bool esc = has_flg(ESCAPE_UNICODE) != 0; + bool inv = has_allow(INVALID_UNICODE) != 0; + usize spaces = has_flg(PRETTY_TWO_SPACES) ? 2 : 4; + bool newline = has_flg(NEWLINE_AT_END) != 0; + + alc_len = root->uni.ofs / sizeof(yyjson_val); + alc_len = alc_len * YYJSON_WRITER_ESTIMATED_PRETTY_RATIO + 64; + alc_len = size_align_up(alc_len, sizeof(yyjson_write_ctx)); + hdr = (u8 *)alc.malloc(alc.ctx, alc_len); + if (!hdr) goto fail_alloc; + cur = hdr; + end = hdr + alc_len; + ctx = (yyjson_write_ctx *)(void *)end; + +doc_begin: + val = constcast(yyjson_val *)root; + val_type = unsafe_yyjson_get_type(val); + ctn_obj = (val_type == YYJSON_TYPE_OBJ); + ctn_len = unsafe_yyjson_get_len(val) << (u8)ctn_obj; + *cur++ = (u8)('[' | ((u8)ctn_obj << 5)); + *cur++ = '\n'; + val++; + level = 1; + +val_begin: + val_type = unsafe_yyjson_get_type(val); + if (val_type == YYJSON_TYPE_STR) { + is_key = (bool)((u8)ctn_obj & (u8)~ctn_len); + no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); + str_len = unsafe_yyjson_get_len(val); + str_ptr = (const u8 *)unsafe_yyjson_get_str(val); + check_str_len(str_len); + incr_len(str_len * 6 + 16 + (no_indent ? 0 : level * 4)); + cur = write_indent(cur, no_indent ? 0 : level, spaces); + if (likely(cpy) && unsafe_yyjson_get_subtype(val)) { + cur = write_str_noesc(cur, str_ptr, str_len); + } else { + cur = write_str(cur, esc, inv, str_ptr, str_len, enc_table); + if (unlikely(!cur)) goto fail_str; + } + *cur++ = is_key ? ':' : ','; + *cur++ = is_key ? ' ' : '\n'; + goto val_end; + } + if (val_type == YYJSON_TYPE_NUM) { + no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); + incr_len(FP_BUF_LEN + (no_indent ? 0 : level * 4)); + cur = write_indent(cur, no_indent ? 0 : level, spaces); + cur = write_num(cur, val, flg); + if (unlikely(!cur)) goto fail_num; + *cur++ = ','; + *cur++ = '\n'; + goto val_end; + } + if ((val_type & (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) == + (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) { + no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); + ctn_len_tmp = unsafe_yyjson_get_len(val); + ctn_obj_tmp = (val_type == YYJSON_TYPE_OBJ); + if (unlikely(ctn_len_tmp == 0)) { + /* write empty container */ + incr_len(16 + (no_indent ? 0 : level * 4)); + cur = write_indent(cur, no_indent ? 0 : level, spaces); + *cur++ = (u8)('[' | ((u8)ctn_obj_tmp << 5)); + *cur++ = (u8)(']' | ((u8)ctn_obj_tmp << 5)); + *cur++ = ','; + *cur++ = '\n'; + goto val_end; + } else { + /* push context, setup new container */ + incr_len(32 + (no_indent ? 0 : level * 4)); + yyjson_write_ctx_set(--ctx, ctn_len, ctn_obj); + ctn_len = ctn_len_tmp << (u8)ctn_obj_tmp; + ctn_obj = ctn_obj_tmp; + cur = write_indent(cur, no_indent ? 0 : level, spaces); + level++; + *cur++ = (u8)('[' | ((u8)ctn_obj << 5)); + *cur++ = '\n'; + val++; + goto val_begin; + } + } + if (val_type == YYJSON_TYPE_BOOL) { + no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); + incr_len(16 + (no_indent ? 0 : level * 4)); + cur = write_indent(cur, no_indent ? 0 : level, spaces); + cur = write_bool(cur, unsafe_yyjson_get_bool(val)); + cur += 2; + goto val_end; + } + if (val_type == YYJSON_TYPE_NULL) { + no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); + incr_len(16 + (no_indent ? 0 : level * 4)); + cur = write_indent(cur, no_indent ? 0 : level, spaces); + cur = write_null(cur); + cur += 2; + goto val_end; + } + if (val_type == YYJSON_TYPE_RAW) { + no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); + str_len = unsafe_yyjson_get_len(val); + str_ptr = (const u8 *)unsafe_yyjson_get_str(val); + check_str_len(str_len); + incr_len(str_len + 3 + (no_indent ? 0 : level * 4)); + cur = write_indent(cur, no_indent ? 0 : level, spaces); + cur = write_raw(cur, str_ptr, str_len); + *cur++ = ','; + *cur++ = '\n'; + goto val_end; + } + goto fail_type; + +val_end: + val++; + ctn_len--; + if (unlikely(ctn_len == 0)) goto ctn_end; + goto val_begin; + +ctn_end: + cur -= 2; + *cur++ = '\n'; + incr_len(level * 4); + cur = write_indent(cur, --level, spaces); + *cur++ = (u8)(']' | ((u8)ctn_obj << 5)); + if (unlikely((u8 *)ctx >= end)) goto doc_end; + yyjson_write_ctx_get(ctx++, &ctn_len, &ctn_obj); + ctn_len--; + *cur++ = ','; + *cur++ = '\n'; + if (likely(ctn_len > 0)) { + goto val_begin; + } else { + goto ctn_end; + } + +doc_end: + if (newline) { + incr_len(2); + *cur++ = '\n'; + } + *cur = '\0'; + *dat_len = (usize)(cur - hdr); + memset(err, 0, sizeof(yyjson_write_err)); + return hdr; + +fail_alloc: return_err(MEMORY_ALLOCATION, MSG_MALLOC); +fail_type: return_err(INVALID_VALUE_TYPE, MSG_ERR_TYPE); +fail_num: return_err(NAN_OR_INF, MSG_NAN_INF); +fail_str: return_err(INVALID_STRING, MSG_ERR_UTF8); + +#undef return_err +#undef incr_len +#undef check_str_len +} + + + +/*============================================================================== + * MARK: - JSON Writer (Public) + *============================================================================*/ + +char *yyjson_val_write_opts(const yyjson_val *val, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + usize *dat_len, + yyjson_write_err *err) { + yyjson_write_err tmp_err; + usize tmp_dat_len; + yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC; + yyjson_val *root = constcast(yyjson_val *)val; + + if (!err) err = &tmp_err; + if (!dat_len) dat_len = &tmp_dat_len; + + if (unlikely(!root)) { + *dat_len = 0; + err->msg = "input JSON is NULL"; + err->code = YYJSON_READ_ERROR_INVALID_PARAMETER; + return NULL; + } + + if (!unsafe_yyjson_is_ctn(root) || unsafe_yyjson_get_len(root) == 0) { + return (char *)yyjson_write_single(root, flg, alc, dat_len, err); + } else if (flg & (YYJSON_WRITE_PRETTY | YYJSON_WRITE_PRETTY_TWO_SPACES)) { + return (char *)yyjson_write_pretty(root, flg, alc, dat_len, err); + } else { + return (char *)yyjson_write_minify(root, flg, alc, dat_len, err); + } +} + +char *yyjson_write_opts(const yyjson_doc *doc, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + usize *dat_len, + yyjson_write_err *err) { + yyjson_val *root = doc ? doc->root : NULL; + return yyjson_val_write_opts(root, flg, alc_ptr, dat_len, err); +} + +bool yyjson_val_write_file(const char *path, + const yyjson_val *val, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + yyjson_write_err *err) { + yyjson_write_err tmp_err; + yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC; + u8 *dat; + usize dat_len = 0; + yyjson_val *root = constcast(yyjson_val *)val; + bool suc; + + if (!err) err = &tmp_err; + if (unlikely(!path || !*path)) { + err->msg = "input path is invalid"; + err->code = YYJSON_READ_ERROR_INVALID_PARAMETER; + return false; + } + + dat = (u8 *)yyjson_val_write_opts(root, flg, &alc, &dat_len, err); + if (unlikely(!dat)) return false; + suc = write_dat_to_file(path, dat, dat_len, err); + alc.free(alc.ctx, dat); + return suc; +} + +bool yyjson_val_write_fp(FILE *fp, + const yyjson_val *val, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + yyjson_write_err *err) { + yyjson_write_err tmp_err; + yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC; + u8 *dat; + usize dat_len = 0; + yyjson_val *root = constcast(yyjson_val *)val; + bool suc; + + if (!err) err = &tmp_err; + if (unlikely(!fp)) { + err->msg = "input fp is invalid"; + err->code = YYJSON_READ_ERROR_INVALID_PARAMETER; + return false; + } + + dat = (u8 *)yyjson_val_write_opts(root, flg, &alc, &dat_len, err); + if (unlikely(!dat)) return false; + suc = write_dat_to_fp(fp, dat, dat_len, err); + alc.free(alc.ctx, dat); + return suc; +} + +bool yyjson_write_file(const char *path, + const yyjson_doc *doc, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + yyjson_write_err *err) { + yyjson_val *root = doc ? doc->root : NULL; + return yyjson_val_write_file(path, root, flg, alc_ptr, err); +} + +bool yyjson_write_fp(FILE *fp, + const yyjson_doc *doc, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + yyjson_write_err *err) { + yyjson_val *root = doc ? doc->root : NULL; + return yyjson_val_write_fp(fp, root, flg, alc_ptr, err); +} + + + +/*============================================================================== + * MARK: - Mutable JSON Writer Implementation (Private) + *============================================================================*/ + +typedef struct yyjson_mut_write_ctx { + usize tag; + yyjson_mut_val *ctn; +} yyjson_mut_write_ctx; + +static_inline void yyjson_mut_write_ctx_set(yyjson_mut_write_ctx *ctx, + yyjson_mut_val *ctn, + usize size, bool is_obj) { + ctx->tag = (size << 1) | (usize)is_obj; + ctx->ctn = ctn; +} + +static_inline void yyjson_mut_write_ctx_get(yyjson_mut_write_ctx *ctx, + yyjson_mut_val **ctn, + usize *size, bool *is_obj) { + usize tag = ctx->tag; + *size = tag >> 1; + *is_obj = (bool)(tag & 1); + *ctn = ctx->ctn; +} + +/** Get the estimated number of values for the mutable JSON document. */ +static_inline usize yyjson_mut_doc_estimated_val_num( + const yyjson_mut_doc *doc) { + usize sum = 0; + yyjson_val_chunk *chunk = doc->val_pool.chunks; + while (chunk) { + sum += chunk->chunk_size / sizeof(yyjson_mut_val) - 1; + if (chunk == doc->val_pool.chunks) { + sum -= (usize)(doc->val_pool.end - doc->val_pool.cur); + } + chunk = chunk->next; + } + return sum; +} + +/** Write single JSON value. */ +static_inline u8 *yyjson_mut_write_single(yyjson_mut_val *val, + yyjson_write_flag flg, + yyjson_alc alc, + usize *dat_len, + yyjson_write_err *err) { + return yyjson_write_single((yyjson_val *)val, flg, alc, dat_len, err); +} + +/** Write JSON document minify. + The root of this document should be a non-empty container. */ +static_inline u8 *yyjson_mut_write_minify(const yyjson_mut_val *root, + usize estimated_val_num, + yyjson_write_flag flg, + yyjson_alc alc, + usize *dat_len, + yyjson_write_err *err) { +#define return_err(_code, _msg) do { \ + *dat_len = 0; \ + err->code = YYJSON_WRITE_ERROR_##_code; \ + err->msg = _msg; \ + if (hdr) alc.free(alc.ctx, hdr); \ + return NULL; \ +} while (false) + +#define incr_len(_len) do { \ + ext_len = (usize)(_len); \ + if (unlikely((u8 *)(cur + ext_len) >= (u8 *)ctx)) { \ + usize ctx_pos = (usize)((u8 *)ctx - hdr); \ + usize cur_pos = (usize)(cur - hdr); \ + ctx_len = (usize)(end - (u8 *)ctx); \ + alc_inc = yyjson_max(alc_len / 2, ext_len); \ + alc_inc = size_align_up(alc_inc, sizeof(yyjson_mut_write_ctx)); \ + if ((sizeof(usize) < 8) && size_add_is_overflow(alc_len, alc_inc)) \ + goto fail_alloc; \ + alc_len += alc_inc; \ + tmp = (u8 *)alc.realloc(alc.ctx, hdr, alc_len - alc_inc, alc_len); \ + if (unlikely(!tmp)) goto fail_alloc; \ + ctx_tmp = (yyjson_mut_write_ctx *)(void *)(tmp + (alc_len - ctx_len)); \ + memmove((void *)ctx_tmp, (void *)(tmp + ctx_pos), ctx_len); \ + ctx = ctx_tmp; \ + cur = tmp + cur_pos; \ + end = tmp + alc_len; \ + hdr = tmp; \ + } \ +} while (false) + +#define check_str_len(_len) do { \ + if ((sizeof(usize) < 8) && (_len >= (USIZE_MAX - 16) / 6)) \ + goto fail_alloc; \ +} while (false) + + yyjson_mut_val *val, *ctn; + yyjson_type val_type; + usize ctn_len, ctn_len_tmp; + bool ctn_obj, ctn_obj_tmp, is_key; + u8 *hdr, *cur, *end, *tmp; + yyjson_mut_write_ctx *ctx, *ctx_tmp; + usize alc_len, alc_inc, ctx_len, ext_len, str_len; + const u8 *str_ptr; + const char_enc_type *enc_table = get_enc_table_with_flag(flg); + bool cpy = (enc_table == enc_table_cpy); + bool esc = has_flg(ESCAPE_UNICODE) != 0; + bool inv = has_allow(INVALID_UNICODE) != 0; + bool newline = has_flg(NEWLINE_AT_END) != 0; + + alc_len = estimated_val_num * YYJSON_WRITER_ESTIMATED_MINIFY_RATIO + 64; + alc_len = size_align_up(alc_len, sizeof(yyjson_mut_write_ctx)); + hdr = (u8 *)alc.malloc(alc.ctx, alc_len); + if (!hdr) goto fail_alloc; + cur = hdr; + end = hdr + alc_len; + ctx = (yyjson_mut_write_ctx *)(void *)end; + +doc_begin: + val = constcast(yyjson_mut_val *)root; + val_type = unsafe_yyjson_get_type(val); + ctn_obj = (val_type == YYJSON_TYPE_OBJ); + ctn_len = unsafe_yyjson_get_len(val) << (u8)ctn_obj; + *cur++ = (u8)('[' | ((u8)ctn_obj << 5)); + ctn = val; + val = (yyjson_mut_val *)val->uni.ptr; /* tail */ + val = ctn_obj ? val->next->next : val->next; + +val_begin: + val_type = unsafe_yyjson_get_type(val); + if (val_type == YYJSON_TYPE_STR) { + is_key = ((u8)ctn_obj & (u8)~ctn_len); + str_len = unsafe_yyjson_get_len(val); + str_ptr = (const u8 *)unsafe_yyjson_get_str(val); + check_str_len(str_len); + incr_len(str_len * 6 + 16); + if (likely(cpy) && unsafe_yyjson_get_subtype(val)) { + cur = write_str_noesc(cur, str_ptr, str_len); + } else { + cur = write_str(cur, esc, inv, str_ptr, str_len, enc_table); + if (unlikely(!cur)) goto fail_str; + } + *cur++ = is_key ? ':' : ','; + goto val_end; + } + if (val_type == YYJSON_TYPE_NUM) { + incr_len(FP_BUF_LEN); + cur = write_num(cur, (yyjson_val *)val, flg); + if (unlikely(!cur)) goto fail_num; + *cur++ = ','; + goto val_end; + } + if ((val_type & (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) == + (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) { + ctn_len_tmp = unsafe_yyjson_get_len(val); + ctn_obj_tmp = (val_type == YYJSON_TYPE_OBJ); + incr_len(16); + if (unlikely(ctn_len_tmp == 0)) { + /* write empty container */ + *cur++ = (u8)('[' | ((u8)ctn_obj_tmp << 5)); + *cur++ = (u8)(']' | ((u8)ctn_obj_tmp << 5)); + *cur++ = ','; + goto val_end; + } else { + /* push context, setup new container */ + yyjson_mut_write_ctx_set(--ctx, ctn, ctn_len, ctn_obj); + ctn_len = ctn_len_tmp << (u8)ctn_obj_tmp; + ctn_obj = ctn_obj_tmp; + *cur++ = (u8)('[' | ((u8)ctn_obj << 5)); + ctn = val; + val = (yyjson_mut_val *)ctn->uni.ptr; /* tail */ + val = ctn_obj ? val->next->next : val->next; + goto val_begin; + } + } + if (val_type == YYJSON_TYPE_BOOL) { + incr_len(16); + cur = write_bool(cur, unsafe_yyjson_get_bool(val)); + cur++; + goto val_end; + } + if (val_type == YYJSON_TYPE_NULL) { + incr_len(16); + cur = write_null(cur); + cur++; + goto val_end; + } + if (val_type == YYJSON_TYPE_RAW) { + str_len = unsafe_yyjson_get_len(val); + str_ptr = (const u8 *)unsafe_yyjson_get_str(val); + check_str_len(str_len); + incr_len(str_len + 2); + cur = write_raw(cur, str_ptr, str_len); + *cur++ = ','; + goto val_end; + } + goto fail_type; + +val_end: + ctn_len--; + if (unlikely(ctn_len == 0)) goto ctn_end; + val = val->next; + goto val_begin; + +ctn_end: + cur--; + *cur++ = (u8)(']' | ((u8)ctn_obj << 5)); + *cur++ = ','; + if (unlikely((u8 *)ctx >= end)) goto doc_end; + val = ctn->next; + yyjson_mut_write_ctx_get(ctx++, &ctn, &ctn_len, &ctn_obj); + ctn_len--; + if (likely(ctn_len > 0)) { + goto val_begin; + } else { + goto ctn_end; + } + +doc_end: + if (newline) { + incr_len(2); + *(cur - 1) = '\n'; + cur++; + } + *--cur = '\0'; + *dat_len = (usize)(cur - hdr); + err->code = YYJSON_WRITE_SUCCESS; + err->msg = NULL; + return hdr; + +fail_alloc: return_err(MEMORY_ALLOCATION, MSG_MALLOC); +fail_type: return_err(INVALID_VALUE_TYPE, MSG_ERR_TYPE); +fail_num: return_err(NAN_OR_INF, MSG_NAN_INF); +fail_str: return_err(INVALID_STRING, MSG_ERR_UTF8); + +#undef return_err +#undef incr_len +#undef check_str_len +} + +/** Write JSON document pretty. + The root of this document should be a non-empty container. */ +static_inline u8 *yyjson_mut_write_pretty(const yyjson_mut_val *root, + usize estimated_val_num, + yyjson_write_flag flg, + yyjson_alc alc, + usize *dat_len, + yyjson_write_err *err) { +#define return_err(_code, _msg) do { \ + *dat_len = 0; \ + err->code = YYJSON_WRITE_ERROR_##_code; \ + err->msg = _msg; \ + if (hdr) alc.free(alc.ctx, hdr); \ + return NULL; \ +} while (false) + +#define incr_len(_len) do { \ + ext_len = (usize)(_len); \ + if (unlikely((u8 *)(cur + ext_len) >= (u8 *)ctx)) { \ + usize ctx_pos = (usize)((u8 *)ctx - hdr); \ + usize cur_pos = (usize)(cur - hdr); \ + ctx_len = (usize)(end - (u8 *)ctx); \ + alc_inc = yyjson_max(alc_len / 2, ext_len); \ + alc_inc = size_align_up(alc_inc, sizeof(yyjson_mut_write_ctx)); \ + if ((sizeof(usize) < 8) && size_add_is_overflow(alc_len, alc_inc)) \ + goto fail_alloc; \ + alc_len += alc_inc; \ + tmp = (u8 *)alc.realloc(alc.ctx, hdr, alc_len - alc_inc, alc_len); \ + if (unlikely(!tmp)) goto fail_alloc; \ + ctx_tmp = (yyjson_mut_write_ctx *)(void *)(tmp + (alc_len - ctx_len)); \ + memmove((void *)ctx_tmp, (void *)(tmp + ctx_pos), ctx_len); \ + ctx = ctx_tmp; \ + cur = tmp + cur_pos; \ + end = tmp + alc_len; \ + hdr = tmp; \ + } \ +} while (false) + +#define check_str_len(_len) do { \ + if ((sizeof(usize) < 8) && (_len >= (USIZE_MAX - 16) / 6)) \ + goto fail_alloc; \ +} while (false) + + yyjson_mut_val *val, *ctn; + yyjson_type val_type; + usize ctn_len, ctn_len_tmp; + bool ctn_obj, ctn_obj_tmp, is_key, no_indent; + u8 *hdr, *cur, *end, *tmp; + yyjson_mut_write_ctx *ctx, *ctx_tmp; + usize alc_len, alc_inc, ctx_len, ext_len, str_len, level; + const u8 *str_ptr; + const char_enc_type *enc_table = get_enc_table_with_flag(flg); + bool cpy = (enc_table == enc_table_cpy); + bool esc = has_flg(ESCAPE_UNICODE) != 0; + bool inv = has_allow(INVALID_UNICODE) != 0; + usize spaces = has_flg(PRETTY_TWO_SPACES) ? 2 : 4; + bool newline = has_flg(NEWLINE_AT_END) != 0; + + alc_len = estimated_val_num * YYJSON_WRITER_ESTIMATED_PRETTY_RATIO + 64; + alc_len = size_align_up(alc_len, sizeof(yyjson_mut_write_ctx)); + hdr = (u8 *)alc.malloc(alc.ctx, alc_len); + if (!hdr) goto fail_alloc; + cur = hdr; + end = hdr + alc_len; + ctx = (yyjson_mut_write_ctx *)(void *)end; + +doc_begin: + val = constcast(yyjson_mut_val *)root; + val_type = unsafe_yyjson_get_type(val); + ctn_obj = (val_type == YYJSON_TYPE_OBJ); + ctn_len = unsafe_yyjson_get_len(val) << (u8)ctn_obj; + *cur++ = (u8)('[' | ((u8)ctn_obj << 5)); + *cur++ = '\n'; + ctn = val; + val = (yyjson_mut_val *)val->uni.ptr; /* tail */ + val = ctn_obj ? val->next->next : val->next; + level = 1; + +val_begin: + val_type = unsafe_yyjson_get_type(val); + if (val_type == YYJSON_TYPE_STR) { + is_key = (bool)((u8)ctn_obj & (u8)~ctn_len); + no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); + str_len = unsafe_yyjson_get_len(val); + str_ptr = (const u8 *)unsafe_yyjson_get_str(val); + check_str_len(str_len); + incr_len(str_len * 6 + 16 + (no_indent ? 0 : level * 4)); + cur = write_indent(cur, no_indent ? 0 : level, spaces); + if (likely(cpy) && unsafe_yyjson_get_subtype(val)) { + cur = write_str_noesc(cur, str_ptr, str_len); + } else { + cur = write_str(cur, esc, inv, str_ptr, str_len, enc_table); + if (unlikely(!cur)) goto fail_str; + } + *cur++ = is_key ? ':' : ','; + *cur++ = is_key ? ' ' : '\n'; + goto val_end; + } + if (val_type == YYJSON_TYPE_NUM) { + no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); + incr_len(FP_BUF_LEN + (no_indent ? 0 : level * 4)); + cur = write_indent(cur, no_indent ? 0 : level, spaces); + cur = write_num(cur, (yyjson_val *)val, flg); + if (unlikely(!cur)) goto fail_num; + *cur++ = ','; + *cur++ = '\n'; + goto val_end; + } + if ((val_type & (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) == + (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) { + no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); + ctn_len_tmp = unsafe_yyjson_get_len(val); + ctn_obj_tmp = (val_type == YYJSON_TYPE_OBJ); + if (unlikely(ctn_len_tmp == 0)) { + /* write empty container */ + incr_len(16 + (no_indent ? 0 : level * 4)); + cur = write_indent(cur, no_indent ? 0 : level, spaces); + *cur++ = (u8)('[' | ((u8)ctn_obj_tmp << 5)); + *cur++ = (u8)(']' | ((u8)ctn_obj_tmp << 5)); + *cur++ = ','; + *cur++ = '\n'; + goto val_end; + } else { + /* push context, setup new container */ + incr_len(32 + (no_indent ? 0 : level * 4)); + yyjson_mut_write_ctx_set(--ctx, ctn, ctn_len, ctn_obj); + ctn_len = ctn_len_tmp << (u8)ctn_obj_tmp; + ctn_obj = ctn_obj_tmp; + cur = write_indent(cur, no_indent ? 0 : level, spaces); + level++; + *cur++ = (u8)('[' | ((u8)ctn_obj << 5)); + *cur++ = '\n'; + ctn = val; + val = (yyjson_mut_val *)ctn->uni.ptr; /* tail */ + val = ctn_obj ? val->next->next : val->next; + goto val_begin; + } + } + if (val_type == YYJSON_TYPE_BOOL) { + no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); + incr_len(16 + (no_indent ? 0 : level * 4)); + cur = write_indent(cur, no_indent ? 0 : level, spaces); + cur = write_bool(cur, unsafe_yyjson_get_bool(val)); + cur += 2; + goto val_end; + } + if (val_type == YYJSON_TYPE_NULL) { + no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); + incr_len(16 + (no_indent ? 0 : level * 4)); + cur = write_indent(cur, no_indent ? 0 : level, spaces); + cur = write_null(cur); + cur += 2; + goto val_end; + } + if (val_type == YYJSON_TYPE_RAW) { + no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); + str_len = unsafe_yyjson_get_len(val); + str_ptr = (const u8 *)unsafe_yyjson_get_str(val); + check_str_len(str_len); + incr_len(str_len + 3 + (no_indent ? 0 : level * 4)); + cur = write_indent(cur, no_indent ? 0 : level, spaces); + cur = write_raw(cur, str_ptr, str_len); + *cur++ = ','; + *cur++ = '\n'; + goto val_end; + } + goto fail_type; + +val_end: + ctn_len--; + if (unlikely(ctn_len == 0)) goto ctn_end; + val = val->next; + goto val_begin; + +ctn_end: + cur -= 2; + *cur++ = '\n'; + incr_len(level * 4); + cur = write_indent(cur, --level, spaces); + *cur++ = (u8)(']' | ((u8)ctn_obj << 5)); + if (unlikely((u8 *)ctx >= end)) goto doc_end; + val = ctn->next; + yyjson_mut_write_ctx_get(ctx++, &ctn, &ctn_len, &ctn_obj); + ctn_len--; + *cur++ = ','; + *cur++ = '\n'; + if (likely(ctn_len > 0)) { + goto val_begin; + } else { + goto ctn_end; + } + +doc_end: + if (newline) { + incr_len(2); + *cur++ = '\n'; + } + *cur = '\0'; + *dat_len = (usize)(cur - hdr); + err->code = YYJSON_WRITE_SUCCESS; + err->msg = NULL; + return hdr; + +fail_alloc: return_err(MEMORY_ALLOCATION, MSG_MALLOC); +fail_type: return_err(INVALID_VALUE_TYPE, MSG_ERR_TYPE); +fail_num: return_err(NAN_OR_INF, MSG_NAN_INF); +fail_str: return_err(INVALID_STRING, MSG_ERR_UTF8); + +#undef return_err +#undef incr_len +#undef check_str_len +} + +static char *yyjson_mut_write_opts_impl(const yyjson_mut_val *val, + usize estimated_val_num, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + usize *dat_len, + yyjson_write_err *err) { + yyjson_write_err tmp_err; + usize tmp_dat_len; + yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC; + yyjson_mut_val *root = constcast(yyjson_mut_val *)val; + + if (!err) err = &tmp_err; + if (!dat_len) dat_len = &tmp_dat_len; + + if (unlikely(!root)) { + *dat_len = 0; + err->msg = "input JSON is NULL"; + err->code = YYJSON_WRITE_ERROR_INVALID_PARAMETER; + return NULL; + } + + if (!unsafe_yyjson_is_ctn(root) || unsafe_yyjson_get_len(root) == 0) { + return (char *)yyjson_mut_write_single(root, flg, alc, dat_len, err); + } else if (flg & (YYJSON_WRITE_PRETTY | YYJSON_WRITE_PRETTY_TWO_SPACES)) { + return (char *)yyjson_mut_write_pretty(root, estimated_val_num, + flg, alc, dat_len, err); + } else { + return (char *)yyjson_mut_write_minify(root, estimated_val_num, + flg, alc, dat_len, err); + } +} + + + +/*============================================================================== + * MARK: - Mutable JSON Writer (Public) + *============================================================================*/ + +char *yyjson_mut_val_write_opts(const yyjson_mut_val *val, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + usize *dat_len, + yyjson_write_err *err) { + return yyjson_mut_write_opts_impl(val, 0, flg, alc_ptr, dat_len, err); +} + +char *yyjson_mut_write_opts(const yyjson_mut_doc *doc, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + usize *dat_len, + yyjson_write_err *err) { + yyjson_mut_val *root; + usize estimated_val_num; + if (likely(doc)) { + root = doc->root; + estimated_val_num = yyjson_mut_doc_estimated_val_num(doc); + } else { + root = NULL; + estimated_val_num = 0; + } + return yyjson_mut_write_opts_impl(root, estimated_val_num, + flg, alc_ptr, dat_len, err); +} + +bool yyjson_mut_val_write_file(const char *path, + const yyjson_mut_val *val, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + yyjson_write_err *err) { + yyjson_write_err tmp_err; + yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC; + u8 *dat; + usize dat_len = 0; + yyjson_mut_val *root = constcast(yyjson_mut_val *)val; + bool suc; + + if (!err) err = &tmp_err; + if (unlikely(!path || !*path)) { + err->msg = "input path is invalid"; + err->code = YYJSON_WRITE_ERROR_INVALID_PARAMETER; + return false; + } + + dat = (u8 *)yyjson_mut_val_write_opts(root, flg, &alc, &dat_len, err); + if (unlikely(!dat)) return false; + suc = write_dat_to_file(path, dat, dat_len, err); + alc.free(alc.ctx, dat); + return suc; +} + +bool yyjson_mut_val_write_fp(FILE *fp, + const yyjson_mut_val *val, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + yyjson_write_err *err) { + yyjson_write_err tmp_err; + yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC; + u8 *dat; + usize dat_len = 0; + yyjson_mut_val *root = constcast(yyjson_mut_val *)val; + bool suc; + + if (!err) err = &tmp_err; + if (unlikely(!fp)) { + err->msg = "input fp is invalid"; + err->code = YYJSON_WRITE_ERROR_INVALID_PARAMETER; + return false; + } + + dat = (u8 *)yyjson_mut_val_write_opts(root, flg, &alc, &dat_len, err); + if (unlikely(!dat)) return false; + suc = write_dat_to_fp(fp, dat, dat_len, err); + alc.free(alc.ctx, dat); + return suc; +} + +bool yyjson_mut_write_file(const char *path, + const yyjson_mut_doc *doc, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + yyjson_write_err *err) { + yyjson_mut_val *root = doc ? doc->root : NULL; + return yyjson_mut_val_write_file(path, root, flg, alc_ptr, err); +} + +bool yyjson_mut_write_fp(FILE *fp, + const yyjson_mut_doc *doc, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + yyjson_write_err *err) { + yyjson_mut_val *root = doc ? doc->root : NULL; + return yyjson_mut_val_write_fp(fp, root, flg, alc_ptr, err); +} + +#undef has_flg +#undef has_allow +#endif /* YYJSON_DISABLE_WRITER */ + + + +#if !YYJSON_DISABLE_UTILS + +/*============================================================================== + * MARK: - JSON Pointer API (RFC 6901) (Public) + *============================================================================*/ + +/** + Get a token from JSON pointer string. + @param ptr [in] string that points to current token prefix `/` + [out] string that points to next token prefix `/`, or string end + @param end [in] end of the entire JSON Pointer string + @param len [out] unescaped token length + @param esc [out] number of escaped characters in this token + @return head of the token, or NULL if syntax error + */ +static_inline const char *ptr_next_token(const char **ptr, const char *end, + usize *len, usize *esc) { + const char *hdr = *ptr + 1; + const char *cur = hdr; + /* skip unescaped characters */ + while (cur < end && *cur != '/' && *cur != '~') cur++; + if (likely(cur == end || *cur != '~')) { + /* no escaped characters, return */ + *ptr = cur; + *len = (usize)(cur - hdr); + *esc = 0; + return hdr; + } else { + /* handle escaped characters */ + usize esc_num = 0; + while (cur < end && *cur != '/') { + if (*cur++ == '~') { + if (cur == end || (*cur != '0' && *cur != '1')) { + *ptr = cur - 1; + return NULL; + } + esc_num++; + } + } + *ptr = cur; + *len = (usize)(cur - hdr) - esc_num; + *esc = esc_num; + return hdr; + } +} + +/** + Convert token string to index. + @param cur [in] token head + @param len [in] token length + @param idx [out] the index number, or USIZE_MAX if token is '-' + @return true if token is a valid array index + */ +static_inline bool ptr_token_to_idx(const char *cur, usize len, usize *idx) { + const char *end = cur + len; + usize num = 0, add; + if (unlikely(len == 0 || len > USIZE_SAFE_DIG)) return false; + if (*cur == '0') { + if (unlikely(len > 1)) return false; + *idx = 0; + return true; + } + if (*cur == '-') { + if (unlikely(len > 1)) return false; + *idx = USIZE_MAX; + return true; + } + for (; cur < end && (add = (usize)((u8)*cur - (u8)'0')) <= 9; cur++) { + num = num * 10 + add; + } + if (unlikely(num == 0 || cur < end)) return false; + *idx = num; + return true; +} + +/** + Compare JSON key with token. + @param key a string key (yyjson_val or yyjson_mut_val) + @param token a JSON pointer token + @param len unescaped token length + @param esc number of escaped characters in this token + @return true if `str` is equals to `token` + */ +static_inline bool ptr_token_eq(void *key, + const char *token, usize len, usize esc) { + yyjson_val *val = (yyjson_val *)key; + if (unsafe_yyjson_get_len(val) != len) return false; + if (likely(!esc)) { + return memcmp(val->uni.str, token, len) == 0; + } else { + const char *str = val->uni.str; + for (; len-- > 0; token++, str++) { + if (*token == '~') { + if (*str != (*++token == '0' ? '~' : '/')) return false; + } else { + if (*str != *token) return false; + } + } + return true; + } +} + +/** + Get a value from array by token. + @param arr an array, should not be NULL or non-array type + @param token a JSON pointer token + @param len unescaped token length + @param esc number of escaped characters in this token + @return value at index, or NULL if token is not index or index is out of range + */ +static_inline yyjson_val *ptr_arr_get(yyjson_val *arr, const char *token, + usize len, usize esc) { + yyjson_val *val = unsafe_yyjson_get_first(arr); + usize num = unsafe_yyjson_get_len(arr), idx = 0; + if (unlikely(num == 0)) return NULL; + if (unlikely(!ptr_token_to_idx(token, len, &idx))) return NULL; + if (unlikely(idx >= num)) return NULL; + if (unsafe_yyjson_arr_is_flat(arr)) { + return val + idx; + } else { + while (idx-- > 0) val = unsafe_yyjson_get_next(val); + return val; + } +} + +/** + Get a value from object by token. + @param obj [in] an object, should not be NULL or non-object type + @param token [in] a JSON pointer token + @param len [in] unescaped token length + @param esc [in] number of escaped characters in this token + @return value associated with the token, or NULL if no value + */ +static_inline yyjson_val *ptr_obj_get(yyjson_val *obj, const char *token, + usize len, usize esc) { + yyjson_val *key = unsafe_yyjson_get_first(obj); + usize num = unsafe_yyjson_get_len(obj); + if (unlikely(num == 0)) return NULL; + for (; num > 0; num--, key = unsafe_yyjson_get_next(key + 1)) { + if (ptr_token_eq(key, token, len, esc)) return key + 1; + } + return NULL; +} + +/** + Get a value from array by token. + @param arr [in] an array, should not be NULL or non-array type + @param token [in] a JSON pointer token + @param len [in] unescaped token length + @param esc [in] number of escaped characters in this token + @param pre [out] previous (sibling) value of the returned value + @param last [out] whether index is last + @return value at index, or NULL if token is not index or index is out of range + */ +static_inline yyjson_mut_val *ptr_mut_arr_get(yyjson_mut_val *arr, + const char *token, + usize len, usize esc, + yyjson_mut_val **pre, + bool *last) { + yyjson_mut_val *val = (yyjson_mut_val *)arr->uni.ptr; /* last (tail) */ + usize num = unsafe_yyjson_get_len(arr), idx; + if (last) *last = false; + if (pre) *pre = NULL; + if (unlikely(num == 0)) { + if (last && len == 1 && (*token == '0' || *token == '-')) *last = true; + return NULL; + } + if (unlikely(!ptr_token_to_idx(token, len, &idx))) return NULL; + if (last) *last = (idx == num || idx == USIZE_MAX); + if (unlikely(idx >= num)) return NULL; + while (idx-- > 0) val = val->next; + if (pre) *pre = val; + return val->next; +} + +/** + Get a value from object by token. + @param obj [in] an object, should not be NULL or non-object type + @param token [in] a JSON pointer token + @param len [in] unescaped token length + @param esc [in] number of escaped characters in this token + @param pre [out] previous (sibling) key of the returned value's key + @return value associated with the token, or NULL if no value + */ +static_inline yyjson_mut_val *ptr_mut_obj_get(yyjson_mut_val *obj, + const char *token, + usize len, usize esc, + yyjson_mut_val **pre) { + yyjson_mut_val *pre_key = (yyjson_mut_val *)obj->uni.ptr, *key; + usize num = unsafe_yyjson_get_len(obj); + if (pre) *pre = NULL; + if (unlikely(num == 0)) return NULL; + for (; num > 0; num--, pre_key = key) { + key = pre_key->next->next; + if (ptr_token_eq(key, token, len, esc)) { + if (pre) *pre = pre_key; + return key->next; + } + } + return NULL; +} + +/** + Create a string value with JSON pointer token. + @param token [in] a JSON pointer token + @param len [in] unescaped token length + @param esc [in] number of escaped characters in this token + @param doc [in] used for memory allocation when creating value + @return new string value, or NULL if memory allocation failed + */ +static_inline yyjson_mut_val *ptr_new_key(const char *token, + usize len, usize esc, + yyjson_mut_doc *doc) { + const char *src = token; + if (likely(!esc)) { + return yyjson_mut_strncpy(doc, src, len); + } else { + const char *end = src + len + esc; + char *dst = unsafe_yyjson_mut_str_alc(doc, len + esc); + char *str = dst; + if (unlikely(!dst)) return NULL; + for (; src < end; src++, dst++) { + if (*src != '~') *dst = *src; + else *dst = (*++src == '0' ? '~' : '/'); + } + *dst = '\0'; + return yyjson_mut_strn(doc, str, len); + } +} + +/* macros for yyjson_ptr */ +#define return_err(_ret, _code, _pos, _msg) do { \ + if (err) { \ + err->code = YYJSON_PTR_ERR_##_code; \ + err->msg = _msg; \ + err->pos = (usize)(_pos); \ + } \ + return _ret; \ +} while (false) + +#define return_err_resolve(_ret, _pos) \ + return_err(_ret, RESOLVE, _pos, "JSON pointer cannot be resolved") +#define return_err_syntax(_ret, _pos) \ + return_err(_ret, SYNTAX, _pos, "invalid escaped character") +#define return_err_alloc(_ret) \ + return_err(_ret, MEMORY_ALLOCATION, 0, "failed to create value") + +yyjson_val *unsafe_yyjson_ptr_getx(yyjson_val *val, + const char *ptr, size_t ptr_len, + yyjson_ptr_err *err) { + + const char *hdr = ptr, *end = ptr + ptr_len, *token; + usize len, esc; + yyjson_type type; + + while (true) { + token = ptr_next_token(&ptr, end, &len, &esc); + if (unlikely(!token)) return_err_syntax(NULL, ptr - hdr); + type = unsafe_yyjson_get_type(val); + if (type == YYJSON_TYPE_OBJ) { + val = ptr_obj_get(val, token, len, esc); + } else if (type == YYJSON_TYPE_ARR) { + val = ptr_arr_get(val, token, len, esc); + } else { + val = NULL; + } + if (!val) return_err_resolve(NULL, token - hdr); + if (ptr == end) return val; + } +} + +yyjson_mut_val *unsafe_yyjson_mut_ptr_getx( + yyjson_mut_val *val, const char *ptr, size_t ptr_len, + yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { + + const char *hdr = ptr, *end = ptr + ptr_len, *token; + usize len, esc; + yyjson_mut_val *ctn, *pre = NULL; + yyjson_type type; + bool idx_is_last = false; + + while (true) { + token = ptr_next_token(&ptr, end, &len, &esc); + if (unlikely(!token)) return_err_syntax(NULL, ptr - hdr); + ctn = val; + type = unsafe_yyjson_get_type(val); + if (type == YYJSON_TYPE_OBJ) { + val = ptr_mut_obj_get(val, token, len, esc, &pre); + } else if (type == YYJSON_TYPE_ARR) { + val = ptr_mut_arr_get(val, token, len, esc, &pre, &idx_is_last); + } else { + val = NULL; + } + if (ctx && (ptr == end)) { + if (type == YYJSON_TYPE_OBJ || + (type == YYJSON_TYPE_ARR && (val || idx_is_last))) { + ctx->ctn = ctn; + ctx->pre = pre; + } + } + if (!val) return_err_resolve(NULL, token - hdr); + if (ptr == end) return val; + } +} + +bool unsafe_yyjson_mut_ptr_putx( + yyjson_mut_val *val, const char *ptr, size_t ptr_len, + yyjson_mut_val *new_val, yyjson_mut_doc *doc, bool create_parent, + bool insert_new, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { + + const char *hdr = ptr, *end = ptr + ptr_len, *token; + usize token_len, esc, ctn_len; + yyjson_mut_val *ctn, *key, *pre = NULL; + yyjson_mut_val *sep_ctn = NULL, *sep_key = NULL, *sep_val = NULL; + yyjson_type ctn_type; + bool idx_is_last = false; + + /* skip exist parent nodes */ + while (true) { + token = ptr_next_token(&ptr, end, &token_len, &esc); + if (unlikely(!token)) return_err_syntax(false, ptr - hdr); + ctn = val; + ctn_type = unsafe_yyjson_get_type(ctn); + if (ctn_type == YYJSON_TYPE_OBJ) { + val = ptr_mut_obj_get(ctn, token, token_len, esc, &pre); + } else if (ctn_type == YYJSON_TYPE_ARR) { + val = ptr_mut_arr_get(ctn, token, token_len, esc, &pre, + &idx_is_last); + } else return_err_resolve(false, token - hdr); + if (!val) break; + if (ptr == end) break; /* is last token */ + } + + /* create parent nodes if not exist */ + if (unlikely(ptr != end)) { /* not last token */ + if (!create_parent) return_err_resolve(false, token - hdr); + + /* add value at last index if container is array */ + if (ctn_type == YYJSON_TYPE_ARR) { + if (!idx_is_last || !insert_new) { + return_err_resolve(false, token - hdr); + } + val = yyjson_mut_obj(doc); + if (!val) return_err_alloc(false); + + /* delay attaching until all operations are completed */ + sep_ctn = ctn; + sep_key = NULL; + sep_val = val; + + /* move to next token */ + ctn = val; + val = NULL; + ctn_type = YYJSON_TYPE_OBJ; + token = ptr_next_token(&ptr, end, &token_len, &esc); + if (unlikely(!token)) return_err_resolve(false, token - hdr); + } + + /* container is object, create parent nodes */ + while (ptr != end) { /* not last token */ + key = ptr_new_key(token, token_len, esc, doc); + if (!key) return_err_alloc(false); + val = yyjson_mut_obj(doc); + if (!val) return_err_alloc(false); + + /* delay attaching until all operations are completed */ + if (!sep_ctn) { + sep_ctn = ctn; + sep_key = key; + sep_val = val; + } else { + yyjson_mut_obj_add(ctn, key, val); + } + + /* move to next token */ + ctn = val; + val = NULL; + token = ptr_next_token(&ptr, end, &token_len, &esc); + if (unlikely(!token)) return_err_syntax(false, ptr - hdr); + } + } + + /* JSON pointer is resolved, insert or replace target value */ + ctn_len = unsafe_yyjson_get_len(ctn); + if (ctn_type == YYJSON_TYPE_OBJ) { + if (ctx) ctx->ctn = ctn; + if (!val || insert_new) { + /* insert new key-value pair */ + key = ptr_new_key(token, token_len, esc, doc); + if (unlikely(!key)) return_err_alloc(false); + if (ctx) ctx->pre = ctn_len ? (yyjson_mut_val *)ctn->uni.ptr : key; + unsafe_yyjson_mut_obj_add(ctn, key, new_val, ctn_len); + } else { + /* replace exist value */ + key = pre->next->next; + if (ctx) ctx->pre = pre; + if (ctx) ctx->old = val; + yyjson_mut_obj_put(ctn, key, new_val); + } + } else { + /* array */ + if (ctx && (val || idx_is_last)) ctx->ctn = ctn; + if (insert_new) { + /* append new value */ + if (val) { + pre->next = new_val; + new_val->next = val; + if (ctx) ctx->pre = pre; + unsafe_yyjson_set_len(ctn, ctn_len + 1); + } else if (idx_is_last) { + if (ctx) ctx->pre = ctn_len ? + (yyjson_mut_val *)ctn->uni.ptr : new_val; + yyjson_mut_arr_append(ctn, new_val); + } else { + return_err_resolve(false, token - hdr); + } + } else { + /* replace exist value */ + if (!val) return_err_resolve(false, token - hdr); + if (ctn_len > 1) { + new_val->next = val->next; + pre->next = new_val; + if (ctn->uni.ptr == val) ctn->uni.ptr = new_val; + } else { + new_val->next = new_val; + ctn->uni.ptr = new_val; + pre = new_val; + } + if (ctx) ctx->pre = pre; + if (ctx) ctx->old = val; + } + } + + /* all operations are completed, attach the new components to the target */ + if (unlikely(sep_ctn)) { + if (sep_key) yyjson_mut_obj_add(sep_ctn, sep_key, sep_val); + else yyjson_mut_arr_append(sep_ctn, sep_val); + } + return true; +} + +yyjson_mut_val *unsafe_yyjson_mut_ptr_replacex( + yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val, + yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { + + yyjson_mut_val *cur_val; + yyjson_ptr_ctx cur_ctx; + memset(&cur_ctx, 0, sizeof(cur_ctx)); + if (!ctx) ctx = &cur_ctx; + cur_val = unsafe_yyjson_mut_ptr_getx(val, ptr, len, ctx, err); + if (!cur_val) return NULL; + + if (yyjson_mut_is_obj(ctx->ctn)) { + yyjson_mut_val *key = ctx->pre->next->next; + yyjson_mut_obj_put(ctx->ctn, key, new_val); + } else { + yyjson_ptr_ctx_replace(ctx, new_val); + } + ctx->old = cur_val; + return cur_val; +} + +yyjson_mut_val *unsafe_yyjson_mut_ptr_removex( + yyjson_mut_val *val, const char *ptr, size_t len, + yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { + + yyjson_mut_val *cur_val; + yyjson_ptr_ctx cur_ctx; + memset(&cur_ctx, 0, sizeof(cur_ctx)); + if (!ctx) ctx = &cur_ctx; + cur_val = unsafe_yyjson_mut_ptr_getx(val, ptr, len, ctx, err); + if (cur_val) { + if (yyjson_mut_is_obj(ctx->ctn)) { + yyjson_mut_val *key = ctx->pre->next->next; + yyjson_mut_obj_put(ctx->ctn, key, NULL); + } else { + yyjson_ptr_ctx_remove(ctx); + } + ctx->pre = NULL; + ctx->old = cur_val; + } + return cur_val; +} + +/* macros for yyjson_ptr */ +#undef return_err +#undef return_err_resolve +#undef return_err_syntax +#undef return_err_alloc + + + +/*============================================================================== + * MARK: - JSON Patch API (RFC 6902) (Public) + *============================================================================*/ + +/* JSON Patch operation */ +typedef enum patch_op { + PATCH_OP_ADD, /* path, value */ + PATCH_OP_REMOVE, /* path */ + PATCH_OP_REPLACE, /* path, value */ + PATCH_OP_MOVE, /* from, path */ + PATCH_OP_COPY, /* from, path */ + PATCH_OP_TEST, /* path, value */ + PATCH_OP_NONE /* invalid */ +} patch_op; + +static patch_op patch_op_get(yyjson_val *op) { + const char *str = op->uni.str; + switch (unsafe_yyjson_get_len(op)) { + case 3: + if (!memcmp(str, "add", 3)) return PATCH_OP_ADD; + return PATCH_OP_NONE; + case 4: + if (!memcmp(str, "move", 4)) return PATCH_OP_MOVE; + if (!memcmp(str, "copy", 4)) return PATCH_OP_COPY; + if (!memcmp(str, "test", 4)) return PATCH_OP_TEST; + return PATCH_OP_NONE; + case 6: + if (!memcmp(str, "remove", 6)) return PATCH_OP_REMOVE; + return PATCH_OP_NONE; + case 7: + if (!memcmp(str, "replace", 7)) return PATCH_OP_REPLACE; + return PATCH_OP_NONE; + default: + return PATCH_OP_NONE; + } +} + +/* macros for yyjson_patch */ +#define return_err(_code, _msg) do { \ + if (err->ptr.code == YYJSON_PTR_ERR_MEMORY_ALLOCATION) { \ + err->code = YYJSON_PATCH_ERROR_MEMORY_ALLOCATION; \ + err->msg = _msg; \ + memset(&err->ptr, 0, sizeof(yyjson_ptr_err)); \ + } else { \ + err->code = YYJSON_PATCH_ERROR_##_code; \ + err->msg = _msg; \ + err->idx = iter.idx ? iter.idx - 1 : 0; \ + } \ + return NULL; \ +} while (false) + +#define return_err_copy() \ + return_err(MEMORY_ALLOCATION, "failed to copy value") +#define return_err_key(_key) \ + return_err(MISSING_KEY, "missing key " _key) +#define return_err_val(_key) \ + return_err(INVALID_MEMBER, "invalid member " _key) + +#define ptr_get(_ptr) yyjson_mut_ptr_getx( \ + root, _ptr->uni.str, _ptr##_len, NULL, &err->ptr) +#define ptr_add(_ptr, _val) yyjson_mut_ptr_addx( \ + root, _ptr->uni.str, _ptr##_len, _val, doc, false, NULL, &err->ptr) +#define ptr_remove(_ptr) yyjson_mut_ptr_removex( \ + root, _ptr->uni.str, _ptr##_len, NULL, &err->ptr) +#define ptr_replace(_ptr, _val)yyjson_mut_ptr_replacex( \ + root, _ptr->uni.str, _ptr##_len, _val, NULL, &err->ptr) + +yyjson_mut_val *yyjson_patch(yyjson_mut_doc *doc, + yyjson_val *orig, + yyjson_val *patch, + yyjson_patch_err *err) { + + yyjson_mut_val *root; + yyjson_val *obj; + yyjson_arr_iter iter; + yyjson_patch_err err_tmp; + if (!err) err = &err_tmp; + memset(err, 0, sizeof(*err)); + memset(&iter, 0, sizeof(iter)); + + if (unlikely(!doc || !orig || !patch)) { + return_err(INVALID_PARAMETER, "input parameter is NULL"); + } + if (unlikely(!yyjson_is_arr(patch))) { + return_err(INVALID_PARAMETER, "input patch is not array"); + } + root = yyjson_val_mut_copy(doc, orig); + if (unlikely(!root)) return_err_copy(); + + /* iterate through the patch array */ + yyjson_arr_iter_init(patch, &iter); + while ((obj = yyjson_arr_iter_next(&iter))) { + patch_op op_enum; + yyjson_val *op, *path, *from = NULL, *value; + yyjson_mut_val *val = NULL, *test; + usize path_len, from_len = 0; + if (unlikely(!unsafe_yyjson_is_obj(obj))) { + return_err(INVALID_OPERATION, "JSON patch operation is not object"); + } + + /* get required member: op */ + op = yyjson_obj_get(obj, "op"); + if (unlikely(!op)) return_err_key("`op`"); + if (unlikely(!yyjson_is_str(op))) return_err_val("`op`"); + op_enum = patch_op_get(op); + + /* get required member: path */ + path = yyjson_obj_get(obj, "path"); + if (unlikely(!path)) return_err_key("`path`"); + if (unlikely(!yyjson_is_str(path))) return_err_val("`path`"); + path_len = unsafe_yyjson_get_len(path); + + /* get required member: value, from */ + switch ((int)op_enum) { + case PATCH_OP_ADD: case PATCH_OP_REPLACE: case PATCH_OP_TEST: + value = yyjson_obj_get(obj, "value"); + if (unlikely(!value)) return_err_key("`value`"); + val = yyjson_val_mut_copy(doc, value); + if (unlikely(!val)) return_err_copy(); + break; + case PATCH_OP_MOVE: case PATCH_OP_COPY: + from = yyjson_obj_get(obj, "from"); + if (unlikely(!from)) return_err_key("`from`"); + if (unlikely(!yyjson_is_str(from))) return_err_val("`from`"); + from_len = unsafe_yyjson_get_len(from); + break; + default: + break; + } + + /* perform an operation */ + switch ((int)op_enum) { + case PATCH_OP_ADD: /* add(path, val) */ + if (unlikely(path_len == 0)) { root = val; break; } + if (unlikely(!ptr_add(path, val))) { + return_err(POINTER, "failed to add `path`"); + } + break; + case PATCH_OP_REMOVE: /* remove(path) */ + if (unlikely(!ptr_remove(path))) { + return_err(POINTER, "failed to remove `path`"); + } + break; + case PATCH_OP_REPLACE: /* replace(path, val) */ + if (unlikely(path_len == 0)) { root = val; break; } + if (unlikely(!ptr_replace(path, val))) { + return_err(POINTER, "failed to replace `path`"); + } + break; + case PATCH_OP_MOVE: /* val = remove(from), add(path, val) */ + if (unlikely(from_len == 0 && path_len == 0)) break; + val = ptr_remove(from); + if (unlikely(!val)) { + return_err(POINTER, "failed to remove `from`"); + } + if (unlikely(path_len == 0)) { root = val; break; } + if (unlikely(!ptr_add(path, val))) { + return_err(POINTER, "failed to add `path`"); + } + break; + case PATCH_OP_COPY: /* val = get(from).copy, add(path, val) */ + val = ptr_get(from); + if (unlikely(!val)) { + return_err(POINTER, "failed to get `from`"); + } + if (unlikely(path_len == 0)) { root = val; break; } + val = yyjson_mut_val_mut_copy(doc, val); + if (unlikely(!val)) return_err_copy(); + if (unlikely(!ptr_add(path, val))) { + return_err(POINTER, "failed to add `path`"); + } + break; + case PATCH_OP_TEST: /* test = get(path), test.eq(val) */ + test = ptr_get(path); + if (unlikely(!test)) { + return_err(POINTER, "failed to get `path`"); + } + if (unlikely(!yyjson_mut_equals(val, test))) { + return_err(EQUAL, "failed to test equal"); + } + break; + default: + return_err(INVALID_MEMBER, "unsupported `op`"); + } + } + return root; +} + +yyjson_mut_val *yyjson_mut_patch(yyjson_mut_doc *doc, + yyjson_mut_val *orig, + yyjson_mut_val *patch, + yyjson_patch_err *err) { + yyjson_mut_val *root, *obj; + yyjson_mut_arr_iter iter; + yyjson_patch_err err_tmp; + if (!err) err = &err_tmp; + memset(err, 0, sizeof(*err)); + memset(&iter, 0, sizeof(iter)); + + if (unlikely(!doc || !orig || !patch)) { + return_err(INVALID_PARAMETER, "input parameter is NULL"); + } + if (unlikely(!yyjson_mut_is_arr(patch))) { + return_err(INVALID_PARAMETER, "input patch is not array"); + } + root = yyjson_mut_val_mut_copy(doc, orig); + if (unlikely(!root)) return_err_copy(); + + /* iterate through the patch array */ + yyjson_mut_arr_iter_init(patch, &iter); + while ((obj = yyjson_mut_arr_iter_next(&iter))) { + patch_op op_enum; + yyjson_mut_val *op, *path, *from = NULL, *value; + yyjson_mut_val *val = NULL, *test; + usize path_len, from_len = 0; + if (!unsafe_yyjson_is_obj(obj)) { + return_err(INVALID_OPERATION, "JSON patch operation is not object"); + } + + /* get required member: op */ + op = yyjson_mut_obj_get(obj, "op"); + if (unlikely(!op)) return_err_key("`op`"); + if (unlikely(!yyjson_mut_is_str(op))) return_err_val("`op`"); + op_enum = patch_op_get((yyjson_val *)(void *)op); + + /* get required member: path */ + path = yyjson_mut_obj_get(obj, "path"); + if (unlikely(!path)) return_err_key("`path`"); + if (unlikely(!yyjson_mut_is_str(path))) return_err_val("`path`"); + path_len = unsafe_yyjson_get_len(path); + + /* get required member: value, from */ + switch ((int)op_enum) { + case PATCH_OP_ADD: case PATCH_OP_REPLACE: case PATCH_OP_TEST: + value = yyjson_mut_obj_get(obj, "value"); + if (unlikely(!value)) return_err_key("`value`"); + val = yyjson_mut_val_mut_copy(doc, value); + if (unlikely(!val)) return_err_copy(); + break; + case PATCH_OP_MOVE: case PATCH_OP_COPY: + from = yyjson_mut_obj_get(obj, "from"); + if (unlikely(!from)) return_err_key("`from`"); + if (unlikely(!yyjson_mut_is_str(from))) { + return_err_val("`from`"); + } + from_len = unsafe_yyjson_get_len(from); + break; + default: + break; + } + + /* perform an operation */ + switch ((int)op_enum) { + case PATCH_OP_ADD: /* add(path, val) */ + if (unlikely(path_len == 0)) { root = val; break; } + if (unlikely(!ptr_add(path, val))) { + return_err(POINTER, "failed to add `path`"); + } + break; + case PATCH_OP_REMOVE: /* remove(path) */ + if (unlikely(!ptr_remove(path))) { + return_err(POINTER, "failed to remove `path`"); + } + break; + case PATCH_OP_REPLACE: /* replace(path, val) */ + if (unlikely(path_len == 0)) { root = val; break; } + if (unlikely(!ptr_replace(path, val))) { + return_err(POINTER, "failed to replace `path`"); + } + break; + case PATCH_OP_MOVE: /* val = remove(from), add(path, val) */ + if (unlikely(from_len == 0 && path_len == 0)) break; + val = ptr_remove(from); + if (unlikely(!val)) { + return_err(POINTER, "failed to remove `from`"); + } + if (unlikely(path_len == 0)) { root = val; break; } + if (unlikely(!ptr_add(path, val))) { + return_err(POINTER, "failed to add `path`"); + } + break; + case PATCH_OP_COPY: /* val = get(from).copy, add(path, val) */ + val = ptr_get(from); + if (unlikely(!val)) { + return_err(POINTER, "failed to get `from`"); + } + if (unlikely(path_len == 0)) { root = val; break; } + val = yyjson_mut_val_mut_copy(doc, val); + if (unlikely(!val)) return_err_copy(); + if (unlikely(!ptr_add(path, val))) { + return_err(POINTER, "failed to add `path`"); + } + break; + case PATCH_OP_TEST: /* test = get(path), test.eq(val) */ + test = ptr_get(path); + if (unlikely(!test)) { + return_err(POINTER, "failed to get `path`"); + } + if (unlikely(!yyjson_mut_equals(val, test))) { + return_err(EQUAL, "failed to test equal"); + } + break; + default: + return_err(INVALID_MEMBER, "unsupported `op`"); + } + } + return root; +} + +/* macros for yyjson_patch */ +#undef return_err +#undef return_err_copy +#undef return_err_key +#undef return_err_val +#undef ptr_get +#undef ptr_add +#undef ptr_remove +#undef ptr_replace + + + +/*============================================================================== + * MARK: - JSON Merge-Patch API (RFC 7386) (Public) + *============================================================================*/ + +yyjson_mut_val *yyjson_merge_patch(yyjson_mut_doc *doc, + yyjson_val *orig, + yyjson_val *patch) { + usize idx, max; + yyjson_val *key, *orig_val, *patch_val, local_orig; + yyjson_mut_val *builder, *mut_key, *mut_val, *merged_val; + + if (unlikely(!yyjson_is_obj(patch))) { + return yyjson_val_mut_copy(doc, patch); + } + + builder = yyjson_mut_obj(doc); + if (unlikely(!builder)) return NULL; + + memset(&local_orig, 0, sizeof(local_orig)); + if (!yyjson_is_obj(orig)) { + orig = &local_orig; + orig->tag = builder->tag; + orig->uni = builder->uni; + } + + /* If orig is contributing, copy any items not modified by the patch */ + if (orig != &local_orig) { + yyjson_obj_foreach(orig, idx, max, key, orig_val) { + patch_val = yyjson_obj_getn(patch, + unsafe_yyjson_get_str(key), + unsafe_yyjson_get_len(key)); + if (!patch_val) { + mut_key = yyjson_val_mut_copy(doc, key); + mut_val = yyjson_val_mut_copy(doc, orig_val); + if (!yyjson_mut_obj_add(builder, mut_key, mut_val)) return NULL; + } + } + } + + /* Merge items modified by the patch. */ + yyjson_obj_foreach(patch, idx, max, key, patch_val) { + /* null indicates the field is removed. */ + if (unsafe_yyjson_is_null(patch_val)) { + continue; + } + mut_key = yyjson_val_mut_copy(doc, key); + orig_val = yyjson_obj_getn(orig, + unsafe_yyjson_get_str(key), + unsafe_yyjson_get_len(key)); + merged_val = yyjson_merge_patch(doc, orig_val, patch_val); + if (!yyjson_mut_obj_add(builder, mut_key, merged_val)) return NULL; + } + + return builder; +} + +yyjson_mut_val *yyjson_mut_merge_patch(yyjson_mut_doc *doc, + yyjson_mut_val *orig, + yyjson_mut_val *patch) { + usize idx, max; + yyjson_mut_val *key, *orig_val, *patch_val, local_orig; + yyjson_mut_val *builder, *mut_key, *mut_val, *merged_val; + + if (unlikely(!yyjson_mut_is_obj(patch))) { + return yyjson_mut_val_mut_copy(doc, patch); + } + + builder = yyjson_mut_obj(doc); + if (unlikely(!builder)) return NULL; + + memset(&local_orig, 0, sizeof(local_orig)); + if (!yyjson_mut_is_obj(orig)) { + orig = &local_orig; + orig->tag = builder->tag; + orig->uni = builder->uni; + } + + /* If orig is contributing, copy any items not modified by the patch */ + if (orig != &local_orig) { + yyjson_mut_obj_foreach(orig, idx, max, key, orig_val) { + patch_val = yyjson_mut_obj_getn(patch, + unsafe_yyjson_get_str(key), + unsafe_yyjson_get_len(key)); + if (!patch_val) { + mut_key = yyjson_mut_val_mut_copy(doc, key); + mut_val = yyjson_mut_val_mut_copy(doc, orig_val); + if (!yyjson_mut_obj_add(builder, mut_key, mut_val)) return NULL; + } + } + } + + /* Merge items modified by the patch. */ + yyjson_mut_obj_foreach(patch, idx, max, key, patch_val) { + /* null indicates the field is removed. */ + if (unsafe_yyjson_is_null(patch_val)) { + continue; + } + mut_key = yyjson_mut_val_mut_copy(doc, key); + orig_val = yyjson_mut_obj_getn(orig, + unsafe_yyjson_get_str(key), + unsafe_yyjson_get_len(key)); + merged_val = yyjson_mut_merge_patch(doc, orig_val, patch_val); + if (!yyjson_mut_obj_add(builder, mut_key, merged_val)) return NULL; + } + + return builder; +} + +#endif /* YYJSON_DISABLE_UTILS */ diff --git a/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/sources/vendor/yyjson/yyjson.h b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/sources/vendor/yyjson/yyjson.h new file mode 100644 index 0000000..5eb6d46 --- /dev/null +++ b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/sources/vendor/yyjson/yyjson.h @@ -0,0 +1,8230 @@ +/*============================================================================== + Copyright (c) 2020 YaoYuan <[email protected]> + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + *============================================================================*/ + +/** + @file yyjson.h + @date 2019-03-09 + @author YaoYuan + */ + +#ifndef YYJSON_H +#define YYJSON_H + + + +/*============================================================================== + * MARK: - Header Files + *============================================================================*/ + +#include <stdio.h> +#include <stdlib.h> +#include <stddef.h> +#include <limits.h> +#include <string.h> +#include <float.h> + + + +/*============================================================================== + * MARK: - Compile-time Options + *============================================================================*/ + +/* + Define as 1 to disable JSON reader at compile-time. + This disables functions with "read" in their name. + Reduces binary size by about 60%. + */ +#ifndef YYJSON_DISABLE_READER +#endif + +/* + Define as 1 to disable JSON writer at compile-time. + This disables functions with "write" in their name. + Reduces binary size by about 30%. + */ +#ifndef YYJSON_DISABLE_WRITER +#endif + +/* + Define as 1 to disable JSON incremental reader at compile-time. + This disables functions with "incr" in their name. + */ +#ifndef YYJSON_DISABLE_INCR_READER +#endif + +/* + Define as 1 to disable JSON Pointer, JSON Patch and JSON Merge Patch supports. + This disables functions with "ptr" or "patch" in their name. + */ +#ifndef YYJSON_DISABLE_UTILS +#endif + +/* + Define as 1 to disable the fast floating-point number conversion in yyjson. + Libc's `strtod/snprintf` will be used instead. + + This reduces binary size by about 30%, but significantly slows down the + floating-point read/write speed. + */ +#ifndef YYJSON_DISABLE_FAST_FP_CONV +#endif + +/* + Define as 1 to disable non-standard JSON features support at compile-time, + such as YYJSON_READ_ALLOW_XXX and YYJSON_WRITE_ALLOW_XXX. + + This reduces binary size by about 10%, and slightly improves performance. + */ +#ifndef YYJSON_DISABLE_NON_STANDARD +#endif + +/* + Define as 1 to disable UTF-8 validation at compile-time. + + Use this if all input strings are guaranteed to be valid UTF-8 + (e.g. language-level String types are already validated). + + Disabling UTF-8 validation improves performance for non-ASCII strings by about + 3% to 7%. + + Note: If this flag is enabled while passing illegal UTF-8 strings, + the following errors may occur: + - Escaped characters may be ignored when parsing JSON strings. + - Ending quotes may be ignored when parsing JSON strings, causing the + string to merge with the next value. + - When serializing with `yyjson_mut_val`, the string's end may be accessed + out of bounds, potentially causing a segmentation fault. + */ +#ifndef YYJSON_DISABLE_UTF8_VALIDATION +#endif + +/* + Define as 1 to improve performance on architectures that do not support + unaligned memory access. + + Normally, this does not need to be set manually. See the C file for details. + */ +#ifndef YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS +#endif + +/* Define as 1 to export symbols when building this library as a Windows DLL. */ +#ifndef YYJSON_EXPORTS +#endif + +/* Define as 1 to import symbols when using this library as a Windows DLL. */ +#ifndef YYJSON_IMPORTS +#endif + +/* Define as 1 to include <stdint.h> for compilers without C99 support. */ +#ifndef YYJSON_HAS_STDINT_H +#endif + +/* Define as 1 to include <stdbool.h> for compilers without C99 support. */ +#ifndef YYJSON_HAS_STDBOOL_H +#endif + + + +/*============================================================================== + * MARK: - Compiler Macros + *============================================================================*/ + +/** compiler version (MSVC) */ +#ifdef _MSC_VER +# define YYJSON_MSC_VER _MSC_VER +#else +# define YYJSON_MSC_VER 0 +#endif + +/** compiler version (GCC) */ +#ifdef __GNUC__ +# define YYJSON_GCC_VER __GNUC__ +# if defined(__GNUC_PATCHLEVEL__) +# define yyjson_gcc_available(major, minor, patch) \ + ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) \ + >= (major * 10000 + minor * 100 + patch)) +# else +# define yyjson_gcc_available(major, minor, patch) \ + ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100) \ + >= (major * 10000 + minor * 100 + patch)) +# endif +#else +# define YYJSON_GCC_VER 0 +# define yyjson_gcc_available(major, minor, patch) 0 +#endif + +/** real gcc check */ +#if defined(__GNUC__) && defined(__GNUC_MINOR__) && \ + !defined(__clang__) && !defined(__llvm__) && \ + !defined(__INTEL_COMPILER) && !defined(__ICC) && \ + !defined(__NVCC__) && !defined(__PGI) && !defined(__TINYC__) +# define YYJSON_IS_REAL_GCC 1 +#else +# define YYJSON_IS_REAL_GCC 0 +#endif + +/** C version (STDC) */ +#if defined(__STDC__) && (__STDC__ >= 1) && defined(__STDC_VERSION__) +# define YYJSON_STDC_VER __STDC_VERSION__ +#else +# define YYJSON_STDC_VER 0 +#endif + +/** C++ version */ +#if defined(__cplusplus) +# define YYJSON_CPP_VER __cplusplus +#else +# define YYJSON_CPP_VER 0 +#endif + +/** compiler builtin check (since gcc 10.0, clang 2.6, icc 2021) */ +#ifndef yyjson_has_builtin +# ifdef __has_builtin +# define yyjson_has_builtin(x) __has_builtin(x) +# else +# define yyjson_has_builtin(x) 0 +# endif +#endif + +/** compiler attribute check (since gcc 5.0, clang 2.9, icc 17) */ +#ifndef yyjson_has_attribute +# ifdef __has_attribute +# define yyjson_has_attribute(x) __has_attribute(x) +# else +# define yyjson_has_attribute(x) 0 +# endif +#endif + +/** compiler feature check (since clang 2.6, icc 17) */ +#ifndef yyjson_has_feature +# ifdef __has_feature +# define yyjson_has_feature(x) __has_feature(x) +# else +# define yyjson_has_feature(x) 0 +# endif +#endif + +/** include check (since gcc 5.0, clang 2.7, icc 16, msvc 2017 15.3) */ +#ifndef yyjson_has_include +# ifdef __has_include +# define yyjson_has_include(x) __has_include(x) +# else +# define yyjson_has_include(x) 0 +# endif +#endif + +/** inline for compiler */ +#ifndef yyjson_inline +# if YYJSON_MSC_VER >= 1200 +# define yyjson_inline __forceinline +# elif defined(_MSC_VER) +# define yyjson_inline __inline +# elif yyjson_has_attribute(always_inline) || YYJSON_GCC_VER >= 4 +# define yyjson_inline __inline__ __attribute__((always_inline)) +# elif defined(__clang__) || defined(__GNUC__) +# define yyjson_inline __inline__ +# elif defined(__cplusplus) || YYJSON_STDC_VER >= 199901L +# define yyjson_inline inline +# else +# define yyjson_inline +# endif +#endif + +/** noinline for compiler */ +#ifndef yyjson_noinline +# if YYJSON_MSC_VER >= 1400 +# define yyjson_noinline __declspec(noinline) +# elif yyjson_has_attribute(noinline) || YYJSON_GCC_VER >= 4 +# define yyjson_noinline __attribute__((noinline)) +# else +# define yyjson_noinline +# endif +#endif + +/** align for compiler */ +#ifndef yyjson_align +# if YYJSON_MSC_VER >= 1300 +# define yyjson_align(x) __declspec(align(x)) +# elif yyjson_has_attribute(aligned) || defined(__GNUC__) +# define yyjson_align(x) __attribute__((aligned(x))) +# elif YYJSON_CPP_VER >= 201103L +# define yyjson_align(x) alignas(x) +# else +# define yyjson_align(x) +# endif +#endif + +/** likely for compiler */ +#ifndef yyjson_likely +# if yyjson_has_builtin(__builtin_expect) || \ + (YYJSON_GCC_VER >= 4 && YYJSON_GCC_VER != 5) +# define yyjson_likely(expr) __builtin_expect(!!(expr), 1) +# else +# define yyjson_likely(expr) (expr) +# endif +#endif + +/** unlikely for compiler */ +#ifndef yyjson_unlikely +# if yyjson_has_builtin(__builtin_expect) || \ + (YYJSON_GCC_VER >= 4 && YYJSON_GCC_VER != 5) +# define yyjson_unlikely(expr) __builtin_expect(!!(expr), 0) +# else +# define yyjson_unlikely(expr) (expr) +# endif +#endif + +/** compile-time constant check for compiler */ +#ifndef yyjson_constant_p +# if yyjson_has_builtin(__builtin_constant_p) || (YYJSON_GCC_VER >= 3) +# define YYJSON_HAS_CONSTANT_P 1 +# define yyjson_constant_p(value) __builtin_constant_p(value) +# else +# define YYJSON_HAS_CONSTANT_P 0 +# define yyjson_constant_p(value) 0 +# endif +#endif + +/** deprecate warning */ +#ifndef yyjson_deprecated +# if YYJSON_MSC_VER >= 1400 +# define yyjson_deprecated(msg) __declspec(deprecated(msg)) +# elif yyjson_has_feature(attribute_deprecated_with_message) || \ + (YYJSON_GCC_VER > 4 || (YYJSON_GCC_VER == 4 && __GNUC_MINOR__ >= 5)) +# define yyjson_deprecated(msg) __attribute__((deprecated(msg))) +# elif YYJSON_GCC_VER >= 3 +# define yyjson_deprecated(msg) __attribute__((deprecated)) +# else +# define yyjson_deprecated(msg) +# endif +#endif + +/** function export */ +#ifndef yyjson_api +# if defined(_WIN32) +# if defined(YYJSON_EXPORTS) && YYJSON_EXPORTS +# define yyjson_api __declspec(dllexport) +# elif defined(YYJSON_IMPORTS) && YYJSON_IMPORTS +# define yyjson_api __declspec(dllimport) +# else +# define yyjson_api +# endif +# elif yyjson_has_attribute(visibility) || YYJSON_GCC_VER >= 4 +# define yyjson_api __attribute__((visibility("default"))) +# else +# define yyjson_api +# endif +#endif + +/** inline function export */ +#ifndef yyjson_api_inline +# define yyjson_api_inline static yyjson_inline +#endif + +/** stdint (C89 compatible) */ +#if (defined(YYJSON_HAS_STDINT_H) && YYJSON_HAS_STDINT_H) || \ + YYJSON_MSC_VER >= 1600 || YYJSON_STDC_VER >= 199901L || \ + defined(_STDINT_H) || defined(_STDINT_H_) || \ + defined(__CLANG_STDINT_H) || defined(_STDINT_H_INCLUDED) || \ + yyjson_has_include(<stdint.h>) +# include <stdint.h> +#elif defined(_MSC_VER) +# if _MSC_VER < 1300 + typedef signed char int8_t; + typedef signed short int16_t; + typedef signed int int32_t; + typedef unsigned char uint8_t; + typedef unsigned short uint16_t; + typedef unsigned int uint32_t; + typedef signed __int64 int64_t; + typedef unsigned __int64 uint64_t; +# else + typedef signed __int8 int8_t; + typedef signed __int16 int16_t; + typedef signed __int32 int32_t; + typedef unsigned __int8 uint8_t; + typedef unsigned __int16 uint16_t; + typedef unsigned __int32 uint32_t; + typedef signed __int64 int64_t; + typedef unsigned __int64 uint64_t; +# endif +#else +# if UCHAR_MAX == 0xFFU + typedef signed char int8_t; + typedef unsigned char uint8_t; +# else +# error cannot find 8-bit integer type +# endif +# if USHRT_MAX == 0xFFFFU + typedef unsigned short uint16_t; + typedef signed short int16_t; +# elif UINT_MAX == 0xFFFFU + typedef unsigned int uint16_t; + typedef signed int int16_t; +# else +# error cannot find 16-bit integer type +# endif +# if UINT_MAX == 0xFFFFFFFFUL + typedef unsigned int uint32_t; + typedef signed int int32_t; +# elif ULONG_MAX == 0xFFFFFFFFUL + typedef unsigned long uint32_t; + typedef signed long int32_t; +# elif USHRT_MAX == 0xFFFFFFFFUL + typedef unsigned short uint32_t; + typedef signed short int32_t; +# else +# error cannot find 32-bit integer type +# endif +# if defined(__INT64_TYPE__) && defined(__UINT64_TYPE__) + typedef __INT64_TYPE__ int64_t; + typedef __UINT64_TYPE__ uint64_t; +# elif defined(__GNUC__) || defined(__clang__) +# if !defined(_SYS_TYPES_H) && !defined(__int8_t_defined) + __extension__ typedef long long int64_t; +# endif + __extension__ typedef unsigned long long uint64_t; +# elif defined(_LONG_LONG) || defined(__MWERKS__) || defined(_CRAYC) || \ + defined(__SUNPRO_C) || defined(__SUNPRO_CC) + typedef long long int64_t; + typedef unsigned long long uint64_t; +# elif (defined(__BORLANDC__) && __BORLANDC__ > 0x460) || \ + defined(__WATCOM_INT64__) || defined (__alpha) || defined (__DECC) + typedef __int64 int64_t; + typedef unsigned __int64 uint64_t; +# else +# error cannot find 64-bit integer type +# endif +#endif + +/** stdbool (C89 compatible) */ +#if (defined(YYJSON_HAS_STDBOOL_H) && YYJSON_HAS_STDBOOL_H) || \ + (yyjson_has_include(<stdbool.h>) && !defined(__STRICT_ANSI__)) || \ + YYJSON_MSC_VER >= 1800 || YYJSON_STDC_VER >= 199901L +# include <stdbool.h> +#elif !defined(__bool_true_false_are_defined) +# define __bool_true_false_are_defined 1 +# if defined(__cplusplus) +# if defined(__GNUC__) && !defined(__STRICT_ANSI__) +# define _Bool bool +# if __cplusplus < 201103L +# define bool bool +# define false false +# define true true +# endif +# endif +# else +# define bool unsigned char +# define true 1 +# define false 0 +# endif +#endif + +/** char bit check */ +#if defined(CHAR_BIT) +# if CHAR_BIT != 8 +# error non 8-bit char is not supported +# endif +#endif + +/** + Microsoft Visual C++ 6.0 doesn't support converting number from u64 to f64: + error C2520: conversion from unsigned __int64 to double not implemented. + */ +#ifndef YYJSON_U64_TO_F64_NO_IMPL +# if (0 < YYJSON_MSC_VER) && (YYJSON_MSC_VER <= 1200) +# define YYJSON_U64_TO_F64_NO_IMPL 1 +# else +# define YYJSON_U64_TO_F64_NO_IMPL 0 +# endif +#endif + + + +/*============================================================================== + * MARK: - Compile Hint Begin + *============================================================================*/ + +/* extern "C" begin */ +#ifdef __cplusplus +extern "C" { +#endif + +/* warning suppress begin */ +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wunused-function" +# pragma clang diagnostic ignored "-Wunused-parameter" +#elif defined(__GNUC__) +# if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) +# pragma GCC diagnostic push +# endif +# pragma GCC diagnostic ignored "-Wunused-function" +# pragma GCC diagnostic ignored "-Wunused-parameter" +#elif defined(_MSC_VER) +# pragma warning(push) +# pragma warning(disable:4800) /* 'int': forcing value to 'true' or 'false' */ +#endif + + + +/*============================================================================== + * MARK: - Version + *============================================================================*/ + +/** The major version of yyjson. */ +#define YYJSON_VERSION_MAJOR 0 + +/** The minor version of yyjson. */ +#define YYJSON_VERSION_MINOR 12 + +/** The patch version of yyjson. */ +#define YYJSON_VERSION_PATCH 0 + +/** The version of yyjson in hex: `(major << 16) | (minor << 8) | (patch)`. */ +#define YYJSON_VERSION_HEX 0x000C00 + +/** The version string of yyjson. */ +#define YYJSON_VERSION_STRING "0.12.0" + +/** The version of yyjson in hex, same as `YYJSON_VERSION_HEX`. */ +yyjson_api uint32_t yyjson_version(void); + + + +/*============================================================================== + * MARK: - JSON Types + *============================================================================*/ + +/** Type of a JSON value (3 bit). */ +typedef uint8_t yyjson_type; +/** No type, invalid. */ +#define YYJSON_TYPE_NONE ((uint8_t)0) /* _____000 */ +/** Raw string type, no subtype. */ +#define YYJSON_TYPE_RAW ((uint8_t)1) /* _____001 */ +/** Null type: `null` literal, no subtype. */ +#define YYJSON_TYPE_NULL ((uint8_t)2) /* _____010 */ +/** Boolean type, subtype: TRUE, FALSE. */ +#define YYJSON_TYPE_BOOL ((uint8_t)3) /* _____011 */ +/** Number type, subtype: UINT, SINT, REAL. */ +#define YYJSON_TYPE_NUM ((uint8_t)4) /* _____100 */ +/** String type, subtype: NONE, NOESC. */ +#define YYJSON_TYPE_STR ((uint8_t)5) /* _____101 */ +/** Array type, no subtype. */ +#define YYJSON_TYPE_ARR ((uint8_t)6) /* _____110 */ +/** Object type, no subtype. */ +#define YYJSON_TYPE_OBJ ((uint8_t)7) /* _____111 */ + +/** Subtype of a JSON value (2 bit). */ +typedef uint8_t yyjson_subtype; +/** No subtype. */ +#define YYJSON_SUBTYPE_NONE ((uint8_t)(0 << 3)) /* ___00___ */ +/** False subtype: `false` literal. */ +#define YYJSON_SUBTYPE_FALSE ((uint8_t)(0 << 3)) /* ___00___ */ +/** True subtype: `true` literal. */ +#define YYJSON_SUBTYPE_TRUE ((uint8_t)(1 << 3)) /* ___01___ */ +/** Unsigned integer subtype: `uint64_t`. */ +#define YYJSON_SUBTYPE_UINT ((uint8_t)(0 << 3)) /* ___00___ */ +/** Signed integer subtype: `int64_t`. */ +#define YYJSON_SUBTYPE_SINT ((uint8_t)(1 << 3)) /* ___01___ */ +/** Real number subtype: `double`. */ +#define YYJSON_SUBTYPE_REAL ((uint8_t)(2 << 3)) /* ___10___ */ +/** String that do not need to be escaped for writing (internal use). */ +#define YYJSON_SUBTYPE_NOESC ((uint8_t)(1 << 3)) /* ___01___ */ + +/** The mask used to extract the type of a JSON value. */ +#define YYJSON_TYPE_MASK ((uint8_t)0x07) /* _____111 */ +/** The number of bits used by the type. */ +#define YYJSON_TYPE_BIT ((uint8_t)3) +/** The mask used to extract the subtype of a JSON value. */ +#define YYJSON_SUBTYPE_MASK ((uint8_t)0x18) /* ___11___ */ +/** The number of bits used by the subtype. */ +#define YYJSON_SUBTYPE_BIT ((uint8_t)2) +/** The mask used to extract the reserved bits of a JSON value. */ +#define YYJSON_RESERVED_MASK ((uint8_t)0xE0) /* 111_____ */ +/** The number of reserved bits. */ +#define YYJSON_RESERVED_BIT ((uint8_t)3) +/** The mask used to extract the tag of a JSON value. */ +#define YYJSON_TAG_MASK ((uint8_t)0xFF) /* 11111111 */ +/** The number of bits used by the tag. */ +#define YYJSON_TAG_BIT ((uint8_t)8) + +/** Padding size for JSON reader. */ +#define YYJSON_PADDING_SIZE 4 + + + +/*============================================================================== + * MARK: - Allocator + *============================================================================*/ + +/** + A memory allocator. + + Typically you don't need to use it, unless you want to customize your own + memory allocator. + */ +typedef struct yyjson_alc { + /** Same as libc's malloc(size), should not be NULL. */ + void *(*malloc)(void *ctx, size_t size); + /** Same as libc's realloc(ptr, size), should not be NULL. */ + void *(*realloc)(void *ctx, void *ptr, size_t old_size, size_t size); + /** Same as libc's free(ptr), should not be NULL. */ + void (*free)(void *ctx, void *ptr); + /** A context for malloc/realloc/free, can be NULL. */ + void *ctx; +} yyjson_alc; + +/** + A pool allocator uses fixed length pre-allocated memory. + + This allocator may be used to avoid malloc/realloc calls. The pre-allocated + memory should be held by the caller. The maximum amount of memory required to + read a JSON can be calculated using the `yyjson_read_max_memory_usage()` + function, but the amount of memory required to write a JSON cannot be directly + calculated. + + This is not a general-purpose allocator. It is designed to handle a single JSON + data at a time. If it is used for overly complex memory tasks, such as parsing + multiple JSON documents using the same allocator but releasing only a few of + them, it may cause memory fragmentation, resulting in performance degradation + and memory waste. + + @param alc The allocator to be initialized. + If this parameter is NULL, the function will fail and return false. + If `buf` or `size` is invalid, this will be set to an empty allocator. + @param buf The buffer memory for this allocator. + If this parameter is NULL, the function will fail and return false. + @param size The size of `buf`, in bytes. + If this parameter is less than 8 words (32/64 bytes on 32/64-bit OS), the + function will fail and return false. + @return true if the `alc` has been successfully initialized. + + @b Example + @code + // parse JSON with stack memory + char buf[1024]; + yyjson_alc alc; + yyjson_alc_pool_init(&alc, buf, 1024); + + const char *json = "{\"name\":\"Helvetica\",\"size\":16}" + yyjson_doc *doc = yyjson_read_opts(json, strlen(json), 0, &alc, NULL); + // the memory of `doc` is on the stack + @endcode + + @warning This Allocator is not thread-safe. + */ +yyjson_api bool yyjson_alc_pool_init(yyjson_alc *alc, void *buf, size_t size); + +/** + A dynamic allocator. + + This allocator has a similar usage to the pool allocator above. However, when + there is not enough memory, this allocator will dynamically request more memory + using libc's `malloc` function, and frees it all at once when it is destroyed. + + @return A new dynamic allocator, or NULL if memory allocation failed. + @note The returned value should be freed with `yyjson_alc_dyn_free()`. + + @warning This Allocator is not thread-safe. + */ +yyjson_api yyjson_alc *yyjson_alc_dyn_new(void); + +/** + Free a dynamic allocator which is created by `yyjson_alc_dyn_new()`. + @param alc The dynamic allocator to be destroyed. + */ +yyjson_api void yyjson_alc_dyn_free(yyjson_alc *alc); + + + +/*============================================================================== + * MARK: - Text Locating + *============================================================================*/ + +/** + Locate the line and column number for a byte position in a string. + This can be used to get better description for error position. + + @param str The input string. + @param len The byte length of the input string. + @param pos The byte position within the input string. + @param line A pointer to receive the line number, starting from 1. + @param col A pointer to receive the column number, starting from 1. + @param chr A pointer to receive the character index, starting from 0. + @return true on success, false if `str` is NULL or `pos` is out of bounds. + @note Line/column/character are calculated based on Unicode characters for + compatibility with text editors. For multi-byte UTF-8 characters, + the returned value may not directly correspond to the byte position. + */ +yyjson_api bool yyjson_locate_pos(const char *str, size_t len, size_t pos, + size_t *line, size_t *col, size_t *chr); + + + +/*============================================================================== + * MARK: - JSON Structure + *============================================================================*/ + +/** + An immutable document for reading JSON. + This document holds memory for all its JSON values and strings. When it is no + longer used, the user should call `yyjson_doc_free()` to free its memory. + */ +typedef struct yyjson_doc yyjson_doc; + +/** + An immutable value for reading JSON. + A JSON Value has the same lifetime as its document. The memory is held by its + document and and cannot be freed alone. + */ +typedef struct yyjson_val yyjson_val; + +/** + A mutable document for building JSON. + This document holds memory for all its JSON values and strings. When it is no + longer used, the user should call `yyjson_mut_doc_free()` to free its memory. + */ +typedef struct yyjson_mut_doc yyjson_mut_doc; + +/** + A mutable value for building JSON. + A JSON Value has the same lifetime as its document. The memory is held by its + document and and cannot be freed alone. + */ +typedef struct yyjson_mut_val yyjson_mut_val; + + + +/*============================================================================== + * MARK: - JSON Reader API + *============================================================================*/ + +/** Run-time options for JSON reader. */ +typedef uint32_t yyjson_read_flag; + +/** Default option (RFC 8259 compliant): + - Read positive integer as uint64_t. + - Read negative integer as int64_t. + - Read floating-point number as double with round-to-nearest mode. + - Read integer which cannot fit in uint64_t or int64_t as double. + - Report error if double number is infinity. + - Report error if string contains invalid UTF-8 character or BOM. + - Report error on trailing commas, comments, inf and nan literals. */ +static const yyjson_read_flag YYJSON_READ_NOFLAG = 0; + +/** Read the input data in-situ. + This option allows the reader to modify and use input data to store string + values, which can increase reading speed slightly. + The caller should hold the input data before free the document. + The input data must be padded by at least `YYJSON_PADDING_SIZE` bytes. + For example: `[1,2]` should be `[1,2]\0\0\0\0`, input length should be 5. */ +static const yyjson_read_flag YYJSON_READ_INSITU = 1 << 0; + +/** Stop when done instead of issuing an error if there's additional content + after a JSON document. This option may be used to parse small pieces of JSON + in larger data, such as `NDJSON`. */ +static const yyjson_read_flag YYJSON_READ_STOP_WHEN_DONE = 1 << 1; + +/** Allow single trailing comma at the end of an object or array, + such as `[1,2,3,]`, `{"a":1,"b":2,}` (non-standard). */ +static const yyjson_read_flag YYJSON_READ_ALLOW_TRAILING_COMMAS = 1 << 2; + +/** Allow C-style single-line and mult-line comments (non-standard). */ +static const yyjson_read_flag YYJSON_READ_ALLOW_COMMENTS = 1 << 3; + +/** Allow inf/nan number and literal, case-insensitive, + such as 1e999, NaN, inf, -Infinity (non-standard). */ +static const yyjson_read_flag YYJSON_READ_ALLOW_INF_AND_NAN = 1 << 4; + +/** Read all numbers as raw strings (value with `YYJSON_TYPE_RAW` type), + inf/nan literal is also read as raw with `ALLOW_INF_AND_NAN` flag. */ +static const yyjson_read_flag YYJSON_READ_NUMBER_AS_RAW = 1 << 5; + +/** Allow reading invalid unicode when parsing string values (non-standard). + Invalid characters will be allowed to appear in the string values, but + invalid escape sequences will still be reported as errors. + This flag does not affect the performance of correctly encoded strings. + + @warning Strings in JSON values may contain incorrect encoding when this + option is used, you need to handle these strings carefully to avoid security + risks. */ +static const yyjson_read_flag YYJSON_READ_ALLOW_INVALID_UNICODE = 1 << 6; + +/** Read big numbers as raw strings. These big numbers include integers that + cannot be represented by `int64_t` and `uint64_t`, and floating-point + numbers that cannot be represented by finite `double`. + The flag will be overridden by `YYJSON_READ_NUMBER_AS_RAW` flag. */ +static const yyjson_read_flag YYJSON_READ_BIGNUM_AS_RAW = 1 << 7; + +/** Allow UTF-8 BOM and skip it before parsing if any (non-standard). */ +static const yyjson_read_flag YYJSON_READ_ALLOW_BOM = 1 << 8; + +/** Allow extended number formats (non-standard): + - Hexadecimal numbers, such as `0x7B`. + - Numbers with leading or trailing decimal point, such as `.123`, `123.`. + - Numbers with a leading plus sign, such as `+123`. */ +static const yyjson_read_flag YYJSON_READ_ALLOW_EXT_NUMBER = 1 << 9; + +/** Allow extended escape sequences in strings (non-standard): + - Additional escapes: `\a`, `\e`, `\v`, ``\'``, `\?`, `\0`. + - Hex escapes: `\xNN`, such as `\x7B`. + - Line continuation: backslash followed by line terminator sequences. + - Unknown escape: if backslash is followed by an unsupported character, + the backslash will be removed and the character will be kept as-is. + However, `\1`-`\9` will still trigger an error. */ +static const yyjson_read_flag YYJSON_READ_ALLOW_EXT_ESCAPE = 1 << 10; + +/** Allow extended whitespace characters (non-standard): + - Vertical tab `\v` and form feed `\f`. + - Line separator `\u2028` and paragraph separator `\u2029`. + - Non-breaking space `\xA0`. + - Byte order mark: `\uFEFF`. + - Other Unicode characters in the Zs (Separator, space) category. */ +static const yyjson_read_flag YYJSON_READ_ALLOW_EXT_WHITESPACE = 1 << 11; + +/** Allow strings enclosed in single quotes (non-standard), such as ``'ab'``. */ +static const yyjson_read_flag YYJSON_READ_ALLOW_SINGLE_QUOTED_STR = 1 << 12; + +/** Allow object keys without quotes (non-standard), such as `{a:1,b:2}`. + This extends the ECMAScript IdentifierName rule by allowing any + non-whitespace character with code point above `U+007F`. */ +static const yyjson_read_flag YYJSON_READ_ALLOW_UNQUOTED_KEY = 1 << 13; + +/** Allow JSON5 format, see: [https://json5.org]. + This flag supports all JSON5 features with some additional extensions: + - Accepts more escape sequences than JSON5 (e.g. `\a`, `\e`). + - Unquoted keys are not limited to ECMAScript IdentifierName. + - Allow case-insensitive `NaN`, `Inf` and `Infinity` literals. */ +static const yyjson_read_flag YYJSON_READ_JSON5 = + (1 << 2) | /* YYJSON_READ_ALLOW_TRAILING_COMMAS */ + (1 << 3) | /* YYJSON_READ_ALLOW_COMMENTS */ + (1 << 4) | /* YYJSON_READ_ALLOW_INF_AND_NAN */ + (1 << 9) | /* YYJSON_READ_ALLOW_EXT_NUMBER */ + (1 << 10) | /* YYJSON_READ_ALLOW_EXT_ESCAPE */ + (1 << 11) | /* YYJSON_READ_ALLOW_EXT_WHITESPACE */ + (1 << 12) | /* YYJSON_READ_ALLOW_SINGLE_QUOTED_STR */ + (1 << 13); /* YYJSON_READ_ALLOW_UNQUOTED_KEY */ + + + +/** Result code for JSON reader. */ +typedef uint32_t yyjson_read_code; + +/** Success, no error. */ +static const yyjson_read_code YYJSON_READ_SUCCESS = 0; + +/** Invalid parameter, such as NULL input string or 0 input length. */ +static const yyjson_read_code YYJSON_READ_ERROR_INVALID_PARAMETER = 1; + +/** Memory allocation failed. */ +static const yyjson_read_code YYJSON_READ_ERROR_MEMORY_ALLOCATION = 2; + +/** Input JSON string is empty. */ +static const yyjson_read_code YYJSON_READ_ERROR_EMPTY_CONTENT = 3; + +/** Unexpected content after document, such as `[123]abc`. */ +static const yyjson_read_code YYJSON_READ_ERROR_UNEXPECTED_CONTENT = 4; + +/** Unexpected end of input, the parsed part is valid, such as `[123`. */ +static const yyjson_read_code YYJSON_READ_ERROR_UNEXPECTED_END = 5; + +/** Unexpected character inside the document, such as `[abc]`. */ +static const yyjson_read_code YYJSON_READ_ERROR_UNEXPECTED_CHARACTER = 6; + +/** Invalid JSON structure, such as `[1,]`. */ +static const yyjson_read_code YYJSON_READ_ERROR_JSON_STRUCTURE = 7; + +/** Invalid comment, deprecated, use `UNEXPECTED_END` for unclosed comment. */ +static const yyjson_read_code YYJSON_READ_ERROR_INVALID_COMMENT = 8; + +/** Invalid number, such as `123.e12`, `000`. */ +static const yyjson_read_code YYJSON_READ_ERROR_INVALID_NUMBER = 9; + +/** Invalid string, such as invalid escaped character inside a string. */ +static const yyjson_read_code YYJSON_READ_ERROR_INVALID_STRING = 10; + +/** Invalid JSON literal, such as `truu`. */ +static const yyjson_read_code YYJSON_READ_ERROR_LITERAL = 11; + +/** Failed to open a file. */ +static const yyjson_read_code YYJSON_READ_ERROR_FILE_OPEN = 12; + +/** Failed to read a file. */ +static const yyjson_read_code YYJSON_READ_ERROR_FILE_READ = 13; + +/** Incomplete input during incremental parsing; parsing state is preserved. */ +static const yyjson_read_code YYJSON_READ_ERROR_MORE = 14; + +/** Error information for JSON reader. */ +typedef struct yyjson_read_err { + /** Error code, see `yyjson_read_code` for all possible values. */ + yyjson_read_code code; + /** Error message, constant, no need to free (NULL if success). */ + const char *msg; + /** Error byte position for input data (0 if success). */ + size_t pos; +} yyjson_read_err; + + + +#if !defined(YYJSON_DISABLE_READER) || !YYJSON_DISABLE_READER + +/** + Read JSON with options. + + This function is thread-safe when: + 1. The `dat` is not modified by other threads. + 2. The `alc` is thread-safe or NULL. + + @param dat The JSON data (UTF-8 without BOM), null-terminator is not required. + If this parameter is NULL, the function will fail and return NULL. + The `dat` will not be modified without the flag `YYJSON_READ_INSITU`, so you + can pass a `const char *` string and case it to `char *` if you don't use + the `YYJSON_READ_INSITU` flag. + @param len The length of JSON data in bytes. + If this parameter is 0, the function will fail and return NULL. + @param flg The JSON read options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON reader. + Pass NULL to use the libc's default allocator. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return A new JSON document, or NULL if an error occurs. + When it's no longer needed, it should be freed with `yyjson_doc_free()`. + */ +yyjson_api yyjson_doc *yyjson_read_opts(char *dat, + size_t len, + yyjson_read_flag flg, + const yyjson_alc *alc, + yyjson_read_err *err); + +/** + Read a JSON file. + + This function is thread-safe when: + 1. The file is not modified by other threads. + 2. The `alc` is thread-safe or NULL. + + @param path The JSON file's path. + This should be a null-terminated string using the system's native encoding. + If this path is NULL or invalid, the function will fail and return NULL. + @param flg The JSON read options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON reader. + Pass NULL to use the libc's default allocator. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return A new JSON document, or NULL if an error occurs. + When it's no longer needed, it should be freed with `yyjson_doc_free()`. + + @warning On 32-bit operating system, files larger than 2GB may fail to read. + */ +yyjson_api yyjson_doc *yyjson_read_file(const char *path, + yyjson_read_flag flg, + const yyjson_alc *alc, + yyjson_read_err *err); + +/** + Read JSON from a file pointer. + + @param fp The file pointer. + The data will be read from the current position of the FILE to the end. + If this fp is NULL or invalid, the function will fail and return NULL. + @param flg The JSON read options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON reader. + Pass NULL to use the libc's default allocator. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return A new JSON document, or NULL if an error occurs. + When it's no longer needed, it should be freed with `yyjson_doc_free()`. + + @warning On 32-bit operating system, files larger than 2GB may fail to read. + */ +yyjson_api yyjson_doc *yyjson_read_fp(FILE *fp, + yyjson_read_flag flg, + const yyjson_alc *alc, + yyjson_read_err *err); + +/** + Read a JSON string. + + This function is thread-safe. + + @param dat The JSON data (UTF-8 without BOM), null-terminator is not required. + If this parameter is NULL, the function will fail and return NULL. + @param len The length of JSON data in bytes. + If this parameter is 0, the function will fail and return NULL. + @param flg The JSON read options. + Multiple options can be combined with `|` operator. 0 means no options. + @return A new JSON document, or NULL if an error occurs. + When it's no longer needed, it should be freed with `yyjson_doc_free()`. + */ +yyjson_api_inline yyjson_doc *yyjson_read(const char *dat, + size_t len, + yyjson_read_flag flg) { + flg &= ~YYJSON_READ_INSITU; /* const string cannot be modified */ + return yyjson_read_opts((char *)(void *)(size_t)(const void *)dat, + len, flg, NULL, NULL); +} + + + +#if !defined(YYJSON_DISABLE_INCR_READER) || !YYJSON_DISABLE_INCR_READER + +/** Opaque state for incremental JSON reader. */ +typedef struct yyjson_incr_state yyjson_incr_state; + +/** + Initialize state for incremental read. + + To read a large JSON document incrementally: + 1. Call `yyjson_incr_new()` to create the state for incremental reading. + 2. Call `yyjson_incr_read()` repeatedly. + 3. Call `yyjson_incr_free()` to free the state. + + Note: The incremental JSON reader only supports standard JSON. + Flags for non-standard features (e.g. comments, trailing commas) are ignored. + + @param buf The JSON data, null-terminator is not required. + If this parameter is NULL, the function will fail and return NULL. + @param buf_len The length of the JSON data in `buf`. + If use `YYJSON_READ_INSITU`, `buf_len` should not include the padding size. + @param flg The JSON read options. + Multiple options can be combined with `|` operator. + @param alc The memory allocator used by JSON reader. + Pass NULL to use the libc's default allocator. + @return A state for incremental reading. + It should be freed with `yyjson_incr_free()`. + NULL is returned if memory allocation fails. +*/ +yyjson_api yyjson_incr_state *yyjson_incr_new(char *buf, size_t buf_len, + yyjson_read_flag flg, + const yyjson_alc *alc); + +/** + Performs incremental read of up to `len` bytes. + + If NULL is returned and `err->code` is set to `YYJSON_READ_ERROR_MORE`, it + indicates that more data is required to continue parsing. Then, call this + function again with incremented `len`. Continue until a document is returned or + an error other than `YYJSON_READ_ERROR_MORE` is returned. + + Note: Parsing in very small increments is not efficient. An increment of + several kilobytes or megabytes is recommended. + + @param state The state for incremental reading, created using + `yyjson_incr_new()`. + @param len The number of bytes of JSON data available to parse. + If this parameter is 0, the function will fail and return NULL. + @param err A pointer to receive error information. + @return A new JSON document, or NULL if an error occurs. + When the document is no longer needed, it should be freed with + `yyjson_doc_free()`. +*/ +yyjson_api yyjson_doc *yyjson_incr_read(yyjson_incr_state *state, size_t len, + yyjson_read_err *err); + +/** Release the incremental read state and free the memory. */ +yyjson_api void yyjson_incr_free(yyjson_incr_state *state); + +#endif /* YYJSON_DISABLE_INCR_READER */ + +/** + Returns the size of maximum memory usage to read a JSON data. + + You may use this value to avoid malloc() or calloc() call inside the reader + to get better performance, or read multiple JSON with one piece of memory. + + @param len The length of JSON data in bytes. + @param flg The JSON read options. + @return The maximum memory size to read this JSON, or 0 if overflow. + + @b Example + @code + // read multiple JSON with same pre-allocated memory + + char *dat1, *dat2, *dat3; // JSON data + size_t len1, len2, len3; // JSON length + size_t max_len = MAX(len1, MAX(len2, len3)); + yyjson_doc *doc; + + // use one allocator for multiple JSON + size_t size = yyjson_read_max_memory_usage(max_len, 0); + void *buf = malloc(size); + yyjson_alc alc; + yyjson_alc_pool_init(&alc, buf, size); + + // no more alloc() or realloc() call during reading + doc = yyjson_read_opts(dat1, len1, 0, &alc, NULL); + yyjson_doc_free(doc); + doc = yyjson_read_opts(dat2, len2, 0, &alc, NULL); + yyjson_doc_free(doc); + doc = yyjson_read_opts(dat3, len3, 0, &alc, NULL); + yyjson_doc_free(doc); + + free(buf); + @endcode + @see yyjson_alc_pool_init() + */ +yyjson_api_inline size_t yyjson_read_max_memory_usage(size_t len, + yyjson_read_flag flg) { + /* + 1. The max value count is (json_size / 2 + 1), + for example: "[1,2,3,4]" size is 9, value count is 5. + 2. Some broken JSON may cost more memory during reading, but fail at end, + for example: "[[[[[[[[". + 3. yyjson use 16 bytes per value, see struct yyjson_val. + 4. yyjson use dynamic memory with a growth factor of 1.5. + + The max memory size is (json_size / 2 * 16 * 1.5 + padding). + */ + size_t mul = (size_t)12 + !(flg & YYJSON_READ_INSITU); + size_t pad = 256; + size_t max = (size_t)(~(size_t)0); + if (flg & YYJSON_READ_STOP_WHEN_DONE) len = len < 256 ? 256 : len; + if (len >= (max - pad - mul) / mul) return 0; + return len * mul + pad; +} + +/** + Read a JSON number. + + This function is thread-safe when data is not modified by other threads. + + @param dat The JSON data (UTF-8 without BOM), null-terminator is required. + If this parameter is NULL, the function will fail and return NULL. + @param val The output value where result is stored. + If this parameter is NULL, the function will fail and return NULL. + The value will hold either UINT or SINT or REAL number; + @param flg The JSON read options. + Multiple options can be combined with `|` operator. 0 means no options. + Supports `YYJSON_READ_NUMBER_AS_RAW` and `YYJSON_READ_ALLOW_INF_AND_NAN`. + @param alc The memory allocator used for long number. + It is only used when the built-in floating point reader is disabled. + Pass NULL to use the libc's default allocator. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return If successful, a pointer to the character after the last character + used in the conversion, NULL if an error occurs. + */ +yyjson_api const char *yyjson_read_number(const char *dat, + yyjson_val *val, + yyjson_read_flag flg, + const yyjson_alc *alc, + yyjson_read_err *err); + +/** Same as `yyjson_read_number()`. */ +yyjson_api_inline const char *yyjson_mut_read_number(const char *dat, + yyjson_mut_val *val, + yyjson_read_flag flg, + const yyjson_alc *alc, + yyjson_read_err *err) { + return yyjson_read_number(dat, (yyjson_val *)val, flg, alc, err); +} + +#endif /* YYJSON_DISABLE_READER) */ + + + +/*============================================================================== + * MARK: - JSON Writer API + *============================================================================*/ + +/** Run-time options for JSON writer. */ +typedef uint32_t yyjson_write_flag; + +/** Default option: + - Write JSON minify. + - Report error on inf or nan number. + - Report error on invalid UTF-8 string. + - Do not escape unicode or slash. */ +static const yyjson_write_flag YYJSON_WRITE_NOFLAG = 0; + +/** Write JSON pretty with 4 space indent. */ +static const yyjson_write_flag YYJSON_WRITE_PRETTY = 1 << 0; + +/** Escape unicode as `uXXXX`, make the output ASCII only. */ +static const yyjson_write_flag YYJSON_WRITE_ESCAPE_UNICODE = 1 << 1; + +/** Escape '/' as '\/'. */ +static const yyjson_write_flag YYJSON_WRITE_ESCAPE_SLASHES = 1 << 2; + +/** Write inf and nan number as 'Infinity' and 'NaN' literal (non-standard). */ +static const yyjson_write_flag YYJSON_WRITE_ALLOW_INF_AND_NAN = 1 << 3; + +/** Write inf and nan number as null literal. + This flag will override `YYJSON_WRITE_ALLOW_INF_AND_NAN` flag. */ +static const yyjson_write_flag YYJSON_WRITE_INF_AND_NAN_AS_NULL = 1 << 4; + +/** Allow invalid unicode when encoding string values (non-standard). + Invalid characters in string value will be copied byte by byte. + If `YYJSON_WRITE_ESCAPE_UNICODE` flag is also set, invalid character will be + escaped as `U+FFFD` (replacement character). + This flag does not affect the performance of correctly encoded strings. */ +static const yyjson_write_flag YYJSON_WRITE_ALLOW_INVALID_UNICODE = 1 << 5; + +/** Write JSON pretty with 2 space indent. + This flag will override `YYJSON_WRITE_PRETTY` flag. */ +static const yyjson_write_flag YYJSON_WRITE_PRETTY_TWO_SPACES = 1 << 6; + +/** Adds a newline character `\n` at the end of the JSON. + This can be helpful for text editors or NDJSON. */ +static const yyjson_write_flag YYJSON_WRITE_NEWLINE_AT_END = 1 << 7; + + + +/** The highest 8 bits of `yyjson_write_flag` and real number value's `tag` + are reserved for controlling the output format of floating-point numbers. */ +#define YYJSON_WRITE_FP_FLAG_BITS 8 + +/** The highest 4 bits of flag are reserved for precision value. */ +#define YYJSON_WRITE_FP_PREC_BITS 4 + +/** Write floating-point number using fixed-point notation. + - This is similar to ECMAScript `Number.prototype.toFixed(prec)`, + but with trailing zeros removed. The `prec` ranges from 1 to 15. + - This will produce shorter output but may lose some precision. */ +#define YYJSON_WRITE_FP_TO_FIXED(prec) ((yyjson_write_flag)( \ + (uint32_t)((uint32_t)(prec)) << (32 - 4) )) + +/** Write floating-point numbers using single-precision (float). + - This casts `double` to `float` before serialization. + - This will produce shorter output, but may lose some precision. + - This flag is ignored if `YYJSON_WRITE_FP_TO_FIXED(prec)` is also used. */ +#define YYJSON_WRITE_FP_TO_FLOAT ((yyjson_write_flag)(1 << (32 - 5))) + + + +/** Result code for JSON writer */ +typedef uint32_t yyjson_write_code; + +/** Success, no error. */ +static const yyjson_write_code YYJSON_WRITE_SUCCESS = 0; + +/** Invalid parameter, such as NULL document. */ +static const yyjson_write_code YYJSON_WRITE_ERROR_INVALID_PARAMETER = 1; + +/** Memory allocation failure occurs. */ +static const yyjson_write_code YYJSON_WRITE_ERROR_MEMORY_ALLOCATION = 2; + +/** Invalid value type in JSON document. */ +static const yyjson_write_code YYJSON_WRITE_ERROR_INVALID_VALUE_TYPE = 3; + +/** NaN or Infinity number occurs. */ +static const yyjson_write_code YYJSON_WRITE_ERROR_NAN_OR_INF = 4; + +/** Failed to open a file. */ +static const yyjson_write_code YYJSON_WRITE_ERROR_FILE_OPEN = 5; + +/** Failed to write a file. */ +static const yyjson_write_code YYJSON_WRITE_ERROR_FILE_WRITE = 6; + +/** Invalid unicode in string. */ +static const yyjson_write_code YYJSON_WRITE_ERROR_INVALID_STRING = 7; + +/** Error information for JSON writer. */ +typedef struct yyjson_write_err { + /** Error code, see `yyjson_write_code` for all possible values. */ + yyjson_write_code code; + /** Error message, constant, no need to free (NULL if success). */ + const char *msg; +} yyjson_write_err; + + + +#if !defined(YYJSON_DISABLE_WRITER) || !YYJSON_DISABLE_WRITER + +/*============================================================================== + * MARK: - JSON Document Writer API + *============================================================================*/ + +/** + Write a document to JSON string with options. + + This function is thread-safe when: + The `alc` is thread-safe or NULL. + + @param doc The JSON document. + If this doc is NULL or has no root, the function will fail and return false. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON writer. + Pass NULL to use the libc's default allocator. + @param len A pointer to receive output length in bytes (not including the + null-terminator). Pass NULL if you don't need length information. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return A new JSON string, or NULL if an error occurs. + This string is encoded as UTF-8 with a null-terminator. + When it's no longer needed, it should be freed with free() or alc->free(). + */ +yyjson_api char *yyjson_write_opts(const yyjson_doc *doc, + yyjson_write_flag flg, + const yyjson_alc *alc, + size_t *len, + yyjson_write_err *err); + +/** + Write a document to JSON file with options. + + This function is thread-safe when: + 1. The file is not accessed by other threads. + 2. The `alc` is thread-safe or NULL. + + @param path The JSON file's path. + This should be a null-terminated string using the system's native encoding. + If this path is NULL or invalid, the function will fail and return false. + If this file is not empty, the content will be discarded. + @param doc The JSON document. + If this doc is NULL or has no root, the function will fail and return false. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON writer. + Pass NULL to use the libc's default allocator. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return true if successful, false if an error occurs. + + @warning On 32-bit operating system, files larger than 2GB may fail to write. + */ +yyjson_api bool yyjson_write_file(const char *path, + const yyjson_doc *doc, + yyjson_write_flag flg, + const yyjson_alc *alc, + yyjson_write_err *err); + +/** + Write a document to file pointer with options. + + @param fp The file pointer. + The data will be written to the current position of the file. + If this fp is NULL or invalid, the function will fail and return false. + @param doc The JSON document. + If this doc is NULL or has no root, the function will fail and return false. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON writer. + Pass NULL to use the libc's default allocator. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return true if successful, false if an error occurs. + + @warning On 32-bit operating system, files larger than 2GB may fail to write. + */ +yyjson_api bool yyjson_write_fp(FILE *fp, + const yyjson_doc *doc, + yyjson_write_flag flg, + const yyjson_alc *alc, + yyjson_write_err *err); + +/** + Write a document to JSON string. + + This function is thread-safe. + + @param doc The JSON document. + If this doc is NULL or has no root, the function will fail and return false. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param len A pointer to receive output length in bytes (not including the + null-terminator). Pass NULL if you don't need length information. + @return A new JSON string, or NULL if an error occurs. + This string is encoded as UTF-8 with a null-terminator. + When it's no longer needed, it should be freed with free(). + */ +yyjson_api_inline char *yyjson_write(const yyjson_doc *doc, + yyjson_write_flag flg, + size_t *len) { + return yyjson_write_opts(doc, flg, NULL, len, NULL); +} + + + +/** + Write a document to JSON string with options. + + This function is thread-safe when: + 1. The `doc` is not modified by other threads. + 2. The `alc` is thread-safe or NULL. + + @param doc The mutable JSON document. + If this doc is NULL or has no root, the function will fail and return false. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON writer. + Pass NULL to use the libc's default allocator. + @param len A pointer to receive output length in bytes (not including the + null-terminator). Pass NULL if you don't need length information. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return A new JSON string, or NULL if an error occurs. + This string is encoded as UTF-8 with a null-terminator. + When it's no longer needed, it should be freed with free() or alc->free(). + */ +yyjson_api char *yyjson_mut_write_opts(const yyjson_mut_doc *doc, + yyjson_write_flag flg, + const yyjson_alc *alc, + size_t *len, + yyjson_write_err *err); + +/** + Write a document to JSON file with options. + + This function is thread-safe when: + 1. The file is not accessed by other threads. + 2. The `doc` is not modified by other threads. + 3. The `alc` is thread-safe or NULL. + + @param path The JSON file's path. + This should be a null-terminated string using the system's native encoding. + If this path is NULL or invalid, the function will fail and return false. + If this file is not empty, the content will be discarded. + @param doc The mutable JSON document. + If this doc is NULL or has no root, the function will fail and return false. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON writer. + Pass NULL to use the libc's default allocator. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return true if successful, false if an error occurs. + + @warning On 32-bit operating system, files larger than 2GB may fail to write. + */ +yyjson_api bool yyjson_mut_write_file(const char *path, + const yyjson_mut_doc *doc, + yyjson_write_flag flg, + const yyjson_alc *alc, + yyjson_write_err *err); + +/** + Write a document to file pointer with options. + + @param fp The file pointer. + The data will be written to the current position of the file. + If this fp is NULL or invalid, the function will fail and return false. + @param doc The mutable JSON document. + If this doc is NULL or has no root, the function will fail and return false. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON writer. + Pass NULL to use the libc's default allocator. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return true if successful, false if an error occurs. + + @warning On 32-bit operating system, files larger than 2GB may fail to write. + */ +yyjson_api bool yyjson_mut_write_fp(FILE *fp, + const yyjson_mut_doc *doc, + yyjson_write_flag flg, + const yyjson_alc *alc, + yyjson_write_err *err); + +/** + Write a document to JSON string. + + This function is thread-safe when: + The `doc` is not modified by other threads. + + @param doc The JSON document. + If this doc is NULL or has no root, the function will fail and return false. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param len A pointer to receive output length in bytes (not including the + null-terminator). Pass NULL if you don't need length information. + @return A new JSON string, or NULL if an error occurs. + This string is encoded as UTF-8 with a null-terminator. + When it's no longer needed, it should be freed with free(). + */ +yyjson_api_inline char *yyjson_mut_write(const yyjson_mut_doc *doc, + yyjson_write_flag flg, + size_t *len) { + return yyjson_mut_write_opts(doc, flg, NULL, len, NULL); +} + + + +/*============================================================================== + * MARK: - JSON Value Writer API + *============================================================================*/ + +/** + Write a value to JSON string with options. + + This function is thread-safe when: + The `alc` is thread-safe or NULL. + + @param val The JSON root value. + If this parameter is NULL, the function will fail and return NULL. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON writer. + Pass NULL to use the libc's default allocator. + @param len A pointer to receive output length in bytes (not including the + null-terminator). Pass NULL if you don't need length information. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return A new JSON string, or NULL if an error occurs. + This string is encoded as UTF-8 with a null-terminator. + When it's no longer needed, it should be freed with free() or alc->free(). + */ +yyjson_api char *yyjson_val_write_opts(const yyjson_val *val, + yyjson_write_flag flg, + const yyjson_alc *alc, + size_t *len, + yyjson_write_err *err); + +/** + Write a value to JSON file with options. + + This function is thread-safe when: + 1. The file is not accessed by other threads. + 2. The `alc` is thread-safe or NULL. + + @param path The JSON file's path. + This should be a null-terminated string using the system's native encoding. + If this path is NULL or invalid, the function will fail and return false. + If this file is not empty, the content will be discarded. + @param val The JSON root value. + If this parameter is NULL, the function will fail and return NULL. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON writer. + Pass NULL to use the libc's default allocator. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return true if successful, false if an error occurs. + + @warning On 32-bit operating system, files larger than 2GB may fail to write. + */ +yyjson_api bool yyjson_val_write_file(const char *path, + const yyjson_val *val, + yyjson_write_flag flg, + const yyjson_alc *alc, + yyjson_write_err *err); + +/** + Write a value to file pointer with options. + + @param fp The file pointer. + The data will be written to the current position of the file. + If this path is NULL or invalid, the function will fail and return false. + @param val The JSON root value. + If this parameter is NULL, the function will fail and return NULL. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON writer. + Pass NULL to use the libc's default allocator. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return true if successful, false if an error occurs. + + @warning On 32-bit operating system, files larger than 2GB may fail to write. + */ +yyjson_api bool yyjson_val_write_fp(FILE *fp, + const yyjson_val *val, + yyjson_write_flag flg, + const yyjson_alc *alc, + yyjson_write_err *err); + +/** + Write a value to JSON string. + + This function is thread-safe. + + @param val The JSON root value. + If this parameter is NULL, the function will fail and return NULL. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param len A pointer to receive output length in bytes (not including the + null-terminator). Pass NULL if you don't need length information. + @return A new JSON string, or NULL if an error occurs. + This string is encoded as UTF-8 with a null-terminator. + When it's no longer needed, it should be freed with free(). + */ +yyjson_api_inline char *yyjson_val_write(const yyjson_val *val, + yyjson_write_flag flg, + size_t *len) { + return yyjson_val_write_opts(val, flg, NULL, len, NULL); +} + +/** + Write a value to JSON string with options. + + This function is thread-safe when: + 1. The `val` is not modified by other threads. + 2. The `alc` is thread-safe or NULL. + + @param val The mutable JSON root value. + If this parameter is NULL, the function will fail and return NULL. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON writer. + Pass NULL to use the libc's default allocator. + @param len A pointer to receive output length in bytes (not including the + null-terminator). Pass NULL if you don't need length information. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return A new JSON string, or NULL if an error occurs. + This string is encoded as UTF-8 with a null-terminator. + When it's no longer needed, it should be freed with free() or alc->free(). + */ +yyjson_api char *yyjson_mut_val_write_opts(const yyjson_mut_val *val, + yyjson_write_flag flg, + const yyjson_alc *alc, + size_t *len, + yyjson_write_err *err); + +/** + Write a value to JSON file with options. + + This function is thread-safe when: + 1. The file is not accessed by other threads. + 2. The `val` is not modified by other threads. + 3. The `alc` is thread-safe or NULL. + + @param path The JSON file's path. + This should be a null-terminated string using the system's native encoding. + If this path is NULL or invalid, the function will fail and return false. + If this file is not empty, the content will be discarded. + @param val The mutable JSON root value. + If this parameter is NULL, the function will fail and return NULL. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON writer. + Pass NULL to use the libc's default allocator. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return true if successful, false if an error occurs. + + @warning On 32-bit operating system, files larger than 2GB may fail to write. + */ +yyjson_api bool yyjson_mut_val_write_file(const char *path, + const yyjson_mut_val *val, + yyjson_write_flag flg, + const yyjson_alc *alc, + yyjson_write_err *err); + +/** + Write a value to JSON file with options. + + @param fp The file pointer. + The data will be written to the current position of the file. + If this path is NULL or invalid, the function will fail and return false. + @param val The mutable JSON root value. + If this parameter is NULL, the function will fail and return NULL. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON writer. + Pass NULL to use the libc's default allocator. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return true if successful, false if an error occurs. + + @warning On 32-bit operating system, files larger than 2GB may fail to write. + */ +yyjson_api bool yyjson_mut_val_write_fp(FILE *fp, + const yyjson_mut_val *val, + yyjson_write_flag flg, + const yyjson_alc *alc, + yyjson_write_err *err); + +/** + Write a value to JSON string. + + This function is thread-safe when: + The `val` is not modified by other threads. + + @param val The JSON root value. + If this parameter is NULL, the function will fail and return NULL. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param len A pointer to receive output length in bytes (not including the + null-terminator). Pass NULL if you don't need length information. + @return A new JSON string, or NULL if an error occurs. + This string is encoded as UTF-8 with a null-terminator. + When it's no longer needed, it should be freed with free(). + */ +yyjson_api_inline char *yyjson_mut_val_write(const yyjson_mut_val *val, + yyjson_write_flag flg, + size_t *len) { + return yyjson_mut_val_write_opts(val, flg, NULL, len, NULL); +} + +/** + Write a JSON number. + + @param val A JSON number value to be converted to a string. + If this parameter is invalid, the function will fail and return NULL. + @param buf A buffer to store the resulting null-terminated string. + If this parameter is NULL, the function will fail and return NULL. + For integer values, the buffer must be at least 21 bytes. + For floating-point values, the buffer must be at least 40 bytes. + @return On success, returns a pointer to the character after the last + written character. On failure, returns NULL. + @note + - This function is thread-safe and does not allocate memory + (when `YYJSON_DISABLE_FAST_FP_CONV` is not defined). + - This function will fail and return NULL only in the following cases: + 1) `val` or `buf` is NULL; + 2) `val` is not a number type; + 3) `val` is `inf` or `nan`, and non-standard JSON is explicitly disabled + via the `YYJSON_DISABLE_NON_STANDARD` flag. + */ +yyjson_api char *yyjson_write_number(const yyjson_val *val, char *buf); + +/** Same as `yyjson_write_number()`. */ +yyjson_api_inline char *yyjson_mut_write_number(const yyjson_mut_val *val, + char *buf) { + return yyjson_write_number((const yyjson_val *)val, buf); +} + +#endif /* YYJSON_DISABLE_WRITER */ + + + +/*============================================================================== + * MARK: - JSON Document API + *============================================================================*/ + +/** Returns the root value of this JSON document. + Returns NULL if `doc` is NULL. */ +yyjson_api_inline yyjson_val *yyjson_doc_get_root(yyjson_doc *doc); + +/** Returns read size of input JSON data. + Returns 0 if `doc` is NULL. + For example: the read size of `[1,2,3]` is 7 bytes. */ +yyjson_api_inline size_t yyjson_doc_get_read_size(yyjson_doc *doc); + +/** Returns total value count in this JSON document. + Returns 0 if `doc` is NULL. + For example: the value count of `[1,2,3]` is 4. */ +yyjson_api_inline size_t yyjson_doc_get_val_count(yyjson_doc *doc); + +/** Release the JSON document and free the memory. + After calling this function, the `doc` and all values from the `doc` are no + longer available. This function will do nothing if the `doc` is NULL. */ +yyjson_api_inline void yyjson_doc_free(yyjson_doc *doc); + + + +/*============================================================================== + * MARK: - JSON Value Type API + *============================================================================*/ + +/** Returns whether the JSON value is raw. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_raw(yyjson_val *val); + +/** Returns whether the JSON value is `null`. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_null(yyjson_val *val); + +/** Returns whether the JSON value is `true`. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_true(yyjson_val *val); + +/** Returns whether the JSON value is `false`. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_false(yyjson_val *val); + +/** Returns whether the JSON value is bool (true/false). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_bool(yyjson_val *val); + +/** Returns whether the JSON value is unsigned integer (uint64_t). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_uint(yyjson_val *val); + +/** Returns whether the JSON value is signed integer (int64_t). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_sint(yyjson_val *val); + +/** Returns whether the JSON value is integer (uint64_t/int64_t). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_int(yyjson_val *val); + +/** Returns whether the JSON value is real number (double). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_real(yyjson_val *val); + +/** Returns whether the JSON value is number (uint64_t/int64_t/double). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_num(yyjson_val *val); + +/** Returns whether the JSON value is string. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_str(yyjson_val *val); + +/** Returns whether the JSON value is array. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_arr(yyjson_val *val); + +/** Returns whether the JSON value is object. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_obj(yyjson_val *val); + +/** Returns whether the JSON value is container (array/object). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_ctn(yyjson_val *val); + + + +/*============================================================================== + * MARK: - JSON Value Content API + *============================================================================*/ + +/** Returns the JSON value's type. + Returns YYJSON_TYPE_NONE if `val` is NULL. */ +yyjson_api_inline yyjson_type yyjson_get_type(yyjson_val *val); + +/** Returns the JSON value's subtype. + Returns YYJSON_SUBTYPE_NONE if `val` is NULL. */ +yyjson_api_inline yyjson_subtype yyjson_get_subtype(yyjson_val *val); + +/** Returns the JSON value's tag. + Returns 0 if `val` is NULL. */ +yyjson_api_inline uint8_t yyjson_get_tag(yyjson_val *val); + +/** Returns the JSON value's type description. + The return value should be one of these strings: "raw", "null", "string", + "array", "object", "true", "false", "uint", "sint", "real", "unknown". */ +yyjson_api_inline const char *yyjson_get_type_desc(yyjson_val *val); + +/** Returns the content if the value is raw. + Returns NULL if `val` is NULL or type is not raw. */ +yyjson_api_inline const char *yyjson_get_raw(yyjson_val *val); + +/** Returns the content if the value is bool. + Returns false if `val` is NULL or type is not bool. */ +yyjson_api_inline bool yyjson_get_bool(yyjson_val *val); + +/** Returns the content and cast to uint64_t. + Returns 0 if `val` is NULL or type is not integer(sint/uint). */ +yyjson_api_inline uint64_t yyjson_get_uint(yyjson_val *val); + +/** Returns the content and cast to int64_t. + Returns 0 if `val` is NULL or type is not integer(sint/uint). */ +yyjson_api_inline int64_t yyjson_get_sint(yyjson_val *val); + +/** Returns the content and cast to int. + Returns 0 if `val` is NULL or type is not integer(sint/uint). */ +yyjson_api_inline int yyjson_get_int(yyjson_val *val); + +/** Returns the content if the value is real number, or 0.0 on error. + Returns 0.0 if `val` is NULL or type is not real(double). */ +yyjson_api_inline double yyjson_get_real(yyjson_val *val); + +/** Returns the content and typecast to `double` if the value is number. + Returns 0.0 if `val` is NULL or type is not number(uint/sint/real). */ +yyjson_api_inline double yyjson_get_num(yyjson_val *val); + +/** Returns the content if the value is string. + Returns NULL if `val` is NULL or type is not string. */ +yyjson_api_inline const char *yyjson_get_str(yyjson_val *val); + +/** Returns the content length (string length, array size, object size. + Returns 0 if `val` is NULL or type is not string/array/object. */ +yyjson_api_inline size_t yyjson_get_len(yyjson_val *val); + +/** Returns whether the JSON value is equals to a string. + Returns false if input is NULL or type is not string. */ +yyjson_api_inline bool yyjson_equals_str(yyjson_val *val, const char *str); + +/** Returns whether the JSON value is equals to a string. + The `str` should be a UTF-8 string, null-terminator is not required. + Returns false if input is NULL or type is not string. */ +yyjson_api_inline bool yyjson_equals_strn(yyjson_val *val, const char *str, + size_t len); + +/** Returns whether two JSON values are equal (deep compare). + Returns false if input is NULL. + @note the result may be inaccurate if object has duplicate keys. + @warning This function is recursive and may cause a stack overflow + if the object level is too deep. */ +yyjson_api_inline bool yyjson_equals(yyjson_val *lhs, yyjson_val *rhs); + +/** Set the value to raw. + Returns false if input is NULL or `val` is object or array. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_raw(yyjson_val *val, + const char *raw, size_t len); + +/** Set the value to null. + Returns false if input is NULL or `val` is object or array. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_null(yyjson_val *val); + +/** Set the value to bool. + Returns false if input is NULL or `val` is object or array. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_bool(yyjson_val *val, bool num); + +/** Set the value to uint. + Returns false if input is NULL or `val` is object or array. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_uint(yyjson_val *val, uint64_t num); + +/** Set the value to sint. + Returns false if input is NULL or `val` is object or array. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_sint(yyjson_val *val, int64_t num); + +/** Set the value to int. + Returns false if input is NULL or `val` is object or array. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_int(yyjson_val *val, int num); + +/** Set the value to float. + Returns false if input is NULL or `val` is object or array. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_float(yyjson_val *val, float num); + +/** Set the value to double. + Returns false if input is NULL or `val` is object or array. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_double(yyjson_val *val, double num); + +/** Set the value to real. + Returns false if input is NULL or `val` is object or array. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_real(yyjson_val *val, double num); + +/** Set the floating-point number's output format to fixed-point notation. + Returns false if input is NULL or `val` is not real type. + @see YYJSON_WRITE_FP_TO_FIXED flag. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_fp_to_fixed(yyjson_val *val, int prec); + +/** Set the floating-point number's output format to single-precision. + Returns false if input is NULL or `val` is not real type. + @see YYJSON_WRITE_FP_TO_FLOAT flag. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_fp_to_float(yyjson_val *val, bool flt); + +/** Set the value to string (null-terminated). + Returns false if input is NULL or `val` is object or array. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_str(yyjson_val *val, const char *str); + +/** Set the value to string (with length). + Returns false if input is NULL or `val` is object or array. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_strn(yyjson_val *val, + const char *str, size_t len); + +/** Marks this string as not needing to be escaped during JSON writing. + This can be used to avoid the overhead of escaping if the string contains + only characters that do not require escaping. + Returns false if input is NULL or `val` is not string. + @see YYJSON_SUBTYPE_NOESC subtype. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_str_noesc(yyjson_val *val, bool noesc); + + + +/*============================================================================== + * MARK: - JSON Array API + *============================================================================*/ + +/** Returns the number of elements in this array. + Returns 0 if `arr` is NULL or type is not array. */ +yyjson_api_inline size_t yyjson_arr_size(yyjson_val *arr); + +/** Returns the element at the specified position in this array. + Returns NULL if array is NULL/empty or the index is out of bounds. + @warning This function takes a linear search time if array is not flat. + For example: `[1,{},3]` is flat, `[1,[2],3]` is not flat. */ +yyjson_api_inline yyjson_val *yyjson_arr_get(yyjson_val *arr, size_t idx); + +/** Returns the first element of this array. + Returns NULL if `arr` is NULL/empty or type is not array. */ +yyjson_api_inline yyjson_val *yyjson_arr_get_first(yyjson_val *arr); + +/** Returns the last element of this array. + Returns NULL if `arr` is NULL/empty or type is not array. + @warning This function takes a linear search time if array is not flat. + For example: `[1,{},3]` is flat, `[1,[2],3]` is not flat.*/ +yyjson_api_inline yyjson_val *yyjson_arr_get_last(yyjson_val *arr); + + + +/*============================================================================== + * MARK: - JSON Array Iterator API + *============================================================================*/ + +/** + A JSON array iterator. + + @b Example + @code + yyjson_val *val; + yyjson_arr_iter iter = yyjson_arr_iter_with(arr); + while ((val = yyjson_arr_iter_next(&iter))) { + your_func(val); + } + @endcode + */ +typedef struct yyjson_arr_iter { + size_t idx; /**< next value's index */ + size_t max; /**< maximum index (arr.size) */ + yyjson_val *cur; /**< next value */ +} yyjson_arr_iter; + +/** + Initialize an iterator for this array. + + @param arr The array to be iterated over. + If this parameter is NULL or not an array, `iter` will be set to empty. + @param iter The iterator to be initialized. + If this parameter is NULL, the function will fail and return false. + @return true if the `iter` has been successfully initialized. + + @note The iterator does not need to be destroyed. + */ +yyjson_api_inline bool yyjson_arr_iter_init(yyjson_val *arr, + yyjson_arr_iter *iter); + +/** + Create an iterator with an array , same as `yyjson_arr_iter_init()`. + + @param arr The array to be iterated over. + If this parameter is NULL or not an array, an empty iterator will returned. + @return A new iterator for the array. + + @note The iterator does not need to be destroyed. + */ +yyjson_api_inline yyjson_arr_iter yyjson_arr_iter_with(yyjson_val *arr); + +/** + Returns whether the iteration has more elements. + If `iter` is NULL, this function will return false. + */ +yyjson_api_inline bool yyjson_arr_iter_has_next(yyjson_arr_iter *iter); + +/** + Returns the next element in the iteration, or NULL on end. + If `iter` is NULL, this function will return NULL. + */ +yyjson_api_inline yyjson_val *yyjson_arr_iter_next(yyjson_arr_iter *iter); + +/** + Macro for iterating over an array. + It works like iterator, but with a more intuitive API. + + @b Example + @code + size_t idx, max; + yyjson_val *val; + yyjson_arr_foreach(arr, idx, max, val) { + your_func(idx, val); + } + @endcode + */ +#define yyjson_arr_foreach(arr, idx, max, val) \ + for ((idx) = 0, \ + (max) = yyjson_arr_size(arr), \ + (val) = yyjson_arr_get_first(arr); \ + (idx) < (max); \ + (idx)++, \ + (val) = unsafe_yyjson_get_next(val)) + + + +/*============================================================================== + * MARK: - JSON Object API + *============================================================================*/ + +/** Returns the number of key-value pairs in this object. + Returns 0 if `obj` is NULL or type is not object. */ +yyjson_api_inline size_t yyjson_obj_size(yyjson_val *obj); + +/** Returns the value to which the specified key is mapped. + Returns NULL if this object contains no mapping for the key. + Returns NULL if `obj/key` is NULL, or type is not object. + + The `key` should be a null-terminated UTF-8 string. + + @warning This function takes a linear search time. */ +yyjson_api_inline yyjson_val *yyjson_obj_get(yyjson_val *obj, const char *key); + +/** Returns the value to which the specified key is mapped. + Returns NULL if this object contains no mapping for the key. + Returns NULL if `obj/key` is NULL, or type is not object. + + The `key` should be a UTF-8 string, null-terminator is not required. + The `key_len` should be the length of the key, in bytes. + + @warning This function takes a linear search time. */ +yyjson_api_inline yyjson_val *yyjson_obj_getn(yyjson_val *obj, const char *key, + size_t key_len); + + + +/*============================================================================== + * MARK: - JSON Object Iterator API + *============================================================================*/ + +/** + A JSON object iterator. + + @b Example + @code + yyjson_val *key, *val; + yyjson_obj_iter iter = yyjson_obj_iter_with(obj); + while ((key = yyjson_obj_iter_next(&iter))) { + val = yyjson_obj_iter_get_val(key); + your_func(key, val); + } + @endcode + + If the ordering of the keys is known at compile-time, you can use this method + to speed up value lookups: + @code + // {"k1":1, "k2": 3, "k3": 3} + yyjson_val *key, *val; + yyjson_obj_iter iter = yyjson_obj_iter_with(obj); + yyjson_val *v1 = yyjson_obj_iter_get(&iter, "k1"); + yyjson_val *v3 = yyjson_obj_iter_get(&iter, "k3"); + @endcode + @see yyjson_obj_iter_get() and yyjson_obj_iter_getn() + */ +typedef struct yyjson_obj_iter { + size_t idx; /**< next key's index */ + size_t max; /**< maximum key index (obj.size) */ + yyjson_val *cur; /**< next key */ + yyjson_val *obj; /**< the object being iterated */ +} yyjson_obj_iter; + +/** + Initialize an iterator for this object. + + @param obj The object to be iterated over. + If this parameter is NULL or not an object, `iter` will be set to empty. + @param iter The iterator to be initialized. + If this parameter is NULL, the function will fail and return false. + @return true if the `iter` has been successfully initialized. + + @note The iterator does not need to be destroyed. + */ +yyjson_api_inline bool yyjson_obj_iter_init(yyjson_val *obj, + yyjson_obj_iter *iter); + +/** + Create an iterator with an object, same as `yyjson_obj_iter_init()`. + + @param obj The object to be iterated over. + If this parameter is NULL or not an object, an empty iterator will returned. + @return A new iterator for the object. + + @note The iterator does not need to be destroyed. + */ +yyjson_api_inline yyjson_obj_iter yyjson_obj_iter_with(yyjson_val *obj); + +/** + Returns whether the iteration has more elements. + If `iter` is NULL, this function will return false. + */ +yyjson_api_inline bool yyjson_obj_iter_has_next(yyjson_obj_iter *iter); + +/** + Returns the next key in the iteration, or NULL on end. + If `iter` is NULL, this function will return NULL. + */ +yyjson_api_inline yyjson_val *yyjson_obj_iter_next(yyjson_obj_iter *iter); + +/** + Returns the value for key inside the iteration. + If `iter` is NULL, this function will return NULL. + */ +yyjson_api_inline yyjson_val *yyjson_obj_iter_get_val(yyjson_val *key); + +/** + Iterates to a specified key and returns the value. + + This function does the same thing as `yyjson_obj_get()`, but is much faster + if the ordering of the keys is known at compile-time and you are using the same + order to look up the values. If the key exists in this object, then the + iterator will stop at the next key, otherwise the iterator will not change and + NULL is returned. + + @param iter The object iterator, should not be NULL. + @param key The key, should be a UTF-8 string with null-terminator. + @return The value to which the specified key is mapped. + NULL if this object contains no mapping for the key or input is invalid. + + @warning This function takes a linear search time if the key is not nearby. + */ +yyjson_api_inline yyjson_val *yyjson_obj_iter_get(yyjson_obj_iter *iter, + const char *key); + +/** + Iterates to a specified key and returns the value. + + This function does the same thing as `yyjson_obj_getn()`, but is much faster + if the ordering of the keys is known at compile-time and you are using the same + order to look up the values. If the key exists in this object, then the + iterator will stop at the next key, otherwise the iterator will not change and + NULL is returned. + + @param iter The object iterator, should not be NULL. + @param key The key, should be a UTF-8 string, null-terminator is not required. + @param key_len The the length of `key`, in bytes. + @return The value to which the specified key is mapped. + NULL if this object contains no mapping for the key or input is invalid. + + @warning This function takes a linear search time if the key is not nearby. + */ +yyjson_api_inline yyjson_val *yyjson_obj_iter_getn(yyjson_obj_iter *iter, + const char *key, + size_t key_len); + +/** + Macro for iterating over an object. + It works like iterator, but with a more intuitive API. + + @b Example + @code + size_t idx, max; + yyjson_val *key, *val; + yyjson_obj_foreach(obj, idx, max, key, val) { + your_func(key, val); + } + @endcode + */ +#define yyjson_obj_foreach(obj, idx, max, key, val) \ + for ((idx) = 0, \ + (max) = yyjson_obj_size(obj), \ + (key) = (obj) ? unsafe_yyjson_get_first(obj) : NULL, \ + (val) = (key) + 1; \ + (idx) < (max); \ + (idx)++, \ + (key) = unsafe_yyjson_get_next(val), \ + (val) = (key) + 1) + + + +/*============================================================================== + * MARK: - Mutable JSON Document API + *============================================================================*/ + +/** Returns the root value of this JSON document. + Returns NULL if `doc` is NULL. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_get_root(yyjson_mut_doc *doc); + +/** Sets the root value of this JSON document. + Pass NULL to clear root value of the document. */ +yyjson_api_inline void yyjson_mut_doc_set_root(yyjson_mut_doc *doc, + yyjson_mut_val *root); + +/** + Set the string pool size for a mutable document. + This function does not allocate memory immediately, but uses the size when + the next memory allocation is needed. + + If the caller knows the approximate bytes of strings that the document needs to + store (e.g. copy string with `yyjson_mut_strcpy` function), setting a larger + size can avoid multiple memory allocations and improve performance. + + @param doc The mutable document. + @param len The desired string pool size in bytes (total string length). + @return true if successful, false if size is 0 or overflow. + */ +yyjson_api bool yyjson_mut_doc_set_str_pool_size(yyjson_mut_doc *doc, + size_t len); + +/** + Set the value pool size for a mutable document. + This function does not allocate memory immediately, but uses the size when + the next memory allocation is needed. + + If the caller knows the approximate number of values that the document needs to + store (e.g. create new value with `yyjson_mut_xxx` functions), setting a larger + size can avoid multiple memory allocations and improve performance. + + @param doc The mutable document. + @param count The desired value pool size (number of `yyjson_mut_val`). + @return true if successful, false if size is 0 or overflow. + */ +yyjson_api bool yyjson_mut_doc_set_val_pool_size(yyjson_mut_doc *doc, + size_t count); + +/** Release the JSON document and free the memory. + After calling this function, the `doc` and all values from the `doc` are no + longer available. This function will do nothing if the `doc` is NULL. */ +yyjson_api void yyjson_mut_doc_free(yyjson_mut_doc *doc); + +/** Creates and returns a new mutable JSON document, returns NULL on error. + If allocator is NULL, the default allocator will be used. */ +yyjson_api yyjson_mut_doc *yyjson_mut_doc_new(const yyjson_alc *alc); + +/** Copies and returns a new mutable document from input, returns NULL on error. + This makes a `deep-copy` on the immutable document. + If allocator is NULL, the default allocator will be used. + @note `imut_doc` -> `mut_doc`. */ +yyjson_api yyjson_mut_doc *yyjson_doc_mut_copy(yyjson_doc *doc, + const yyjson_alc *alc); + +/** Copies and returns a new mutable document from input, returns NULL on error. + This makes a `deep-copy` on the mutable document. + If allocator is NULL, the default allocator will be used. + @note `mut_doc` -> `mut_doc`. */ +yyjson_api yyjson_mut_doc *yyjson_mut_doc_mut_copy(yyjson_mut_doc *doc, + const yyjson_alc *alc); + +/** Copies and returns a new mutable value from input, returns NULL on error. + This makes a `deep-copy` on the immutable value. + The memory was managed by mutable document. + @note `imut_val` -> `mut_val`. */ +yyjson_api yyjson_mut_val *yyjson_val_mut_copy(yyjson_mut_doc *doc, + yyjson_val *val); + +/** Copies and returns a new mutable value from input, returns NULL on error. + This makes a `deep-copy` on the mutable value. + The memory was managed by mutable document. + @note `mut_val` -> `mut_val`. + @warning This function is recursive and may cause a stack overflow + if the object level is too deep. */ +yyjson_api yyjson_mut_val *yyjson_mut_val_mut_copy(yyjson_mut_doc *doc, + yyjson_mut_val *val); + +/** Copies and returns a new immutable document from input, + returns NULL on error. This makes a `deep-copy` on the mutable document. + The returned document should be freed with `yyjson_doc_free()`. + @note `mut_doc` -> `imut_doc`. + @warning This function is recursive and may cause a stack overflow + if the object level is too deep. */ +yyjson_api yyjson_doc *yyjson_mut_doc_imut_copy(yyjson_mut_doc *doc, + const yyjson_alc *alc); + +/** Copies and returns a new immutable document from input, + returns NULL on error. This makes a `deep-copy` on the mutable value. + The returned document should be freed with `yyjson_doc_free()`. + @note `mut_val` -> `imut_doc`. + @warning This function is recursive and may cause a stack overflow + if the object level is too deep. */ +yyjson_api yyjson_doc *yyjson_mut_val_imut_copy(yyjson_mut_val *val, + const yyjson_alc *alc); + + + +/*============================================================================== + * MARK: - Mutable JSON Value Type API + *============================================================================*/ + +/** Returns whether the JSON value is raw. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_raw(yyjson_mut_val *val); + +/** Returns whether the JSON value is `null`. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_null(yyjson_mut_val *val); + +/** Returns whether the JSON value is `true`. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_true(yyjson_mut_val *val); + +/** Returns whether the JSON value is `false`. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_false(yyjson_mut_val *val); + +/** Returns whether the JSON value is bool (true/false). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_bool(yyjson_mut_val *val); + +/** Returns whether the JSON value is unsigned integer (uint64_t). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_uint(yyjson_mut_val *val); + +/** Returns whether the JSON value is signed integer (int64_t). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_sint(yyjson_mut_val *val); + +/** Returns whether the JSON value is integer (uint64_t/int64_t). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_int(yyjson_mut_val *val); + +/** Returns whether the JSON value is real number (double). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_real(yyjson_mut_val *val); + +/** Returns whether the JSON value is number (uint/sint/real). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_num(yyjson_mut_val *val); + +/** Returns whether the JSON value is string. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_str(yyjson_mut_val *val); + +/** Returns whether the JSON value is array. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_arr(yyjson_mut_val *val); + +/** Returns whether the JSON value is object. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_obj(yyjson_mut_val *val); + +/** Returns whether the JSON value is container (array/object). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_ctn(yyjson_mut_val *val); + + + +/*============================================================================== + * MARK: - Mutable JSON Value Content API + *============================================================================*/ + +/** Returns the JSON value's type. + Returns `YYJSON_TYPE_NONE` if `val` is NULL. */ +yyjson_api_inline yyjson_type yyjson_mut_get_type(yyjson_mut_val *val); + +/** Returns the JSON value's subtype. + Returns `YYJSON_SUBTYPE_NONE` if `val` is NULL. */ +yyjson_api_inline yyjson_subtype yyjson_mut_get_subtype(yyjson_mut_val *val); + +/** Returns the JSON value's tag. + Returns 0 if `val` is NULL. */ +yyjson_api_inline uint8_t yyjson_mut_get_tag(yyjson_mut_val *val); + +/** Returns the JSON value's type description. + The return value should be one of these strings: "raw", "null", "string", + "array", "object", "true", "false", "uint", "sint", "real", "unknown". */ +yyjson_api_inline const char *yyjson_mut_get_type_desc(yyjson_mut_val *val); + +/** Returns the content if the value is raw. + Returns NULL if `val` is NULL or type is not raw. */ +yyjson_api_inline const char *yyjson_mut_get_raw(yyjson_mut_val *val); + +/** Returns the content if the value is bool. + Returns NULL if `val` is NULL or type is not bool. */ +yyjson_api_inline bool yyjson_mut_get_bool(yyjson_mut_val *val); + +/** Returns the content and cast to uint64_t. + Returns 0 if `val` is NULL or type is not integer(sint/uint). */ +yyjson_api_inline uint64_t yyjson_mut_get_uint(yyjson_mut_val *val); + +/** Returns the content and cast to int64_t. + Returns 0 if `val` is NULL or type is not integer(sint/uint). */ +yyjson_api_inline int64_t yyjson_mut_get_sint(yyjson_mut_val *val); + +/** Returns the content and cast to int. + Returns 0 if `val` is NULL or type is not integer(sint/uint). */ +yyjson_api_inline int yyjson_mut_get_int(yyjson_mut_val *val); + +/** Returns the content if the value is real number. + Returns 0.0 if `val` is NULL or type is not real(double). */ +yyjson_api_inline double yyjson_mut_get_real(yyjson_mut_val *val); + +/** Returns the content and typecast to `double` if the value is number. + Returns 0.0 if `val` is NULL or type is not number(uint/sint/real). */ +yyjson_api_inline double yyjson_mut_get_num(yyjson_mut_val *val); + +/** Returns the content if the value is string. + Returns NULL if `val` is NULL or type is not string. */ +yyjson_api_inline const char *yyjson_mut_get_str(yyjson_mut_val *val); + +/** Returns the content length (string length, array size, object size. + Returns 0 if `val` is NULL or type is not string/array/object. */ +yyjson_api_inline size_t yyjson_mut_get_len(yyjson_mut_val *val); + +/** Returns whether the JSON value is equals to a string. + The `str` should be a null-terminated UTF-8 string. + Returns false if input is NULL or type is not string. */ +yyjson_api_inline bool yyjson_mut_equals_str(yyjson_mut_val *val, + const char *str); + +/** Returns whether the JSON value is equals to a string. + The `str` should be a UTF-8 string, null-terminator is not required. + Returns false if input is NULL or type is not string. */ +yyjson_api_inline bool yyjson_mut_equals_strn(yyjson_mut_val *val, + const char *str, size_t len); + +/** Returns whether two JSON values are equal (deep compare). + Returns false if input is NULL. + @note the result may be inaccurate if object has duplicate keys. + @warning This function is recursive and may cause a stack overflow + if the object level is too deep. */ +yyjson_api_inline bool yyjson_mut_equals(yyjson_mut_val *lhs, + yyjson_mut_val *rhs); + +/** Set the value to raw. + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_raw(yyjson_mut_val *val, + const char *raw, size_t len); + +/** Set the value to null. + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_null(yyjson_mut_val *val); + +/** Set the value to bool. + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_bool(yyjson_mut_val *val, bool num); + +/** Set the value to uint. + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_uint(yyjson_mut_val *val, uint64_t num); + +/** Set the value to sint. + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_sint(yyjson_mut_val *val, int64_t num); + +/** Set the value to int. + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_int(yyjson_mut_val *val, int num); + +/** Set the value to float. + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_float(yyjson_mut_val *val, float num); + +/** Set the value to double. + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_double(yyjson_mut_val *val, double num); + +/** Set the value to real. + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_real(yyjson_mut_val *val, double num); + +/** Set the floating-point number's output format to fixed-point notation. + Returns false if input is NULL or `val` is not real type. + @see YYJSON_WRITE_FP_TO_FIXED flag. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_mut_set_fp_to_fixed(yyjson_mut_val *val, + int prec); + +/** Set the floating-point number's output format to single-precision. + Returns false if input is NULL or `val` is not real type. + @see YYJSON_WRITE_FP_TO_FLOAT flag. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_mut_set_fp_to_float(yyjson_mut_val *val, + bool flt); + +/** Set the value to string (null-terminated). + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_str(yyjson_mut_val *val, const char *str); + +/** Set the value to string (with length). + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_strn(yyjson_mut_val *val, + const char *str, size_t len); + +/** Marks this string as not needing to be escaped during JSON writing. + This can be used to avoid the overhead of escaping if the string contains + only characters that do not require escaping. + Returns false if input is NULL or `val` is not string. + @see YYJSON_SUBTYPE_NOESC subtype. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_mut_set_str_noesc(yyjson_mut_val *val, + bool noesc); + +/** Set the value to array. + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_arr(yyjson_mut_val *val); + +/** Set the value to array. + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_obj(yyjson_mut_val *val); + + + +/*============================================================================== + * MARK: - Mutable JSON Value Creation API + *============================================================================*/ + +/** Creates and returns a raw value, returns NULL on error. + The `str` should be a null-terminated UTF-8 string. + + @warning The input string is not copied, you should keep this string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_raw(yyjson_mut_doc *doc, + const char *str); + +/** Creates and returns a raw value, returns NULL on error. + The `str` should be a UTF-8 string, null-terminator is not required. + + @warning The input string is not copied, you should keep this string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_rawn(yyjson_mut_doc *doc, + const char *str, + size_t len); + +/** Creates and returns a raw value, returns NULL on error. + The `str` should be a null-terminated UTF-8 string. + The input string is copied and held by the document. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_rawcpy(yyjson_mut_doc *doc, + const char *str); + +/** Creates and returns a raw value, returns NULL on error. + The `str` should be a UTF-8 string, null-terminator is not required. + The input string is copied and held by the document. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_rawncpy(yyjson_mut_doc *doc, + const char *str, + size_t len); + +/** Creates and returns a null value, returns NULL on error. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_null(yyjson_mut_doc *doc); + +/** Creates and returns a true value, returns NULL on error. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_true(yyjson_mut_doc *doc); + +/** Creates and returns a false value, returns NULL on error. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_false(yyjson_mut_doc *doc); + +/** Creates and returns a bool value, returns NULL on error. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_bool(yyjson_mut_doc *doc, + bool val); + +/** Creates and returns an unsigned integer value, returns NULL on error. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_uint(yyjson_mut_doc *doc, + uint64_t num); + +/** Creates and returns a signed integer value, returns NULL on error. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_sint(yyjson_mut_doc *doc, + int64_t num); + +/** Creates and returns a signed integer value, returns NULL on error. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_int(yyjson_mut_doc *doc, + int64_t num); + +/** Creates and returns a float number value, returns NULL on error. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_float(yyjson_mut_doc *doc, + float num); + +/** Creates and returns a double number value, returns NULL on error. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_double(yyjson_mut_doc *doc, + double num); + +/** Creates and returns a real number value, returns NULL on error. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_real(yyjson_mut_doc *doc, + double num); + +/** Creates and returns a string value, returns NULL on error. + The `str` should be a null-terminated UTF-8 string. + @warning The input string is not copied, you should keep this string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_str(yyjson_mut_doc *doc, + const char *str); + +/** Creates and returns a string value, returns NULL on error. + The `str` should be a UTF-8 string, null-terminator is not required. + @warning The input string is not copied, you should keep this string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_strn(yyjson_mut_doc *doc, + const char *str, + size_t len); + +/** Creates and returns a string value, returns NULL on error. + The `str` should be a null-terminated UTF-8 string. + The input string is copied and held by the document. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_strcpy(yyjson_mut_doc *doc, + const char *str); + +/** Creates and returns a string value, returns NULL on error. + The `str` should be a UTF-8 string, null-terminator is not required. + The input string is copied and held by the document. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_strncpy(yyjson_mut_doc *doc, + const char *str, + size_t len); + + + +/*============================================================================== + * MARK: - Mutable JSON Array API + *============================================================================*/ + +/** Returns the number of elements in this array. + Returns 0 if `arr` is NULL or type is not array. */ +yyjson_api_inline size_t yyjson_mut_arr_size(yyjson_mut_val *arr); + +/** Returns the element at the specified position in this array. + Returns NULL if array is NULL/empty or the index is out of bounds. + @warning This function takes a linear search time. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_get(yyjson_mut_val *arr, + size_t idx); + +/** Returns the first element of this array. + Returns NULL if `arr` is NULL/empty or type is not array. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_get_first(yyjson_mut_val *arr); + +/** Returns the last element of this array. + Returns NULL if `arr` is NULL/empty or type is not array. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_get_last(yyjson_mut_val *arr); + + + +/*============================================================================== + * MARK: - Mutable JSON Array Iterator API + *============================================================================*/ + +/** + A mutable JSON array iterator. + + @warning You should not modify the array while iterating over it, but you can + use `yyjson_mut_arr_iter_remove()` to remove current value. + + @b Example + @code + yyjson_mut_val *val; + yyjson_mut_arr_iter iter = yyjson_mut_arr_iter_with(arr); + while ((val = yyjson_mut_arr_iter_next(&iter))) { + your_func(val); + if (your_val_is_unused(val)) { + yyjson_mut_arr_iter_remove(&iter); + } + } + @endcode + */ +typedef struct yyjson_mut_arr_iter { + size_t idx; /**< next value's index */ + size_t max; /**< maximum index (arr.size) */ + yyjson_mut_val *cur; /**< current value */ + yyjson_mut_val *pre; /**< previous value */ + yyjson_mut_val *arr; /**< the array being iterated */ +} yyjson_mut_arr_iter; + +/** + Initialize an iterator for this array. + + @param arr The array to be iterated over. + If this parameter is NULL or not an array, `iter` will be set to empty. + @param iter The iterator to be initialized. + If this parameter is NULL, the function will fail and return false. + @return true if the `iter` has been successfully initialized. + + @note The iterator does not need to be destroyed. + */ +yyjson_api_inline bool yyjson_mut_arr_iter_init(yyjson_mut_val *arr, + yyjson_mut_arr_iter *iter); + +/** + Create an iterator with an array , same as `yyjson_mut_arr_iter_init()`. + + @param arr The array to be iterated over. + If this parameter is NULL or not an array, an empty iterator will returned. + @return A new iterator for the array. + + @note The iterator does not need to be destroyed. + */ +yyjson_api_inline yyjson_mut_arr_iter yyjson_mut_arr_iter_with( + yyjson_mut_val *arr); + +/** + Returns whether the iteration has more elements. + If `iter` is NULL, this function will return false. + */ +yyjson_api_inline bool yyjson_mut_arr_iter_has_next( + yyjson_mut_arr_iter *iter); + +/** + Returns the next element in the iteration, or NULL on end. + If `iter` is NULL, this function will return NULL. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_iter_next( + yyjson_mut_arr_iter *iter); + +/** + Removes and returns current element in the iteration. + If `iter` is NULL, this function will return NULL. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_iter_remove( + yyjson_mut_arr_iter *iter); + +/** + Macro for iterating over an array. + It works like iterator, but with a more intuitive API. + + @warning You should not modify the array while iterating over it. + + @b Example + @code + size_t idx, max; + yyjson_mut_val *val; + yyjson_mut_arr_foreach(arr, idx, max, val) { + your_func(idx, val); + } + @endcode + */ +#define yyjson_mut_arr_foreach(arr, idx, max, val) \ + for ((idx) = 0, \ + (max) = yyjson_mut_arr_size(arr), \ + (val) = yyjson_mut_arr_get_first(arr); \ + (idx) < (max); \ + (idx)++, \ + (val) = (val)->next) + + + +/*============================================================================== + * MARK: - Mutable JSON Array Creation API + *============================================================================*/ + +/** + Creates and returns an empty mutable array. + @param doc A mutable document, used for memory allocation only. + @return The new array. NULL if input is NULL or memory allocation failed. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr(yyjson_mut_doc *doc); + +/** + Creates and returns a new mutable array with the given boolean values. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of boolean values. + @param count The value count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const bool vals[3] = { true, false, true }; + yyjson_mut_val *arr = yyjson_mut_arr_with_bool(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_bool( + yyjson_mut_doc *doc, const bool *vals, size_t count); + +/** + Creates and returns a new mutable array with the given sint numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of sint numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const int64_t vals[3] = { -1, 0, 1 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_sint64(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint( + yyjson_mut_doc *doc, const int64_t *vals, size_t count); + +/** + Creates and returns a new mutable array with the given uint numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of uint numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const uint64_t vals[3] = { 0, 1, 0 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_uint(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint( + yyjson_mut_doc *doc, const uint64_t *vals, size_t count); + +/** + Creates and returns a new mutable array with the given real numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of real numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const double vals[3] = { 0.1, 0.2, 0.3 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_real(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_real( + yyjson_mut_doc *doc, const double *vals, size_t count); + +/** + Creates and returns a new mutable array with the given int8 numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of int8 numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const int8_t vals[3] = { -1, 0, 1 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_sint8(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint8( + yyjson_mut_doc *doc, const int8_t *vals, size_t count); + +/** + Creates and returns a new mutable array with the given int16 numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of int16 numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const int16_t vals[3] = { -1, 0, 1 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_sint16(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint16( + yyjson_mut_doc *doc, const int16_t *vals, size_t count); + +/** + Creates and returns a new mutable array with the given int32 numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of int32 numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const int32_t vals[3] = { -1, 0, 1 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_sint32(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint32( + yyjson_mut_doc *doc, const int32_t *vals, size_t count); + +/** + Creates and returns a new mutable array with the given int64 numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of int64 numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const int64_t vals[3] = { -1, 0, 1 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_sint64(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint64( + yyjson_mut_doc *doc, const int64_t *vals, size_t count); + +/** + Creates and returns a new mutable array with the given uint8 numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of uint8 numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const uint8_t vals[3] = { 0, 1, 0 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_uint8(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint8( + yyjson_mut_doc *doc, const uint8_t *vals, size_t count); + +/** + Creates and returns a new mutable array with the given uint16 numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of uint16 numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const uint16_t vals[3] = { 0, 1, 0 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_uint16(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint16( + yyjson_mut_doc *doc, const uint16_t *vals, size_t count); + +/** + Creates and returns a new mutable array with the given uint32 numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of uint32 numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const uint32_t vals[3] = { 0, 1, 0 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_uint32(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint32( + yyjson_mut_doc *doc, const uint32_t *vals, size_t count); + +/** + Creates and returns a new mutable array with the given uint64 numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of uint64 numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const uint64_t vals[3] = { 0, 1, 0 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_uint64(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint64( + yyjson_mut_doc *doc, const uint64_t *vals, size_t count); + +/** + Creates and returns a new mutable array with the given float numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of float numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const float vals[3] = { -1.0f, 0.0f, 1.0f }; + yyjson_mut_val *arr = yyjson_mut_arr_with_float(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_float( + yyjson_mut_doc *doc, const float *vals, size_t count); + +/** + Creates and returns a new mutable array with the given double numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of double numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const double vals[3] = { -1.0, 0.0, 1.0 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_double(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_double( + yyjson_mut_doc *doc, const double *vals, size_t count); + +/** + Creates and returns a new mutable array with the given strings, these strings + will not be copied. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of UTF-8 null-terminator strings. + If this array contains NULL, the function will fail and return NULL. + @param count The number of values in `vals`. + If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @warning The input strings are not copied, you should keep these strings + unmodified for the lifetime of this JSON document. If these strings will be + modified, you should use `yyjson_mut_arr_with_strcpy()` instead. + + @b Example + @code + const char *vals[3] = { "a", "b", "c" }; + yyjson_mut_val *arr = yyjson_mut_arr_with_str(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_str( + yyjson_mut_doc *doc, const char **vals, size_t count); + +/** + Creates and returns a new mutable array with the given strings and string + lengths, these strings will not be copied. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of UTF-8 strings, null-terminator is not required. + If this array contains NULL, the function will fail and return NULL. + @param lens A C array of string lengths, in bytes. + @param count The number of strings in `vals`. + If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @warning The input strings are not copied, you should keep these strings + unmodified for the lifetime of this JSON document. If these strings will be + modified, you should use `yyjson_mut_arr_with_strncpy()` instead. + + @b Example + @code + const char *vals[3] = { "a", "bb", "c" }; + const size_t lens[3] = { 1, 2, 1 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_strn(doc, vals, lens, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_strn( + yyjson_mut_doc *doc, const char **vals, const size_t *lens, size_t count); + +/** + Creates and returns a new mutable array with the given strings, these strings + will be copied. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of UTF-8 null-terminator strings. + If this array contains NULL, the function will fail and return NULL. + @param count The number of values in `vals`. + If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const char *vals[3] = { "a", "b", "c" }; + yyjson_mut_val *arr = yyjson_mut_arr_with_strcpy(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_strcpy( + yyjson_mut_doc *doc, const char **vals, size_t count); + +/** + Creates and returns a new mutable array with the given strings and string + lengths, these strings will be copied. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of UTF-8 strings, null-terminator is not required. + If this array contains NULL, the function will fail and return NULL. + @param lens A C array of string lengths, in bytes. + @param count The number of strings in `vals`. + If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const char *vals[3] = { "a", "bb", "c" }; + const size_t lens[3] = { 1, 2, 1 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_strn(doc, vals, lens, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_strncpy( + yyjson_mut_doc *doc, const char **vals, const size_t *lens, size_t count); + + + +/*============================================================================== + * MARK: - Mutable JSON Array Modification API + *============================================================================*/ + +/** + Inserts a value into an array at a given index. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param val The value to be inserted. Returns false if it is NULL. + @param idx The index to which to insert the new value. + Returns false if the index is out of range. + @return Whether successful. + @warning This function takes a linear search time. + */ +yyjson_api_inline bool yyjson_mut_arr_insert(yyjson_mut_val *arr, + yyjson_mut_val *val, size_t idx); + +/** + Inserts a value at the end of the array. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param val The value to be inserted. Returns false if it is NULL. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_append(yyjson_mut_val *arr, + yyjson_mut_val *val); + +/** + Inserts a value at the head of the array. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param val The value to be inserted. Returns false if it is NULL. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_prepend(yyjson_mut_val *arr, + yyjson_mut_val *val); + +/** + Replaces a value at index and returns old value. + @param arr The array to which the value is to be replaced. + Returns false if it is NULL or not an array. + @param idx The index to which to replace the value. + Returns false if the index is out of range. + @param val The new value to replace. Returns false if it is NULL. + @return Old value, or NULL on error. + @warning This function takes a linear search time. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_replace(yyjson_mut_val *arr, + size_t idx, + yyjson_mut_val *val); + +/** + Removes and returns a value at index. + @param arr The array from which the value is to be removed. + Returns false if it is NULL or not an array. + @param idx The index from which to remove the value. + Returns false if the index is out of range. + @return Old value, or NULL on error. + @warning This function takes a linear search time. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_remove(yyjson_mut_val *arr, + size_t idx); + +/** + Removes and returns the first value in this array. + @param arr The array from which the value is to be removed. + Returns false if it is NULL or not an array. + @return The first value, or NULL on error. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_remove_first( + yyjson_mut_val *arr); + +/** + Removes and returns the last value in this array. + @param arr The array from which the value is to be removed. + Returns false if it is NULL or not an array. + @return The last value, or NULL on error. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_remove_last( + yyjson_mut_val *arr); + +/** + Removes all values within a specified range in the array. + @param arr The array from which the value is to be removed. + Returns false if it is NULL or not an array. + @param idx The start index of the range (0 is the first). + @param len The number of items in the range (can be 0). + @return Whether successful. + @warning This function takes a linear search time. + */ +yyjson_api_inline bool yyjson_mut_arr_remove_range(yyjson_mut_val *arr, + size_t idx, size_t len); + +/** + Removes all values in this array. + @param arr The array from which all of the values are to be removed. + Returns false if it is NULL or not an array. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_clear(yyjson_mut_val *arr); + +/** + Rotates values in this array for the given number of times. + For example: `[1,2,3,4,5]` rotate 2 is `[3,4,5,1,2]`. + @param arr The array to be rotated. + @param idx Index (or times) to rotate. + @warning This function takes a linear search time. + */ +yyjson_api_inline bool yyjson_mut_arr_rotate(yyjson_mut_val *arr, + size_t idx); + + + +/*============================================================================== + * MARK: - Mutable JSON Array Modification Convenience API + *============================================================================*/ + +/** + Adds a value at the end of the array. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param val The value to be inserted. Returns false if it is NULL. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_val(yyjson_mut_val *arr, + yyjson_mut_val *val); + +/** + Adds a `null` value at the end of the array. + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_null(yyjson_mut_doc *doc, + yyjson_mut_val *arr); + +/** + Adds a `true` value at the end of the array. + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_true(yyjson_mut_doc *doc, + yyjson_mut_val *arr); + +/** + Adds a `false` value at the end of the array. + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_false(yyjson_mut_doc *doc, + yyjson_mut_val *arr); + +/** + Adds a bool value at the end of the array. + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param val The bool value to be added. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_bool(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + bool val); + +/** + Adds an unsigned integer value at the end of the array. + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param num The number to be added. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_uint(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + uint64_t num); + +/** + Adds a signed integer value at the end of the array. + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param num The number to be added. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_sint(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + int64_t num); + +/** + Adds an integer value at the end of the array. + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param num The number to be added. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_int(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + int64_t num); + +/** + Adds a float value at the end of the array. + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param num The number to be added. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_float(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + float num); + +/** + Adds a double value at the end of the array. + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param num The number to be added. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_double(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + double num); + +/** + Adds a double value at the end of the array. + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param num The number to be added. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_real(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + double num); + +/** + Adds a string value at the end of the array (no copy). + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param str A null-terminated UTF-8 string. + @return Whether successful. + @warning The input string is not copied, you should keep this string unmodified + for the lifetime of this JSON document. + */ +yyjson_api_inline bool yyjson_mut_arr_add_str(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + const char *str); + +/** + Adds a string value at the end of the array (no copy). + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param str A UTF-8 string, null-terminator is not required. + @param len The length of the string, in bytes. + @return Whether successful. + @warning The input string is not copied, you should keep this string unmodified + for the lifetime of this JSON document. + */ +yyjson_api_inline bool yyjson_mut_arr_add_strn(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + const char *str, + size_t len); + +/** + Adds a string value at the end of the array (copied). + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param str A null-terminated UTF-8 string. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_strcpy(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + const char *str); + +/** + Adds a string value at the end of the array (copied). + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param str A UTF-8 string, null-terminator is not required. + @param len The length of the string, in bytes. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_strncpy(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + const char *str, + size_t len); + +/** + Creates and adds a new array at the end of the array. + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @return The new array, or NULL on error. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_add_arr(yyjson_mut_doc *doc, + yyjson_mut_val *arr); + +/** + Creates and adds a new object at the end of the array. + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @return The new object, or NULL on error. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_add_obj(yyjson_mut_doc *doc, + yyjson_mut_val *arr); + + + +/*============================================================================== + * MARK: - Mutable JSON Object API + *============================================================================*/ + +/** Returns the number of key-value pairs in this object. + Returns 0 if `obj` is NULL or type is not object. */ +yyjson_api_inline size_t yyjson_mut_obj_size(yyjson_mut_val *obj); + +/** Returns the value to which the specified key is mapped. + Returns NULL if this object contains no mapping for the key. + Returns NULL if `obj/key` is NULL, or type is not object. + + The `key` should be a null-terminated UTF-8 string. + + @warning This function takes a linear search time. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_get(yyjson_mut_val *obj, + const char *key); + +/** Returns the value to which the specified key is mapped. + Returns NULL if this object contains no mapping for the key. + Returns NULL if `obj/key` is NULL, or type is not object. + + The `key` should be a UTF-8 string, null-terminator is not required. + The `key_len` should be the length of the key, in bytes. + + @warning This function takes a linear search time. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_getn(yyjson_mut_val *obj, + const char *key, + size_t key_len); + + + +/*============================================================================== + * MARK: - Mutable JSON Object Iterator API + *============================================================================*/ + +/** + A mutable JSON object iterator. + + @warning You should not modify the object while iterating over it, but you can + use `yyjson_mut_obj_iter_remove()` to remove current value. + + @b Example + @code + yyjson_mut_val *key, *val; + yyjson_mut_obj_iter iter = yyjson_mut_obj_iter_with(obj); + while ((key = yyjson_mut_obj_iter_next(&iter))) { + val = yyjson_mut_obj_iter_get_val(key); + your_func(key, val); + if (your_val_is_unused(key, val)) { + yyjson_mut_obj_iter_remove(&iter); + } + } + @endcode + + If the ordering of the keys is known at compile-time, you can use this method + to speed up value lookups: + @code + // {"k1":1, "k2": 3, "k3": 3} + yyjson_mut_val *key, *val; + yyjson_mut_obj_iter iter = yyjson_mut_obj_iter_with(obj); + yyjson_mut_val *v1 = yyjson_mut_obj_iter_get(&iter, "k1"); + yyjson_mut_val *v3 = yyjson_mut_obj_iter_get(&iter, "k3"); + @endcode + @see `yyjson_mut_obj_iter_get()` and `yyjson_mut_obj_iter_getn()` + */ +typedef struct yyjson_mut_obj_iter { + size_t idx; /**< next key's index */ + size_t max; /**< maximum key index (obj.size) */ + yyjson_mut_val *cur; /**< current key */ + yyjson_mut_val *pre; /**< previous key */ + yyjson_mut_val *obj; /**< the object being iterated */ +} yyjson_mut_obj_iter; + +/** + Initialize an iterator for this object. + + @param obj The object to be iterated over. + If this parameter is NULL or not an array, `iter` will be set to empty. + @param iter The iterator to be initialized. + If this parameter is NULL, the function will fail and return false. + @return true if the `iter` has been successfully initialized. + + @note The iterator does not need to be destroyed. + */ +yyjson_api_inline bool yyjson_mut_obj_iter_init(yyjson_mut_val *obj, + yyjson_mut_obj_iter *iter); + +/** + Create an iterator with an object, same as `yyjson_obj_iter_init()`. + + @param obj The object to be iterated over. + If this parameter is NULL or not an object, an empty iterator will returned. + @return A new iterator for the object. + + @note The iterator does not need to be destroyed. + */ +yyjson_api_inline yyjson_mut_obj_iter yyjson_mut_obj_iter_with( + yyjson_mut_val *obj); + +/** + Returns whether the iteration has more elements. + If `iter` is NULL, this function will return false. + */ +yyjson_api_inline bool yyjson_mut_obj_iter_has_next( + yyjson_mut_obj_iter *iter); + +/** + Returns the next key in the iteration, or NULL on end. + If `iter` is NULL, this function will return NULL. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_next( + yyjson_mut_obj_iter *iter); + +/** + Returns the value for key inside the iteration. + If `iter` is NULL, this function will return NULL. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_get_val( + yyjson_mut_val *key); + +/** + Removes current key-value pair in the iteration, returns the removed value. + If `iter` is NULL, this function will return NULL. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_remove( + yyjson_mut_obj_iter *iter); + +/** + Iterates to a specified key and returns the value. + + This function does the same thing as `yyjson_mut_obj_get()`, but is much faster + if the ordering of the keys is known at compile-time and you are using the same + order to look up the values. If the key exists in this object, then the + iterator will stop at the next key, otherwise the iterator will not change and + NULL is returned. + + @param iter The object iterator, should not be NULL. + @param key The key, should be a UTF-8 string with null-terminator. + @return The value to which the specified key is mapped. + NULL if this object contains no mapping for the key or input is invalid. + + @warning This function takes a linear search time if the key is not nearby. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_get( + yyjson_mut_obj_iter *iter, const char *key); + +/** + Iterates to a specified key and returns the value. + + This function does the same thing as `yyjson_mut_obj_getn()` but is much faster + if the ordering of the keys is known at compile-time and you are using the same + order to look up the values. If the key exists in this object, then the + iterator will stop at the next key, otherwise the iterator will not change and + NULL is returned. + + @param iter The object iterator, should not be NULL. + @param key The key, should be a UTF-8 string, null-terminator is not required. + @param key_len The the length of `key`, in bytes. + @return The value to which the specified key is mapped. + NULL if this object contains no mapping for the key or input is invalid. + + @warning This function takes a linear search time if the key is not nearby. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_getn( + yyjson_mut_obj_iter *iter, const char *key, size_t key_len); + +/** + Macro for iterating over an object. + It works like iterator, but with a more intuitive API. + + @warning You should not modify the object while iterating over it. + + @b Example + @code + size_t idx, max; + yyjson_mut_val *key, *val; + yyjson_mut_obj_foreach(obj, idx, max, key, val) { + your_func(key, val); + } + @endcode + */ +#define yyjson_mut_obj_foreach(obj, idx, max, key, val) \ + for ((idx) = 0, \ + (max) = yyjson_mut_obj_size(obj), \ + (key) = (max) ? ((yyjson_mut_val *)(obj)->uni.ptr)->next->next : NULL, \ + (val) = (key) ? (key)->next : NULL; \ + (idx) < (max); \ + (idx)++, \ + (key) = (val)->next, \ + (val) = (key)->next) + + + +/*============================================================================== + * MARK: - Mutable JSON Object Creation API + *============================================================================*/ + +/** Creates and returns a mutable object, returns NULL on error. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj(yyjson_mut_doc *doc); + +/** + Creates and returns a mutable object with keys and values, returns NULL on + error. The keys and values are not copied. The strings should be a + null-terminated UTF-8 string. + + @warning The input string is not copied, you should keep this string + unmodified for the lifetime of this JSON document. + + @b Example + @code + const char *keys[2] = { "id", "name" }; + const char *vals[2] = { "01", "Harry" }; + yyjson_mut_val *obj = yyjson_mut_obj_with_str(doc, keys, vals, 2); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_with_str(yyjson_mut_doc *doc, + const char **keys, + const char **vals, + size_t count); + +/** + Creates and returns a mutable object with key-value pairs and pair count, + returns NULL on error. The keys and values are not copied. The strings should + be a null-terminated UTF-8 string. + + @warning The input string is not copied, you should keep this string + unmodified for the lifetime of this JSON document. + + @b Example + @code + const char *kv_pairs[4] = { "id", "01", "name", "Harry" }; + yyjson_mut_val *obj = yyjson_mut_obj_with_kv(doc, kv_pairs, 2); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_with_kv(yyjson_mut_doc *doc, + const char **kv_pairs, + size_t pair_count); + + + +/*============================================================================== + * MARK: - Mutable JSON Object Modification API + *============================================================================*/ + +/** + Adds a key-value pair at the end of the object. + This function allows duplicated key in one object. + @param obj The object to which the new key-value pair is to be added. + @param key The key, should be a string which is created by `yyjson_mut_str()`, + `yyjson_mut_strn()`, `yyjson_mut_strcpy()` or `yyjson_mut_strncpy()`. + @param val The value to add to the object. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_obj_add(yyjson_mut_val *obj, + yyjson_mut_val *key, + yyjson_mut_val *val); +/** + Sets a key-value pair at the end of the object. + This function may remove all key-value pairs for the given key before add. + @param obj The object to which the new key-value pair is to be added. + @param key The key, should be a string which is created by `yyjson_mut_str()`, + `yyjson_mut_strn()`, `yyjson_mut_strcpy()` or `yyjson_mut_strncpy()`. + @param val The value to add to the object. If this value is null, the behavior + is same as `yyjson_mut_obj_remove()`. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_obj_put(yyjson_mut_val *obj, + yyjson_mut_val *key, + yyjson_mut_val *val); + +/** + Inserts a key-value pair to the object at the given position. + This function allows duplicated key in one object. + @param obj The object to which the new key-value pair is to be added. + @param key The key, should be a string which is created by `yyjson_mut_str()`, + `yyjson_mut_strn()`, `yyjson_mut_strcpy()` or `yyjson_mut_strncpy()`. + @param val The value to add to the object. + @param idx The index to which to insert the new pair. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_obj_insert(yyjson_mut_val *obj, + yyjson_mut_val *key, + yyjson_mut_val *val, + size_t idx); + +/** + Removes all key-value pair from the object with given key. + @param obj The object from which the key-value pair is to be removed. + @param key The key, should be a string value. + @return The first matched value, or NULL if no matched value. + @warning This function takes a linear search time. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove(yyjson_mut_val *obj, + yyjson_mut_val *key); + +/** + Removes all key-value pair from the object with given key. + @param obj The object from which the key-value pair is to be removed. + @param key The key, should be a UTF-8 string with null-terminator. + @return The first matched value, or NULL if no matched value. + @warning This function takes a linear search time. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_key( + yyjson_mut_val *obj, const char *key); + +/** + Removes all key-value pair from the object with given key. + @param obj The object from which the key-value pair is to be removed. + @param key The key, should be a UTF-8 string, null-terminator is not required. + @param key_len The length of the key. + @return The first matched value, or NULL if no matched value. + @warning This function takes a linear search time. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_keyn( + yyjson_mut_val *obj, const char *key, size_t key_len); + +/** + Removes all key-value pairs in this object. + @param obj The object from which all of the values are to be removed. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_obj_clear(yyjson_mut_val *obj); + +/** + Replaces value from the object with given key. + If the key is not exist, or the value is NULL, it will fail. + @param obj The object to which the value is to be replaced. + @param key The key, should be a string value. + @param val The value to replace into the object. + @return Whether successful. + @warning This function takes a linear search time. + */ +yyjson_api_inline bool yyjson_mut_obj_replace(yyjson_mut_val *obj, + yyjson_mut_val *key, + yyjson_mut_val *val); + +/** + Rotates key-value pairs in the object for the given number of times. + For example: `{"a":1,"b":2,"c":3,"d":4}` rotate 1 is + `{"b":2,"c":3,"d":4,"a":1}`. + @param obj The object to be rotated. + @param idx Index (or times) to rotate. + @return Whether successful. + @warning This function takes a linear search time. + */ +yyjson_api_inline bool yyjson_mut_obj_rotate(yyjson_mut_val *obj, + size_t idx); + + + +/*============================================================================== + * MARK: - Mutable JSON Object Modification Convenience API + *============================================================================*/ + +/** Adds a `null` value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep the string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_null(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key); + +/** Adds a `true` value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep the string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_true(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key); + +/** Adds a `false` value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep the string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_false(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key); + +/** Adds a bool value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep the string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_bool(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, bool val); + +/** Adds an unsigned integer value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep the string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_uint(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, uint64_t val); + +/** Adds a signed integer value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep the string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_sint(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, int64_t val); + +/** Adds an int value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep the string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_int(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, int64_t val); + +/** Adds a float value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep the string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_float(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, float val); + +/** Adds a double value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep the string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_double(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, double val); + +/** Adds a real value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep the string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_real(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, double val); + +/** Adds a string value at the end of the object. + The `key` and `val` should be null-terminated UTF-8 strings. + This function allows duplicated key in one object. + + @warning The key/value strings are not copied, you should keep these strings + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_str(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, const char *val); + +/** Adds a string value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + The `val` should be a UTF-8 string, null-terminator is not required. + The `len` should be the length of the `val`, in bytes. + This function allows duplicated key in one object. + + @warning The key/value strings are not copied, you should keep these strings + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_strn(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, + const char *val, size_t len); + +/** Adds a string value at the end of the object. + The `key` and `val` should be null-terminated UTF-8 strings. + The value string is copied. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep the string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_strcpy(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, + const char *val); + +/** Adds a string value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + The `val` should be a UTF-8 string, null-terminator is not required. + The `len` should be the length of the `val`, in bytes. + This function allows duplicated key in one object. + + @warning The key strings are not copied, you should keep these strings + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_strncpy(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, + const char *val, size_t len); + +/** + Creates and adds a new array to the target object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep these strings + unmodified for the lifetime of this JSON document. + @return The new array, or NULL on error. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_add_arr(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key); + +/** + Creates and adds a new object to the target object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep these strings + unmodified for the lifetime of this JSON document. + @return The new object, or NULL on error. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_add_obj(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key); + +/** Adds a JSON value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep the string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_val(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, + yyjson_mut_val *val); + +/** Removes all key-value pairs for the given key. + Returns the first value to which the specified key is mapped or NULL if this + object contains no mapping for the key. + The `key` should be a null-terminated UTF-8 string. + + @warning This function takes a linear search time. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_str( + yyjson_mut_val *obj, const char *key); + +/** Removes all key-value pairs for the given key. + Returns the first value to which the specified key is mapped or NULL if this + object contains no mapping for the key. + The `key` should be a UTF-8 string, null-terminator is not required. + The `len` should be the length of the key, in bytes. + + @warning This function takes a linear search time. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_strn( + yyjson_mut_val *obj, const char *key, size_t len); + +/** Replaces all matching keys with the new key. + Returns true if at least one key was renamed. + The `key` and `new_key` should be a null-terminated UTF-8 string. + The `new_key` is copied and held by doc. + + @warning This function takes a linear search time. + If `new_key` already exists, it will cause duplicate keys. + */ +yyjson_api_inline bool yyjson_mut_obj_rename_key(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, + const char *new_key); + +/** Replaces all matching keys with the new key. + Returns true if at least one key was renamed. + The `key` and `new_key` should be a UTF-8 string, + null-terminator is not required. The `new_key` is copied and held by doc. + + @warning This function takes a linear search time. + If `new_key` already exists, it will cause duplicate keys. + */ +yyjson_api_inline bool yyjson_mut_obj_rename_keyn(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, + size_t len, + const char *new_key, + size_t new_len); + + + +#if !defined(YYJSON_DISABLE_UTILS) || !YYJSON_DISABLE_UTILS + +/*============================================================================== + * MARK: - JSON Pointer API (RFC 6901) + * https://tools.ietf.org/html/rfc6901 + *============================================================================*/ + +/** JSON Pointer error code. */ +typedef uint32_t yyjson_ptr_code; + +/** No JSON pointer error. */ +static const yyjson_ptr_code YYJSON_PTR_ERR_NONE = 0; + +/** Invalid input parameter, such as NULL input. */ +static const yyjson_ptr_code YYJSON_PTR_ERR_PARAMETER = 1; + +/** JSON pointer syntax error, such as invalid escape, token no prefix. */ +static const yyjson_ptr_code YYJSON_PTR_ERR_SYNTAX = 2; + +/** JSON pointer resolve failed, such as index out of range, key not found. */ +static const yyjson_ptr_code YYJSON_PTR_ERR_RESOLVE = 3; + +/** Document's root is NULL, but it is required for the function call. */ +static const yyjson_ptr_code YYJSON_PTR_ERR_NULL_ROOT = 4; + +/** Cannot set root as the target is not a document. */ +static const yyjson_ptr_code YYJSON_PTR_ERR_SET_ROOT = 5; + +/** The memory allocation failed and a new value could not be created. */ +static const yyjson_ptr_code YYJSON_PTR_ERR_MEMORY_ALLOCATION = 6; + +/** Error information for JSON pointer. */ +typedef struct yyjson_ptr_err { + /** Error code, see `yyjson_ptr_code` for all possible values. */ + yyjson_ptr_code code; + /** Error message, constant, no need to free (NULL if no error). */ + const char *msg; + /** Error byte position for input JSON pointer (0 if no error). */ + size_t pos; +} yyjson_ptr_err; + +/** + A context for JSON pointer operation. + + This struct stores the context of JSON Pointer operation result. The struct + can be used with three helper functions: `ctx_append()`, `ctx_replace()`, and + `ctx_remove()`, which perform the corresponding operations on the container + without re-parsing the JSON Pointer. + + For example: + @code + // doc before: {"a":[0,1,null]} + // ptr: "/a/2" + val = yyjson_mut_doc_ptr_getx(doc, ptr, strlen(ptr), &ctx, &err); + if (yyjson_is_null(val)) { + yyjson_ptr_ctx_remove(&ctx); + } + // doc after: {"a":[0,1]} + @endcode + */ +typedef struct yyjson_ptr_ctx { + /** + The container (parent) of the target value. It can be either an array or + an object. If the target location has no value, but all its parent + containers exist, and the target location can be used to insert a new + value, then `ctn` is the parent container of the target location. + Otherwise, `ctn` is NULL. + */ + yyjson_mut_val *ctn; + /** + The previous sibling of the target value. It can be either a value in an + array or a key in an object. As the container is a `circular linked list` + of elements, `pre` is the previous node of the target value. If the + operation is `add` or `set`, then `pre` is the previous node of the new + value, not the original target value. If the target value does not exist, + `pre` is NULL. + */ + yyjson_mut_val *pre; + /** + The removed value if the operation is `set`, `replace` or `remove`. It can + be used to restore the original state of the document if needed. + */ + yyjson_mut_val *old; +} yyjson_ptr_ctx; + +/** + Get value by a JSON Pointer. + @param doc The JSON document to be queried. + @param ptr The JSON pointer string (UTF-8 with null-terminator). + @return The value referenced by the JSON pointer. + NULL if `doc` or `ptr` is NULL, or the JSON pointer cannot be resolved. + */ +yyjson_api_inline yyjson_val *yyjson_doc_ptr_get(yyjson_doc *doc, + const char *ptr); + +/** + Get value by a JSON Pointer. + @param doc The JSON document to be queried. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @return The value referenced by the JSON pointer. + NULL if `doc` or `ptr` is NULL, or the JSON pointer cannot be resolved. + */ +yyjson_api_inline yyjson_val *yyjson_doc_ptr_getn(yyjson_doc *doc, + const char *ptr, size_t len); + +/** + Get value by a JSON Pointer. + @param doc The JSON document to be queried. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param err A pointer to store the error information, or NULL if not needed. + @return The value referenced by the JSON pointer. + NULL if `doc` or `ptr` is NULL, or the JSON pointer cannot be resolved. + */ +yyjson_api_inline yyjson_val *yyjson_doc_ptr_getx(yyjson_doc *doc, + const char *ptr, size_t len, + yyjson_ptr_err *err); + +/** + Get value by a JSON Pointer. + @param val The JSON value to be queried. + @param ptr The JSON pointer string (UTF-8 with null-terminator). + @return The value referenced by the JSON pointer. + NULL if `val` or `ptr` is NULL, or the JSON pointer cannot be resolved. + */ +yyjson_api_inline yyjson_val *yyjson_ptr_get(yyjson_val *val, + const char *ptr); + +/** + Get value by a JSON Pointer. + @param val The JSON value to be queried. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @return The value referenced by the JSON pointer. + NULL if `val` or `ptr` is NULL, or the JSON pointer cannot be resolved. + */ +yyjson_api_inline yyjson_val *yyjson_ptr_getn(yyjson_val *val, + const char *ptr, size_t len); + +/** + Get value by a JSON Pointer. + @param val The JSON value to be queried. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param err A pointer to store the error information, or NULL if not needed. + @return The value referenced by the JSON pointer. + NULL if `val` or `ptr` is NULL, or the JSON pointer cannot be resolved. + */ +yyjson_api_inline yyjson_val *yyjson_ptr_getx(yyjson_val *val, + const char *ptr, size_t len, + yyjson_ptr_err *err); + +/** + Get value by a JSON Pointer. + @param doc The JSON document to be queried. + @param ptr The JSON pointer string (UTF-8 with null-terminator). + @return The value referenced by the JSON pointer. + NULL if `doc` or `ptr` is NULL, or the JSON pointer cannot be resolved. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_get(yyjson_mut_doc *doc, + const char *ptr); + +/** + Get value by a JSON Pointer. + @param doc The JSON document to be queried. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @return The value referenced by the JSON pointer. + NULL if `doc` or `ptr` is NULL, or the JSON pointer cannot be resolved. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_getn(yyjson_mut_doc *doc, + const char *ptr, + size_t len); + +/** + Get value by a JSON Pointer. + @param doc The JSON document to be queried. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param ctx A pointer to store the result context, or NULL if not needed. + @param err A pointer to store the error information, or NULL if not needed. + @return The value referenced by the JSON pointer. + NULL if `doc` or `ptr` is NULL, or the JSON pointer cannot be resolved. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_getx(yyjson_mut_doc *doc, + const char *ptr, + size_t len, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err); + +/** + Get value by a JSON Pointer. + @param val The JSON value to be queried. + @param ptr The JSON pointer string (UTF-8 with null-terminator). + @return The value referenced by the JSON pointer. + NULL if `val` or `ptr` is NULL, or the JSON pointer cannot be resolved. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_get(yyjson_mut_val *val, + const char *ptr); + +/** + Get value by a JSON Pointer. + @param val The JSON value to be queried. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @return The value referenced by the JSON pointer. + NULL if `val` or `ptr` is NULL, or the JSON pointer cannot be resolved. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_getn(yyjson_mut_val *val, + const char *ptr, + size_t len); + +/** + Get value by a JSON Pointer. + @param val The JSON value to be queried. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param ctx A pointer to store the result context, or NULL if not needed. + @param err A pointer to store the error information, or NULL if not needed. + @return The value referenced by the JSON pointer. + NULL if `val` or `ptr` is NULL, or the JSON pointer cannot be resolved. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_getx(yyjson_mut_val *val, + const char *ptr, + size_t len, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err); + +/** + Add (insert) value by a JSON pointer. + @param doc The target JSON document. + @param ptr The JSON pointer string (UTF-8 with null-terminator). + @param new_val The value to be added. + @return true if JSON pointer is valid and new value is added, false otherwise. + @note The parent nodes will be created if they do not exist. + */ +yyjson_api_inline bool yyjson_mut_doc_ptr_add(yyjson_mut_doc *doc, + const char *ptr, + yyjson_mut_val *new_val); + +/** + Add (insert) value by a JSON pointer. + @param doc The target JSON document. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param new_val The value to be added. + @return true if JSON pointer is valid and new value is added, false otherwise. + @note The parent nodes will be created if they do not exist. + */ +yyjson_api_inline bool yyjson_mut_doc_ptr_addn(yyjson_mut_doc *doc, + const char *ptr, size_t len, + yyjson_mut_val *new_val); + +/** + Add (insert) value by a JSON pointer. + @param doc The target JSON document. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param new_val The value to be added. + @param create_parent Whether to create parent nodes if not exist. + @param ctx A pointer to store the result context, or NULL if not needed. + @param err A pointer to store the error information, or NULL if not needed. + @return true if JSON pointer is valid and new value is added, false otherwise. + */ +yyjson_api_inline bool yyjson_mut_doc_ptr_addx(yyjson_mut_doc *doc, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + bool create_parent, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err); + +/** + Add (insert) value by a JSON pointer. + @param val The target JSON value. + @param ptr The JSON pointer string (UTF-8 with null-terminator). + @param doc Only used to create new values when needed. + @param new_val The value to be added. + @return true if JSON pointer is valid and new value is added, false otherwise. + @note The parent nodes will be created if they do not exist. + */ +yyjson_api_inline bool yyjson_mut_ptr_add(yyjson_mut_val *val, + const char *ptr, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc); + +/** + Add (insert) value by a JSON pointer. + @param val The target JSON value. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param doc Only used to create new values when needed. + @param new_val The value to be added. + @return true if JSON pointer is valid and new value is added, false otherwise. + @note The parent nodes will be created if they do not exist. + */ +yyjson_api_inline bool yyjson_mut_ptr_addn(yyjson_mut_val *val, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc); + +/** + Add (insert) value by a JSON pointer. + @param val The target JSON value. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param doc Only used to create new values when needed. + @param new_val The value to be added. + @param create_parent Whether to create parent nodes if not exist. + @param ctx A pointer to store the result context, or NULL if not needed. + @param err A pointer to store the error information, or NULL if not needed. + @return true if JSON pointer is valid and new value is added, false otherwise. + */ +yyjson_api_inline bool yyjson_mut_ptr_addx(yyjson_mut_val *val, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc, + bool create_parent, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err); + +/** + Set value by a JSON pointer. + @param doc The target JSON document. + @param ptr The JSON pointer string (UTF-8 with null-terminator). + @param new_val The value to be set, pass NULL to remove. + @return true if JSON pointer is valid and new value is set, false otherwise. + @note The parent nodes will be created if they do not exist. + If the target value already exists, it will be replaced by the new value. + */ +yyjson_api_inline bool yyjson_mut_doc_ptr_set(yyjson_mut_doc *doc, + const char *ptr, + yyjson_mut_val *new_val); + +/** + Set value by a JSON pointer. + @param doc The target JSON document. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param new_val The value to be set, pass NULL to remove. + @return true if JSON pointer is valid and new value is set, false otherwise. + @note The parent nodes will be created if they do not exist. + If the target value already exists, it will be replaced by the new value. + */ +yyjson_api_inline bool yyjson_mut_doc_ptr_setn(yyjson_mut_doc *doc, + const char *ptr, size_t len, + yyjson_mut_val *new_val); + +/** + Set value by a JSON pointer. + @param doc The target JSON document. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param new_val The value to be set, pass NULL to remove. + @param create_parent Whether to create parent nodes if not exist. + @param ctx A pointer to store the result context, or NULL if not needed. + @param err A pointer to store the error information, or NULL if not needed. + @return true if JSON pointer is valid and new value is set, false otherwise. + @note If the target value already exists, it will be replaced by the new value. + */ +yyjson_api_inline bool yyjson_mut_doc_ptr_setx(yyjson_mut_doc *doc, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + bool create_parent, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err); + +/** + Set value by a JSON pointer. + @param val The target JSON value. + @param ptr The JSON pointer string (UTF-8 with null-terminator). + @param new_val The value to be set, pass NULL to remove. + @param doc Only used to create new values when needed. + @return true if JSON pointer is valid and new value is set, false otherwise. + @note The parent nodes will be created if they do not exist. + If the target value already exists, it will be replaced by the new value. + */ +yyjson_api_inline bool yyjson_mut_ptr_set(yyjson_mut_val *val, + const char *ptr, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc); + +/** + Set value by a JSON pointer. + @param val The target JSON value. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param new_val The value to be set, pass NULL to remove. + @param doc Only used to create new values when needed. + @return true if JSON pointer is valid and new value is set, false otherwise. + @note The parent nodes will be created if they do not exist. + If the target value already exists, it will be replaced by the new value. + */ +yyjson_api_inline bool yyjson_mut_ptr_setn(yyjson_mut_val *val, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc); + +/** + Set value by a JSON pointer. + @param val The target JSON value. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param new_val The value to be set, pass NULL to remove. + @param doc Only used to create new values when needed. + @param create_parent Whether to create parent nodes if not exist. + @param ctx A pointer to store the result context, or NULL if not needed. + @param err A pointer to store the error information, or NULL if not needed. + @return true if JSON pointer is valid and new value is set, false otherwise. + @note If the target value already exists, it will be replaced by the new value. + */ +yyjson_api_inline bool yyjson_mut_ptr_setx(yyjson_mut_val *val, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc, + bool create_parent, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err); + +/** + Replace value by a JSON pointer. + @param doc The target JSON document. + @param ptr The JSON pointer string (UTF-8 with null-terminator). + @param new_val The new value to replace the old one. + @return The old value that was replaced, or NULL if not found. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_replace( + yyjson_mut_doc *doc, const char *ptr, yyjson_mut_val *new_val); + +/** + Replace value by a JSON pointer. + @param doc The target JSON document. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param new_val The new value to replace the old one. + @return The old value that was replaced, or NULL if not found. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_replacen( + yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_mut_val *new_val); + +/** + Replace value by a JSON pointer. + @param doc The target JSON document. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param new_val The new value to replace the old one. + @param ctx A pointer to store the result context, or NULL if not needed. + @param err A pointer to store the error information, or NULL if not needed. + @return The old value that was replaced, or NULL if not found. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_replacex( + yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_mut_val *new_val, + yyjson_ptr_ctx *ctx, yyjson_ptr_err *err); + +/** + Replace value by a JSON pointer. + @param val The target JSON value. + @param ptr The JSON pointer string (UTF-8 with null-terminator). + @param new_val The new value to replace the old one. + @return The old value that was replaced, or NULL if not found. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_replace( + yyjson_mut_val *val, const char *ptr, yyjson_mut_val *new_val); + +/** + Replace value by a JSON pointer. + @param val The target JSON value. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param new_val The new value to replace the old one. + @return The old value that was replaced, or NULL if not found. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_replacen( + yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val); + +/** + Replace value by a JSON pointer. + @param val The target JSON value. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param new_val The new value to replace the old one. + @param ctx A pointer to store the result context, or NULL if not needed. + @param err A pointer to store the error information, or NULL if not needed. + @return The old value that was replaced, or NULL if not found. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_replacex( + yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val, + yyjson_ptr_ctx *ctx, yyjson_ptr_err *err); + +/** + Remove value by a JSON pointer. + @param doc The target JSON document. + @param ptr The JSON pointer string (UTF-8 with null-terminator). + @return The removed value, or NULL on error. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_remove( + yyjson_mut_doc *doc, const char *ptr); + +/** + Remove value by a JSON pointer. + @param doc The target JSON document. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @return The removed value, or NULL on error. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_removen( + yyjson_mut_doc *doc, const char *ptr, size_t len); + +/** + Remove value by a JSON pointer. + @param doc The target JSON document. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param ctx A pointer to store the result context, or NULL if not needed. + @param err A pointer to store the error information, or NULL if not needed. + @return The removed value, or NULL on error. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_removex( + yyjson_mut_doc *doc, const char *ptr, size_t len, + yyjson_ptr_ctx *ctx, yyjson_ptr_err *err); + +/** + Remove value by a JSON pointer. + @param val The target JSON value. + @param ptr The JSON pointer string (UTF-8 with null-terminator). + @return The removed value, or NULL on error. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_remove(yyjson_mut_val *val, + const char *ptr); + +/** + Remove value by a JSON pointer. + @param val The target JSON value. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @return The removed value, or NULL on error. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_removen(yyjson_mut_val *val, + const char *ptr, + size_t len); + +/** + Remove value by a JSON pointer. + @param val The target JSON value. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param ctx A pointer to store the result context, or NULL if not needed. + @param err A pointer to store the error information, or NULL if not needed. + @return The removed value, or NULL on error. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_removex(yyjson_mut_val *val, + const char *ptr, + size_t len, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err); + +/** + Append value by JSON pointer context. + @param ctx The context from the `yyjson_mut_ptr_xxx()` calls. + @param key New key if `ctx->ctn` is object, or NULL if `ctx->ctn` is array. + @param val New value to be added. + @return true on success or false on fail. + */ +yyjson_api_inline bool yyjson_ptr_ctx_append(yyjson_ptr_ctx *ctx, + yyjson_mut_val *key, + yyjson_mut_val *val); + +/** + Replace value by JSON pointer context. + @param ctx The context from the `yyjson_mut_ptr_xxx()` calls. + @param val New value to be replaced. + @return true on success or false on fail. + @note If success, the old value will be returned via `ctx->old`. + */ +yyjson_api_inline bool yyjson_ptr_ctx_replace(yyjson_ptr_ctx *ctx, + yyjson_mut_val *val); + +/** + Remove value by JSON pointer context. + @param ctx The context from the `yyjson_mut_ptr_xxx()` calls. + @return true on success or false on fail. + @note If success, the old value will be returned via `ctx->old`. + */ +yyjson_api_inline bool yyjson_ptr_ctx_remove(yyjson_ptr_ctx *ctx); + + + +/*============================================================================== + * MARK: - JSON Patch API (RFC 6902) + * https://tools.ietf.org/html/rfc6902 + *============================================================================*/ + +/** Result code for JSON patch. */ +typedef uint32_t yyjson_patch_code; + +/** Success, no error. */ +static const yyjson_patch_code YYJSON_PATCH_SUCCESS = 0; + +/** Invalid parameter, such as NULL input or non-array patch. */ +static const yyjson_patch_code YYJSON_PATCH_ERROR_INVALID_PARAMETER = 1; + +/** Memory allocation failure occurs. */ +static const yyjson_patch_code YYJSON_PATCH_ERROR_MEMORY_ALLOCATION = 2; + +/** JSON patch operation is not object type. */ +static const yyjson_patch_code YYJSON_PATCH_ERROR_INVALID_OPERATION = 3; + +/** JSON patch operation is missing a required key. */ +static const yyjson_patch_code YYJSON_PATCH_ERROR_MISSING_KEY = 4; + +/** JSON patch operation member is invalid. */ +static const yyjson_patch_code YYJSON_PATCH_ERROR_INVALID_MEMBER = 5; + +/** JSON patch operation `test` not equal. */ +static const yyjson_patch_code YYJSON_PATCH_ERROR_EQUAL = 6; + +/** JSON patch operation failed on JSON pointer. */ +static const yyjson_patch_code YYJSON_PATCH_ERROR_POINTER = 7; + +/** Error information for JSON patch. */ +typedef struct yyjson_patch_err { + /** Error code, see `yyjson_patch_code` for all possible values. */ + yyjson_patch_code code; + /** Index of the error operation (0 if no error). */ + size_t idx; + /** Error message, constant, no need to free (NULL if no error). */ + const char *msg; + /** JSON pointer error if `code == YYJSON_PATCH_ERROR_POINTER`. */ + yyjson_ptr_err ptr; +} yyjson_patch_err; + +/** + Creates and returns a patched JSON value (RFC 6902). + The memory of the returned value is allocated by the `doc`. + The `err` is used to receive error information, pass NULL if not needed. + Returns NULL if the patch could not be applied. + */ +yyjson_api yyjson_mut_val *yyjson_patch(yyjson_mut_doc *doc, + yyjson_val *orig, + yyjson_val *patch, + yyjson_patch_err *err); + +/** + Creates and returns a patched JSON value (RFC 6902). + The memory of the returned value is allocated by the `doc`. + The `err` is used to receive error information, pass NULL if not needed. + Returns NULL if the patch could not be applied. + */ +yyjson_api yyjson_mut_val *yyjson_mut_patch(yyjson_mut_doc *doc, + yyjson_mut_val *orig, + yyjson_mut_val *patch, + yyjson_patch_err *err); + + + +/*============================================================================== + * MARK: - JSON Merge-Patch API (RFC 7386) + * https://tools.ietf.org/html/rfc7386 + *============================================================================*/ + +/** + Creates and returns a merge-patched JSON value (RFC 7386). + The memory of the returned value is allocated by the `doc`. + Returns NULL if the patch could not be applied. + + @warning This function is recursive and may cause a stack overflow if the + object level is too deep. + */ +yyjson_api yyjson_mut_val *yyjson_merge_patch(yyjson_mut_doc *doc, + yyjson_val *orig, + yyjson_val *patch); + +/** + Creates and returns a merge-patched JSON value (RFC 7386). + The memory of the returned value is allocated by the `doc`. + Returns NULL if the patch could not be applied. + + @warning This function is recursive and may cause a stack overflow if the + object level is too deep. + */ +yyjson_api yyjson_mut_val *yyjson_mut_merge_patch(yyjson_mut_doc *doc, + yyjson_mut_val *orig, + yyjson_mut_val *patch); + +#endif /* YYJSON_DISABLE_UTILS */ + + + +/*============================================================================== + * MARK: - JSON Structure (Implementation) + *============================================================================*/ + +/** Payload of a JSON value (8 bytes). */ +typedef union yyjson_val_uni { + uint64_t u64; + int64_t i64; + double f64; + const char *str; + void *ptr; + size_t ofs; +} yyjson_val_uni; + +/** + Immutable JSON value, 16 bytes. + */ +struct yyjson_val { + uint64_t tag; /**< type, subtype and length */ + yyjson_val_uni uni; /**< payload */ +}; + +struct yyjson_doc { + /** Root value of the document (nonnull). */ + yyjson_val *root; + /** Allocator used by document (nonnull). */ + yyjson_alc alc; + /** The total number of bytes read when parsing JSON (nonzero). */ + size_t dat_read; + /** The total number of value read when parsing JSON (nonzero). */ + size_t val_read; + /** The string pool used by JSON values (nullable). */ + char *str_pool; +}; + + + +/*============================================================================== + * MARK: - Unsafe JSON Value API (Implementation) + *============================================================================*/ + +/* + Whether the string does not need to be escaped for serialization. + This function is used to optimize the writing speed of small constant strings. + This function works only if the compiler can evaluate it at compile time. + + Clang supports it since v8.0, + earlier versions do not support constant_p(strlen) and return false. + GCC supports it since at least v4.4, + earlier versions may compile it as run-time instructions. + ICC supports it since at least v16, + earlier versions are uncertain. + + @param str The C string. + @param len The returnd value from strlen(str). + */ +yyjson_api_inline bool unsafe_yyjson_is_str_noesc(const char *str, size_t len) { +#if YYJSON_HAS_CONSTANT_P && \ + (!YYJSON_IS_REAL_GCC || yyjson_gcc_available(4, 4, 0)) + if (yyjson_constant_p(len) && len <= 32) { + /* + Same as the following loop: + + for (size_t i = 0; i < len; i++) { + char c = str[i]; + if (c < ' ' || c > '~' || c == '"' || c == '\\') return false; + } + + GCC evaluates it at compile time only if the string length is within 17 + and -O3 (which turns on the -fpeel-loops flag) is used. + So the loop is unrolled for GCC. + */ +# define yyjson_repeat32_incr(x) \ + x(0) x(1) x(2) x(3) x(4) x(5) x(6) x(7) \ + x(8) x(9) x(10) x(11) x(12) x(13) x(14) x(15) \ + x(16) x(17) x(18) x(19) x(20) x(21) x(22) x(23) \ + x(24) x(25) x(26) x(27) x(28) x(29) x(30) x(31) +# define yyjson_check_char_noesc(i) \ + if (i < len) { \ + char c = str[i]; \ + if (c < ' ' || c > '~' || c == '"' || c == '\\') return false; } + yyjson_repeat32_incr(yyjson_check_char_noesc) +# undef yyjson_repeat32_incr +# undef yyjson_check_char_noesc + return true; + } +#else + (void)str; + (void)len; +#endif + return false; +} + +yyjson_api_inline double unsafe_yyjson_u64_to_f64(uint64_t num) { +#if YYJSON_U64_TO_F64_NO_IMPL + uint64_t msb = ((uint64_t)1) << 63; + if ((num & msb) == 0) { + return (double)(int64_t)num; + } else { + return ((double)(int64_t)((num >> 1) | (num & 1))) * (double)2.0; + } +#else + return (double)num; +#endif +} + +yyjson_api_inline yyjson_type unsafe_yyjson_get_type(void *val) { + uint8_t tag = (uint8_t)((yyjson_val *)val)->tag; + return (yyjson_type)(tag & YYJSON_TYPE_MASK); +} + +yyjson_api_inline yyjson_subtype unsafe_yyjson_get_subtype(void *val) { + uint8_t tag = (uint8_t)((yyjson_val *)val)->tag; + return (yyjson_subtype)(tag & YYJSON_SUBTYPE_MASK); +} + +yyjson_api_inline uint8_t unsafe_yyjson_get_tag(void *val) { + uint8_t tag = (uint8_t)((yyjson_val *)val)->tag; + return (uint8_t)(tag & YYJSON_TAG_MASK); +} + +yyjson_api_inline bool unsafe_yyjson_is_raw(void *val) { + return unsafe_yyjson_get_type(val) == YYJSON_TYPE_RAW; +} + +yyjson_api_inline bool unsafe_yyjson_is_null(void *val) { + return unsafe_yyjson_get_type(val) == YYJSON_TYPE_NULL; +} + +yyjson_api_inline bool unsafe_yyjson_is_bool(void *val) { + return unsafe_yyjson_get_type(val) == YYJSON_TYPE_BOOL; +} + +yyjson_api_inline bool unsafe_yyjson_is_num(void *val) { + return unsafe_yyjson_get_type(val) == YYJSON_TYPE_NUM; +} + +yyjson_api_inline bool unsafe_yyjson_is_str(void *val) { + return unsafe_yyjson_get_type(val) == YYJSON_TYPE_STR; +} + +yyjson_api_inline bool unsafe_yyjson_is_arr(void *val) { + return unsafe_yyjson_get_type(val) == YYJSON_TYPE_ARR; +} + +yyjson_api_inline bool unsafe_yyjson_is_obj(void *val) { + return unsafe_yyjson_get_type(val) == YYJSON_TYPE_OBJ; +} + +yyjson_api_inline bool unsafe_yyjson_is_ctn(void *val) { + uint8_t mask = YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ; + return (unsafe_yyjson_get_tag(val) & mask) == mask; +} + +yyjson_api_inline bool unsafe_yyjson_is_uint(void *val) { + const uint8_t patt = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT; + return unsafe_yyjson_get_tag(val) == patt; +} + +yyjson_api_inline bool unsafe_yyjson_is_sint(void *val) { + const uint8_t patt = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_SINT; + return unsafe_yyjson_get_tag(val) == patt; +} + +yyjson_api_inline bool unsafe_yyjson_is_int(void *val) { + const uint8_t mask = YYJSON_TAG_MASK & (~YYJSON_SUBTYPE_SINT); + const uint8_t patt = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT; + return (unsafe_yyjson_get_tag(val) & mask) == patt; +} + +yyjson_api_inline bool unsafe_yyjson_is_real(void *val) { + const uint8_t patt = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; + return unsafe_yyjson_get_tag(val) == patt; +} + +yyjson_api_inline bool unsafe_yyjson_is_true(void *val) { + const uint8_t patt = YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_TRUE; + return unsafe_yyjson_get_tag(val) == patt; +} + +yyjson_api_inline bool unsafe_yyjson_is_false(void *val) { + const uint8_t patt = YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_FALSE; + return unsafe_yyjson_get_tag(val) == patt; +} + +yyjson_api_inline bool unsafe_yyjson_arr_is_flat(yyjson_val *val) { + size_t ofs = val->uni.ofs; + size_t len = (size_t)(val->tag >> YYJSON_TAG_BIT); + return len * sizeof(yyjson_val) + sizeof(yyjson_val) == ofs; +} + +yyjson_api_inline const char *unsafe_yyjson_get_raw(void *val) { + return ((yyjson_val *)val)->uni.str; +} + +yyjson_api_inline bool unsafe_yyjson_get_bool(void *val) { + uint8_t tag = unsafe_yyjson_get_tag(val); + return (bool)((tag & YYJSON_SUBTYPE_MASK) >> YYJSON_TYPE_BIT); +} + +yyjson_api_inline uint64_t unsafe_yyjson_get_uint(void *val) { + return ((yyjson_val *)val)->uni.u64; +} + +yyjson_api_inline int64_t unsafe_yyjson_get_sint(void *val) { + return ((yyjson_val *)val)->uni.i64; +} + +yyjson_api_inline int unsafe_yyjson_get_int(void *val) { + return (int)((yyjson_val *)val)->uni.i64; +} + +yyjson_api_inline double unsafe_yyjson_get_real(void *val) { + return ((yyjson_val *)val)->uni.f64; +} + +yyjson_api_inline double unsafe_yyjson_get_num(void *val) { + uint8_t tag = unsafe_yyjson_get_tag(val); + if (tag == (YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL)) { + return ((yyjson_val *)val)->uni.f64; + } else if (tag == (YYJSON_TYPE_NUM | YYJSON_SUBTYPE_SINT)) { + return (double)((yyjson_val *)val)->uni.i64; + } else if (tag == (YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT)) { + return unsafe_yyjson_u64_to_f64(((yyjson_val *)val)->uni.u64); + } + return 0.0; +} + +yyjson_api_inline const char *unsafe_yyjson_get_str(void *val) { + return ((yyjson_val *)val)->uni.str; +} + +yyjson_api_inline size_t unsafe_yyjson_get_len(void *val) { + return (size_t)(((yyjson_val *)val)->tag >> YYJSON_TAG_BIT); +} + +yyjson_api_inline yyjson_val *unsafe_yyjson_get_first(yyjson_val *ctn) { + return ctn + 1; +} + +yyjson_api_inline yyjson_val *unsafe_yyjson_get_next(yyjson_val *val) { + bool is_ctn = unsafe_yyjson_is_ctn(val); + size_t ctn_ofs = val->uni.ofs; + size_t ofs = (is_ctn ? ctn_ofs : sizeof(yyjson_val)); + return (yyjson_val *)(void *)((uint8_t *)val + ofs); +} + +yyjson_api_inline bool unsafe_yyjson_equals_strn(void *val, const char *str, + size_t len) { + return unsafe_yyjson_get_len(val) == len && + memcmp(((yyjson_val *)val)->uni.str, str, len) == 0; +} + +yyjson_api_inline bool unsafe_yyjson_equals_str(void *val, const char *str) { + return unsafe_yyjson_equals_strn(val, str, strlen(str)); +} + +yyjson_api_inline void unsafe_yyjson_set_type(void *val, yyjson_type type, + yyjson_subtype subtype) { + uint8_t tag = (type | subtype); + uint64_t new_tag = ((yyjson_val *)val)->tag; + new_tag = (new_tag & (~(uint64_t)YYJSON_TAG_MASK)) | (uint64_t)tag; + ((yyjson_val *)val)->tag = new_tag; +} + +yyjson_api_inline void unsafe_yyjson_set_len(void *val, size_t len) { + uint64_t tag = ((yyjson_val *)val)->tag & YYJSON_TAG_MASK; + tag |= (uint64_t)len << YYJSON_TAG_BIT; + ((yyjson_val *)val)->tag = tag; +} + +yyjson_api_inline void unsafe_yyjson_set_tag(void *val, yyjson_type type, + yyjson_subtype subtype, + size_t len) { + uint64_t tag = (uint64_t)len << YYJSON_TAG_BIT; + tag |= (type | subtype); + ((yyjson_val *)val)->tag = tag; +} + +yyjson_api_inline void unsafe_yyjson_inc_len(void *val) { + uint64_t tag = ((yyjson_val *)val)->tag; + tag += (uint64_t)(1 << YYJSON_TAG_BIT); + ((yyjson_val *)val)->tag = tag; +} + +yyjson_api_inline void unsafe_yyjson_set_raw(void *val, const char *raw, + size_t len) { + unsafe_yyjson_set_tag(val, YYJSON_TYPE_RAW, YYJSON_SUBTYPE_NONE, len); + ((yyjson_val *)val)->uni.str = raw; +} + +yyjson_api_inline void unsafe_yyjson_set_null(void *val) { + unsafe_yyjson_set_tag(val, YYJSON_TYPE_NULL, YYJSON_SUBTYPE_NONE, 0); +} + +yyjson_api_inline void unsafe_yyjson_set_bool(void *val, bool num) { + yyjson_subtype subtype = num ? YYJSON_SUBTYPE_TRUE : YYJSON_SUBTYPE_FALSE; + unsafe_yyjson_set_tag(val, YYJSON_TYPE_BOOL, subtype, 0); +} + +yyjson_api_inline void unsafe_yyjson_set_uint(void *val, uint64_t num) { + unsafe_yyjson_set_tag(val, YYJSON_TYPE_NUM, YYJSON_SUBTYPE_UINT, 0); + ((yyjson_val *)val)->uni.u64 = num; +} + +yyjson_api_inline void unsafe_yyjson_set_sint(void *val, int64_t num) { + unsafe_yyjson_set_tag(val, YYJSON_TYPE_NUM, YYJSON_SUBTYPE_SINT, 0); + ((yyjson_val *)val)->uni.i64 = num; +} + +yyjson_api_inline void unsafe_yyjson_set_fp_to_fixed(void *val, int prec) { + ((yyjson_val *)val)->tag &= ~((uint64_t)YYJSON_WRITE_FP_TO_FIXED(15) << 32); + ((yyjson_val *)val)->tag |= (uint64_t)YYJSON_WRITE_FP_TO_FIXED(prec) << 32; +} + +yyjson_api_inline void unsafe_yyjson_set_fp_to_float(void *val, bool flt) { + uint64_t flag = (uint64_t)YYJSON_WRITE_FP_TO_FLOAT << 32; + if (flt) ((yyjson_val *)val)->tag |= flag; + else ((yyjson_val *)val)->tag &= ~flag; +} + +yyjson_api_inline void unsafe_yyjson_set_float(void *val, float num) { + unsafe_yyjson_set_tag(val, YYJSON_TYPE_NUM, YYJSON_SUBTYPE_REAL, 0); + ((yyjson_val *)val)->tag |= (uint64_t)YYJSON_WRITE_FP_TO_FLOAT << 32; + ((yyjson_val *)val)->uni.f64 = (double)num; +} + +yyjson_api_inline void unsafe_yyjson_set_double(void *val, double num) { + unsafe_yyjson_set_tag(val, YYJSON_TYPE_NUM, YYJSON_SUBTYPE_REAL, 0); + ((yyjson_val *)val)->uni.f64 = num; +} + +yyjson_api_inline void unsafe_yyjson_set_real(void *val, double num) { + unsafe_yyjson_set_tag(val, YYJSON_TYPE_NUM, YYJSON_SUBTYPE_REAL, 0); + ((yyjson_val *)val)->uni.f64 = num; +} + +yyjson_api_inline void unsafe_yyjson_set_str_noesc(void *val, bool noesc) { + ((yyjson_val *)val)->tag &= ~(uint64_t)YYJSON_SUBTYPE_MASK; + if (noesc) ((yyjson_val *)val)->tag |= (uint64_t)YYJSON_SUBTYPE_NOESC; +} + +yyjson_api_inline void unsafe_yyjson_set_strn(void *val, const char *str, + size_t len) { + unsafe_yyjson_set_tag(val, YYJSON_TYPE_STR, YYJSON_SUBTYPE_NONE, len); + ((yyjson_val *)val)->uni.str = str; +} + +yyjson_api_inline void unsafe_yyjson_set_str(void *val, const char *str) { + size_t len = strlen(str); + bool noesc = unsafe_yyjson_is_str_noesc(str, len); + yyjson_subtype subtype = noesc ? YYJSON_SUBTYPE_NOESC : YYJSON_SUBTYPE_NONE; + unsafe_yyjson_set_tag(val, YYJSON_TYPE_STR, subtype, len); + ((yyjson_val *)val)->uni.str = str; +} + +yyjson_api_inline void unsafe_yyjson_set_arr(void *val, size_t size) { + unsafe_yyjson_set_tag(val, YYJSON_TYPE_ARR, YYJSON_SUBTYPE_NONE, size); +} + +yyjson_api_inline void unsafe_yyjson_set_obj(void *val, size_t size) { + unsafe_yyjson_set_tag(val, YYJSON_TYPE_OBJ, YYJSON_SUBTYPE_NONE, size); +} + + + +/*============================================================================== + * MARK: - JSON Document API (Implementation) + *============================================================================*/ + +yyjson_api_inline yyjson_val *yyjson_doc_get_root(yyjson_doc *doc) { + return doc ? doc->root : NULL; +} + +yyjson_api_inline size_t yyjson_doc_get_read_size(yyjson_doc *doc) { + return doc ? doc->dat_read : 0; +} + +yyjson_api_inline size_t yyjson_doc_get_val_count(yyjson_doc *doc) { + return doc ? doc->val_read : 0; +} + +yyjson_api_inline void yyjson_doc_free(yyjson_doc *doc) { + if (doc) { + yyjson_alc alc = doc->alc; + memset(&doc->alc, 0, sizeof(alc)); + if (doc->str_pool) alc.free(alc.ctx, doc->str_pool); + alc.free(alc.ctx, doc); + } +} + + + +/*============================================================================== + * MARK: - JSON Value Type API (Implementation) + *============================================================================*/ + +yyjson_api_inline bool yyjson_is_raw(yyjson_val *val) { + return val ? unsafe_yyjson_is_raw(val) : false; +} + +yyjson_api_inline bool yyjson_is_null(yyjson_val *val) { + return val ? unsafe_yyjson_is_null(val) : false; +} + +yyjson_api_inline bool yyjson_is_true(yyjson_val *val) { + return val ? unsafe_yyjson_is_true(val) : false; +} + +yyjson_api_inline bool yyjson_is_false(yyjson_val *val) { + return val ? unsafe_yyjson_is_false(val) : false; +} + +yyjson_api_inline bool yyjson_is_bool(yyjson_val *val) { + return val ? unsafe_yyjson_is_bool(val) : false; +} + +yyjson_api_inline bool yyjson_is_uint(yyjson_val *val) { + return val ? unsafe_yyjson_is_uint(val) : false; +} + +yyjson_api_inline bool yyjson_is_sint(yyjson_val *val) { + return val ? unsafe_yyjson_is_sint(val) : false; +} + +yyjson_api_inline bool yyjson_is_int(yyjson_val *val) { + return val ? unsafe_yyjson_is_int(val) : false; +} + +yyjson_api_inline bool yyjson_is_real(yyjson_val *val) { + return val ? unsafe_yyjson_is_real(val) : false; +} + +yyjson_api_inline bool yyjson_is_num(yyjson_val *val) { + return val ? unsafe_yyjson_is_num(val) : false; +} + +yyjson_api_inline bool yyjson_is_str(yyjson_val *val) { + return val ? unsafe_yyjson_is_str(val) : false; +} + +yyjson_api_inline bool yyjson_is_arr(yyjson_val *val) { + return val ? unsafe_yyjson_is_arr(val) : false; +} + +yyjson_api_inline bool yyjson_is_obj(yyjson_val *val) { + return val ? unsafe_yyjson_is_obj(val) : false; +} + +yyjson_api_inline bool yyjson_is_ctn(yyjson_val *val) { + return val ? unsafe_yyjson_is_ctn(val) : false; +} + + + +/*============================================================================== + * MARK: - JSON Value Content API (Implementation) + *============================================================================*/ + +yyjson_api_inline yyjson_type yyjson_get_type(yyjson_val *val) { + return val ? unsafe_yyjson_get_type(val) : YYJSON_TYPE_NONE; +} + +yyjson_api_inline yyjson_subtype yyjson_get_subtype(yyjson_val *val) { + return val ? unsafe_yyjson_get_subtype(val) : YYJSON_SUBTYPE_NONE; +} + +yyjson_api_inline uint8_t yyjson_get_tag(yyjson_val *val) { + return val ? unsafe_yyjson_get_tag(val) : 0; +} + +yyjson_api_inline const char *yyjson_get_type_desc(yyjson_val *val) { + switch (yyjson_get_tag(val)) { + case YYJSON_TYPE_RAW | YYJSON_SUBTYPE_NONE: return "raw"; + case YYJSON_TYPE_NULL | YYJSON_SUBTYPE_NONE: return "null"; + case YYJSON_TYPE_STR | YYJSON_SUBTYPE_NONE: return "string"; + case YYJSON_TYPE_STR | YYJSON_SUBTYPE_NOESC: return "string"; + case YYJSON_TYPE_ARR | YYJSON_SUBTYPE_NONE: return "array"; + case YYJSON_TYPE_OBJ | YYJSON_SUBTYPE_NONE: return "object"; + case YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_TRUE: return "true"; + case YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_FALSE: return "false"; + case YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT: return "uint"; + case YYJSON_TYPE_NUM | YYJSON_SUBTYPE_SINT: return "sint"; + case YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL: return "real"; + default: return "unknown"; + } +} + +yyjson_api_inline const char *yyjson_get_raw(yyjson_val *val) { + return yyjson_is_raw(val) ? unsafe_yyjson_get_raw(val) : NULL; +} + +yyjson_api_inline bool yyjson_get_bool(yyjson_val *val) { + return yyjson_is_bool(val) ? unsafe_yyjson_get_bool(val) : false; +} + +yyjson_api_inline uint64_t yyjson_get_uint(yyjson_val *val) { + return yyjson_is_int(val) ? unsafe_yyjson_get_uint(val) : 0; +} + +yyjson_api_inline int64_t yyjson_get_sint(yyjson_val *val) { + return yyjson_is_int(val) ? unsafe_yyjson_get_sint(val) : 0; +} + +yyjson_api_inline int yyjson_get_int(yyjson_val *val) { + return yyjson_is_int(val) ? unsafe_yyjson_get_int(val) : 0; +} + +yyjson_api_inline double yyjson_get_real(yyjson_val *val) { + return yyjson_is_real(val) ? unsafe_yyjson_get_real(val) : 0.0; +} + +yyjson_api_inline double yyjson_get_num(yyjson_val *val) { + return val ? unsafe_yyjson_get_num(val) : 0.0; +} + +yyjson_api_inline const char *yyjson_get_str(yyjson_val *val) { + return yyjson_is_str(val) ? unsafe_yyjson_get_str(val) : NULL; +} + +yyjson_api_inline size_t yyjson_get_len(yyjson_val *val) { + return val ? unsafe_yyjson_get_len(val) : 0; +} + +yyjson_api_inline bool yyjson_equals_str(yyjson_val *val, const char *str) { + if (yyjson_likely(val && str)) { + return unsafe_yyjson_is_str(val) && + unsafe_yyjson_equals_str(val, str); + } + return false; +} + +yyjson_api_inline bool yyjson_equals_strn(yyjson_val *val, const char *str, + size_t len) { + if (yyjson_likely(val && str)) { + return unsafe_yyjson_is_str(val) && + unsafe_yyjson_equals_strn(val, str, len); + } + return false; +} + +yyjson_api bool unsafe_yyjson_equals(yyjson_val *lhs, yyjson_val *rhs); + +yyjson_api_inline bool yyjson_equals(yyjson_val *lhs, yyjson_val *rhs) { + if (yyjson_unlikely(!lhs || !rhs)) return false; + return unsafe_yyjson_equals(lhs, rhs); +} + +yyjson_api_inline bool yyjson_set_raw(yyjson_val *val, + const char *raw, size_t len) { + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + unsafe_yyjson_set_raw(val, raw, len); + return true; +} + +yyjson_api_inline bool yyjson_set_null(yyjson_val *val) { + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + unsafe_yyjson_set_null(val); + return true; +} + +yyjson_api_inline bool yyjson_set_bool(yyjson_val *val, bool num) { + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + unsafe_yyjson_set_bool(val, num); + return true; +} + +yyjson_api_inline bool yyjson_set_uint(yyjson_val *val, uint64_t num) { + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + unsafe_yyjson_set_uint(val, num); + return true; +} + +yyjson_api_inline bool yyjson_set_sint(yyjson_val *val, int64_t num) { + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + unsafe_yyjson_set_sint(val, num); + return true; +} + +yyjson_api_inline bool yyjson_set_int(yyjson_val *val, int num) { + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + unsafe_yyjson_set_sint(val, (int64_t)num); + return true; +} + +yyjson_api_inline bool yyjson_set_float(yyjson_val *val, float num) { + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + unsafe_yyjson_set_float(val, num); + return true; +} + +yyjson_api_inline bool yyjson_set_double(yyjson_val *val, double num) { + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + unsafe_yyjson_set_double(val, num); + return true; +} + +yyjson_api_inline bool yyjson_set_real(yyjson_val *val, double num) { + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + unsafe_yyjson_set_real(val, num); + return true; +} + +yyjson_api_inline bool yyjson_set_fp_to_fixed(yyjson_val *val, int prec) { + if (yyjson_unlikely(!yyjson_is_real(val))) return false; + unsafe_yyjson_set_fp_to_fixed(val, prec); + return true; +} + +yyjson_api_inline bool yyjson_set_fp_to_float(yyjson_val *val, bool flt) { + if (yyjson_unlikely(!yyjson_is_real(val))) return false; + unsafe_yyjson_set_fp_to_float(val, flt); + return true; +} + +yyjson_api_inline bool yyjson_set_str(yyjson_val *val, const char *str) { + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + if (yyjson_unlikely(!str)) return false; + unsafe_yyjson_set_str(val, str); + return true; +} + +yyjson_api_inline bool yyjson_set_strn(yyjson_val *val, + const char *str, size_t len) { + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + if (yyjson_unlikely(!str)) return false; + unsafe_yyjson_set_strn(val, str, len); + return true; +} + +yyjson_api_inline bool yyjson_set_str_noesc(yyjson_val *val, bool noesc) { + if (yyjson_unlikely(!yyjson_is_str(val))) return false; + unsafe_yyjson_set_str_noesc(val, noesc); + return true; +} + + + +/*============================================================================== + * MARK: - JSON Array API (Implementation) + *============================================================================*/ + +yyjson_api_inline size_t yyjson_arr_size(yyjson_val *arr) { + return yyjson_is_arr(arr) ? unsafe_yyjson_get_len(arr) : 0; +} + +yyjson_api_inline yyjson_val *yyjson_arr_get(yyjson_val *arr, size_t idx) { + if (yyjson_likely(yyjson_is_arr(arr))) { + if (yyjson_likely(unsafe_yyjson_get_len(arr) > idx)) { + yyjson_val *val = unsafe_yyjson_get_first(arr); + if (unsafe_yyjson_arr_is_flat(arr)) { + return val + idx; + } else { + while (idx-- > 0) val = unsafe_yyjson_get_next(val); + return val; + } + } + } + return NULL; +} + +yyjson_api_inline yyjson_val *yyjson_arr_get_first(yyjson_val *arr) { + if (yyjson_likely(yyjson_is_arr(arr))) { + if (yyjson_likely(unsafe_yyjson_get_len(arr) > 0)) { + return unsafe_yyjson_get_first(arr); + } + } + return NULL; +} + +yyjson_api_inline yyjson_val *yyjson_arr_get_last(yyjson_val *arr) { + if (yyjson_likely(yyjson_is_arr(arr))) { + size_t len = unsafe_yyjson_get_len(arr); + if (yyjson_likely(len > 0)) { + yyjson_val *val = unsafe_yyjson_get_first(arr); + if (unsafe_yyjson_arr_is_flat(arr)) { + return val + (len - 1); + } else { + while (len-- > 1) val = unsafe_yyjson_get_next(val); + return val; + } + } + } + return NULL; +} + + + +/*============================================================================== + * MARK: - JSON Array Iterator API (Implementation) + *============================================================================*/ + +yyjson_api_inline bool yyjson_arr_iter_init(yyjson_val *arr, + yyjson_arr_iter *iter) { + if (yyjson_likely(yyjson_is_arr(arr) && iter)) { + iter->idx = 0; + iter->max = unsafe_yyjson_get_len(arr); + iter->cur = unsafe_yyjson_get_first(arr); + return true; + } + if (iter) memset(iter, 0, sizeof(yyjson_arr_iter)); + return false; +} + +yyjson_api_inline yyjson_arr_iter yyjson_arr_iter_with(yyjson_val *arr) { + yyjson_arr_iter iter; + yyjson_arr_iter_init(arr, &iter); + return iter; +} + +yyjson_api_inline bool yyjson_arr_iter_has_next(yyjson_arr_iter *iter) { + return iter ? iter->idx < iter->max : false; +} + +yyjson_api_inline yyjson_val *yyjson_arr_iter_next(yyjson_arr_iter *iter) { + yyjson_val *val; + if (iter && iter->idx < iter->max) { + val = iter->cur; + iter->cur = unsafe_yyjson_get_next(val); + iter->idx++; + return val; + } + return NULL; +} + + + +/*============================================================================== + * MARK: - JSON Object API (Implementation) + *============================================================================*/ + +yyjson_api_inline size_t yyjson_obj_size(yyjson_val *obj) { + return yyjson_is_obj(obj) ? unsafe_yyjson_get_len(obj) : 0; +} + +yyjson_api_inline yyjson_val *yyjson_obj_get(yyjson_val *obj, + const char *key) { + return yyjson_obj_getn(obj, key, key ? strlen(key) : 0); +} + +yyjson_api_inline yyjson_val *yyjson_obj_getn(yyjson_val *obj, + const char *_key, + size_t key_len) { + if (yyjson_likely(yyjson_is_obj(obj) && _key)) { + size_t len = unsafe_yyjson_get_len(obj); + yyjson_val *key = unsafe_yyjson_get_first(obj); + while (len-- > 0) { + if (unsafe_yyjson_equals_strn(key, _key, key_len)) return key + 1; + key = unsafe_yyjson_get_next(key + 1); + } + } + return NULL; +} + + + +/*============================================================================== + * MARK: - JSON Object Iterator API (Implementation) + *============================================================================*/ + +yyjson_api_inline bool yyjson_obj_iter_init(yyjson_val *obj, + yyjson_obj_iter *iter) { + if (yyjson_likely(yyjson_is_obj(obj) && iter)) { + iter->idx = 0; + iter->max = unsafe_yyjson_get_len(obj); + iter->cur = unsafe_yyjson_get_first(obj); + iter->obj = obj; + return true; + } + if (iter) memset(iter, 0, sizeof(yyjson_obj_iter)); + return false; +} + +yyjson_api_inline yyjson_obj_iter yyjson_obj_iter_with(yyjson_val *obj) { + yyjson_obj_iter iter; + yyjson_obj_iter_init(obj, &iter); + return iter; +} + +yyjson_api_inline bool yyjson_obj_iter_has_next(yyjson_obj_iter *iter) { + return iter ? iter->idx < iter->max : false; +} + +yyjson_api_inline yyjson_val *yyjson_obj_iter_next(yyjson_obj_iter *iter) { + if (iter && iter->idx < iter->max) { + yyjson_val *key = iter->cur; + iter->idx++; + iter->cur = unsafe_yyjson_get_next(key + 1); + return key; + } + return NULL; +} + +yyjson_api_inline yyjson_val *yyjson_obj_iter_get_val(yyjson_val *key) { + return key ? key + 1 : NULL; +} + +yyjson_api_inline yyjson_val *yyjson_obj_iter_get(yyjson_obj_iter *iter, + const char *key) { + return yyjson_obj_iter_getn(iter, key, key ? strlen(key) : 0); +} + +yyjson_api_inline yyjson_val *yyjson_obj_iter_getn(yyjson_obj_iter *iter, + const char *key, + size_t key_len) { + if (iter && key) { + size_t idx = iter->idx; + size_t max = iter->max; + yyjson_val *cur = iter->cur; + if (yyjson_unlikely(idx == max)) { + idx = 0; + cur = unsafe_yyjson_get_first(iter->obj); + } + while (idx++ < max) { + yyjson_val *next = unsafe_yyjson_get_next(cur + 1); + if (unsafe_yyjson_equals_strn(cur, key, key_len)) { + iter->idx = idx; + iter->cur = next; + return cur + 1; + } + cur = next; + if (idx == iter->max && iter->idx < iter->max) { + idx = 0; + max = iter->idx; + cur = unsafe_yyjson_get_first(iter->obj); + } + } + } + return NULL; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Structure (Implementation) + *============================================================================*/ + +/** + Mutable JSON value, 24 bytes. + The 'tag' and 'uni' field is same as immutable value. + The 'next' field links all elements inside the container to be a cycle. + */ +struct yyjson_mut_val { + uint64_t tag; /**< type, subtype and length */ + yyjson_val_uni uni; /**< payload */ + yyjson_mut_val *next; /**< the next value in circular linked list */ +}; + +/** + A memory chunk in string memory pool. + */ +typedef struct yyjson_str_chunk { + struct yyjson_str_chunk *next; /* next chunk linked list */ + size_t chunk_size; /* chunk size in bytes */ + /* char str[]; flexible array member */ +} yyjson_str_chunk; + +/** + A memory pool to hold all strings in a mutable document. + */ +typedef struct yyjson_str_pool { + char *cur; /* cursor inside current chunk */ + char *end; /* the end of current chunk */ + size_t chunk_size; /* chunk size in bytes while creating new chunk */ + size_t chunk_size_max; /* maximum chunk size in bytes */ + yyjson_str_chunk *chunks; /* a linked list of chunks, nullable */ +} yyjson_str_pool; + +/** + A memory chunk in value memory pool. + `sizeof(yyjson_val_chunk)` should not larger than `sizeof(yyjson_mut_val)`. + */ +typedef struct yyjson_val_chunk { + struct yyjson_val_chunk *next; /* next chunk linked list */ + size_t chunk_size; /* chunk size in bytes */ + /* char pad[sizeof(yyjson_mut_val) - sizeof(yyjson_val_chunk)]; padding */ + /* yyjson_mut_val vals[]; flexible array member */ +} yyjson_val_chunk; + +/** + A memory pool to hold all values in a mutable document. + */ +typedef struct yyjson_val_pool { + yyjson_mut_val *cur; /* cursor inside current chunk */ + yyjson_mut_val *end; /* the end of current chunk */ + size_t chunk_size; /* chunk size in bytes while creating new chunk */ + size_t chunk_size_max; /* maximum chunk size in bytes */ + yyjson_val_chunk *chunks; /* a linked list of chunks, nullable */ +} yyjson_val_pool; + +struct yyjson_mut_doc { + yyjson_mut_val *root; /**< root value of the JSON document, nullable */ + yyjson_alc alc; /**< a valid allocator, nonnull */ + yyjson_str_pool str_pool; /**< string memory pool */ + yyjson_val_pool val_pool; /**< value memory pool */ +}; + +/* Ensures the capacity to at least equal to the specified byte length. */ +yyjson_api bool unsafe_yyjson_str_pool_grow(yyjson_str_pool *pool, + const yyjson_alc *alc, + size_t len); + +/* Ensures the capacity to at least equal to the specified value count. */ +yyjson_api bool unsafe_yyjson_val_pool_grow(yyjson_val_pool *pool, + const yyjson_alc *alc, + size_t count); + +/* Allocate memory for string. */ +yyjson_api_inline char *unsafe_yyjson_mut_str_alc(yyjson_mut_doc *doc, + size_t len) { + char *mem; + const yyjson_alc *alc = &doc->alc; + yyjson_str_pool *pool = &doc->str_pool; + if (yyjson_unlikely((size_t)(pool->end - pool->cur) <= len)) { + if (yyjson_unlikely(!unsafe_yyjson_str_pool_grow(pool, alc, len + 1))) { + return NULL; + } + } + mem = pool->cur; + pool->cur = mem + len + 1; + return mem; +} + +yyjson_api_inline char *unsafe_yyjson_mut_strncpy(yyjson_mut_doc *doc, + const char *str, size_t len) { + char *mem = unsafe_yyjson_mut_str_alc(doc, len); + if (yyjson_unlikely(!mem)) return NULL; + memcpy((void *)mem, (const void *)str, len); + mem[len] = '\0'; + return mem; +} + +yyjson_api_inline yyjson_mut_val *unsafe_yyjson_mut_val(yyjson_mut_doc *doc, + size_t count) { + yyjson_mut_val *val; + yyjson_alc *alc = &doc->alc; + yyjson_val_pool *pool = &doc->val_pool; + if (yyjson_unlikely((size_t)(pool->end - pool->cur) < count)) { + if (yyjson_unlikely(!unsafe_yyjson_val_pool_grow(pool, alc, count))) { + return NULL; + } + } + val = pool->cur; + pool->cur += count; + return val; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Document API (Implementation) + *============================================================================*/ + +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_get_root(yyjson_mut_doc *doc) { + return doc ? doc->root : NULL; +} + +yyjson_api_inline void yyjson_mut_doc_set_root(yyjson_mut_doc *doc, + yyjson_mut_val *root) { + if (doc) doc->root = root; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Value Type API (Implementation) + *============================================================================*/ + +yyjson_api_inline bool yyjson_mut_is_raw(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_raw(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_null(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_null(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_true(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_true(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_false(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_false(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_bool(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_bool(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_uint(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_uint(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_sint(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_sint(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_int(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_int(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_real(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_real(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_num(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_num(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_str(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_str(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_arr(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_arr(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_obj(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_obj(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_ctn(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_ctn(val) : false; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Value Content API (Implementation) + *============================================================================*/ + +yyjson_api_inline yyjson_type yyjson_mut_get_type(yyjson_mut_val *val) { + return yyjson_get_type((yyjson_val *)val); +} + +yyjson_api_inline yyjson_subtype yyjson_mut_get_subtype(yyjson_mut_val *val) { + return yyjson_get_subtype((yyjson_val *)val); +} + +yyjson_api_inline uint8_t yyjson_mut_get_tag(yyjson_mut_val *val) { + return yyjson_get_tag((yyjson_val *)val); +} + +yyjson_api_inline const char *yyjson_mut_get_type_desc(yyjson_mut_val *val) { + return yyjson_get_type_desc((yyjson_val *)val); +} + +yyjson_api_inline const char *yyjson_mut_get_raw(yyjson_mut_val *val) { + return yyjson_get_raw((yyjson_val *)val); +} + +yyjson_api_inline bool yyjson_mut_get_bool(yyjson_mut_val *val) { + return yyjson_get_bool((yyjson_val *)val); +} + +yyjson_api_inline uint64_t yyjson_mut_get_uint(yyjson_mut_val *val) { + return yyjson_get_uint((yyjson_val *)val); +} + +yyjson_api_inline int64_t yyjson_mut_get_sint(yyjson_mut_val *val) { + return yyjson_get_sint((yyjson_val *)val); +} + +yyjson_api_inline int yyjson_mut_get_int(yyjson_mut_val *val) { + return yyjson_get_int((yyjson_val *)val); +} + +yyjson_api_inline double yyjson_mut_get_real(yyjson_mut_val *val) { + return yyjson_get_real((yyjson_val *)val); +} + +yyjson_api_inline double yyjson_mut_get_num(yyjson_mut_val *val) { + return yyjson_get_num((yyjson_val *)val); +} + +yyjson_api_inline const char *yyjson_mut_get_str(yyjson_mut_val *val) { + return yyjson_get_str((yyjson_val *)val); +} + +yyjson_api_inline size_t yyjson_mut_get_len(yyjson_mut_val *val) { + return yyjson_get_len((yyjson_val *)val); +} + +yyjson_api_inline bool yyjson_mut_equals_str(yyjson_mut_val *val, + const char *str) { + return yyjson_equals_str((yyjson_val *)val, str); +} + +yyjson_api_inline bool yyjson_mut_equals_strn(yyjson_mut_val *val, + const char *str, size_t len) { + return yyjson_equals_strn((yyjson_val *)val, str, len); +} + +yyjson_api bool unsafe_yyjson_mut_equals(yyjson_mut_val *lhs, + yyjson_mut_val *rhs); + +yyjson_api_inline bool yyjson_mut_equals(yyjson_mut_val *lhs, + yyjson_mut_val *rhs) { + if (yyjson_unlikely(!lhs || !rhs)) return false; + return unsafe_yyjson_mut_equals(lhs, rhs); +} + +yyjson_api_inline bool yyjson_mut_set_raw(yyjson_mut_val *val, + const char *raw, size_t len) { + if (yyjson_unlikely(!val || !raw)) return false; + unsafe_yyjson_set_raw(val, raw, len); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_null(yyjson_mut_val *val) { + if (yyjson_unlikely(!val)) return false; + unsafe_yyjson_set_null(val); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_bool(yyjson_mut_val *val, bool num) { + if (yyjson_unlikely(!val)) return false; + unsafe_yyjson_set_bool(val, num); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_uint(yyjson_mut_val *val, uint64_t num) { + if (yyjson_unlikely(!val)) return false; + unsafe_yyjson_set_uint(val, num); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_sint(yyjson_mut_val *val, int64_t num) { + if (yyjson_unlikely(!val)) return false; + unsafe_yyjson_set_sint(val, num); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_int(yyjson_mut_val *val, int num) { + if (yyjson_unlikely(!val)) return false; + unsafe_yyjson_set_sint(val, (int64_t)num); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_float(yyjson_mut_val *val, float num) { + if (yyjson_unlikely(!val)) return false; + unsafe_yyjson_set_float(val, num); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_double(yyjson_mut_val *val, double num) { + if (yyjson_unlikely(!val)) return false; + unsafe_yyjson_set_double(val, num); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_real(yyjson_mut_val *val, double num) { + if (yyjson_unlikely(!val)) return false; + unsafe_yyjson_set_real(val, num); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_fp_to_fixed(yyjson_mut_val *val, + int prec) { + if (yyjson_unlikely(!yyjson_mut_is_real(val))) return false; + unsafe_yyjson_set_fp_to_fixed(val, prec); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_fp_to_float(yyjson_mut_val *val, + bool flt) { + if (yyjson_unlikely(!yyjson_mut_is_real(val))) return false; + unsafe_yyjson_set_fp_to_float(val, flt); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_str(yyjson_mut_val *val, + const char *str) { + if (yyjson_unlikely(!val || !str)) return false; + unsafe_yyjson_set_str(val, str); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_strn(yyjson_mut_val *val, + const char *str, size_t len) { + if (yyjson_unlikely(!val || !str)) return false; + unsafe_yyjson_set_strn(val, str, len); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_str_noesc(yyjson_mut_val *val, + bool noesc) { + if (yyjson_unlikely(!yyjson_mut_is_str(val))) return false; + unsafe_yyjson_set_str_noesc(val, noesc); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_arr(yyjson_mut_val *val) { + if (yyjson_unlikely(!val)) return false; + unsafe_yyjson_set_arr(val, 0); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_obj(yyjson_mut_val *val) { + if (yyjson_unlikely(!val)) return false; + unsafe_yyjson_set_obj(val, 0); + return true; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Value Creation API (Implementation) + *============================================================================*/ + +#define yyjson_mut_val_one(func) \ + if (yyjson_likely(doc)) { \ + yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); \ + if (yyjson_likely(val)) { \ + func \ + return val; \ + } \ + } \ + return NULL + +#define yyjson_mut_val_one_str(func) \ + if (yyjson_likely(doc && str)) { \ + yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); \ + if (yyjson_likely(val)) { \ + func \ + return val; \ + } \ + } \ + return NULL + +yyjson_api_inline yyjson_mut_val *yyjson_mut_raw(yyjson_mut_doc *doc, + const char *str) { + yyjson_mut_val_one_str({ unsafe_yyjson_set_raw(val, str, strlen(str)); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_rawn(yyjson_mut_doc *doc, + const char *str, + size_t len) { + yyjson_mut_val_one_str({ unsafe_yyjson_set_raw(val, str, len); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_rawcpy(yyjson_mut_doc *doc, + const char *str) { + yyjson_mut_val_one_str({ + size_t len = strlen(str); + char *new_str = unsafe_yyjson_mut_strncpy(doc, str, len); + if (yyjson_unlikely(!new_str)) return NULL; + unsafe_yyjson_set_raw(val, new_str, len); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_rawncpy(yyjson_mut_doc *doc, + const char *str, + size_t len) { + yyjson_mut_val_one_str({ + char *new_str = unsafe_yyjson_mut_strncpy(doc, str, len); + if (yyjson_unlikely(!new_str)) return NULL; + unsafe_yyjson_set_raw(val, new_str, len); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_null(yyjson_mut_doc *doc) { + yyjson_mut_val_one({ unsafe_yyjson_set_null(val); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_true(yyjson_mut_doc *doc) { + yyjson_mut_val_one({ unsafe_yyjson_set_bool(val, true); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_false(yyjson_mut_doc *doc) { + yyjson_mut_val_one({ unsafe_yyjson_set_bool(val, false); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_bool(yyjson_mut_doc *doc, + bool _val) { + yyjson_mut_val_one({ unsafe_yyjson_set_bool(val, _val); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_uint(yyjson_mut_doc *doc, + uint64_t num) { + yyjson_mut_val_one({ unsafe_yyjson_set_uint(val, num); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_sint(yyjson_mut_doc *doc, + int64_t num) { + yyjson_mut_val_one({ unsafe_yyjson_set_sint(val, num); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_int(yyjson_mut_doc *doc, + int64_t num) { + yyjson_mut_val_one({ unsafe_yyjson_set_sint(val, num); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_float(yyjson_mut_doc *doc, + float num) { + yyjson_mut_val_one({ unsafe_yyjson_set_float(val, num); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_double(yyjson_mut_doc *doc, + double num) { + yyjson_mut_val_one({ unsafe_yyjson_set_double(val, num); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_real(yyjson_mut_doc *doc, + double num) { + yyjson_mut_val_one({ unsafe_yyjson_set_real(val, num); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_str(yyjson_mut_doc *doc, + const char *str) { + yyjson_mut_val_one_str({ unsafe_yyjson_set_str(val, str); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_strn(yyjson_mut_doc *doc, + const char *str, + size_t len) { + yyjson_mut_val_one_str({ unsafe_yyjson_set_strn(val, str, len); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_strcpy(yyjson_mut_doc *doc, + const char *str) { + yyjson_mut_val_one_str({ + size_t len = strlen(str); + bool noesc = unsafe_yyjson_is_str_noesc(str, len); + yyjson_subtype sub = noesc ? YYJSON_SUBTYPE_NOESC : YYJSON_SUBTYPE_NONE; + char *new_str = unsafe_yyjson_mut_strncpy(doc, str, len); + if (yyjson_unlikely(!new_str)) return NULL; + unsafe_yyjson_set_tag(val, YYJSON_TYPE_STR, sub, len); + val->uni.str = new_str; + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_strncpy(yyjson_mut_doc *doc, + const char *str, + size_t len) { + yyjson_mut_val_one_str({ + char *new_str = unsafe_yyjson_mut_strncpy(doc, str, len); + if (yyjson_unlikely(!new_str)) return NULL; + unsafe_yyjson_set_strn(val, new_str, len); + }); +} + +#undef yyjson_mut_val_one +#undef yyjson_mut_val_one_str + + + +/*============================================================================== + * MARK: - Mutable JSON Array API (Implementation) + *============================================================================*/ + +yyjson_api_inline size_t yyjson_mut_arr_size(yyjson_mut_val *arr) { + return yyjson_mut_is_arr(arr) ? unsafe_yyjson_get_len(arr) : 0; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_get(yyjson_mut_val *arr, + size_t idx) { + if (yyjson_likely(idx < yyjson_mut_arr_size(arr))) { + yyjson_mut_val *val = (yyjson_mut_val *)arr->uni.ptr; + while (idx-- > 0) val = val->next; + return val->next; + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_get_first( + yyjson_mut_val *arr) { + if (yyjson_likely(yyjson_mut_arr_size(arr) > 0)) { + return ((yyjson_mut_val *)arr->uni.ptr)->next; + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_get_last( + yyjson_mut_val *arr) { + if (yyjson_likely(yyjson_mut_arr_size(arr) > 0)) { + return ((yyjson_mut_val *)arr->uni.ptr); + } + return NULL; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Array Iterator API (Implementation) + *============================================================================*/ + +yyjson_api_inline bool yyjson_mut_arr_iter_init(yyjson_mut_val *arr, + yyjson_mut_arr_iter *iter) { + if (yyjson_likely(yyjson_mut_is_arr(arr) && iter)) { + iter->idx = 0; + iter->max = unsafe_yyjson_get_len(arr); + iter->cur = iter->max ? (yyjson_mut_val *)arr->uni.ptr : NULL; + iter->pre = NULL; + iter->arr = arr; + return true; + } + if (iter) memset(iter, 0, sizeof(yyjson_mut_arr_iter)); + return false; +} + +yyjson_api_inline yyjson_mut_arr_iter yyjson_mut_arr_iter_with( + yyjson_mut_val *arr) { + yyjson_mut_arr_iter iter; + yyjson_mut_arr_iter_init(arr, &iter); + return iter; +} + +yyjson_api_inline bool yyjson_mut_arr_iter_has_next(yyjson_mut_arr_iter *iter) { + return iter ? iter->idx < iter->max : false; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_iter_next( + yyjson_mut_arr_iter *iter) { + if (iter && iter->idx < iter->max) { + yyjson_mut_val *val = iter->cur; + iter->pre = val; + iter->cur = val->next; + iter->idx++; + return iter->cur; + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_iter_remove( + yyjson_mut_arr_iter *iter) { + if (yyjson_likely(iter && 0 < iter->idx && iter->idx <= iter->max)) { + yyjson_mut_val *prev = iter->pre; + yyjson_mut_val *cur = iter->cur; + yyjson_mut_val *next = cur->next; + if (yyjson_unlikely(iter->idx == iter->max)) iter->arr->uni.ptr = prev; + iter->idx--; + iter->max--; + unsafe_yyjson_set_len(iter->arr, iter->max); + prev->next = next; + iter->cur = prev; + return cur; + } + return NULL; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Array Creation API (Implementation) + *============================================================================*/ + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr(yyjson_mut_doc *doc) { + if (yyjson_likely(doc)) { + yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); + if (yyjson_likely(val)) { + val->tag = YYJSON_TYPE_ARR | YYJSON_SUBTYPE_NONE; + return val; + } + } + return NULL; +} + +#define yyjson_mut_arr_with_func(func) \ + if (yyjson_likely(doc && ((0 < count && count < \ + (~(size_t)0) / sizeof(yyjson_mut_val) && vals) || count == 0))) { \ + yyjson_mut_val *arr = unsafe_yyjson_mut_val(doc, 1 + count); \ + if (yyjson_likely(arr)) { \ + arr->tag = ((uint64_t)count << YYJSON_TAG_BIT) | YYJSON_TYPE_ARR; \ + if (count > 0) { \ + size_t i; \ + for (i = 0; i < count; i++) { \ + yyjson_mut_val *val = arr + i + 1; \ + func \ + val->next = val + 1; \ + } \ + arr[count].next = arr + 1; \ + arr->uni.ptr = arr + count; \ + } \ + return arr; \ + } \ + } \ + return NULL + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_bool( + yyjson_mut_doc *doc, const bool *vals, size_t count) { + yyjson_mut_arr_with_func({ + unsafe_yyjson_set_bool(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint( + yyjson_mut_doc *doc, const int64_t *vals, size_t count) { + return yyjson_mut_arr_with_sint64(doc, vals, count); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint( + yyjson_mut_doc *doc, const uint64_t *vals, size_t count) { + return yyjson_mut_arr_with_uint64(doc, vals, count); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_real( + yyjson_mut_doc *doc, const double *vals, size_t count) { + yyjson_mut_arr_with_func({ + unsafe_yyjson_set_real(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint8( + yyjson_mut_doc *doc, const int8_t *vals, size_t count) { + yyjson_mut_arr_with_func({ + unsafe_yyjson_set_sint(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint16( + yyjson_mut_doc *doc, const int16_t *vals, size_t count) { + yyjson_mut_arr_with_func({ + unsafe_yyjson_set_sint(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint32( + yyjson_mut_doc *doc, const int32_t *vals, size_t count) { + yyjson_mut_arr_with_func({ + unsafe_yyjson_set_sint(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint64( + yyjson_mut_doc *doc, const int64_t *vals, size_t count) { + yyjson_mut_arr_with_func({ + unsafe_yyjson_set_sint(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint8( + yyjson_mut_doc *doc, const uint8_t *vals, size_t count) { + yyjson_mut_arr_with_func({ + unsafe_yyjson_set_uint(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint16( + yyjson_mut_doc *doc, const uint16_t *vals, size_t count) { + yyjson_mut_arr_with_func({ + unsafe_yyjson_set_uint(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint32( + yyjson_mut_doc *doc, const uint32_t *vals, size_t count) { + yyjson_mut_arr_with_func({ + unsafe_yyjson_set_uint(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint64( + yyjson_mut_doc *doc, const uint64_t *vals, size_t count) { + yyjson_mut_arr_with_func({ + unsafe_yyjson_set_uint(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_float( + yyjson_mut_doc *doc, const float *vals, size_t count) { + yyjson_mut_arr_with_func({ + unsafe_yyjson_set_float(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_double( + yyjson_mut_doc *doc, const double *vals, size_t count) { + yyjson_mut_arr_with_func({ + unsafe_yyjson_set_double(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_str( + yyjson_mut_doc *doc, const char **vals, size_t count) { + yyjson_mut_arr_with_func({ + if (yyjson_unlikely(!vals[i])) return NULL; + unsafe_yyjson_set_str(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_strn( + yyjson_mut_doc *doc, const char **vals, const size_t *lens, size_t count) { + if (yyjson_unlikely(count > 0 && !lens)) return NULL; + yyjson_mut_arr_with_func({ + if (yyjson_unlikely(!vals[i])) return NULL; + unsafe_yyjson_set_strn(val, vals[i], lens[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_strcpy( + yyjson_mut_doc *doc, const char **vals, size_t count) { + size_t len; + const char *str, *new_str; + yyjson_mut_arr_with_func({ + str = vals[i]; + if (yyjson_unlikely(!str)) return NULL; + len = strlen(str); + new_str = unsafe_yyjson_mut_strncpy(doc, str, len); + if (yyjson_unlikely(!new_str)) return NULL; + unsafe_yyjson_set_strn(val, new_str, len); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_strncpy( + yyjson_mut_doc *doc, const char **vals, const size_t *lens, size_t count) { + size_t len; + const char *str, *new_str; + if (yyjson_unlikely(count > 0 && !lens)) return NULL; + yyjson_mut_arr_with_func({ + str = vals[i]; + if (yyjson_unlikely(!str)) return NULL; + len = lens[i]; + new_str = unsafe_yyjson_mut_strncpy(doc, str, len); + if (yyjson_unlikely(!new_str)) return NULL; + unsafe_yyjson_set_strn(val, new_str, len); + }); +} + +#undef yyjson_mut_arr_with_func + + + +/*============================================================================== + * MARK: - Mutable JSON Array Modification API (Implementation) + *============================================================================*/ + +yyjson_api_inline bool yyjson_mut_arr_insert(yyjson_mut_val *arr, + yyjson_mut_val *val, size_t idx) { + if (yyjson_likely(yyjson_mut_is_arr(arr) && val)) { + size_t len = unsafe_yyjson_get_len(arr); + if (yyjson_likely(idx <= len)) { + unsafe_yyjson_set_len(arr, len + 1); + if (len == 0) { + val->next = val; + arr->uni.ptr = val; + } else { + yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); + yyjson_mut_val *next = prev->next; + if (idx == len) { + prev->next = val; + val->next = next; + arr->uni.ptr = val; + } else { + while (idx-- > 0) { + prev = next; + next = next->next; + } + prev->next = val; + val->next = next; + } + } + return true; + } + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_append(yyjson_mut_val *arr, + yyjson_mut_val *val) { + if (yyjson_likely(yyjson_mut_is_arr(arr) && val)) { + size_t len = unsafe_yyjson_get_len(arr); + unsafe_yyjson_set_len(arr, len + 1); + if (len == 0) { + val->next = val; + } else { + yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); + yyjson_mut_val *next = prev->next; + prev->next = val; + val->next = next; + } + arr->uni.ptr = val; + return true; + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_prepend(yyjson_mut_val *arr, + yyjson_mut_val *val) { + if (yyjson_likely(yyjson_mut_is_arr(arr) && val)) { + size_t len = unsafe_yyjson_get_len(arr); + unsafe_yyjson_set_len(arr, len + 1); + if (len == 0) { + val->next = val; + arr->uni.ptr = val; + } else { + yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); + yyjson_mut_val *next = prev->next; + prev->next = val; + val->next = next; + } + return true; + } + return false; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_replace(yyjson_mut_val *arr, + size_t idx, + yyjson_mut_val *val) { + if (yyjson_likely(yyjson_mut_is_arr(arr) && val)) { + size_t len = unsafe_yyjson_get_len(arr); + if (yyjson_likely(idx < len)) { + if (yyjson_likely(len > 1)) { + yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); + yyjson_mut_val *next = prev->next; + while (idx-- > 0) { + prev = next; + next = next->next; + } + prev->next = val; + val->next = next->next; + if ((void *)next == arr->uni.ptr) arr->uni.ptr = val; + return next; + } else { + yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); + val->next = val; + arr->uni.ptr = val; + return prev; + } + } + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_remove(yyjson_mut_val *arr, + size_t idx) { + if (yyjson_likely(yyjson_mut_is_arr(arr))) { + size_t len = unsafe_yyjson_get_len(arr); + if (yyjson_likely(idx < len)) { + unsafe_yyjson_set_len(arr, len - 1); + if (yyjson_likely(len > 1)) { + yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); + yyjson_mut_val *next = prev->next; + while (idx-- > 0) { + prev = next; + next = next->next; + } + prev->next = next->next; + if ((void *)next == arr->uni.ptr) arr->uni.ptr = prev; + return next; + } else { + return ((yyjson_mut_val *)arr->uni.ptr); + } + } + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_remove_first( + yyjson_mut_val *arr) { + if (yyjson_likely(yyjson_mut_is_arr(arr))) { + size_t len = unsafe_yyjson_get_len(arr); + if (len > 1) { + yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); + yyjson_mut_val *next = prev->next; + prev->next = next->next; + unsafe_yyjson_set_len(arr, len - 1); + return next; + } else if (len == 1) { + yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); + unsafe_yyjson_set_len(arr, 0); + return prev; + } + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_remove_last( + yyjson_mut_val *arr) { + if (yyjson_likely(yyjson_mut_is_arr(arr))) { + size_t len = unsafe_yyjson_get_len(arr); + if (yyjson_likely(len > 1)) { + yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); + yyjson_mut_val *next = prev->next; + unsafe_yyjson_set_len(arr, len - 1); + while (--len > 0) prev = prev->next; + prev->next = next; + next = (yyjson_mut_val *)arr->uni.ptr; + arr->uni.ptr = prev; + return next; + } else if (len == 1) { + yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); + unsafe_yyjson_set_len(arr, 0); + return prev; + } + } + return NULL; +} + +yyjson_api_inline bool yyjson_mut_arr_remove_range(yyjson_mut_val *arr, + size_t _idx, size_t _len) { + if (yyjson_likely(yyjson_mut_is_arr(arr))) { + yyjson_mut_val *prev, *next; + bool tail_removed; + size_t len = unsafe_yyjson_get_len(arr); + if (yyjson_unlikely(_idx + _len > len)) return false; + if (yyjson_unlikely(_len == 0)) return true; + unsafe_yyjson_set_len(arr, len - _len); + if (yyjson_unlikely(len == _len)) return true; + tail_removed = (_idx + _len == len); + prev = ((yyjson_mut_val *)arr->uni.ptr); + while (_idx-- > 0) prev = prev->next; + next = prev->next; + while (_len-- > 0) next = next->next; + prev->next = next; + if (yyjson_unlikely(tail_removed)) arr->uni.ptr = prev; + return true; + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_clear(yyjson_mut_val *arr) { + if (yyjson_likely(yyjson_mut_is_arr(arr))) { + unsafe_yyjson_set_len(arr, 0); + return true; + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_rotate(yyjson_mut_val *arr, + size_t idx) { + if (yyjson_likely(yyjson_mut_is_arr(arr) && + unsafe_yyjson_get_len(arr) > idx)) { + yyjson_mut_val *val = (yyjson_mut_val *)arr->uni.ptr; + while (idx-- > 0) val = val->next; + arr->uni.ptr = (void *)val; + return true; + } + return false; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Array Modification Convenience API (Implementation) + *============================================================================*/ + +yyjson_api_inline bool yyjson_mut_arr_add_val(yyjson_mut_val *arr, + yyjson_mut_val *val) { + return yyjson_mut_arr_append(arr, val); +} + +yyjson_api_inline bool yyjson_mut_arr_add_null(yyjson_mut_doc *doc, + yyjson_mut_val *arr) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_null(doc); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_true(yyjson_mut_doc *doc, + yyjson_mut_val *arr) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_true(doc); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_false(yyjson_mut_doc *doc, + yyjson_mut_val *arr) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_false(doc); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_bool(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + bool _val) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_bool(doc, _val); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_uint(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + uint64_t num) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_uint(doc, num); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_sint(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + int64_t num) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_sint(doc, num); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_int(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + int64_t num) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_sint(doc, num); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_float(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + float num) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_float(doc, num); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_double(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + double num) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_double(doc, num); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_real(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + double num) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_real(doc, num); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_str(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + const char *str) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_str(doc, str); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_strn(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + const char *str, size_t len) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_strn(doc, str, len); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_strcpy(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + const char *str) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_strcpy(doc, str); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_strncpy(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + const char *str, size_t len) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_strncpy(doc, str, len); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_add_arr(yyjson_mut_doc *doc, + yyjson_mut_val *arr) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_arr(doc); + return yyjson_mut_arr_append(arr, val) ? val : NULL; + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_add_obj(yyjson_mut_doc *doc, + yyjson_mut_val *arr) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_obj(doc); + return yyjson_mut_arr_append(arr, val) ? val : NULL; + } + return NULL; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Object API (Implementation) + *============================================================================*/ + +yyjson_api_inline size_t yyjson_mut_obj_size(yyjson_mut_val *obj) { + return yyjson_mut_is_obj(obj) ? unsafe_yyjson_get_len(obj) : 0; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_get(yyjson_mut_val *obj, + const char *key) { + return yyjson_mut_obj_getn(obj, key, key ? strlen(key) : 0); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_getn(yyjson_mut_val *obj, + const char *_key, + size_t key_len) { + size_t len = yyjson_mut_obj_size(obj); + if (yyjson_likely(len && _key)) { + yyjson_mut_val *key = ((yyjson_mut_val *)obj->uni.ptr)->next->next; + while (len-- > 0) { + if (unsafe_yyjson_equals_strn(key, _key, key_len)) return key->next; + key = key->next->next; + } + } + return NULL; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Object Iterator API (Implementation) + *============================================================================*/ + +yyjson_api_inline bool yyjson_mut_obj_iter_init(yyjson_mut_val *obj, + yyjson_mut_obj_iter *iter) { + if (yyjson_likely(yyjson_mut_is_obj(obj) && iter)) { + iter->idx = 0; + iter->max = unsafe_yyjson_get_len(obj); + iter->cur = iter->max ? (yyjson_mut_val *)obj->uni.ptr : NULL; + iter->pre = NULL; + iter->obj = obj; + return true; + } + if (iter) memset(iter, 0, sizeof(yyjson_mut_obj_iter)); + return false; +} + +yyjson_api_inline yyjson_mut_obj_iter yyjson_mut_obj_iter_with( + yyjson_mut_val *obj) { + yyjson_mut_obj_iter iter; + yyjson_mut_obj_iter_init(obj, &iter); + return iter; +} + +yyjson_api_inline bool yyjson_mut_obj_iter_has_next(yyjson_mut_obj_iter *iter) { + return iter ? iter->idx < iter->max : false; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_next( + yyjson_mut_obj_iter *iter) { + if (iter && iter->idx < iter->max) { + yyjson_mut_val *key = iter->cur; + iter->pre = key; + iter->cur = key->next->next; + iter->idx++; + return iter->cur; + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_get_val( + yyjson_mut_val *key) { + return key ? key->next : NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_remove( + yyjson_mut_obj_iter *iter) { + if (yyjson_likely(iter && 0 < iter->idx && iter->idx <= iter->max)) { + yyjson_mut_val *prev = iter->pre; + yyjson_mut_val *cur = iter->cur; + yyjson_mut_val *next = cur->next->next; + if (yyjson_unlikely(iter->idx == iter->max)) iter->obj->uni.ptr = prev; + iter->idx--; + iter->max--; + unsafe_yyjson_set_len(iter->obj, iter->max); + prev->next->next = next; + iter->cur = prev; + return cur->next; + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_get( + yyjson_mut_obj_iter *iter, const char *key) { + return yyjson_mut_obj_iter_getn(iter, key, key ? strlen(key) : 0); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_getn( + yyjson_mut_obj_iter *iter, const char *key, size_t key_len) { + if (iter && key) { + size_t idx = 0; + size_t max = iter->max; + yyjson_mut_val *pre, *cur = iter->cur; + while (idx++ < max) { + pre = cur; + cur = cur->next->next; + if (unsafe_yyjson_equals_strn(cur, key, key_len)) { + iter->idx += idx; + if (iter->idx > max) iter->idx -= max + 1; + iter->pre = pre; + iter->cur = cur; + return cur->next; + } + } + } + return NULL; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Object Creation API (Implementation) + *============================================================================*/ + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj(yyjson_mut_doc *doc) { + if (yyjson_likely(doc)) { + yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); + if (yyjson_likely(val)) { + val->tag = YYJSON_TYPE_OBJ | YYJSON_SUBTYPE_NONE; + return val; + } + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_with_str(yyjson_mut_doc *doc, + const char **keys, + const char **vals, + size_t count) { + if (yyjson_likely(doc && ((count > 0 && keys && vals) || (count == 0)))) { + yyjson_mut_val *obj = unsafe_yyjson_mut_val(doc, 1 + count * 2); + if (yyjson_likely(obj)) { + obj->tag = ((uint64_t)count << YYJSON_TAG_BIT) | YYJSON_TYPE_OBJ; + if (count > 0) { + size_t i; + for (i = 0; i < count; i++) { + yyjson_mut_val *key = obj + (i * 2 + 1); + yyjson_mut_val *val = obj + (i * 2 + 2); + uint64_t key_len = (uint64_t)strlen(keys[i]); + uint64_t val_len = (uint64_t)strlen(vals[i]); + key->tag = (key_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; + val->tag = (val_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; + key->uni.str = keys[i]; + val->uni.str = vals[i]; + key->next = val; + val->next = val + 1; + } + obj[count * 2].next = obj + 1; + obj->uni.ptr = obj + (count * 2 - 1); + } + return obj; + } + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_with_kv(yyjson_mut_doc *doc, + const char **pairs, + size_t count) { + if (yyjson_likely(doc && ((count > 0 && pairs) || (count == 0)))) { + yyjson_mut_val *obj = unsafe_yyjson_mut_val(doc, 1 + count * 2); + if (yyjson_likely(obj)) { + obj->tag = ((uint64_t)count << YYJSON_TAG_BIT) | YYJSON_TYPE_OBJ; + if (count > 0) { + size_t i; + for (i = 0; i < count; i++) { + yyjson_mut_val *key = obj + (i * 2 + 1); + yyjson_mut_val *val = obj + (i * 2 + 2); + const char *key_str = pairs[i * 2 + 0]; + const char *val_str = pairs[i * 2 + 1]; + uint64_t key_len = (uint64_t)strlen(key_str); + uint64_t val_len = (uint64_t)strlen(val_str); + key->tag = (key_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; + val->tag = (val_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; + key->uni.str = key_str; + val->uni.str = val_str; + key->next = val; + val->next = val + 1; + } + obj[count * 2].next = obj + 1; + obj->uni.ptr = obj + (count * 2 - 1); + } + return obj; + } + } + return NULL; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Object Modification API (Implementation) + *============================================================================*/ + +yyjson_api_inline void unsafe_yyjson_mut_obj_add(yyjson_mut_val *obj, + yyjson_mut_val *key, + yyjson_mut_val *val, + size_t len) { + if (yyjson_likely(len)) { + yyjson_mut_val *prev_val = ((yyjson_mut_val *)obj->uni.ptr)->next; + yyjson_mut_val *next_key = prev_val->next; + prev_val->next = key; + val->next = next_key; + } else { + val->next = key; + } + key->next = val; + obj->uni.ptr = (void *)key; + unsafe_yyjson_set_len(obj, len + 1); +} + +yyjson_api_inline yyjson_mut_val *unsafe_yyjson_mut_obj_remove( + yyjson_mut_val *obj, const char *key, size_t key_len) { + size_t obj_len = unsafe_yyjson_get_len(obj); + if (obj_len) { + yyjson_mut_val *pre_key = (yyjson_mut_val *)obj->uni.ptr; + yyjson_mut_val *cur_key = pre_key->next->next; + yyjson_mut_val *removed_item = NULL; + size_t i; + for (i = 0; i < obj_len; i++) { + if (unsafe_yyjson_equals_strn(cur_key, key, key_len)) { + if (!removed_item) removed_item = cur_key->next; + cur_key = cur_key->next->next; + pre_key->next->next = cur_key; + if (i + 1 == obj_len) obj->uni.ptr = pre_key; + i--; + obj_len--; + } else { + pre_key = cur_key; + cur_key = cur_key->next->next; + } + } + unsafe_yyjson_set_len(obj, obj_len); + return removed_item; + } else { + return NULL; + } +} + +yyjson_api_inline bool unsafe_yyjson_mut_obj_replace(yyjson_mut_val *obj, + yyjson_mut_val *key, + yyjson_mut_val *val) { + size_t key_len = unsafe_yyjson_get_len(key); + size_t obj_len = unsafe_yyjson_get_len(obj); + if (obj_len) { + yyjson_mut_val *pre_key = (yyjson_mut_val *)obj->uni.ptr; + yyjson_mut_val *cur_key = pre_key->next->next; + size_t i; + for (i = 0; i < obj_len; i++) { + if (unsafe_yyjson_equals_strn(cur_key, key->uni.str, key_len)) { + cur_key->next->tag = val->tag; + cur_key->next->uni.u64 = val->uni.u64; + return true; + } else { + cur_key = cur_key->next->next; + } + } + } + return false; +} + +yyjson_api_inline void unsafe_yyjson_mut_obj_rotate(yyjson_mut_val *obj, + size_t idx) { + yyjson_mut_val *key = (yyjson_mut_val *)obj->uni.ptr; + while (idx-- > 0) key = key->next->next; + obj->uni.ptr = (void *)key; +} + +yyjson_api_inline bool yyjson_mut_obj_add(yyjson_mut_val *obj, + yyjson_mut_val *key, + yyjson_mut_val *val) { + if (yyjson_likely(yyjson_mut_is_obj(obj) && + yyjson_mut_is_str(key) && val)) { + unsafe_yyjson_mut_obj_add(obj, key, val, unsafe_yyjson_get_len(obj)); + return true; + } + return false; +} + +yyjson_api_inline bool yyjson_mut_obj_put(yyjson_mut_val *obj, + yyjson_mut_val *key, + yyjson_mut_val *val) { + bool replaced = false; + size_t key_len; + yyjson_mut_obj_iter iter; + yyjson_mut_val *cur_key; + if (yyjson_unlikely(!yyjson_mut_is_obj(obj) || + !yyjson_mut_is_str(key))) return false; + key_len = unsafe_yyjson_get_len(key); + yyjson_mut_obj_iter_init(obj, &iter); + while ((cur_key = yyjson_mut_obj_iter_next(&iter)) != 0) { + if (unsafe_yyjson_equals_strn(cur_key, key->uni.str, key_len)) { + if (!replaced && val) { + replaced = true; + val->next = cur_key->next->next; + cur_key->next = val; + } else { + yyjson_mut_obj_iter_remove(&iter); + } + } + } + if (!replaced && val) unsafe_yyjson_mut_obj_add(obj, key, val, iter.max); + return true; +} + +yyjson_api_inline bool yyjson_mut_obj_insert(yyjson_mut_val *obj, + yyjson_mut_val *key, + yyjson_mut_val *val, + size_t idx) { + if (yyjson_likely(yyjson_mut_is_obj(obj) && + yyjson_mut_is_str(key) && val)) { + size_t len = unsafe_yyjson_get_len(obj); + if (yyjson_likely(len >= idx)) { + if (len > idx) { + void *ptr = obj->uni.ptr; + unsafe_yyjson_mut_obj_rotate(obj, idx); + unsafe_yyjson_mut_obj_add(obj, key, val, len); + obj->uni.ptr = ptr; + } else { + unsafe_yyjson_mut_obj_add(obj, key, val, len); + } + return true; + } + } + return false; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove(yyjson_mut_val *obj, + yyjson_mut_val *key) { + if (yyjson_likely(yyjson_mut_is_obj(obj) && yyjson_mut_is_str(key))) { + return unsafe_yyjson_mut_obj_remove(obj, key->uni.str, + unsafe_yyjson_get_len(key)); + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_key( + yyjson_mut_val *obj, const char *key) { + if (yyjson_likely(yyjson_mut_is_obj(obj) && key)) { + size_t key_len = strlen(key); + return unsafe_yyjson_mut_obj_remove(obj, key, key_len); + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_keyn( + yyjson_mut_val *obj, const char *key, size_t key_len) { + if (yyjson_likely(yyjson_mut_is_obj(obj) && key)) { + return unsafe_yyjson_mut_obj_remove(obj, key, key_len); + } + return NULL; +} + +yyjson_api_inline bool yyjson_mut_obj_clear(yyjson_mut_val *obj) { + if (yyjson_likely(yyjson_mut_is_obj(obj))) { + unsafe_yyjson_set_len(obj, 0); + return true; + } + return false; +} + +yyjson_api_inline bool yyjson_mut_obj_replace(yyjson_mut_val *obj, + yyjson_mut_val *key, + yyjson_mut_val *val) { + if (yyjson_likely(yyjson_mut_is_obj(obj) && + yyjson_mut_is_str(key) && val)) { + return unsafe_yyjson_mut_obj_replace(obj, key, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_obj_rotate(yyjson_mut_val *obj, + size_t idx) { + if (yyjson_likely(yyjson_mut_is_obj(obj) && + unsafe_yyjson_get_len(obj) > idx)) { + unsafe_yyjson_mut_obj_rotate(obj, idx); + return true; + } + return false; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Object Modification Convenience API (Implementation) + *============================================================================*/ + +#define yyjson_mut_obj_add_func(func) \ + if (yyjson_likely(doc && yyjson_mut_is_obj(obj) && _key)) { \ + yyjson_mut_val *key = unsafe_yyjson_mut_val(doc, 2); \ + if (yyjson_likely(key)) { \ + size_t len = unsafe_yyjson_get_len(obj); \ + yyjson_mut_val *val = key + 1; \ + size_t key_len = strlen(_key); \ + bool noesc = unsafe_yyjson_is_str_noesc(_key, key_len); \ + key->tag = YYJSON_TYPE_STR; \ + key->tag |= noesc ? YYJSON_SUBTYPE_NOESC : YYJSON_SUBTYPE_NONE; \ + key->tag |= (uint64_t)strlen(_key) << YYJSON_TAG_BIT; \ + key->uni.str = _key; \ + func \ + unsafe_yyjson_mut_obj_add(obj, key, val, len); \ + return true; \ + } \ + } \ + return false + +yyjson_api_inline bool yyjson_mut_obj_add_null(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key) { + yyjson_mut_obj_add_func({ unsafe_yyjson_set_null(val); }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_true(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key) { + yyjson_mut_obj_add_func({ unsafe_yyjson_set_bool(val, true); }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_false(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key) { + yyjson_mut_obj_add_func({ unsafe_yyjson_set_bool(val, false); }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_bool(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key, + bool _val) { + yyjson_mut_obj_add_func({ unsafe_yyjson_set_bool(val, _val); }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_uint(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key, + uint64_t _val) { + yyjson_mut_obj_add_func({ unsafe_yyjson_set_uint(val, _val); }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_sint(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key, + int64_t _val) { + yyjson_mut_obj_add_func({ unsafe_yyjson_set_sint(val, _val); }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_int(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key, + int64_t _val) { + yyjson_mut_obj_add_func({ unsafe_yyjson_set_sint(val, _val); }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_float(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key, + float _val) { + yyjson_mut_obj_add_func({ unsafe_yyjson_set_float(val, _val); }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_double(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key, + double _val) { + yyjson_mut_obj_add_func({ unsafe_yyjson_set_double(val, _val); }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_real(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key, + double _val) { + yyjson_mut_obj_add_func({ unsafe_yyjson_set_real(val, _val); }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_str(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key, + const char *_val) { + if (yyjson_unlikely(!_val)) return false; + yyjson_mut_obj_add_func({ + size_t val_len = strlen(_val); + bool val_noesc = unsafe_yyjson_is_str_noesc(_val, val_len); + val->tag = ((uint64_t)strlen(_val) << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; + val->tag |= val_noesc ? YYJSON_SUBTYPE_NOESC : YYJSON_SUBTYPE_NONE; + val->uni.str = _val; + }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_strn(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key, + const char *_val, + size_t _len) { + if (yyjson_unlikely(!_val)) return false; + yyjson_mut_obj_add_func({ + val->tag = ((uint64_t)_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; + val->uni.str = _val; + }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_strcpy(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key, + const char *_val) { + if (yyjson_unlikely(!_val)) return false; + yyjson_mut_obj_add_func({ + size_t _len = strlen(_val); + val->uni.str = unsafe_yyjson_mut_strncpy(doc, _val, _len); + if (yyjson_unlikely(!val->uni.str)) return false; + val->tag = ((uint64_t)_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; + }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_strncpy(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key, + const char *_val, + size_t _len) { + if (yyjson_unlikely(!_val)) return false; + yyjson_mut_obj_add_func({ + val->uni.str = unsafe_yyjson_mut_strncpy(doc, _val, _len); + if (yyjson_unlikely(!val->uni.str)) return false; + val->tag = ((uint64_t)_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_add_arr(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key) { + yyjson_mut_val *key = yyjson_mut_str(doc, _key); + yyjson_mut_val *val = yyjson_mut_arr(doc); + return yyjson_mut_obj_add(obj, key, val) ? val : NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_add_obj(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key) { + yyjson_mut_val *key = yyjson_mut_str(doc, _key); + yyjson_mut_val *val = yyjson_mut_obj(doc); + return yyjson_mut_obj_add(obj, key, val) ? val : NULL; +} + +yyjson_api_inline bool yyjson_mut_obj_add_val(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key, + yyjson_mut_val *_val) { + if (yyjson_unlikely(!_val)) return false; + yyjson_mut_obj_add_func({ + val = _val; + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_str(yyjson_mut_val *obj, + const char *key) { + return yyjson_mut_obj_remove_strn(obj, key, key ? strlen(key) : 0); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_strn( + yyjson_mut_val *obj, const char *_key, size_t _len) { + if (yyjson_likely(yyjson_mut_is_obj(obj) && _key)) { + yyjson_mut_val *key; + yyjson_mut_obj_iter iter; + yyjson_mut_val *val_removed = NULL; + yyjson_mut_obj_iter_init(obj, &iter); + while ((key = yyjson_mut_obj_iter_next(&iter)) != NULL) { + if (unsafe_yyjson_equals_strn(key, _key, _len)) { + if (!val_removed) val_removed = key->next; + yyjson_mut_obj_iter_remove(&iter); + } + } + return val_removed; + } + return NULL; +} + +yyjson_api_inline bool yyjson_mut_obj_rename_key(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, + const char *new_key) { + if (!key || !new_key) return false; + return yyjson_mut_obj_rename_keyn(doc, obj, key, strlen(key), + new_key, strlen(new_key)); +} + +yyjson_api_inline bool yyjson_mut_obj_rename_keyn(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, + size_t len, + const char *new_key, + size_t new_len) { + char *cpy_key = NULL; + yyjson_mut_val *old_key; + yyjson_mut_obj_iter iter; + if (!doc || !obj || !key || !new_key) return false; + yyjson_mut_obj_iter_init(obj, &iter); + while ((old_key = yyjson_mut_obj_iter_next(&iter))) { + if (unsafe_yyjson_equals_strn((void *)old_key, key, len)) { + if (!cpy_key) { + cpy_key = unsafe_yyjson_mut_strncpy(doc, new_key, new_len); + if (!cpy_key) return false; + } + yyjson_mut_set_strn(old_key, cpy_key, new_len); + } + } + return cpy_key != NULL; +} + + + +#if !defined(YYJSON_DISABLE_UTILS) || !YYJSON_DISABLE_UTILS + +/*============================================================================== + * MARK: - JSON Pointer API (Implementation) + *============================================================================*/ + +#define yyjson_ptr_set_err(_code, _msg) do { \ + if (err) { \ + err->code = YYJSON_PTR_ERR_##_code; \ + err->msg = _msg; \ + err->pos = 0; \ + } \ +} while(false) + +/* require: val != NULL, *ptr == '/', len > 0 */ +yyjson_api yyjson_val *unsafe_yyjson_ptr_getx(yyjson_val *val, + const char *ptr, size_t len, + yyjson_ptr_err *err); + +/* require: val != NULL, *ptr == '/', len > 0 */ +yyjson_api yyjson_mut_val *unsafe_yyjson_mut_ptr_getx(yyjson_mut_val *val, + const char *ptr, + size_t len, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err); + +/* require: val/new_val/doc != NULL, *ptr == '/', len > 0 */ +yyjson_api bool unsafe_yyjson_mut_ptr_putx(yyjson_mut_val *val, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc, + bool create_parent, bool insert_new, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err); + +/* require: val/err != NULL, *ptr == '/', len > 0 */ +yyjson_api yyjson_mut_val *unsafe_yyjson_mut_ptr_replacex( + yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val, + yyjson_ptr_ctx *ctx, yyjson_ptr_err *err); + +/* require: val/err != NULL, *ptr == '/', len > 0 */ +yyjson_api yyjson_mut_val *unsafe_yyjson_mut_ptr_removex(yyjson_mut_val *val, + const char *ptr, + size_t len, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err); + +yyjson_api_inline yyjson_val *yyjson_doc_ptr_get(yyjson_doc *doc, + const char *ptr) { + if (yyjson_unlikely(!ptr)) return NULL; + return yyjson_doc_ptr_getn(doc, ptr, strlen(ptr)); +} + +yyjson_api_inline yyjson_val *yyjson_doc_ptr_getn(yyjson_doc *doc, + const char *ptr, size_t len) { + return yyjson_doc_ptr_getx(doc, ptr, len, NULL); +} + +yyjson_api_inline yyjson_val *yyjson_doc_ptr_getx(yyjson_doc *doc, + const char *ptr, size_t len, + yyjson_ptr_err *err) { + yyjson_ptr_set_err(NONE, NULL); + if (yyjson_unlikely(!doc || !ptr)) { + yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); + return NULL; + } + if (yyjson_unlikely(!doc->root)) { + yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL"); + return NULL; + } + if (yyjson_unlikely(len == 0)) { + return doc->root; + } + if (yyjson_unlikely(*ptr != '/')) { + yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); + return NULL; + } + return unsafe_yyjson_ptr_getx(doc->root, ptr, len, err); +} + +yyjson_api_inline yyjson_val *yyjson_ptr_get(yyjson_val *val, + const char *ptr) { + if (yyjson_unlikely(!ptr)) return NULL; + return yyjson_ptr_getn(val, ptr, strlen(ptr)); +} + +yyjson_api_inline yyjson_val *yyjson_ptr_getn(yyjson_val *val, + const char *ptr, size_t len) { + return yyjson_ptr_getx(val, ptr, len, NULL); +} + +yyjson_api_inline yyjson_val *yyjson_ptr_getx(yyjson_val *val, + const char *ptr, size_t len, + yyjson_ptr_err *err) { + yyjson_ptr_set_err(NONE, NULL); + if (yyjson_unlikely(!val || !ptr)) { + yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); + return NULL; + } + if (yyjson_unlikely(len == 0)) { + return val; + } + if (yyjson_unlikely(*ptr != '/')) { + yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); + return NULL; + } + return unsafe_yyjson_ptr_getx(val, ptr, len, err); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_get(yyjson_mut_doc *doc, + const char *ptr) { + if (!ptr) return NULL; + return yyjson_mut_doc_ptr_getn(doc, ptr, strlen(ptr)); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_getn(yyjson_mut_doc *doc, + const char *ptr, + size_t len) { + return yyjson_mut_doc_ptr_getx(doc, ptr, len, NULL, NULL); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_getx(yyjson_mut_doc *doc, + const char *ptr, + size_t len, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err) { + yyjson_ptr_set_err(NONE, NULL); + if (ctx) memset(ctx, 0, sizeof(*ctx)); + + if (yyjson_unlikely(!doc || !ptr)) { + yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); + return NULL; + } + if (yyjson_unlikely(!doc->root)) { + yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL"); + return NULL; + } + if (yyjson_unlikely(len == 0)) { + return doc->root; + } + if (yyjson_unlikely(*ptr != '/')) { + yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); + return NULL; + } + return unsafe_yyjson_mut_ptr_getx(doc->root, ptr, len, ctx, err); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_get(yyjson_mut_val *val, + const char *ptr) { + if (!ptr) return NULL; + return yyjson_mut_ptr_getn(val, ptr, strlen(ptr)); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_getn(yyjson_mut_val *val, + const char *ptr, + size_t len) { + return yyjson_mut_ptr_getx(val, ptr, len, NULL, NULL); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_getx(yyjson_mut_val *val, + const char *ptr, + size_t len, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err) { + yyjson_ptr_set_err(NONE, NULL); + if (ctx) memset(ctx, 0, sizeof(*ctx)); + + if (yyjson_unlikely(!val || !ptr)) { + yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); + return NULL; + } + if (yyjson_unlikely(len == 0)) { + return val; + } + if (yyjson_unlikely(*ptr != '/')) { + yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); + return NULL; + } + return unsafe_yyjson_mut_ptr_getx(val, ptr, len, ctx, err); +} + +yyjson_api_inline bool yyjson_mut_doc_ptr_add(yyjson_mut_doc *doc, + const char *ptr, + yyjson_mut_val *new_val) { + if (yyjson_unlikely(!ptr)) return false; + return yyjson_mut_doc_ptr_addn(doc, ptr, strlen(ptr), new_val); +} + +yyjson_api_inline bool yyjson_mut_doc_ptr_addn(yyjson_mut_doc *doc, + const char *ptr, + size_t len, + yyjson_mut_val *new_val) { + return yyjson_mut_doc_ptr_addx(doc, ptr, len, new_val, true, NULL, NULL); +} + +yyjson_api_inline bool yyjson_mut_doc_ptr_addx(yyjson_mut_doc *doc, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + bool create_parent, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err) { + yyjson_ptr_set_err(NONE, NULL); + if (ctx) memset(ctx, 0, sizeof(*ctx)); + + if (yyjson_unlikely(!doc || !ptr || !new_val)) { + yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); + return false; + } + if (yyjson_unlikely(len == 0)) { + if (doc->root) { + yyjson_ptr_set_err(SET_ROOT, "cannot set document's root"); + return false; + } else { + doc->root = new_val; + return true; + } + } + if (yyjson_unlikely(*ptr != '/')) { + yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); + return false; + } + if (yyjson_unlikely(!doc->root && !create_parent)) { + yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL"); + return false; + } + if (yyjson_unlikely(!doc->root)) { + yyjson_mut_val *root = yyjson_mut_obj(doc); + if (yyjson_unlikely(!root)) { + yyjson_ptr_set_err(MEMORY_ALLOCATION, "failed to create value"); + return false; + } + if (unsafe_yyjson_mut_ptr_putx(root, ptr, len, new_val, doc, + create_parent, true, ctx, err)) { + doc->root = root; + return true; + } + return false; + } + return unsafe_yyjson_mut_ptr_putx(doc->root, ptr, len, new_val, doc, + create_parent, true, ctx, err); +} + +yyjson_api_inline bool yyjson_mut_ptr_add(yyjson_mut_val *val, + const char *ptr, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc) { + if (yyjson_unlikely(!ptr)) return false; + return yyjson_mut_ptr_addn(val, ptr, strlen(ptr), new_val, doc); +} + +yyjson_api_inline bool yyjson_mut_ptr_addn(yyjson_mut_val *val, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc) { + return yyjson_mut_ptr_addx(val, ptr, len, new_val, doc, true, NULL, NULL); +} + +yyjson_api_inline bool yyjson_mut_ptr_addx(yyjson_mut_val *val, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc, + bool create_parent, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err) { + yyjson_ptr_set_err(NONE, NULL); + if (ctx) memset(ctx, 0, sizeof(*ctx)); + + if (yyjson_unlikely(!val || !ptr || !new_val || !doc)) { + yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); + return false; + } + if (yyjson_unlikely(len == 0)) { + yyjson_ptr_set_err(SET_ROOT, "cannot set root"); + return false; + } + if (yyjson_unlikely(*ptr != '/')) { + yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); + return false; + } + return unsafe_yyjson_mut_ptr_putx(val, ptr, len, new_val, + doc, create_parent, true, ctx, err); +} + +yyjson_api_inline bool yyjson_mut_doc_ptr_set(yyjson_mut_doc *doc, + const char *ptr, + yyjson_mut_val *new_val) { + if (yyjson_unlikely(!ptr)) return false; + return yyjson_mut_doc_ptr_setn(doc, ptr, strlen(ptr), new_val); +} + +yyjson_api_inline bool yyjson_mut_doc_ptr_setn(yyjson_mut_doc *doc, + const char *ptr, size_t len, + yyjson_mut_val *new_val) { + return yyjson_mut_doc_ptr_setx(doc, ptr, len, new_val, true, NULL, NULL); +} + +yyjson_api_inline bool yyjson_mut_doc_ptr_setx(yyjson_mut_doc *doc, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + bool create_parent, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err) { + yyjson_ptr_set_err(NONE, NULL); + if (ctx) memset(ctx, 0, sizeof(*ctx)); + + if (yyjson_unlikely(!doc || !ptr)) { + yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); + return false; + } + if (yyjson_unlikely(len == 0)) { + if (ctx) ctx->old = doc->root; + doc->root = new_val; + return true; + } + if (yyjson_unlikely(*ptr != '/')) { + yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); + return false; + } + if (!new_val) { + if (!doc->root) { + yyjson_ptr_set_err(RESOLVE, "JSON pointer cannot be resolved"); + return false; + } + return !!unsafe_yyjson_mut_ptr_removex(doc->root, ptr, len, ctx, err); + } + if (yyjson_unlikely(!doc->root && !create_parent)) { + yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL"); + return false; + } + if (yyjson_unlikely(!doc->root)) { + yyjson_mut_val *root = yyjson_mut_obj(doc); + if (yyjson_unlikely(!root)) { + yyjson_ptr_set_err(MEMORY_ALLOCATION, "failed to create value"); + return false; + } + if (unsafe_yyjson_mut_ptr_putx(root, ptr, len, new_val, doc, + create_parent, false, ctx, err)) { + doc->root = root; + return true; + } + return false; + } + return unsafe_yyjson_mut_ptr_putx(doc->root, ptr, len, new_val, doc, + create_parent, false, ctx, err); +} + +yyjson_api_inline bool yyjson_mut_ptr_set(yyjson_mut_val *val, + const char *ptr, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc) { + if (yyjson_unlikely(!ptr)) return false; + return yyjson_mut_ptr_setn(val, ptr, strlen(ptr), new_val, doc); +} + +yyjson_api_inline bool yyjson_mut_ptr_setn(yyjson_mut_val *val, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc) { + return yyjson_mut_ptr_setx(val, ptr, len, new_val, doc, true, NULL, NULL); +} + +yyjson_api_inline bool yyjson_mut_ptr_setx(yyjson_mut_val *val, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc, + bool create_parent, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err) { + yyjson_ptr_set_err(NONE, NULL); + if (ctx) memset(ctx, 0, sizeof(*ctx)); + + if (yyjson_unlikely(!val || !ptr || !doc)) { + yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); + return false; + } + if (yyjson_unlikely(len == 0)) { + yyjson_ptr_set_err(SET_ROOT, "cannot set root"); + return false; + } + if (yyjson_unlikely(*ptr != '/')) { + yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); + return false; + } + if (!new_val) { + return !!unsafe_yyjson_mut_ptr_removex(val, ptr, len, ctx, err); + } + return unsafe_yyjson_mut_ptr_putx(val, ptr, len, new_val, doc, + create_parent, false, ctx, err); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_replace( + yyjson_mut_doc *doc, const char *ptr, yyjson_mut_val *new_val) { + if (!ptr) return NULL; + return yyjson_mut_doc_ptr_replacen(doc, ptr, strlen(ptr), new_val); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_replacen( + yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_mut_val *new_val) { + return yyjson_mut_doc_ptr_replacex(doc, ptr, len, new_val, NULL, NULL); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_replacex( + yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_mut_val *new_val, + yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { + + yyjson_ptr_set_err(NONE, NULL); + if (ctx) memset(ctx, 0, sizeof(*ctx)); + + if (yyjson_unlikely(!doc || !ptr || !new_val)) { + yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); + return NULL; + } + if (yyjson_unlikely(len == 0)) { + yyjson_mut_val *root = doc->root; + if (yyjson_unlikely(!root)) { + yyjson_ptr_set_err(RESOLVE, "JSON pointer cannot be resolved"); + return NULL; + } + if (ctx) ctx->old = root; + doc->root = new_val; + return root; + } + if (yyjson_unlikely(!doc->root)) { + yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL"); + return NULL; + } + if (yyjson_unlikely(*ptr != '/')) { + yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); + return NULL; + } + return unsafe_yyjson_mut_ptr_replacex(doc->root, ptr, len, new_val, + ctx, err); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_replace( + yyjson_mut_val *val, const char *ptr, yyjson_mut_val *new_val) { + if (!ptr) return NULL; + return yyjson_mut_ptr_replacen(val, ptr, strlen(ptr), new_val); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_replacen( + yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val) { + return yyjson_mut_ptr_replacex(val, ptr, len, new_val, NULL, NULL); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_replacex( + yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val, + yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { + + yyjson_ptr_set_err(NONE, NULL); + if (ctx) memset(ctx, 0, sizeof(*ctx)); + + if (yyjson_unlikely(!val || !ptr || !new_val)) { + yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); + return NULL; + } + if (yyjson_unlikely(len == 0)) { + yyjson_ptr_set_err(SET_ROOT, "cannot set root"); + return NULL; + } + if (yyjson_unlikely(*ptr != '/')) { + yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); + return NULL; + } + return unsafe_yyjson_mut_ptr_replacex(val, ptr, len, new_val, ctx, err); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_remove( + yyjson_mut_doc *doc, const char *ptr) { + if (!ptr) return NULL; + return yyjson_mut_doc_ptr_removen(doc, ptr, strlen(ptr)); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_removen( + yyjson_mut_doc *doc, const char *ptr, size_t len) { + return yyjson_mut_doc_ptr_removex(doc, ptr, len, NULL, NULL); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_removex( + yyjson_mut_doc *doc, const char *ptr, size_t len, + yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { + + yyjson_ptr_set_err(NONE, NULL); + if (ctx) memset(ctx, 0, sizeof(*ctx)); + + if (yyjson_unlikely(!doc || !ptr)) { + yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); + return NULL; + } + if (yyjson_unlikely(!doc->root)) { + yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL"); + return NULL; + } + if (yyjson_unlikely(len == 0)) { + yyjson_mut_val *root = doc->root; + if (ctx) ctx->old = root; + doc->root = NULL; + return root; + } + if (yyjson_unlikely(*ptr != '/')) { + yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); + return NULL; + } + return unsafe_yyjson_mut_ptr_removex(doc->root, ptr, len, ctx, err); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_remove(yyjson_mut_val *val, + const char *ptr) { + if (!ptr) return NULL; + return yyjson_mut_ptr_removen(val, ptr, strlen(ptr)); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_removen(yyjson_mut_val *val, + const char *ptr, + size_t len) { + return yyjson_mut_ptr_removex(val, ptr, len, NULL, NULL); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_removex(yyjson_mut_val *val, + const char *ptr, + size_t len, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err) { + yyjson_ptr_set_err(NONE, NULL); + if (ctx) memset(ctx, 0, sizeof(*ctx)); + + if (yyjson_unlikely(!val || !ptr)) { + yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); + return NULL; + } + if (yyjson_unlikely(len == 0)) { + yyjson_ptr_set_err(SET_ROOT, "cannot set root"); + return NULL; + } + if (yyjson_unlikely(*ptr != '/')) { + yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); + return NULL; + } + return unsafe_yyjson_mut_ptr_removex(val, ptr, len, ctx, err); +} + +yyjson_api_inline bool yyjson_ptr_ctx_append(yyjson_ptr_ctx *ctx, + yyjson_mut_val *key, + yyjson_mut_val *val) { + yyjson_mut_val *ctn, *pre_key, *pre_val, *cur_key, *cur_val; + if (!ctx || !ctx->ctn || !val) return false; + ctn = ctx->ctn; + + if (yyjson_mut_is_obj(ctn)) { + if (!key) return false; + key->next = val; + pre_key = ctx->pre; + if (unsafe_yyjson_get_len(ctn) == 0) { + val->next = key; + ctn->uni.ptr = key; + ctx->pre = key; + } else if (!pre_key) { + pre_key = (yyjson_mut_val *)ctn->uni.ptr; + pre_val = pre_key->next; + val->next = pre_val->next; + pre_val->next = key; + ctn->uni.ptr = key; + ctx->pre = pre_key; + } else { + cur_key = pre_key->next->next; + cur_val = cur_key->next; + val->next = cur_val->next; + cur_val->next = key; + if (ctn->uni.ptr == cur_key) ctn->uni.ptr = key; + ctx->pre = cur_key; + } + } else { + pre_val = ctx->pre; + if (unsafe_yyjson_get_len(ctn) == 0) { + val->next = val; + ctn->uni.ptr = val; + ctx->pre = val; + } else if (!pre_val) { + pre_val = (yyjson_mut_val *)ctn->uni.ptr; + val->next = pre_val->next; + pre_val->next = val; + ctn->uni.ptr = val; + ctx->pre = pre_val; + } else { + cur_val = pre_val->next; + val->next = cur_val->next; + cur_val->next = val; + if (ctn->uni.ptr == cur_val) ctn->uni.ptr = val; + ctx->pre = cur_val; + } + } + unsafe_yyjson_inc_len(ctn); + return true; +} + +yyjson_api_inline bool yyjson_ptr_ctx_replace(yyjson_ptr_ctx *ctx, + yyjson_mut_val *val) { + yyjson_mut_val *ctn, *pre_key, *cur_key, *pre_val, *cur_val; + if (!ctx || !ctx->ctn || !ctx->pre || !val) return false; + ctn = ctx->ctn; + if (yyjson_mut_is_obj(ctn)) { + pre_key = ctx->pre; + pre_val = pre_key->next; + cur_key = pre_val->next; + cur_val = cur_key->next; + /* replace current value */ + cur_key->next = val; + val->next = cur_val->next; + ctx->old = cur_val; + } else { + pre_val = ctx->pre; + cur_val = pre_val->next; + /* replace current value */ + if (pre_val != cur_val) { + val->next = cur_val->next; + pre_val->next = val; + if (ctn->uni.ptr == cur_val) ctn->uni.ptr = val; + } else { + val->next = val; + ctn->uni.ptr = val; + ctx->pre = val; + } + ctx->old = cur_val; + } + return true; +} + +yyjson_api_inline bool yyjson_ptr_ctx_remove(yyjson_ptr_ctx *ctx) { + yyjson_mut_val *ctn, *pre_key, *pre_val, *cur_key, *cur_val; + size_t len; + if (!ctx || !ctx->ctn || !ctx->pre) return false; + ctn = ctx->ctn; + if (yyjson_mut_is_obj(ctn)) { + pre_key = ctx->pre; + pre_val = pre_key->next; + cur_key = pre_val->next; + cur_val = cur_key->next; + /* remove current key-value */ + pre_val->next = cur_val->next; + if (ctn->uni.ptr == cur_key) ctn->uni.ptr = pre_key; + ctx->pre = NULL; + ctx->old = cur_val; + } else { + pre_val = ctx->pre; + cur_val = pre_val->next; + /* remove current key-value */ + pre_val->next = cur_val->next; + if (ctn->uni.ptr == cur_val) ctn->uni.ptr = pre_val; + ctx->pre = NULL; + ctx->old = cur_val; + } + len = unsafe_yyjson_get_len(ctn) - 1; + if (len == 0) ctn->uni.ptr = NULL; + unsafe_yyjson_set_len(ctn, len); + return true; +} + +#undef yyjson_ptr_set_err + + + +/*============================================================================== + * MARK: - JSON Value at Pointer API (Implementation) + *============================================================================*/ + +/** + Set provided `value` if the JSON Pointer (RFC 6901) exists and is type bool. + Returns true if value at `ptr` exists and is the correct type, otherwise false. + */ +yyjson_api_inline bool yyjson_ptr_get_bool( + yyjson_val *root, const char *ptr, bool *value) { + yyjson_val *val = yyjson_ptr_get(root, ptr); + if (value && yyjson_is_bool(val)) { + *value = unsafe_yyjson_get_bool(val); + return true; + } else { + return false; + } +} + +/** + Set provided `value` if the JSON Pointer (RFC 6901) exists and is an integer + that fits in `uint64_t`. Returns true if successful, otherwise false. + */ +yyjson_api_inline bool yyjson_ptr_get_uint( + yyjson_val *root, const char *ptr, uint64_t *value) { + yyjson_val *val = yyjson_ptr_get(root, ptr); + if (value && val) { + uint64_t ret = val->uni.u64; + if (unsafe_yyjson_is_uint(val) || + (unsafe_yyjson_is_sint(val) && !(ret >> 63))) { + *value = ret; + return true; + } + } + return false; +} + +/** + Set provided `value` if the JSON Pointer (RFC 6901) exists and is an integer + that fits in `int64_t`. Returns true if successful, otherwise false. + */ +yyjson_api_inline bool yyjson_ptr_get_sint( + yyjson_val *root, const char *ptr, int64_t *value) { + yyjson_val *val = yyjson_ptr_get(root, ptr); + if (value && val) { + int64_t ret = val->uni.i64; + if (unsafe_yyjson_is_sint(val) || + (unsafe_yyjson_is_uint(val) && ret >= 0)) { + *value = ret; + return true; + } + } + return false; +} + +/** + Set provided `value` if the JSON Pointer (RFC 6901) exists and is type real. + Returns true if value at `ptr` exists and is the correct type, otherwise false. + */ +yyjson_api_inline bool yyjson_ptr_get_real( + yyjson_val *root, const char *ptr, double *value) { + yyjson_val *val = yyjson_ptr_get(root, ptr); + if (value && yyjson_is_real(val)) { + *value = unsafe_yyjson_get_real(val); + return true; + } else { + return false; + } +} + +/** + Set provided `value` if the JSON Pointer (RFC 6901) exists and is type sint, + uint or real. + Returns true if value at `ptr` exists and is the correct type, otherwise false. + */ +yyjson_api_inline bool yyjson_ptr_get_num( + yyjson_val *root, const char *ptr, double *value) { + yyjson_val *val = yyjson_ptr_get(root, ptr); + if (value && yyjson_is_num(val)) { + *value = unsafe_yyjson_get_num(val); + return true; + } else { + return false; + } +} + +/** + Set provided `value` if the JSON Pointer (RFC 6901) exists and is type string. + Returns true if value at `ptr` exists and is the correct type, otherwise false. + */ +yyjson_api_inline bool yyjson_ptr_get_str( + yyjson_val *root, const char *ptr, const char **value) { + yyjson_val *val = yyjson_ptr_get(root, ptr); + if (value && yyjson_is_str(val)) { + *value = unsafe_yyjson_get_str(val); + return true; + } else { + return false; + } +} + + + +/*============================================================================== + * MARK: - Deprecated + *============================================================================*/ + +/** @deprecated renamed to `yyjson_doc_ptr_get` */ +yyjson_deprecated("renamed to yyjson_doc_ptr_get") +yyjson_api_inline yyjson_val *yyjson_doc_get_pointer(yyjson_doc *doc, + const char *ptr) { + return yyjson_doc_ptr_get(doc, ptr); +} + +/** @deprecated renamed to `yyjson_doc_ptr_getn` */ +yyjson_deprecated("renamed to yyjson_doc_ptr_getn") +yyjson_api_inline yyjson_val *yyjson_doc_get_pointern(yyjson_doc *doc, + const char *ptr, + size_t len) { + return yyjson_doc_ptr_getn(doc, ptr, len); +} + +/** @deprecated renamed to `yyjson_mut_doc_ptr_get` */ +yyjson_deprecated("renamed to yyjson_mut_doc_ptr_get") +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_get_pointer( + yyjson_mut_doc *doc, const char *ptr) { + return yyjson_mut_doc_ptr_get(doc, ptr); +} + +/** @deprecated renamed to `yyjson_mut_doc_ptr_getn` */ +yyjson_deprecated("renamed to yyjson_mut_doc_ptr_getn") +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_get_pointern( + yyjson_mut_doc *doc, const char *ptr, size_t len) { + return yyjson_mut_doc_ptr_getn(doc, ptr, len); +} + +/** @deprecated renamed to `yyjson_ptr_get` */ +yyjson_deprecated("renamed to yyjson_ptr_get") +yyjson_api_inline yyjson_val *yyjson_get_pointer(yyjson_val *val, + const char *ptr) { + return yyjson_ptr_get(val, ptr); +} + +/** @deprecated renamed to `yyjson_ptr_getn` */ +yyjson_deprecated("renamed to yyjson_ptr_getn") +yyjson_api_inline yyjson_val *yyjson_get_pointern(yyjson_val *val, + const char *ptr, + size_t len) { + return yyjson_ptr_getn(val, ptr, len); +} + +/** @deprecated renamed to `yyjson_mut_ptr_get` */ +yyjson_deprecated("renamed to yyjson_mut_ptr_get") +yyjson_api_inline yyjson_mut_val *yyjson_mut_get_pointer(yyjson_mut_val *val, + const char *ptr) { + return yyjson_mut_ptr_get(val, ptr); +} + +/** @deprecated renamed to `yyjson_mut_ptr_getn` */ +yyjson_deprecated("renamed to yyjson_mut_ptr_getn") +yyjson_api_inline yyjson_mut_val *yyjson_mut_get_pointern(yyjson_mut_val *val, + const char *ptr, + size_t len) { + return yyjson_mut_ptr_getn(val, ptr, len); +} + +/** @deprecated renamed to `yyjson_mut_ptr_getn` */ +yyjson_deprecated("renamed to unsafe_yyjson_ptr_getn") +yyjson_api_inline yyjson_val *unsafe_yyjson_get_pointer(yyjson_val *val, + const char *ptr, + size_t len) { + yyjson_ptr_err err; + return unsafe_yyjson_ptr_getx(val, ptr, len, &err); +} + +/** @deprecated renamed to `unsafe_yyjson_mut_ptr_getx` */ +yyjson_deprecated("renamed to unsafe_yyjson_mut_ptr_getx") +yyjson_api_inline yyjson_mut_val *unsafe_yyjson_mut_get_pointer( + yyjson_mut_val *val, const char *ptr, size_t len) { + yyjson_ptr_err err; + return unsafe_yyjson_mut_ptr_getx(val, ptr, len, NULL, &err); +} + +#endif /* YYJSON_DISABLE_UTILS */ + + + +/*============================================================================== + * MARK: - Compiler Hint End + *============================================================================*/ + +#if defined(__clang__) +# pragma clang diagnostic pop +#elif defined(__GNUC__) +# if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) +# pragma GCC diagnostic pop +# endif +#elif defined(_MSC_VER) +# pragma warning(pop) +#endif /* warning suppress end */ + +#ifdef __cplusplus +} +#endif /* extern "C" end */ + +#endif /* YYJSON_H */ diff --git a/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/summary.json b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/summary.json new file mode 100644 index 0000000..908043b --- /dev/null +++ b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/summary.json @@ -0,0 +1,4006 @@ +[ + { + "case": "metadata_heavy", + "variant": "borrow", + "samples": 5, + "peak_reserved_bytes": { + "median": 1208192, + "min": 1208192, + "max": 1208192 + }, + "source_peak_bytes": { + "median": 1059888, + "min": 1059888, + "max": 1059888 + }, + "output_peak_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "parser_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "rss_peak_bytes": { + "median": 2785280, + "min": 2768896, + "max": 2801664 + }, + "elapsed_ns": { + "median": 66395496, + "min": 66302663, + "max": 66397387 + }, + "cpu_ns": { + "median": 14840713, + "min": 14680433, + "max": 14949295 + }, + "parse_call_ns": { + "median": 10710339, + "min": 10679603, + "max": 10748920 + }, + "selection_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "reader_copy_bytes": { + "median": 6312628, + "min": 6312628, + "max": 6312628 + }, + "parser_realloc_copy_bytes": { + "median": 14086144, + "min": 14086144, + "max": 14086144 + }, + "source_byte_seconds": { + "median": 67622.063537, + "min": 67603.216745, + "max": 67632.156584 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 26533.881, + "latency_p99_upper_ns": 36864 + }, + { + "peak_count": 64, + "latency_mean_ns": 5055556.934, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8039215.434, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "compact", + "samples": 5, + "peak_reserved_bytes": { + "median": 1209200, + "min": 1209200, + "max": 1209200 + }, + "source_peak_bytes": { + "median": 1059888, + "min": 1059888, + "max": 1059888 + }, + "output_peak_bytes": { + "median": 7168, + "min": 7168, + "max": 7168 + }, + "parser_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "rss_peak_bytes": { + "median": 2916352, + "min": 2899968, + "max": 2932736 + }, + "elapsed_ns": { + "median": 66425702, + "min": 66346982, + "max": 66647996 + }, + "cpu_ns": { + "median": 15174956, + "min": 15115580, + "max": 15645769 + }, + "parse_call_ns": { + "median": 10767457, + "min": 10730381, + "max": 10897093 + }, + "selection_copy_bytes": { + "median": 28672, + "min": 28672, + "max": 28672 + }, + "reader_copy_bytes": { + "median": 6312628, + "min": 6312628, + "max": 6312628 + }, + "parser_realloc_copy_bytes": { + "median": 14086144, + "min": 14086144, + "max": 14086144 + }, + "source_byte_seconds": { + "median": 42524.965388, + "min": 42518.234312, + "max": 42539.689103 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 512, + "min": 512, + "max": 512 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 26833.023, + "latency_p99_upper_ns": 36864 + }, + { + "peak_count": 64, + "latency_mean_ns": 5056115.033, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8039588.77, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "copy", + "samples": 5, + "peak_reserved_bytes": { + "median": 187312, + "min": 187312, + "max": 187312 + }, + "source_peak_bytes": { + "median": 24672, + "min": 24672, + "max": 24672 + }, + "output_peak_bytes": { + "median": 14896, + "min": 14896, + "max": 14896 + }, + "parser_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "rss_peak_bytes": { + "median": 1835008, + "min": 1818624, + "max": 1835008 + }, + "elapsed_ns": { + "median": 66358054, + "min": 66338315, + "max": 66437867 + }, + "cpu_ns": { + "median": 14754424, + "min": 14688841, + "max": 14887131 + }, + "parse_call_ns": { + "median": 10588699, + "min": 10558757, + "max": 10719986 + }, + "selection_copy_bytes": { + "median": 319488, + "min": 319488, + "max": 319488 + }, + "reader_copy_bytes": { + "median": 6312628, + "min": 6312628, + "max": 6312628 + }, + "parser_realloc_copy_bytes": { + "median": 14086144, + "min": 14086144, + "max": 14086144 + }, + "source_byte_seconds": { + "median": 190.767691, + "min": 190.237303, + "max": 192.97609 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 26285.051, + "latency_p99_upper_ns": 36864 + }, + { + "peak_count": 64, + "latency_mean_ns": 5055200.059, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8039957.693, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "copy_no_pool", + "samples": 5, + "peak_reserved_bytes": { + "median": 170672, + "min": 170672, + "max": 170672 + }, + "source_peak_bytes": { + "median": 24672, + "min": 24672, + "max": 24672 + }, + "output_peak_bytes": { + "median": 14896, + "min": 14896, + "max": 14896 + }, + "parser_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "rss_peak_bytes": { + "median": 1835008, + "min": 1835008, + "max": 1851392 + }, + "elapsed_ns": { + "median": 66421906, + "min": 66367572, + "max": 69246534 + }, + "cpu_ns": { + "median": 14937944, + "min": 14844612, + "max": 16610834 + }, + "parse_call_ns": { + "median": 10714630, + "min": 10626817, + "max": 11758115 + }, + "selection_copy_bytes": { + "median": 319488, + "min": 319488, + "max": 319488 + }, + "reader_copy_bytes": { + "median": 6312628, + "min": 6312628, + "max": 6312628 + }, + "parser_realloc_copy_bytes": { + "median": 14086144, + "min": 14086144, + "max": 14086144 + }, + "source_byte_seconds": { + "median": 193.34471, + "min": 191.787957, + "max": 215.365911 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 26630.812, + "latency_p99_upper_ns": 40960 + }, + { + "peak_count": 64, + "latency_mean_ns": 5055539.021, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8039399.533, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "shared_copy", + "samples": 5, + "peak_reserved_bytes": { + "median": 180144, + "min": 180144, + "max": 180144 + }, + "source_peak_bytes": { + "median": 24672, + "min": 24672, + "max": 24672 + }, + "output_peak_bytes": { + "median": 7728, + "min": 7728, + "max": 7728 + }, + "parser_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "rss_peak_bytes": { + "median": 1835008, + "min": 1835008, + "max": 1835008 + }, + "elapsed_ns": { + "median": 66509552, + "min": 66340017, + "max": 67338922 + }, + "cpu_ns": { + "median": 14641398, + "min": 14565611, + "max": 15543047 + }, + "parse_call_ns": { + "median": 10583202, + "min": 10558947, + "max": 10965512 + }, + "selection_copy_bytes": { + "median": 290816, + "min": 290816, + "max": 290816 + }, + "reader_copy_bytes": { + "median": 6312628, + "min": 6312628, + "max": 6312628 + }, + "parser_realloc_copy_bytes": { + "median": 14086144, + "min": 14086144, + "max": 14086144 + }, + "source_byte_seconds": { + "median": 189.850967, + "min": 189.196651, + "max": 198.833427 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 512, + "min": 512, + "max": 512 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 26126.43, + "latency_p99_upper_ns": 32768 + }, + { + "peak_count": 64, + "latency_mean_ns": 5054896.006, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8039936.652, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "threshold2", + "samples": 5, + "peak_reserved_bytes": { + "median": 180144, + "min": 180144, + "max": 180144 + }, + "source_peak_bytes": { + "median": 24672, + "min": 24672, + "max": 24672 + }, + "output_peak_bytes": { + "median": 7728, + "min": 7728, + "max": 7728 + }, + "parser_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "rss_peak_bytes": { + "median": 1835008, + "min": 1835008, + "max": 1851392 + }, + "elapsed_ns": { + "median": 66354498, + "min": 66341459, + "max": 66675868 + }, + "cpu_ns": { + "median": 14610428, + "min": 14573003, + "max": 15617313 + }, + "parse_call_ns": { + "median": 10568715, + "min": 10552983, + "max": 10794500 + }, + "selection_copy_bytes": { + "median": 290816, + "min": 290816, + "max": 290816 + }, + "reader_copy_bytes": { + "median": 6312628, + "min": 6312628, + "max": 6312628 + }, + "parser_realloc_copy_bytes": { + "median": 14086144, + "min": 14086144, + "max": 14086144 + }, + "source_byte_seconds": { + "median": 189.501318, + "min": 189.19959, + "max": 196.368374 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 512, + "min": 512, + "max": 512 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 26103.785, + "latency_p99_upper_ns": 30720 + }, + { + "peak_count": 64, + "latency_mean_ns": 5054791.455, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8037890.609, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "metadata_heavy", + "variant": "threshold8", + "samples": 5, + "peak_reserved_bytes": { + "median": 180144, + "min": 180144, + "max": 180144 + }, + "source_peak_bytes": { + "median": 24672, + "min": 24672, + "max": 24672 + }, + "output_peak_bytes": { + "median": 7728, + "min": 7728, + "max": 7728 + }, + "parser_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "rss_peak_bytes": { + "median": 1835008, + "min": 1835008, + "max": 1851392 + }, + "elapsed_ns": { + "median": 66346091, + "min": 66342183, + "max": 66620533 + }, + "cpu_ns": { + "median": 14678765, + "min": 14624958, + "max": 15009658 + }, + "parse_call_ns": { + "median": 10599246, + "min": 10558072, + "max": 10663838 + }, + "selection_copy_bytes": { + "median": 290816, + "min": 290816, + "max": 290816 + }, + "reader_copy_bytes": { + "median": 6312628, + "min": 6312628, + "max": 6312628 + }, + "parser_realloc_copy_bytes": { + "median": 14086144, + "min": 14086144, + "max": 14086144 + }, + "source_byte_seconds": { + "median": 190.199351, + "min": 189.596919, + "max": 191.566293 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 512, + "min": 512, + "max": 512 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 26178.92, + "latency_p99_upper_ns": 36864 + }, + { + "peak_count": 64, + "latency_mean_ns": 5054797.43, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8038718.686, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "borrow", + "samples": 5, + "peak_reserved_bytes": { + "median": 2097024, + "min": 2097024, + "max": 2097072 + }, + "source_peak_bytes": { + "median": 2047296, + "min": 2047296, + "max": 2047296 + }, + "output_peak_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "parser_peak_bytes": { + "median": 524336, + "min": 524336, + "max": 524336 + }, + "rss_peak_bytes": { + "median": 3719168, + "min": 3702784, + "max": 3719168 + }, + "elapsed_ns": { + "median": 516876187, + "min": 516415971, + "max": 519737827 + }, + "cpu_ns": { + "median": 58189132, + "min": 56956626, + "max": 63401151 + }, + "parse_call_ns": { + "median": 413462854, + "min": 410873515, + "max": 414175159 + }, + "selection_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "reader_copy_bytes": { + "median": 114814580, + "min": 114814580, + "max": 114814580 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 866155.703795, + "min": 865936.173669, + "max": 869390.688093 + }, + "budget_waits": { + "median": 1258, + "min": 1250, + "max": 1267 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 496219.126, + "latency_p99_upper_ns": 7864320 + }, + { + "peak_count": 30, + "latency_mean_ns": 5528237.536, + "latency_p99_upper_ns": 12582912 + }, + { + "peak_count": 30, + "latency_mean_ns": 8542682.03, + "latency_p99_upper_ns": 15728640 + } + ] + }, + { + "case": "mixed_tight", + "variant": "compact", + "samples": 5, + "peak_reserved_bytes": { + "median": 2096656, + "min": 2095936, + "max": 2097104 + }, + "source_peak_bytes": { + "median": 2047296, + "min": 2047296, + "max": 2047296 + }, + "output_peak_bytes": { + "median": 3360, + "min": 3360, + "max": 3360 + }, + "parser_peak_bytes": { + "median": 524336, + "min": 524336, + "max": 524336 + }, + "rss_peak_bytes": { + "median": 3719168, + "min": 3702784, + "max": 3833856 + }, + "elapsed_ns": { + "median": 330507221, + "min": 330325402, + "max": 332809762 + }, + "cpu_ns": { + "median": 57227425, + "min": 56526552, + "max": 64506702 + }, + "parse_call_ns": { + "median": 257390641, + "min": 255295188, + "max": 258042238 + }, + "selection_copy_bytes": { + "median": 57344, + "min": 57344, + "max": 57344 + }, + "reader_copy_bytes": { + "median": 114814580, + "min": 114814580, + "max": 114814580 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 542286.835871, + "min": 542057.64214, + "max": 544031.993873 + }, + "budget_waits": { + "median": 1246, + "min": 1227, + "max": 1262 + }, + "compacted": { + "median": 1024, + "min": 1024, + "max": 1024 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 314160.033, + "latency_p99_upper_ns": 4718592 + }, + { + "peak_count": 30, + "latency_mean_ns": 5361784.028, + "latency_p99_upper_ns": 10485760 + }, + { + "peak_count": 49, + "latency_mean_ns": 8345801.06, + "latency_p99_upper_ns": 12582912 + } + ] + }, + { + "case": "mixed_tight", + "variant": "copy", + "samples": 5, + "peak_reserved_bytes": { + "median": 1104848, + "min": 1104736, + "max": 1104848 + }, + "source_peak_bytes": { + "median": 393312, + "min": 393312, + "max": 393312 + }, + "output_peak_bytes": { + "median": 79920, + "min": 79920, + "max": 79920 + }, + "parser_peak_bytes": { + "median": 524336, + "min": 524336, + "max": 524336 + }, + "rss_peak_bytes": { + "median": 1884160, + "min": 1884160, + "max": 1900544 + }, + "elapsed_ns": { + "median": 134798098, + "min": 134667407, + "max": 135397301 + }, + "cpu_ns": { + "median": 52545277, + "min": 52218674, + "max": 55535720 + }, + "parse_call_ns": { + "median": 26282225, + "min": 26241260, + "max": 28191073 + }, + "selection_copy_bytes": { + "median": 26872064, + "min": 26872064, + "max": 26872064 + }, + "reader_copy_bytes": { + "median": 114814580, + "min": 114814580, + "max": 114814580 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 6883.203763, + "min": 6810.984162, + "max": 7296.683374 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 47583.467, + "latency_p99_upper_ns": 147456 + }, + { + "peak_count": 64, + "latency_mean_ns": 5082343.96, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8083520.998, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "copy_no_pool", + "samples": 5, + "peak_reserved_bytes": { + "median": 842368, + "min": 842368, + "max": 842368 + }, + "source_peak_bytes": { + "median": 393312, + "min": 393312, + "max": 393312 + }, + "output_peak_bytes": { + "median": 79920, + "min": 79920, + "max": 79920 + }, + "parser_peak_bytes": { + "median": 524336, + "min": 524336, + "max": 524336 + }, + "rss_peak_bytes": { + "median": 1933312, + "min": 1916928, + "max": 1949696 + }, + "elapsed_ns": { + "median": 135708499, + "min": 135580728, + "max": 135818181 + }, + "cpu_ns": { + "median": 59498427, + "min": 59055276, + "max": 61310764 + }, + "parse_call_ns": { + "median": 27370335, + "min": 27293452, + "max": 27699522 + }, + "selection_copy_bytes": { + "median": 26872064, + "min": 26872064, + "max": 26872064 + }, + "reader_copy_bytes": { + "median": 114814580, + "min": 114814580, + "max": 114814580 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 8320.069469, + "min": 8268.860241, + "max": 8492.13471 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 54118.737, + "latency_p99_upper_ns": 180224 + }, + { + "peak_count": 64, + "latency_mean_ns": 5093193.132, + "latency_p99_upper_ns": 5767168 + }, + { + "peak_count": 64, + "latency_mean_ns": 8094306.969, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "shared_copy", + "samples": 5, + "peak_reserved_bytes": { + "median": 1097792, + "min": 1097792, + "max": 1097792 + }, + "source_peak_bytes": { + "median": 393312, + "min": 393312, + "max": 393312 + }, + "output_peak_bytes": { + "median": 72752, + "min": 72752, + "max": 72752 + }, + "parser_peak_bytes": { + "median": 524336, + "min": 524336, + "max": 524336 + }, + "rss_peak_bytes": { + "median": 1884160, + "min": 1884160, + "max": 1900544 + }, + "elapsed_ns": { + "median": 134698503, + "min": 134660107, + "max": 134733970 + }, + "cpu_ns": { + "median": 52085095, + "min": 51849496, + "max": 52189389 + }, + "parse_call_ns": { + "median": 26235438, + "min": 26215409, + "max": 26273407 + }, + "selection_copy_bytes": { + "median": 26814720, + "min": 26814720, + "max": 26814720 + }, + "reader_copy_bytes": { + "median": 114814580, + "min": 114814580, + "max": 114814580 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 6831.305534, + "min": 6785.330268, + "max": 6865.482399 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 1024, + "min": 1024, + "max": 1024 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 47354.551, + "latency_p99_upper_ns": 147456 + }, + { + "peak_count": 64, + "latency_mean_ns": 5081713.058, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8082113.784, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "threshold2", + "samples": 5, + "peak_reserved_bytes": { + "median": 1097792, + "min": 1097792, + "max": 1097792 + }, + "source_peak_bytes": { + "median": 393312, + "min": 393312, + "max": 393312 + }, + "output_peak_bytes": { + "median": 72752, + "min": 72752, + "max": 72752 + }, + "parser_peak_bytes": { + "median": 524336, + "min": 524336, + "max": 524336 + }, + "rss_peak_bytes": { + "median": 1884160, + "min": 1867776, + "max": 1900544 + }, + "elapsed_ns": { + "median": 134646087, + "min": 134596389, + "max": 134805557 + }, + "cpu_ns": { + "median": 51969989, + "min": 51772899, + "max": 52099602 + }, + "parse_call_ns": { + "median": 26207832, + "min": 26192074, + "max": 26303805 + }, + "selection_copy_bytes": { + "median": 26814720, + "min": 26814720, + "max": 26814720 + }, + "reader_copy_bytes": { + "median": 114814580, + "min": 114814580, + "max": 114814580 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 6812.54134, + "min": 6795.293198, + "max": 6823.249522 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 1024, + "min": 1024, + "max": 1024 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 47208.702, + "latency_p99_upper_ns": 147456 + }, + { + "peak_count": 64, + "latency_mean_ns": 5082291.09, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8082717.212, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "mixed_tight", + "variant": "threshold8", + "samples": 5, + "peak_reserved_bytes": { + "median": 1097792, + "min": 1097792, + "max": 1097792 + }, + "source_peak_bytes": { + "median": 393312, + "min": 393312, + "max": 393312 + }, + "output_peak_bytes": { + "median": 11312, + "min": 11312, + "max": 11312 + }, + "parser_peak_bytes": { + "median": 524336, + "min": 524336, + "max": 524336 + }, + "rss_peak_bytes": { + "median": 2048000, + "min": 2031616, + "max": 2064384 + }, + "elapsed_ns": { + "median": 134627181, + "min": 134514858, + "max": 135143135 + }, + "cpu_ns": { + "median": 51051158, + "min": 50901202, + "max": 54181725 + }, + "parse_call_ns": { + "median": 26232175, + "min": 26138215, + "max": 28073539 + }, + "selection_copy_bytes": { + "median": 1059072, + "min": 1059072, + "max": 1059072 + }, + "reader_copy_bytes": { + "median": 114814580, + "min": 114814580, + "max": 114814580 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 7499.787736, + "min": 7468.893211, + "max": 7971.142415 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 1024, + "min": 1024, + "max": 1024 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 46365.068, + "latency_p99_upper_ns": 147456 + }, + { + "peak_count": 64, + "latency_mean_ns": 5080938.783, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8081990.295, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "borrow", + "samples": 5, + "peak_reserved_bytes": { + "median": 4427696, + "min": 4427696, + "max": 4427696 + }, + "source_peak_bytes": { + "median": 4230192, + "min": 4230192, + "max": 4230192 + }, + "output_peak_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 5537792, + "min": 5521408, + "max": 5554176 + }, + "elapsed_ns": { + "median": 132124751, + "min": 131976979, + "max": 132469040 + }, + "cpu_ns": { + "median": 38591495, + "min": 37612015, + "max": 41862764 + }, + "parse_call_ns": { + "median": 22573964, + "min": 22444229, + "max": 22964342 + }, + "selection_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 540860.949553, + "min": 540831.163899, + "max": 541099.43903 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 64, + "latency_mean_ns": 8058679.423, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "compact", + "samples": 5, + "peak_reserved_bytes": { + "median": 4427696, + "min": 4427696, + "max": 4427696 + }, + "source_peak_bytes": { + "median": 4230192, + "min": 4230192, + "max": 4230192 + }, + "output_peak_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 5537792, + "min": 5537792, + "max": 5554176 + }, + "elapsed_ns": { + "median": 132110379, + "min": 131996119, + "max": 132186905 + }, + "cpu_ns": { + "median": 38257181, + "min": 38004572, + "max": 38709650 + }, + "parse_call_ns": { + "median": 22486562, + "min": 22434299, + "max": 22557256 + }, + "selection_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 540815.06589, + "min": 540791.270719, + "max": 540907.798619 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 64, + "latency_mean_ns": 8057936.641, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "copy", + "samples": 5, + "peak_reserved_bytes": { + "median": 303072, + "min": 303072, + "max": 303072 + }, + "source_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "output_peak_bytes": { + "median": 7168, + "min": 7168, + "max": 7168 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 1818624, + "min": 1818624, + "max": 1818624 + }, + "elapsed_ns": { + "median": 131689453, + "min": 131600270, + "max": 131752053 + }, + "cpu_ns": { + "median": 34877739, + "min": 34455850, + "max": 35243759 + }, + "parse_call_ns": { + "median": 21993246, + "min": 21964978, + "max": 22030534 + }, + "selection_copy_bytes": { + "median": 57344, + "min": 57344, + "max": 57344 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 1845.194241, + "min": 1832.537919, + "max": 1857.757504 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 64, + "latency_mean_ns": 8053071.22, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "copy_no_pool", + "samples": 5, + "peak_reserved_bytes": { + "median": 237296, + "min": 237296, + "max": 237296 + }, + "source_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "output_peak_bytes": { + "median": 7168, + "min": 7168, + "max": 7168 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 1818624, + "min": 1802240, + "max": 1835008 + }, + "elapsed_ns": { + "median": 132246841, + "min": 132199048, + "max": 137450461 + }, + "cpu_ns": { + "median": 42202499, + "min": 41767998, + "max": 46306762 + }, + "parse_call_ns": { + "median": 24805054, + "min": 24673720, + "max": 25720817 + }, + "selection_copy_bytes": { + "median": 57344, + "min": 57344, + "max": 57344 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 2084.967873, + "min": 2066.312998, + "max": 2217.245474 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 64, + "latency_mean_ns": 8059680.607, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "shared_copy", + "samples": 5, + "peak_reserved_bytes": { + "median": 303072, + "min": 303072, + "max": 303072 + }, + "source_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "output_peak_bytes": { + "median": 7168, + "min": 7168, + "max": 7168 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 1818624, + "min": 1802240, + "max": 1835008 + }, + "elapsed_ns": { + "median": 132103712, + "min": 131708165, + "max": 134003964 + }, + "cpu_ns": { + "median": 35248408, + "min": 34456703, + "max": 37157688 + }, + "parse_call_ns": { + "median": 22044118, + "min": 21940218, + "max": 22141327 + }, + "selection_copy_bytes": { + "median": 57344, + "min": 57344, + "max": 57344 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 1858.44117, + "min": 1833.007769, + "max": 1917.711679 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 64, + "latency_mean_ns": 8054276.953, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "threshold2", + "samples": 5, + "peak_reserved_bytes": { + "median": 303072, + "min": 303072, + "max": 303072 + }, + "source_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "output_peak_bytes": { + "median": 7168, + "min": 7168, + "max": 7168 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 1818624, + "min": 1802240, + "max": 1835008 + }, + "elapsed_ns": { + "median": 132093280, + "min": 131703634, + "max": 132588310 + }, + "cpu_ns": { + "median": 36810738, + "min": 34747849, + "max": 37673671 + }, + "parse_call_ns": { + "median": 22338927, + "min": 21989760, + "max": 22518430 + }, + "selection_copy_bytes": { + "median": 57344, + "min": 57344, + "max": 57344 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 1914.610493, + "min": 1842.615404, + "max": 1949.11739 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 64, + "latency_mean_ns": 8054865.09, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "one_slow", + "variant": "threshold8", + "samples": 5, + "peak_reserved_bytes": { + "median": 303072, + "min": 303072, + "max": 303072 + }, + "source_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "output_peak_bytes": { + "median": 7168, + "min": 7168, + "max": 7168 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 1818624, + "min": 1802240, + "max": 1818624 + }, + "elapsed_ns": { + "median": 131798127, + "min": 131620844, + "max": 131976855 + }, + "cpu_ns": { + "median": 34803856, + "min": 34446035, + "max": 36997295 + }, + "parse_call_ns": { + "median": 22050963, + "min": 21905479, + "max": 22094634 + }, + "selection_copy_bytes": { + "median": 57344, + "min": 57344, + "max": 57344 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 1846.36305, + "min": 1832.609103, + "max": 1904.528214 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 64, + "latency_mean_ns": 8054286.008, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "borrow", + "samples": 5, + "peak_reserved_bytes": { + "median": 4435888, + "min": 4435888, + "max": 4435888 + }, + "source_peak_bytes": { + "median": 4230192, + "min": 4230192, + "max": 4230192 + }, + "output_peak_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 4767744, + "min": 4767744, + "max": 4767744 + }, + "elapsed_ns": { + "median": 133814643, + "min": 133553215, + "max": 134337593 + }, + "cpu_ns": { + "median": 68888479, + "min": 68534602, + "max": 71105404 + }, + "parse_call_ns": { + "median": 22344284, + "min": 22264001, + "max": 22575073 + }, + "selection_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 541341.207084, + "min": 541236.958782, + "max": 541448.462493 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 52115.836, + "latency_p99_upper_ns": 81920 + }, + { + "peak_count": 64, + "latency_mean_ns": 5078986.712, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8067041.718, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "compact", + "samples": 5, + "peak_reserved_bytes": { + "median": 4730672, + "min": 4730672, + "max": 4730672 + }, + "source_peak_bytes": { + "median": 4230192, + "min": 4230192, + "max": 4230192 + }, + "output_peak_bytes": { + "median": 2001776, + "min": 1936144, + "max": 2034592 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 6340608, + "min": 6340608, + "max": 6340608 + }, + "elapsed_ns": { + "median": 134204038, + "min": 134074359, + "max": 135831514 + }, + "cpu_ns": { + "median": 74886880, + "min": 74679639, + "max": 84355786 + }, + "parse_call_ns": { + "median": 22736073, + "min": 22714288, + "max": 23107923 + }, + "selection_copy_bytes": { + "median": 33554432, + "min": 33554432, + "max": 33554432 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 341191.973388, + "min": 341111.908821, + "max": 341580.411374 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 1024, + "min": 1024, + "max": 1024 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 54208.683, + "latency_p99_upper_ns": 90112 + }, + { + "peak_count": 64, + "latency_mean_ns": 5084673.227, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8069796.873, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "copy", + "samples": 5, + "peak_reserved_bytes": { + "median": 4504544, + "min": 4504544, + "max": 4504544 + }, + "source_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "output_peak_bytes": { + "median": 4233264, + "min": 4233264, + "max": 4233264 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 5292032, + "min": 5275648, + "max": 5292032 + }, + "elapsed_ns": { + "median": 134436483, + "min": 134254523, + "max": 139508137 + }, + "cpu_ns": { + "median": 76196602, + "min": 74842901, + "max": 88332555 + }, + "parse_call_ns": { + "median": 22285338, + "min": 22151327, + "max": 22864596 + }, + "selection_copy_bytes": { + "median": 100663296, + "min": 100663296, + "max": 100663296 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 2295.795833, + "min": 2277.11069, + "max": 2528.253394 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 58635.959, + "latency_p99_upper_ns": 90112 + }, + { + "peak_count": 64, + "latency_mean_ns": 5084371.237, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8075247.27, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "copy_no_pool", + "samples": 5, + "peak_reserved_bytes": { + "median": 4373248, + "min": 4373248, + "max": 4373248 + }, + "source_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "output_peak_bytes": { + "median": 4233264, + "min": 4233264, + "max": 4233264 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 5816320, + "min": 5799936, + "max": 6078464 + }, + "elapsed_ns": { + "median": 134471775, + "min": 134289332, + "max": 216945564 + }, + "cpu_ns": { + "median": 76002725, + "min": 75355273, + "max": 116157398 + }, + "parse_call_ns": { + "median": 22740343, + "min": 22600489, + "max": 25703347 + }, + "selection_copy_bytes": { + "median": 100663296, + "min": 100663296, + "max": 100663296 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 2334.193158, + "min": 2317.391148, + "max": 3917.681175 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 59008.762, + "latency_p99_upper_ns": 90112 + }, + { + "peak_count": 64, + "latency_mean_ns": 5084982.783, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8075279.097, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "shared_copy", + "samples": 5, + "peak_reserved_bytes": { + "median": 2371504, + "min": 2371504, + "max": 2371504 + }, + "source_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "output_peak_bytes": { + "median": 2100224, + "min": 2100224, + "max": 2100224 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 3293184, + "min": 3178496, + "max": 3571712 + }, + "elapsed_ns": { + "median": 133593447, + "min": 133495777, + "max": 135030934 + }, + "cpu_ns": { + "median": 66640259, + "min": 66172548, + "max": 71236281 + }, + "parse_call_ns": { + "median": 22303696, + "min": 22176603, + "max": 22446961 + }, + "selection_copy_bytes": { + "median": 33554432, + "min": 33554432, + "max": 33554432 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 2044.238204, + "min": 2031.917671, + "max": 2100.123381 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 2048, + "min": 2048, + "max": 2048 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 51484.234, + "latency_p99_upper_ns": 81920 + }, + { + "peak_count": 64, + "latency_mean_ns": 5078396.125, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8066089.677, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "threshold2", + "samples": 5, + "peak_reserved_bytes": { + "median": 2371504, + "min": 2371504, + "max": 2371504 + }, + "source_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "output_peak_bytes": { + "median": 2100224, + "min": 2100224, + "max": 2100224 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 3194880, + "min": 3194880, + "max": 3244032 + }, + "elapsed_ns": { + "median": 133655494, + "min": 133441147, + "max": 134034428 + }, + "cpu_ns": { + "median": 66434679, + "min": 66234578, + "max": 69077852 + }, + "parse_call_ns": { + "median": 22159339, + "min": 22119254, + "max": 22386881 + }, + "selection_copy_bytes": { + "median": 33554432, + "min": 33554432, + "max": 33554432 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 2045.927873, + "min": 2030.079604, + "max": 2071.219143 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 2048, + "min": 2048, + "max": 2048 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 51484.504, + "latency_p99_upper_ns": 73728 + }, + { + "peak_count": 64, + "latency_mean_ns": 5078118.015, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8066441.419, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "same_large_field", + "variant": "threshold8", + "samples": 5, + "peak_reserved_bytes": { + "median": 4435888, + "min": 4435888, + "max": 4435888 + }, + "source_peak_bytes": { + "median": 4230192, + "min": 4230192, + "max": 4230192 + }, + "output_peak_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 4767744, + "min": 4767744, + "max": 4833280 + }, + "elapsed_ns": { + "median": 133681327, + "min": 133447386, + "max": 134457305 + }, + "cpu_ns": { + "median": 69361342, + "min": 68765370, + "max": 70251788 + }, + "parse_call_ns": { + "median": 22353361, + "min": 22338685, + "max": 22437830 + }, + "selection_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 541359.828153, + "min": 541289.267391, + "max": 541408.186663 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 52372.427, + "latency_p99_upper_ns": 81920 + }, + { + "peak_count": 64, + "latency_mean_ns": 5079700.568, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8067374.837, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "borrow", + "samples": 5, + "peak_reserved_bytes": { + "median": 4435888, + "min": 4435888, + "max": 4435888 + }, + "source_peak_bytes": { + "median": 4230192, + "min": 4230192, + "max": 4230192 + }, + "output_peak_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 4767744, + "min": 4767744, + "max": 5390336 + }, + "elapsed_ns": { + "median": 133311566, + "min": 133254368, + "max": 133477288 + }, + "cpu_ns": { + "median": 53725285, + "min": 52234245, + "max": 54530428 + }, + "parse_call_ns": { + "median": 22266351, + "min": 22239925, + "max": 22789187 + }, + "selection_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 541551.170985, + "min": 541367.893955, + "max": 541575.408384 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 46306.509, + "latency_p99_upper_ns": 61440 + }, + { + "peak_count": 64, + "latency_mean_ns": 5067325.337, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8070214.071, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "compact", + "samples": 5, + "peak_reserved_bytes": { + "median": 4730672, + "min": 4730672, + "max": 4730672 + }, + "source_peak_bytes": { + "median": 4230192, + "min": 4230192, + "max": 4230192 + }, + "output_peak_bytes": { + "median": 2100224, + "min": 2067408, + "max": 2100224 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 6340608, + "min": 6340608, + "max": 6406144 + }, + "elapsed_ns": { + "median": 133282278, + "min": 133118662, + "max": 133472857 + }, + "cpu_ns": { + "median": 59607669, + "min": 59503628, + "max": 62602975 + }, + "parse_call_ns": { + "median": 22648269, + "min": 22558632, + "max": 23134595 + }, + "selection_copy_bytes": { + "median": 33554432, + "min": 33554432, + "max": 33554432 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 340524.867797, + "min": 340502.324772, + "max": 340709.17918 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 1024, + "min": 1024, + "max": 1024 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 47236.674, + "latency_p99_upper_ns": 73728 + }, + { + "peak_count": 64, + "latency_mean_ns": 5071269.907, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8068767.35, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "copy", + "samples": 5, + "peak_reserved_bytes": { + "median": 2378784, + "min": 2378784, + "max": 2378784 + }, + "source_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "output_peak_bytes": { + "median": 2107504, + "min": 2107504, + "max": 2107504 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 3948544, + "min": 3751936, + "max": 3964928 + }, + "elapsed_ns": { + "median": 133179940, + "min": 133174357, + "max": 133407209 + }, + "cpu_ns": { + "median": 52486508, + "min": 52033688, + "max": 55263103 + }, + "parse_call_ns": { + "median": 22154380, + "min": 22117835, + "max": 22433685 + }, + "selection_copy_bytes": { + "median": 33669120, + "min": 33669120, + "max": 33669120 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 2028.917653, + "min": 2021.284206, + "max": 2079.608844 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 46179.91, + "latency_p99_upper_ns": 61440 + }, + { + "peak_count": 64, + "latency_mean_ns": 5068142.38, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8068218.996, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "copy_no_pool", + "samples": 5, + "peak_reserved_bytes": { + "median": 2312896, + "min": 2312896, + "max": 2312896 + }, + "source_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "output_peak_bytes": { + "median": 2107504, + "min": 2107504, + "max": 2107504 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 3194880, + "min": 3178496, + "max": 3194880 + }, + "elapsed_ns": { + "median": 133540522, + "min": 133362779, + "max": 134281084 + }, + "cpu_ns": { + "median": 58472614, + "min": 57999768, + "max": 62190824 + }, + "parse_call_ns": { + "median": 24345793, + "min": 24134627, + "max": 25370210 + }, + "selection_copy_bytes": { + "median": 33669120, + "min": 33669120, + "max": 33669120 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 2208.417867, + "min": 2191.645151, + "max": 2300.277794 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 51364.197, + "latency_p99_upper_ns": 81920 + }, + { + "peak_count": 64, + "latency_mean_ns": 5074603.185, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8073207.582, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "shared_copy", + "samples": 5, + "peak_reserved_bytes": { + "median": 2378672, + "min": 2378672, + "max": 2378672 + }, + "source_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "output_peak_bytes": { + "median": 2107392, + "min": 2107392, + "max": 2107392 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 3899392, + "min": 3293184, + "max": 3948544 + }, + "elapsed_ns": { + "median": 133216315, + "min": 133064931, + "max": 154001095 + }, + "cpu_ns": { + "median": 52117164, + "min": 51631438, + "max": 65368726 + }, + "parse_call_ns": { + "median": 22128273, + "min": 22057182, + "max": 23437273 + }, + "selection_copy_bytes": { + "median": 33611776, + "min": 33611776, + "max": 33611776 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 2026.862393, + "min": 2014.496107, + "max": 2683.230182 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 1024, + "min": 1024, + "max": 1024 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 46182.627, + "latency_p99_upper_ns": 61440 + }, + { + "peak_count": 64, + "latency_mean_ns": 5068255.587, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8067189.304, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "threshold2", + "samples": 5, + "peak_reserved_bytes": { + "median": 2378672, + "min": 2378672, + "max": 2378672 + }, + "source_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "output_peak_bytes": { + "median": 2107392, + "min": 2107392, + "max": 2107392 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 3751936, + "min": 3342336, + "max": 3932160 + }, + "elapsed_ns": { + "median": 133312135, + "min": 133094723, + "max": 134333542 + }, + "cpu_ns": { + "median": 52726291, + "min": 52362717, + "max": 53734268 + }, + "parse_call_ns": { + "median": 22219255, + "min": 22103023, + "max": 22533891 + }, + "selection_copy_bytes": { + "median": 33611776, + "min": 33611776, + "max": 33611776 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 2039.714059, + "min": 2022.420003, + "max": 2071.170012 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 1024, + "min": 1024, + "max": 1024 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 46192.459, + "latency_p99_upper_ns": 65536 + }, + { + "peak_count": 64, + "latency_mean_ns": 5068879.809, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8069081.323, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "slow_large_field", + "variant": "threshold8", + "samples": 5, + "peak_reserved_bytes": { + "median": 4443056, + "min": 4443056, + "max": 4443056 + }, + "source_peak_bytes": { + "median": 4230192, + "min": 4230192, + "max": 4230192 + }, + "output_peak_bytes": { + "median": 7168, + "min": 7168, + "max": 7168 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 5292032, + "min": 4751360, + "max": 5439488 + }, + "elapsed_ns": { + "median": 133341496, + "min": 133297584, + "max": 134650847 + }, + "cpu_ns": { + "median": 54857945, + "min": 53670610, + "max": 58145169 + }, + "parse_call_ns": { + "median": 22618201, + "min": 22263776, + "max": 22801055 + }, + "selection_copy_bytes": { + "median": 57344, + "min": 57344, + "max": 57344 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 541518.37496, + "min": 541459.255198, + "max": 542663.104532 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 1024, + "min": 1024, + "max": 1024 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 47550.497, + "latency_p99_upper_ns": 73728 + }, + { + "peak_count": 64, + "latency_mean_ns": 5070242.543, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8069675.14, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "borrow", + "samples": 5, + "peak_reserved_bytes": { + "median": 4435888, + "min": 4435888, + "max": 4435888 + }, + "source_peak_bytes": { + "median": 4230192, + "min": 4230192, + "max": 4230192 + }, + "output_peak_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 5373952, + "min": 5373952, + "max": 5373952 + }, + "elapsed_ns": { + "median": 132595906, + "min": 132489898, + "max": 133433884 + }, + "cpu_ns": { + "median": 49691116, + "min": 48808681, + "max": 51462618 + }, + "parse_call_ns": { + "median": 22667622, + "min": 22622066, + "max": 23747967 + }, + "selection_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 540593.356702, + "min": 540484.370521, + "max": 540814.68462 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 45356.652, + "latency_p99_upper_ns": 65536 + }, + { + "peak_count": 64, + "latency_mean_ns": 5069713.765, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8055489.045, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "compact", + "samples": 5, + "peak_reserved_bytes": { + "median": 4436784, + "min": 4436784, + "max": 4436784 + }, + "source_peak_bytes": { + "median": 4230192, + "min": 4230192, + "max": 4230192 + }, + "output_peak_bytes": { + "median": 6944, + "min": 6944, + "max": 7056 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 5537792, + "min": 5488640, + "max": 5603328 + }, + "elapsed_ns": { + "median": 132699783, + "min": 132597323, + "max": 132746292 + }, + "cpu_ns": { + "median": 50225388, + "min": 49739534, + "max": 50870250 + }, + "parse_call_ns": { + "median": 22671992, + "min": 22546544, + "max": 22749218 + }, + "selection_copy_bytes": { + "median": 57344, + "min": 57344, + "max": 57344 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 340108.105991, + "min": 340105.112239, + "max": 340246.674827 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 1024, + "min": 1024, + "max": 1024 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 45463.711, + "latency_p99_upper_ns": 65536 + }, + { + "peak_count": 64, + "latency_mean_ns": 5069991.558, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8055038.37, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "copy", + "samples": 5, + "peak_reserved_bytes": { + "median": 318432, + "min": 318432, + "max": 318432 + }, + "source_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "output_peak_bytes": { + "median": 47152, + "min": 47152, + "max": 47152 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 1851392, + "min": 1851392, + "max": 1867776 + }, + "elapsed_ns": { + "median": 132282510, + "min": 132122049, + "max": 132351078 + }, + "cpu_ns": { + "median": 46122525, + "min": 45960158, + "max": 46415608 + }, + "parse_call_ns": { + "median": 22062914, + "min": 22012014, + "max": 22082400 + }, + "selection_copy_bytes": { + "median": 33669120, + "min": 33669120, + "max": 33669120 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 1991.776071, + "min": 1985.913742, + "max": 1996.444688 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 42165.024, + "latency_p99_upper_ns": 53248 + }, + { + "peak_count": 64, + "latency_mean_ns": 5068352.743, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8050279.443, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "copy_no_pool", + "samples": 5, + "peak_reserved_bytes": { + "median": 252544, + "min": 252544, + "max": 252544 + }, + "source_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "output_peak_bytes": { + "median": 47152, + "min": 47152, + "max": 47152 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 1900544, + "min": 1884160, + "max": 1933312 + }, + "elapsed_ns": { + "median": 132297747, + "min": 132221655, + "max": 132985160 + }, + "cpu_ns": { + "median": 46669804, + "min": 46345346, + "max": 49981054 + }, + "parse_call_ns": { + "median": 22170762, + "min": 22094470, + "max": 23442854 + }, + "selection_copy_bytes": { + "median": 33669120, + "min": 33669120, + "max": 33669120 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 2009.648765, + "min": 1998.568774, + "max": 2129.142526 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 0, + "min": 0, + "max": 0 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 42678.905, + "latency_p99_upper_ns": 61440 + }, + { + "peak_count": 64, + "latency_mean_ns": 5068637.263, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8054142.04, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "shared_copy", + "samples": 5, + "peak_reserved_bytes": { + "median": 311264, + "min": 311264, + "max": 311264 + }, + "source_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "output_peak_bytes": { + "median": 39984, + "min": 39984, + "max": 39984 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 1851392, + "min": 1835008, + "max": 1851392 + }, + "elapsed_ns": { + "median": 132284819, + "min": 132140503, + "max": 133179387 + }, + "cpu_ns": { + "median": 45991210, + "min": 45823432, + "max": 47009567 + }, + "parse_call_ns": { + "median": 22104890, + "min": 22053622, + "max": 22145612 + }, + "selection_copy_bytes": { + "median": 33611776, + "min": 33611776, + "max": 33611776 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 1991.371251, + "min": 1983.569581, + "max": 2001.098596 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 1024, + "min": 1024, + "max": 1024 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 42139.616, + "latency_p99_upper_ns": 57344 + }, + { + "peak_count": 64, + "latency_mean_ns": 5068344.258, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8052022.729, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "threshold2", + "samples": 5, + "peak_reserved_bytes": { + "median": 311264, + "min": 311264, + "max": 311264 + }, + "source_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "output_peak_bytes": { + "median": 39984, + "min": 39984, + "max": 39984 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 1851392, + "min": 1835008, + "max": 1867776 + }, + "elapsed_ns": { + "median": 132243573, + "min": 132119197, + "max": 132423215 + }, + "cpu_ns": { + "median": 45811373, + "min": 45674856, + "max": 46202689 + }, + "parse_call_ns": { + "median": 22085581, + "min": 22029775, + "max": 22137673 + }, + "selection_copy_bytes": { + "median": 33611776, + "min": 33611776, + "max": 33611776 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 1984.871517, + "min": 1978.146096, + "max": 1992.776523 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 1024, + "min": 1024, + "max": 1024 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 42043.254, + "latency_p99_upper_ns": 57344 + }, + { + "peak_count": 64, + "latency_mean_ns": 5068193.573, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8050581.195, + "latency_p99_upper_ns": 8388608 + } + ] + }, + { + "case": "three_distinct_speeds", + "variant": "threshold8", + "samples": 5, + "peak_reserved_bytes": { + "median": 311264, + "min": 311264, + "max": 311264 + }, + "source_peak_bytes": { + "median": 98400, + "min": 98400, + "max": 98400 + }, + "output_peak_bytes": { + "median": 7168, + "min": 7168, + "max": 7168 + }, + "parser_peak_bytes": { + "median": 131120, + "min": 131120, + "max": 131120 + }, + "rss_peak_bytes": { + "median": 1851392, + "min": 1851392, + "max": 1851392 + }, + "elapsed_ns": { + "median": 132177385, + "min": 132072752, + "max": 132687220 + }, + "cpu_ns": { + "median": 44977578, + "min": 44815017, + "max": 45610919 + }, + "parse_call_ns": { + "median": 22128368, + "min": 22007505, + "max": 22143479 + }, + "selection_copy_bytes": { + "median": 57344, + "min": 57344, + "max": 57344 + }, + "reader_copy_bytes": { + "median": 75711296, + "min": 75711296, + "max": 75711296 + }, + "parser_realloc_copy_bytes": { + "median": 0, + "min": 0, + "max": 0 + }, + "source_byte_seconds": { + "median": 2381.095196, + "min": 2372.402719, + "max": 2398.303122 + }, + "budget_waits": { + "median": 0, + "min": 0, + "max": 0 + }, + "compacted": { + "median": 0, + "min": 0, + "max": 0 + }, + "dedup_hits": { + "median": 1024, + "min": 1024, + "max": 1024 + }, + "queues": [ + { + "peak_count": 1, + "latency_mean_ns": 41268.295, + "latency_p99_upper_ns": 57344 + }, + { + "peak_count": 64, + "latency_mean_ns": 5067698.961, + "latency_p99_upper_ns": 5242880 + }, + { + "peak_count": 64, + "latency_mean_ns": 8050851.553, + "latency_p99_upper_ns": 8388608 + } + ] + } +] diff --git a/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/verification.json b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/verification.json new file mode 100644 index 0000000..ca94ae7 --- /dev/null +++ b/research/experiments/003-json-fanout/results/2026-09-22-linux-aarch64/verification.json @@ -0,0 +1,114 @@ +{ + "native": [ + "borrow: 1 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "borrow: 2 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "borrow: 3 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "borrow: empty input, final JSON without newline, first duplicate member", + "borrow: eight invalid JSON/schema cases with retained owners", + "borrow: cancellation preserves each branch prefix and releases all shared owners", + "borrow: parser allocation charged and refused within total budget", + "copy: 1 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "copy: 2 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "copy: 3 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "copy: empty input, final JSON without newline, first duplicate member", + "copy: eight invalid JSON/schema cases with retained owners", + "copy: cancellation preserves each branch prefix and releases all shared owners", + "copy: parser allocation charged and refused within total budget", + "shared_copy: 1 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "shared_copy: 2 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "shared_copy: 3 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "shared_copy: empty input, final JSON without newline, first duplicate member", + "shared_copy: eight invalid JSON/schema cases with retained owners", + "shared_copy: cancellation preserves each branch prefix and releases all shared owners", + "shared_copy: parser allocation charged and refused within total budget", + "threshold2: 1 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "threshold2: 2 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "threshold2: 3 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "threshold2: empty input, final JSON without newline, first duplicate member", + "threshold2: eight invalid JSON/schema cases with retained owners", + "threshold2: cancellation preserves each branch prefix and releases all shared owners", + "threshold2: parser allocation charged and refused within total budget", + "threshold8: 1 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "threshold8: 2 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "threshold8: 3 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "threshold8: empty input, final JSON without newline, first duplicate member", + "threshold8: eight invalid JSON/schema cases with retained owners", + "threshold8: cancellation preserves each branch prefix and releases all shared owners", + "threshold8: parser allocation charged and refused within total budget", + "compact: 1 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "compact: 2 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "compact: 3 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "compact: empty input, final JSON without newline, first duplicate member", + "compact: eight invalid JSON/schema cases with retained owners", + "compact: cancellation preserves each branch prefix and releases all shared owners", + "compact: parser allocation charged and refused within total budget", + "copy_no_pool: 1 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "copy_no_pool: 2 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "copy_no_pool: 3 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "copy_no_pool: empty input, final JSON without newline, first duplicate member", + "copy_no_pool: eight invalid JSON/schema cases with retained owners", + "copy_no_pool: cancellation preserves each branch prefix and releases all shared owners", + "copy_no_pool: parser allocation charged and refused within total budget", + "identical selections copied once and live until the final consumer", + "last-owner compaction keeps the delayed decoded value valid", + "overlong NDJSON record refused without leaked source", + "actual /dev/full failure releases multiple owners", + "SIGTERM during delayed fan-out releases all owners" + ], + "asan_ubsan": [ + "borrow: 1 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "borrow: 2 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "borrow: 3 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "borrow: empty input, final JSON without newline, first duplicate member", + "borrow: eight invalid JSON/schema cases with retained owners", + "borrow: cancellation preserves each branch prefix and releases all shared owners", + "borrow: parser allocation charged and refused within total budget", + "copy: 1 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "copy: 2 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "copy: 3 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "copy: empty input, final JSON without newline, first duplicate member", + "copy: eight invalid JSON/schema cases with retained owners", + "copy: cancellation preserves each branch prefix and releases all shared owners", + "copy: parser allocation charged and refused within total budget", + "shared_copy: 1 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "shared_copy: 2 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "shared_copy: 3 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "shared_copy: empty input, final JSON without newline, first duplicate member", + "shared_copy: eight invalid JSON/schema cases with retained owners", + "shared_copy: cancellation preserves each branch prefix and releases all shared owners", + "shared_copy: parser allocation charged and refused within total budget", + "threshold2: 1 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "threshold2: 2 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "threshold2: 3 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "threshold2: empty input, final JSON without newline, first duplicate member", + "threshold2: eight invalid JSON/schema cases with retained owners", + "threshold2: cancellation preserves each branch prefix and releases all shared owners", + "threshold2: parser allocation charged and refused within total budget", + "threshold8: 1 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "threshold8: 2 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "threshold8: 3 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "threshold8: empty input, final JSON without newline, first duplicate member", + "threshold8: eight invalid JSON/schema cases with retained owners", + "threshold8: cancellation preserves each branch prefix and releases all shared owners", + "threshold8: parser allocation charged and refused within total budget", + "compact: 1 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "compact: 2 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "compact: 3 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "compact: empty input, final JSON without newline, first duplicate member", + "compact: eight invalid JSON/schema cases with retained owners", + "compact: cancellation preserves each branch prefix and releases all shared owners", + "compact: parser allocation charged and refused within total budget", + "copy_no_pool: 1 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "copy_no_pool: 2 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "copy_no_pool: 3 consumer(s), UTF-8/escapes/NUL/empty, slot reuse", + "copy_no_pool: empty input, final JSON without newline, first duplicate member", + "copy_no_pool: eight invalid JSON/schema cases with retained owners", + "copy_no_pool: cancellation preserves each branch prefix and releases all shared owners", + "copy_no_pool: parser allocation charged and refused within total budget", + "identical selections copied once and live until the final consumer", + "last-owner compaction keeps the delayed decoded value valid", + "overlong NDJSON record refused without leaked source", + "actual /dev/full failure releases multiple owners", + "SIGTERM during delayed fan-out releases all owners" + ] +} diff --git a/research/experiments/003-json-fanout/run.py b/research/experiments/003-json-fanout/run.py new file mode 100644 index 0000000..e4848bd --- /dev/null +++ b/research/experiments/003-json-fanout/run.py @@ -0,0 +1,351 @@ +#!/usr/bin/env python3 +"""Verify and measure yyjson parsing with bounded, differently paced consumers.""" +import argparse +import csv +import hashlib +import json +import os +from pathlib import Path +import platform +import random +import shlex +import signal +import statistics +import struct +import subprocess +import tempfile +import time + +ROOT = Path(__file__).resolve().parent +FLAGS = ["-std=c17", "-O2", "-g", "-Wall", "-Wextra", "-Wpedantic", "-Werror"] +FLAGS += ["-DYYJSON_DISABLE_WRITER=1", "-DYYJSON_DISABLE_UTILS=1", "-DYYJSON_DISABLE_INCR_READER=1"] +SOURCE_NAMES = ["benchmark.c", "run.py", "plan.json", "vendor/yyjson/UPSTREAM.json", + "vendor/yyjson/yyjson.c", "vendor/yyjson/yyjson.h", "vendor/yyjson/LICENSE"] + + +def digest(path): + with path.open("rb") as stream: + return hashlib.file_digest(stream, "sha256").hexdigest() + + +def dump(path, value): + path.write_text(json.dumps(value, indent=2, ensure_ascii=False) + "\n") + + +def first_members(pairs): + result = {} + for key, value in pairs: + result.setdefault(key, value) + return result + + +def reference(data, keys): + values = [[] for _ in keys] + for line in data.splitlines(): + row = json.loads(line, object_pairs_hook=first_members) + if not isinstance(row, dict): + raise ValueError("object required") + for k, key in enumerate(keys): + if not isinstance(row.get(key), str): + raise ValueError("string field required") + values[k].append(row[key].encode("utf-8")) + return values + + +def decode(data, keys, expected, partial=False): + at = 0 + found = [[] for _ in keys] + while at < len(data): + if len(data) - at < 16: + raise AssertionError("incomplete output header") + k, length, sequence = struct.unpack_from("<IIQ", data, at) + at += 16 + assert k < len(keys) and sequence == len(found[k]) + assert length <= len(data) - at + found[k].append(data[at:at + length]) + at += length + for k in range(len(keys)): + assert found[k] == (expected[k][:len(found[k])] if partial else expected[k]) + return [len(items) for items in found] + + +def build(cc, output, sanitizer=False): + command = [*cc, *FLAGS] + if sanitizer: + command += ["-O1", "-fsanitize=address,undefined", "-fno-omit-frame-pointer"] + command += [str(ROOT / "benchmark.c"), str(ROOT / "vendor/yyjson/yyjson.c"), "-o", str(output)] + start = time.monotonic_ns() + result = subprocess.run(command, capture_output=True, text=True, check=True) + return {"command": command, "stderr": result.stderr, "sha256": digest(output), + "size_bytes": output.stat().st_size, "build_wall_ns": time.monotonic_ns() - start} + + +def command(binary, case, policy, *extra): + keys = case.get("keys", ["body", "tag", "tag"]) + holds = case.get("hold_us", [0, 5000, 8000][:len(keys)]) + services = case.get("service_us", [0] * len(keys)) + result = [str(binary), "--policy", policy["policy"], "--fanout", str(len(keys)), + "--slots", str(case.get("slots", 64)), "--budget", str(case.get("budget", 8388608)), + "--pool", str(policy.get("pool", 1)), "--ratio", str(policy.get("ratio", 2))] + for k, key in enumerate(keys): + result += [f"--key{k}", key, f"--hold{k}-us", str(holds[k]), f"--service{k}-us", str(services[k])] + return result + list(extra) + + +def metrics(stderr): + try: + m = json.loads(stderr) + except (ValueError, UnicodeError) as exc: + raise AssertionError(f"Expected metrics only, got diagnostics: {stderr!r}") from exc + assert m["unreleased_buffer_bytes"] == 0 + assert m["peak_reserved_bytes"] <= m["budget_bytes"] + assert sum(q["emitted"] for q in m["queues"]) == m["emitted"] + assert m["parser_version"] == "0.12.0" + return m + + +def invoke(binary, case, policy, data, *extra): + proc = subprocess.run(command(binary, case, policy, *extra), input=data, + capture_output=True, timeout=20) + return proc, metrics(proc.stderr) + + +def verify(binary, policies, tmp): + checks = [] + rows = [{"body": "A" * 33000, "tag": "one"}, + {"body": "한글😀\n\x00\"\\", "tag": ""}, + {"body": "", "tag": "둘\t\r"}, + {"body": "z" * 66000, "tag": "three", "meta": [True, None, {"x": -3.5}]}] * 7 + data = b"".join(json.dumps(row, ensure_ascii=i % 2 == 0).encode() + b"\n" for i, row in enumerate(rows)) + for policy in policies: + for keys in [["tag"], ["body", "tag"], ["body", "tag", "tag"]]: + case = {"keys": keys, "hold_us": [500 * k for k in range(len(keys))], "slots": 3} + proc, m = invoke(binary, case, policy, data) + assert proc.returncode == 0 and m["status"] == "ok", proc.stderr + counts = decode(proc.stdout, keys, reference(data, keys)) + assert counts == [len(rows)] * len(keys) and m["accepted"] == len(rows) + assert m["live_at_stop_bytes"] == 0 + checks.append(f'{policy["name"]}: {len(keys)} consumer(s), UTF-8/escapes/NUL/empty, slot reuse') + keys = ["body", "tag", "tag"] + for sample in [b"", data.rstrip(b"\n"), b'{"body":"first","body":"second","tag":"x"}\n']: + proc, m = invoke(binary, {}, policy, sample) + assert proc.returncode == 0 and m["status"] == "ok" + decode(proc.stdout, keys, reference(sample, keys)) + checks.append(f'{policy["name"]}: empty input, final JSON without newline, first duplicate member') + malformed = [b'{"body":"x","tag":', b'{"body":"x","tag":"y","extra":[1,]}', + b'{"body":"x","tag":3}', b'{"body":"x"}', b'[]', + b'{"body":"\xff","tag":"x"}', b'\n', + b'{"body":"x","tag":"y"} true'] + for bad in malformed: + proc, m = invoke(binary, {"hold_us": [1000, 2000, 3000]}, policy, data[:data.index(b"\n") + 1] + bad) + assert proc.returncode == 2 and m["status"] in {"invalid_json", "invalid_schema"}, proc.stderr + checks.append(f'{policy["name"]}: eight invalid JSON/schema cases with retained owners') + proc, m = invoke(binary, {}, policy, data, "--cancel-after", "7") + assert proc.returncode == 3 and m["status"] == "cancelled" and m["emitted"] == 7 + counts = decode(proc.stdout, keys, reference(data, keys), partial=True) + assert sum(counts) == 7 + checks.append(f'{policy["name"]}: cancellation preserves each branch prefix and releases all shared owners') + # Source can fit; the many JSON nodes require more parser storage than the budget. + heavy = json.dumps({"body": "x", "tag": "y", "meta": [0] * 20000}).encode() + proc, m = invoke(binary, {"slots": 1, "budget": 160000}, policy, heavy) + assert proc.returncode == 2 and m["status"] == "budget_too_small", proc.stderr + assert m["accepted"] == 0 + checks.append(f'{policy["name"]}: parser allocation charged and refused within total budget') + # Same decoded field is shared after the document metadata has been freed. + sample = json.dumps({"body": "z" * 40000, "tag": "small"}).encode() + b"\n" + case = {"keys": ["tag", "tag", "tag"], "hold_us": [0, 1000, 2000]} + _, separate = invoke(binary, case, {"policy": "copy"}, sample) + proc, shared = invoke(binary, case, {"policy": "shared_copy"}, sample) + decode(proc.stdout, case["keys"], reference(sample, case["keys"])) + assert separate["selection_copy_bytes"] == 15 and shared["selection_copy_bytes"] == 5 + assert shared["dedup_hits"] == 2 + checks.append("identical selections copied once and live until the final consumer") + case = {"keys": ["body", "tag"], "hold_us": [0, 3000]} + proc, m = invoke(binary, case, {"policy": "compact"}, sample) + decode(proc.stdout, case["keys"], reference(sample, case["keys"])) + assert m["compacted"] == 1 and m["selection_copy_bytes"] == 5 + checks.append("last-owner compaction keeps the delayed decoded value valid") + proc, m = invoke(binary, {}, policies[0], b'x' * (1024 * 1024 + 1)) + assert proc.returncode == 2 and m["status"] == "record_too_large" + checks.append("overlong NDJSON record refused without leaked source") + if Path("/dev/full").exists(): + with open("/dev/full", "wb") as sink: + proc = subprocess.run(command(binary, {}, policies[0]), input=sample, + stdout=sink, stderr=subprocess.PIPE, timeout=10) + assert proc.returncode == 2 and metrics(proc.stderr)["status"] == "output_failed" + checks.append("actual /dev/full failure releases multiple owners") + source = tmp / "signal.ndjson" + source.write_bytes(sample * 20) + with source.open("rb") as inp, open(os.devnull, "wb") as sink: + proc = subprocess.Popen(command(binary, {"hold_us": [500000] * 3}, policies[0]), + stdin=inp, stdout=sink, stderr=subprocess.PIPE) + time.sleep(0.1) + proc.send_signal(signal.SIGTERM) + _, stderr = proc.communicate(timeout=5) + assert proc.returncode == 3 and metrics(stderr)["status"] == "cancelled" + checks.append("SIGTERM during delayed fan-out releases all owners") + return checks + + +def make_fixture(path, case, seed): + rng = random.Random(seed) + hashes = [hashlib.sha256() for _ in case["keys"]] + sizes = [0] * len(hashes) + with path.open("wb") as stream: + for seq in range(case["records"]): + if case["shape"] == "large": + body_size, padding = 32768, 8192 + elif case["shape"] == "mixed": + body_size, padding = rng.choice([(256, 1024), (4096, 16384), (32768, 8192), (65536, 65536)]) + elif case["shape"] == "metadata": + body_size, padding = 512, 512 + else: + raise ValueError(case["shape"]) + tile = rng.randbytes(128).hex() + body = (tile * ((body_size + 255) // 256))[:body_size] + tag = f'{seq:08x}-한글-"-\\-\n-\x00-' + tile[:32] + row = {"id": seq, "body": body, "tag": tag, "padding": "p" * padding, + "meta": list(range(2048)) if case["shape"] == "metadata" else {"ok": True, "n": seq}} + encoded = json.dumps(row, ensure_ascii=seq % 2 == 0, separators=(",", ":")).encode("utf-8") + stream.write(encoded + b"\n") + # Python's independent decoder defines the expected decoded UTF-8 output. + decoded = json.loads(encoded) + for k, key in enumerate(case["keys"]): + selected = decoded[key].encode("utf-8") + hashes[k].update(struct.pack("<QI", seq, len(selected)) + selected) + sizes[k] += len(selected) + return {"case": case["name"], "seed": seed, "records": case["records"], "input_bytes": path.stat().st_size, + "input_sha256": digest(path), "keys": case["keys"], "output_bytes_by_branch": sizes, + "output_sha256_by_branch": [h.hexdigest() for h in hashes]} + + +def verify_output(path, fixture): + count = [0] * len(fixture["keys"]) + hashes = [hashlib.sha256() for _ in count] + sizes = [0] * len(count) + with path.open("rb") as stream: + while header := stream.read(16): + assert len(header) == 16 + k, n, seq = struct.unpack("<IIQ", header) + assert k < len(count) and seq == count[k] and n <= 1024 * 1024 + data = stream.read(n) + assert len(data) == n + hashes[k].update(struct.pack("<QI", seq, n) + data) + count[k] += 1 + sizes[k] += n + assert count == [fixture["records"]] * len(count) + assert sizes == fixture["output_bytes_by_branch"] + assert [h.hexdigest() for h in hashes] == fixture["output_sha256_by_branch"] + + +def sample(binary, source, output, case, policy, fixture): + with source.open("rb") as inp, output.open("wb") as sink: + proc = subprocess.run(command(binary, case, policy), stdin=inp, stdout=sink, + stderr=subprocess.PIPE, timeout=30) + m = metrics(proc.stderr) + assert proc.returncode == 0 and m["status"] == "ok", proc.stderr + assert m["accepted"] == case["records"] and m["emitted"] == case["records"] * len(case["keys"]) + assert m["input_bytes"] == fixture["input_bytes"] + assert m["live_at_stop_bytes"] == 0 + verify_output(output, fixture) + return m + + +def summary(rows): + keys = ["peak_reserved_bytes", "source_peak_bytes", "output_peak_bytes", "parser_peak_bytes", + "rss_peak_bytes", "elapsed_ns", "cpu_ns", "parse_call_ns", "selection_copy_bytes", + "reader_copy_bytes", "parser_realloc_copy_bytes", "source_byte_seconds", "budget_waits", + "compacted", "dedup_hits"] + result = [] + for case, variant in sorted({(r["case"], r["variant"]) for r in rows}): + group = [r for r in rows if (r["case"], r["variant"]) == (case, variant)] + item = {"case": case, "variant": variant, "samples": len(group)} + for key in keys: + values = [r[key] for r in group] + item[key] = {"median": statistics.median(values), "min": min(values), "max": max(values)} + item["queues"] = [{key: statistics.median(r["queues"][k][key] for r in group) + for key in ["peak_count", "latency_mean_ns", "latency_p99_upper_ns"]} + for k in range(len(group[0]["queues"]))] + result.append(item) + return result + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--check-only", action="store_true") + parser.add_argument("--output", type=Path) + args = parser.parse_args() + if not args.check_only and args.output is None: + parser.error("provide --check-only or --output NEW_DIRECTORY") + if args.output: + args.output.mkdir(parents=True, exist_ok=False) + upstream = json.loads((ROOT / "vendor/yyjson/UPSTREAM.json").read_text()) + for name, item in upstream["files"].items(): + assert digest(ROOT / "vendor/yyjson" / name) == item["sha256"] + plan = json.loads((ROOT / "plan.json").read_text()) + cc = shlex.split(os.environ.get("CC", "cc")) + affinity = None + if hasattr(os, "sched_getaffinity"): + affinity = min(os.sched_getaffinity(0)) + os.sched_setaffinity(0, {affinity}) + with tempfile.TemporaryDirectory(prefix="pure-fanout-") as folder: + tmp = Path(folder) + binary, sanitizer = tmp / "benchmark", tmp / "benchmark-sanitized" + print("Building optimized parser and pipeline.", flush=True) + builds = [build(cc, binary)] + print("Building parser and pipeline with ASan/UBSan (-O1).", flush=True) + builds.append(build(cc, sanitizer, True)) + print("Checking native and instrumented builds.", flush=True) + checks = {"native": verify(binary, plan["policies"], tmp), + "asan_ubsan": verify(sanitizer, plan["policies"], tmp)} + print(f'Verified {sum(map(len, checks.values()))} scenario groups (native + ASan/UBSan).', flush=True) + if args.check_only: + return + sources = {name: digest(ROOT / name) for name in SOURCE_NAMES} + environment = {"platform": platform.platform(), "machine": platform.machine(), "python": platform.python_version(), + "compiler": subprocess.check_output([*cc, "--version"], text=True), "cpu_affinity": affinity, + "builds": builds, "source_sha256": sources, "upstream": upstream, + "timing": "I/O, parsing, selection, consumers, instrumentation, cleanup; excludes setup/build/verification", + "parse_call_ns": "wall duration inside yyjson_read_opts including allocator backpressure and serviced consumers", + "rss": "Linux current-image VmHWM approximate; zero means unavailable on other OSes", + "limits": "synthetic closed-loop arrivals/delays; one thread; uncontrolled thermals/power; cached file I/O; no fsync", + "started_utc": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())} + if Path("/proc/cpuinfo").exists(): + environment["cpuinfo"] = Path("/proc/cpuinfo").read_text() + dump(args.output / "environment.json", environment) + dump(args.output / "verification.json", checks) + dump(args.output / "plan.json", plan) + for name in sources: + destination = args.output / "sources" / name + destination.parent.mkdir(parents=True, exist_ok=True) + destination.write_bytes((ROOT / name).read_bytes()) + rng, rows, fixtures = random.Random(plan["seed"]), [], [] + for case in plan["cases"]: + source, output = tmp / "input.ndjson", tmp / "branches.bin" + info = make_fixture(source, case, plan["seed"]) + fixtures.append(info) + for policy in plan["policies"]: + sample(binary, source, output, case, policy, info) + for repeat in range(plan["repeats"]): + order = list(plan["policies"]) + rng.shuffle(order) + for policy in order: + value = sample(binary, source, output, case, policy, info) + rows.append({"case": case["name"], "variant": policy["name"], "repeat": repeat, **value}) + dump(args.output / "raw.json", rows) + dump(args.output / "fixtures.json", fixtures) + print(f'Completed {case["name"]}: {len(plan["policies"])} variants x {plan["repeats"]} trials.', flush=True) + dump(args.output / "summary.json", summary(rows)) + flat = [{**{k: v for k, v in row.items() if k != "queues"}, "queues": json.dumps(row["queues"])} for row in rows] + with (args.output / "raw.csv").open("w") as out: + writer = csv.DictWriter(out, fieldnames=list(flat[0])) + writer.writeheader() + writer.writerows(flat) + assert sources == {name: digest(ROOT / name) for name in SOURCE_NAMES} + dump(args.output / "complete.json", {"samples": len(rows), "all_branch_outputs_match": True, + "finished_utc": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())}) + print(args.output.resolve()) + + +if __name__ == "__main__": + main() diff --git a/research/experiments/003-json-fanout/vendor/yyjson/LICENSE b/research/experiments/003-json-fanout/vendor/yyjson/LICENSE new file mode 100644 index 0000000..a09bff3 --- /dev/null +++ b/research/experiments/003-json-fanout/vendor/yyjson/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 YaoYuan <[email protected]> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/research/experiments/003-json-fanout/vendor/yyjson/UPSTREAM.json b/research/experiments/003-json-fanout/vendor/yyjson/UPSTREAM.json new file mode 100644 index 0000000..7de2396 --- /dev/null +++ b/research/experiments/003-json-fanout/vendor/yyjson/UPSTREAM.json @@ -0,0 +1,23 @@ +{ + "project": "yyjson", + "version": "0.12.0", + "commit": "8b4a38dc994a110abaec8a400615567bd996105f", + "license": "MIT", + "files": { + "yyjson.c": { + "url": "https://raw.githubusercontent.com/ibireme/yyjson/8b4a38dc994a110abaec8a400615567bd996105f/src/yyjson.c", + "sha256": "ac2e9bbb2e2d9149d90878d40506a1d624fa0b33c979a11b61075c54782c6d6a", + "bytes": 410813 + }, + "yyjson.h": { + "url": "https://raw.githubusercontent.com/ibireme/yyjson/8b4a38dc994a110abaec8a400615567bd996105f/src/yyjson.h", + "sha256": "175867c5493a5df648cec566717fa1c29aa2f6096f5f0cf1efad0b65e1f6d7b3", + "bytes": 322407 + }, + "LICENSE": { + "url": "https://raw.githubusercontent.com/ibireme/yyjson/8b4a38dc994a110abaec8a400615567bd996105f/LICENSE", + "sha256": "45e384d3d52c73cba3a64d6e6c25d47cd738cd8a55c30629e3201046eda62947", + "bytes": 1084 + } + } +} diff --git a/research/experiments/003-json-fanout/vendor/yyjson/yyjson.c b/research/experiments/003-json-fanout/vendor/yyjson/yyjson.c new file mode 100644 index 0000000..c16d925 --- /dev/null +++ b/research/experiments/003-json-fanout/vendor/yyjson/yyjson.c @@ -0,0 +1,11065 @@ +/*============================================================================== + Copyright (c) 2020 YaoYuan <[email protected]> + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + *============================================================================*/ + +#include "yyjson.h" +#include <math.h> /* for `HUGE_VAL/INFINIY/NAN` macros, no libm required */ + + + +/*============================================================================== + * MARK: - Warning Suppress (Private) + *============================================================================*/ + +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wunused-function" +# pragma clang diagnostic ignored "-Wunused-parameter" +# pragma clang diagnostic ignored "-Wunused-label" +# pragma clang diagnostic ignored "-Wunused-macros" +# pragma clang diagnostic ignored "-Wunused-variable" +#elif defined(__GNUC__) +# pragma GCC diagnostic ignored "-Wunused-function" +# pragma GCC diagnostic ignored "-Wunused-parameter" +# pragma GCC diagnostic ignored "-Wunused-label" +# pragma GCC diagnostic ignored "-Wunused-macros" +# pragma GCC diagnostic ignored "-Wunused-variable" +#elif defined(_MSC_VER) +# pragma warning(disable:4100) /* unreferenced formal parameter */ +# pragma warning(disable:4101) /* unreferenced variable */ +# pragma warning(disable:4102) /* unreferenced label */ +# pragma warning(disable:4127) /* conditional expression is constant */ +# pragma warning(disable:4706) /* assignment within conditional expression */ +#endif + + + +/*============================================================================== + * MARK: - Version (Public) + *============================================================================*/ + +uint32_t yyjson_version(void) { + return YYJSON_VERSION_HEX; +} + + + +/*============================================================================== + * MARK: - Flags (Private) + *============================================================================*/ + +/* msvc intrinsic */ +#if YYJSON_MSC_VER >= 1400 +# include <intrin.h> +# if defined(_M_AMD64) || defined(_M_ARM64) +# define MSC_HAS_BIT_SCAN_64 1 +# pragma intrinsic(_BitScanForward64) +# pragma intrinsic(_BitScanReverse64) +# else +# define MSC_HAS_BIT_SCAN_64 0 +# endif +# if defined(_M_AMD64) || defined(_M_ARM64) || \ + defined(_M_IX86) || defined(_M_ARM) +# define MSC_HAS_BIT_SCAN 1 +# pragma intrinsic(_BitScanForward) +# pragma intrinsic(_BitScanReverse) +# else +# define MSC_HAS_BIT_SCAN 0 +# endif +# if defined(_M_AMD64) +# define MSC_HAS_UMUL128 1 +# pragma intrinsic(_umul128) +# else +# define MSC_HAS_UMUL128 0 +# endif +#else +# define MSC_HAS_BIT_SCAN_64 0 +# define MSC_HAS_BIT_SCAN 0 +# define MSC_HAS_UMUL128 0 +#endif + +/* gcc builtin */ +#if yyjson_has_builtin(__builtin_clzll) || yyjson_gcc_available(3, 4, 0) +# define GCC_HAS_CLZLL 1 +#else +# define GCC_HAS_CLZLL 0 +#endif + +#if yyjson_has_builtin(__builtin_ctzll) || yyjson_gcc_available(3, 4, 0) +# define GCC_HAS_CTZLL 1 +#else +# define GCC_HAS_CTZLL 0 +#endif + +/* int128 type */ +#if defined(__SIZEOF_INT128__) && (__SIZEOF_INT128__ == 16) && \ + (defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)) +# define YYJSON_HAS_INT128 1 +#else +# define YYJSON_HAS_INT128 0 +#endif + +/* IEEE 754 floating-point binary representation */ +#if defined(__STDC_IEC_559__) || defined(__STDC_IEC_60559_BFP__) +# define YYJSON_HAS_IEEE_754 1 +#elif FLT_RADIX == 2 && \ + FLT_MANT_DIG == 24 && FLT_DIG == 6 && \ + FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128 && \ + FLT_MIN_10_EXP == -37 && FLT_MAX_10_EXP == 38 && \ + DBL_MANT_DIG == 53 && DBL_DIG == 15 && \ + DBL_MIN_EXP == -1021 && DBL_MAX_EXP == 1024 && \ + DBL_MIN_10_EXP == -307 && DBL_MAX_10_EXP == 308 +# define YYJSON_HAS_IEEE_754 1 +#else +# define YYJSON_HAS_IEEE_754 0 +# undef YYJSON_DISABLE_FAST_FP_CONV +# define YYJSON_DISABLE_FAST_FP_CONV 1 +#endif + +/* + Correct rounding in double number computations. + + On the x86 architecture, some compilers may use x87 FPU instructions for + floating-point arithmetic. The x87 FPU loads all floating point number as + 80-bit double-extended precision internally, then rounds the result to original + precision, which may produce inaccurate results. For a more detailed + explanation, see the paper: https://arxiv.org/abs/cs/0701192 + + Here are some examples of double precision calculation error: + + 2877.0 / 1e6 == 0.002877, but x87 returns 0.0028770000000000002 + 43683.0 * 1e21 == 4.3683e25, but x87 returns 4.3683000000000004e25 + + Here are some examples of compiler flags to generate x87 instructions on x86: + + clang -m32 -mno-sse + gcc/icc -m32 -mfpmath=387 + msvc /arch:SSE or /arch:IA32 + + If we are sure that there's no similar error described above, we can define the + YYJSON_DOUBLE_MATH_CORRECT as 1 to enable the fast path calculation. This is + not an accurate detection, it's just try to avoid the error at compile-time. + An accurate detection can be done at run-time: + + bool is_double_math_correct(void) { + volatile double r = 43683.0; + r *= 1e21; + return r == 4.3683e25; + } + + See also: utils.h in https://github.com/google/double-conversion/ + */ +#if !defined(FLT_EVAL_METHOD) && defined(__FLT_EVAL_METHOD__) +# define FLT_EVAL_METHOD __FLT_EVAL_METHOD__ +#endif + +#if defined(FLT_EVAL_METHOD) && FLT_EVAL_METHOD != 0 && FLT_EVAL_METHOD != 1 +# define YYJSON_DOUBLE_MATH_CORRECT 0 +#elif defined(i386) || defined(__i386) || defined(__i386__) || \ + defined(_X86_) || defined(__X86__) || defined(_M_IX86) || \ + defined(__I86__) || defined(__IA32__) || defined(__THW_INTEL) +# if (defined(_MSC_VER) && defined(_M_IX86_FP) && _M_IX86_FP == 2) || \ + (defined(__SSE2_MATH__) && __SSE2_MATH__) +# define YYJSON_DOUBLE_MATH_CORRECT 1 +# else +# define YYJSON_DOUBLE_MATH_CORRECT 0 +# endif +#elif defined(__mc68000__) || defined(__pnacl__) || defined(__native_client__) +# define YYJSON_DOUBLE_MATH_CORRECT 0 +#else +# define YYJSON_DOUBLE_MATH_CORRECT 1 +#endif + +/* + Detect the endianness at compile-time. + YYJSON_ENDIAN == YYJSON_BIG_ENDIAN + YYJSON_ENDIAN == YYJSON_LITTLE_ENDIAN + */ +#define YYJSON_BIG_ENDIAN 4321 +#define YYJSON_LITTLE_ENDIAN 1234 + +#if yyjson_has_include(<sys/types.h>) +# include <sys/types.h> /* POSIX */ +#endif +#if yyjson_has_include(<endian.h>) +# include <endian.h> /* Linux */ +#elif yyjson_has_include(<sys/endian.h>) +# include <sys/endian.h> /* BSD, Android */ +#elif yyjson_has_include(<machine/endian.h>) +# include <machine/endian.h> /* BSD, Darwin */ +#endif + +#if defined(BYTE_ORDER) && BYTE_ORDER +# if defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN) +# define YYJSON_ENDIAN YYJSON_BIG_ENDIAN +# elif defined(LITTLE_ENDIAN) && (BYTE_ORDER == LITTLE_ENDIAN) +# define YYJSON_ENDIAN YYJSON_LITTLE_ENDIAN +# endif +#elif defined(__BYTE_ORDER) && __BYTE_ORDER +# if defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN) +# define YYJSON_ENDIAN YYJSON_BIG_ENDIAN +# elif defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN) +# define YYJSON_ENDIAN YYJSON_LITTLE_ENDIAN +# endif +#elif defined(__BYTE_ORDER__) && __BYTE_ORDER__ +# if defined(__ORDER_BIG_ENDIAN__) && \ + (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) +# define YYJSON_ENDIAN YYJSON_BIG_ENDIAN +# elif defined(__ORDER_LITTLE_ENDIAN__) && \ + (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) +# define YYJSON_ENDIAN YYJSON_LITTLE_ENDIAN +# endif +#elif (defined(__LITTLE_ENDIAN__) && __LITTLE_ENDIAN__ == 1) || \ + defined(__i386) || defined(__i386__) || \ + defined(_X86_) || defined(__X86__) || \ + defined(_M_IX86) || defined(__THW_INTEL__) || \ + defined(__x86_64) || defined(__x86_64__) || \ + defined(__amd64) || defined(__amd64__) || \ + defined(_M_AMD64) || defined(_M_X64) || \ + defined(_M_ARM) || defined(_M_ARM64) || \ + defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || \ + defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) || \ + defined(__EMSCRIPTEN__) || defined(__wasm__) || \ + defined(__loongarch__) +# define YYJSON_ENDIAN YYJSON_LITTLE_ENDIAN +#elif (defined(__BIG_ENDIAN__) && __BIG_ENDIAN__ == 1) || \ + defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \ + defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__) || \ + defined(__or1k__) || defined(__OR1K__) +# define YYJSON_ENDIAN YYJSON_BIG_ENDIAN +#else +# define YYJSON_ENDIAN 0 /* unknown endian, detect at run-time */ +#endif + +/* + This macro controls how yyjson handles unaligned memory accesses. + + By default, yyjson uses `memcpy()` for memory copying. This allows the compiler + to optimize the code and emit unaligned memory access instructions when + supported by the target architecture. + + However, on some older compilers or architectures where `memcpy()` is not + well-optimized and may result in unnecessary function calls, defining this + macro as 1 may help. In such cases, yyjson switches to manual byte-by-byte + access, which can potentially improve performance. + + An example of the generated assembly code for ARM can be found here: + https://godbolt.org/z/334jjhxPT + + This flag is already enabled for common architectures in the following code, + so manual configuration is usually unnecessary. If unsure, you can check the + generated assembly or run benchmarks to make an informed decision. + */ +#ifndef YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS +# if defined(__ia64) || defined(_IA64) || defined(__IA64__) || \ + defined(__ia64__) || defined(_M_IA64) || defined(__itanium__) +# define YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS 1 /* Itanium */ +# elif (defined(__arm__) || defined(__arm64__) || defined(__aarch64__)) && \ + (defined(__GNUC__) || defined(__clang__)) && \ + (!defined(__ARM_FEATURE_UNALIGNED) || !__ARM_FEATURE_UNALIGNED) +# define YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS 1 /* ARM */ +# elif defined(__sparc) || defined(__sparc__) +# define YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS 1 /* SPARC */ +# elif defined(__mips) || defined(__mips__) || defined(__MIPS__) +# define YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS 1 /* MIPS */ +# elif defined(__m68k__) || defined(M68000) +# define YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS 1 /* M68K */ +# else +# define YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS 0 +# endif +#endif + +/* + Estimated initial ratio of the JSON data (data_size / value_count). + For example: + + data: {"id":12345678,"name":"Harry"} + data_size: 30 + value_count: 5 + ratio: 6 + + yyjson uses dynamic memory with a growth factor of 1.5 when reading and writing + JSON, the ratios below are used to determine the initial memory size. + + A too large ratio will waste memory, and a too small ratio will cause multiple + memory growths and degrade performance. Currently, these ratios are generated + with some commonly used JSON datasets. + */ +#define YYJSON_READER_ESTIMATED_PRETTY_RATIO 16 +#define YYJSON_READER_ESTIMATED_MINIFY_RATIO 6 +#define YYJSON_WRITER_ESTIMATED_PRETTY_RATIO 32 +#define YYJSON_WRITER_ESTIMATED_MINIFY_RATIO 18 + +/* The initial and maximum size of the memory pool's chunk in yyjson_mut_doc. */ +#define YYJSON_MUT_DOC_STR_POOL_INIT_SIZE 0x100 +#define YYJSON_MUT_DOC_STR_POOL_MAX_SIZE 0x10000000 +#define YYJSON_MUT_DOC_VAL_POOL_INIT_SIZE (0x10 * sizeof(yyjson_mut_val)) +#define YYJSON_MUT_DOC_VAL_POOL_MAX_SIZE (0x1000000 * sizeof(yyjson_mut_val)) + +/* The minimum size of the dynamic allocator's chunk. */ +#define YYJSON_ALC_DYN_MIN_SIZE 0x1000 + +/* Default value for compile-time options. */ +#ifndef YYJSON_DISABLE_READER +#define YYJSON_DISABLE_READER 0 +#endif +#ifndef YYJSON_DISABLE_WRITER +#define YYJSON_DISABLE_WRITER 0 +#endif +#ifndef YYJSON_DISABLE_INCR_READER +#define YYJSON_DISABLE_INCR_READER 0 +#endif +#ifndef YYJSON_DISABLE_UTILS +#define YYJSON_DISABLE_UTILS 0 +#endif +#ifndef YYJSON_DISABLE_FAST_FP_CONV +#define YYJSON_DISABLE_FAST_FP_CONV 0 +#endif +#ifndef YYJSON_DISABLE_NON_STANDARD +#define YYJSON_DISABLE_NON_STANDARD 0 +#endif +#ifndef YYJSON_DISABLE_UTF8_VALIDATION +#define YYJSON_DISABLE_UTF8_VALIDATION 0 +#endif + + + +/*============================================================================== + * MARK: - Macros (Private) + *============================================================================*/ + +/* Macros used for loop unrolling and other purpose. */ +#define repeat2(x) { x x } +#define repeat4(x) { x x x x } +#define repeat8(x) { x x x x x x x x } +#define repeat16(x) { x x x x x x x x x x x x x x x x } + +#define repeat2_incr(x) { x(0) x(1) } +#define repeat4_incr(x) { x(0) x(1) x(2) x(3) } +#define repeat8_incr(x) { x(0) x(1) x(2) x(3) x(4) x(5) x(6) x(7) } +#define repeat16_incr(x) { x(0) x(1) x(2) x(3) x(4) x(5) x(6) x(7) \ + x(8) x(9) x(10) x(11) x(12) x(13) x(14) x(15) } +#define repeat_in_1_18(x) { x(1) x(2) x(3) x(4) x(5) x(6) x(7) x(8) \ + x(9) x(10) x(11) x(12) x(13) x(14) x(15) x(16) \ + x(17) x(18) } + +/* Macros used to provide branch prediction information for compiler. */ +#undef likely +#define likely(x) yyjson_likely(x) +#undef unlikely +#define unlikely(x) yyjson_unlikely(x) + +/* Macros used to provide inline information for compiler. */ +#undef static_inline +#define static_inline static yyjson_inline +#undef static_noinline +#define static_noinline static yyjson_noinline + +/* Macros for min and max. */ +#undef yyjson_min +#define yyjson_min(x, y) ((x) < (y) ? (x) : (y)) +#undef yyjson_max +#define yyjson_max(x, y) ((x) > (y) ? (x) : (y)) + +/* Used to write u64 literal for C89 which doesn't support "ULL" suffix. */ +#undef U64 +#define U64(hi, lo) ((((u64)hi##UL) << 32U) + lo##UL) +#undef U32 +#define U32(hi) ((u32)(hi##UL)) + +/* Used to cast away (remove) const qualifier. */ +#define constcast(type) (type)(void *)(size_t)(const void *) + +/* + Compiler barriers for single variables. + + These macros inform GCC that a read or write access to the given memory + location will occur, preventing certain compiler optimizations or reordering + around the access to 'val'. They do not emit any actual instructions. + + This is useful when GCC's default optimization strategies are suboptimal and + precise control over memory access patterns is required. + These barriers are not needed when using Clang or MSVC. + */ +#if YYJSON_IS_REAL_GCC +# define gcc_load_barrier(val) __asm__ volatile(""::"m"(val)) +# define gcc_store_barrier(val) __asm__ volatile("":"=m"(val)) +# define gcc_full_barrier(val) __asm__ volatile("":"=m"(val):"m"(val)) +#else +# define gcc_load_barrier(val) +# define gcc_store_barrier(val) +# define gcc_full_barrier(val) +#endif + + + +/*============================================================================== + * MARK: - Constants (Private) + *============================================================================*/ + +/* Common error messages. */ +#define MSG_FOPEN "failed to open file" +#define MSG_FREAD "failed to read file" +#define MSG_FWRITE "failed to write file" +#define MSG_FCLOSE "failed to close file" +#define MSG_MALLOC "failed to allocate memory" +#define MSG_CHAR_T "invalid literal, expected 'true'" +#define MSG_CHAR_F "invalid literal, expected 'false'" +#define MSG_CHAR_N "invalid literal, expected 'null'" +#define MSG_CHAR "unexpected character, expected a JSON value" +#define MSG_ARR_END "unexpected character, expected ',' or ']'" +#define MSG_OBJ_KEY "unexpected character, expected a string key" +#define MSG_OBJ_SEP "unexpected character, expected ':' after key" +#define MSG_OBJ_END "unexpected character, expected ',' or '}'" +#define MSG_GARBAGE "unexpected content after document" +#define MSG_NOT_END "unexpected end of data" +#define MSG_COMMENT "unclosed multiline comment" +#define MSG_COMMA "trailing comma is not allowed" +#define MSG_NAN_INF "nan or inf number is not allowed" +#define MSG_ERR_TYPE "invalid JSON value type" +#define MSG_ERR_BOM "UTF-8 byte order mark (BOM) is not supported" +#define MSG_ERR_UTF8 "invalid utf-8 encoding in string" +#define MSG_ERR_UTF16 "UTF-16 encoding is not supported" +#define MSG_ERR_UTF32 "UTF-32 encoding is not supported" + +/* U64 constant values */ +#undef U64_MAX +#define U64_MAX U64(0xFFFFFFFF, 0xFFFFFFFF) +#undef I64_MAX +#define I64_MAX U64(0x7FFFFFFF, 0xFFFFFFFF) +#undef USIZE_MAX +#define USIZE_MAX ((usize)(~(usize)0)) + +/* Maximum number of digits for reading u32/u64/usize safety (not overflow). */ +#undef U32_SAFE_DIG +#define U32_SAFE_DIG 9 /* u32 max is 4294967295, 10 digits */ +#undef U64_SAFE_DIG +#define U64_SAFE_DIG 19 /* u64 max is 18446744073709551615, 20 digits */ +#undef USIZE_SAFE_DIG +#define USIZE_SAFE_DIG (sizeof(usize) == 8 ? U64_SAFE_DIG : U32_SAFE_DIG) + +/* Inf bits (positive) */ +#define F64_BITS_INF U64(0x7FF00000, 0x00000000) + +/* NaN bits (quiet NaN, no payload, no sign) */ +#if defined(__hppa__) || (defined(__mips__) && !defined(__mips_nan2008)) +#define F64_BITS_NAN U64(0x7FF7FFFF, 0xFFFFFFFF) +#else +#define F64_BITS_NAN U64(0x7FF80000, 0x00000000) +#endif + +/* maximum significant digits count in decimal when reading double number */ +#define F64_MAX_DEC_DIG 768 + +/* maximum decimal power of double number (1.7976931348623157e308) */ +#define F64_MAX_DEC_EXP 308 + +/* minimum decimal power of double number (4.9406564584124654e-324) */ +#define F64_MIN_DEC_EXP (-324) + +/* maximum binary power of double number */ +#define F64_MAX_BIN_EXP 1024 + +/* minimum binary power of double number */ +#define F64_MIN_BIN_EXP (-1021) + +/* float/double number bits */ +#define F32_BITS 32 +#define F64_BITS 64 + +/* float/double number exponent part bits */ +#define F32_EXP_BITS 8 +#define F64_EXP_BITS 11 + +/* float/double number significand part bits */ +#define F32_SIG_BITS 23 +#define F64_SIG_BITS 52 + +/* float/double number significand part bits (with 1 hidden bit) */ +#define F32_SIG_FULL_BITS 24 +#define F64_SIG_FULL_BITS 53 + +/* float/double number significand bit mask */ +#define F32_SIG_MASK U32(0x007FFFFF) +#define F64_SIG_MASK U64(0x000FFFFF, 0xFFFFFFFF) + +/* float/double number exponent bit mask */ +#define F32_EXP_MASK U32(0x7F800000) +#define F64_EXP_MASK U64(0x7FF00000, 0x00000000) + +/* float/double number exponent bias */ +#define F32_EXP_BIAS 127 +#define F64_EXP_BIAS 1023 + +/* float/double number significant digits count in decimal */ +#define F32_DEC_DIG 9 +#define F64_DEC_DIG 17 + +/* buffer length required for float/double number writer */ +#define FP_BUF_LEN 40 + +/* maximum length of a number in incremental parsing */ +#define INCR_NUM_MAX_LEN 1024 + + + +/*============================================================================== + * MARK: - Types (Private) + *============================================================================*/ + +/** Type define for primitive types. */ +typedef float f32; +typedef double f64; +typedef int8_t i8; +typedef uint8_t u8; +typedef int16_t i16; +typedef uint16_t u16; +typedef int32_t i32; +typedef uint32_t u32; +typedef int64_t i64; +typedef uint64_t u64; +typedef size_t usize; + +/** 128-bit integer, used by floating-point number reader and writer. */ +#if YYJSON_HAS_INT128 +__extension__ typedef __int128 i128; +__extension__ typedef unsigned __int128 u128; +#endif + +/** 16/32/64-bit vector */ +typedef struct v16 { char c[2]; } v16; +typedef struct v32 { char c[4]; } v32; +typedef struct v64 { char c[8]; } v64; + +/** 16/32/64-bit vector union */ +typedef union v16_uni { v16 v; u16 u; } v16_uni; +typedef union v32_uni { v32 v; u32 u; } v32_uni; +typedef union v64_uni { v64 v; u64 u; } v64_uni; + + + +/*============================================================================== + * MARK: - Load/Store Utils (Private) + *============================================================================*/ + +#define byte_move_idx(x) ((char *)dst)[x] = ((const char *)src)[x]; +#define byte_move_src(x) ((char *)tmp)[x] = ((const char *)src)[x]; +#define byte_move_dst(x) ((char *)dst)[x] = ((const char *)tmp)[x]; + +/** Same as `memcpy(dst, src, 2)`, no overlap. */ +static_inline void byte_copy_2(void *dst, const void *src) { +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + memcpy(dst, src, 2); +#else + repeat2_incr(byte_move_idx) +#endif +} + +/** Same as `memcpy(dst, src, 4)`, no overlap. */ +static_inline void byte_copy_4(void *dst, const void *src) { +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + memcpy(dst, src, 4); +#else + repeat4_incr(byte_move_idx) +#endif +} + +/** Same as `memcpy(dst, src, 8)`, no overlap. */ +static_inline void byte_copy_8(void *dst, const void *src) { +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + memcpy(dst, src, 8); +#else + repeat8_incr(byte_move_idx) +#endif +} + +/** Same as `memcpy(dst, src, 16)`, no overlap. */ +static_inline void byte_copy_16(void *dst, const void *src) { +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + memcpy(dst, src, 16); +#else + repeat16_incr(byte_move_idx) +#endif +} + +/** Same as `memmove(dst, src, 2)`, allows overlap. */ +static_inline void byte_move_2(void *dst, const void *src) { +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + u16 tmp; + memcpy(&tmp, src, 2); + memcpy(dst, &tmp, 2); +#else + char tmp[2]; + repeat2_incr(byte_move_src) + repeat2_incr(byte_move_dst) +#endif +} + +/** Same as `memmove(dst, src, 4)`, allows overlap. */ +static_inline void byte_move_4(void *dst, const void *src) { +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + u32 tmp; + memcpy(&tmp, src, 4); + memcpy(dst, &tmp, 4); +#else + char tmp[4]; + repeat4_incr(byte_move_src) + repeat4_incr(byte_move_dst) +#endif +} + +/** Same as `memmove(dst, src, 8)`, allows overlap. */ +static_inline void byte_move_8(void *dst, const void *src) { +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + u64 tmp; + memcpy(&tmp, src, 8); + memcpy(dst, &tmp, 8); +#else + char tmp[8]; + repeat8_incr(byte_move_src) + repeat8_incr(byte_move_dst) +#endif +} + +/** Same as `memmove(dst, src, 16)`, allows overlap. */ +static_inline void byte_move_16(void *dst, const void *src) { +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + char *pdst = (char *)dst; + const char *psrc = (const char *)src; + u64 tmp1, tmp2; + memcpy(&tmp1, psrc, 8); + memcpy(&tmp2, psrc + 8, 8); + memcpy(pdst, &tmp1, 8); + memcpy(pdst + 8, &tmp2, 8); +#else + char tmp[16]; + repeat16_incr(byte_move_src) + repeat16_incr(byte_move_dst) +#endif +} + +/** Same as `memmove(dst, src, n)`, but only `dst <= src` and `n <= 16`. */ +static_inline void byte_move_forward(void *dst, void *src, usize n) { + char *d = (char *)dst, *s = (char *)src; + n += (n % 2); /* round up to even */ + if (n == 16) { byte_move_16(d, s); return; } + if (n >= 8) { byte_move_8(d, s); n -= 8; d += 8; s += 8; } + if (n >= 4) { byte_move_4(d, s); n -= 4; d += 4; s += 4; } + if (n >= 2) { byte_move_2(d, s); } +} + +/** Same as `memcmp(buf, pat, 2) == 0`. */ +static_inline bool byte_match_2(void *buf, const char *pat) { +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + v16_uni u1, u2; + memcpy(&u1, buf, 2); + memcpy(&u2, pat, 2); + return u1.u == u2.u; +#else + return ((char *)buf)[0] == ((const char *)pat)[0] && + ((char *)buf)[1] == ((const char *)pat)[1]; +#endif +} + +/** Same as `memcmp(buf, pat, 4) == 0`. */ +static_inline bool byte_match_4(void *buf, const char *pat) { +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + v32_uni u1, u2; + memcpy(&u1, buf, 4); + memcpy(&u2, pat, 4); + return u1.u == u2.u; +#else + return ((char *)buf)[0] == ((const char *)pat)[0] && + ((char *)buf)[1] == ((const char *)pat)[1] && + ((char *)buf)[2] == ((const char *)pat)[2] && + ((char *)buf)[3] == ((const char *)pat)[3]; +#endif +} + +/** Loads 2 bytes from `src` as a u16 (native-endian). */ +static_inline u16 byte_load_2(const void *src) { + v16_uni uni; +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + memcpy(&uni, src, 2); +#else + uni.v.c[0] = ((const char *)src)[0]; + uni.v.c[1] = ((const char *)src)[1]; +#endif + return uni.u; +} + +/** Loads 3 bytes from `src` as a u32 (native-endian). */ +static_inline u32 byte_load_3(const void *src) { + v32_uni uni; +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + memcpy(&uni, src, 2); + uni.v.c[2] = ((const char *)src)[2]; + uni.v.c[3] = 0; +#else + uni.v.c[0] = ((const char *)src)[0]; + uni.v.c[1] = ((const char *)src)[1]; + uni.v.c[2] = ((const char *)src)[2]; + uni.v.c[3] = 0; +#endif + return uni.u; +} + +/** Loads 4 bytes from `src` as a u32 (native-endian). */ +static_inline u32 byte_load_4(const void *src) { + v32_uni uni; +#if !YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS + memcpy(&uni, src, 4); +#else + uni.v.c[0] = ((const char *)src)[0]; + uni.v.c[1] = ((const char *)src)[1]; + uni.v.c[2] = ((const char *)src)[2]; + uni.v.c[3] = ((const char *)src)[3]; +#endif + return uni.u; +} + + + +/*============================================================================== + * MARK: - Character Utils (Private) + * These lookup tables were generated by `misc/make_tables.c`. + *============================================================================*/ + +/* char_table1 */ +#define CHAR_TYPE_ASCII (1 << 0) /* Except: ["\], [0x00-0x1F, 0x80-0xFF] */ +#define CHAR_TYPE_ASCII_SQ (1 << 1) /* Except: ['\], [0x00-0x1F, 0x80-0xFF] */ +#define CHAR_TYPE_SPACE (1 << 2) /* Whitespace: [ \t\n\r] */ +#define CHAR_TYPE_SPACE_EXT (1 << 3) /* Whitespace: [ \t\n\r\v\f], JSON5 */ +#define CHAR_TYPE_NUM (1 << 4) /* Number: [.-+0-9] */ +#define CHAR_TYPE_COMMENT (1 << 5) /* Comment: [/] */ + +/* char_table2 */ +#define CHAR_TYPE_EOL (1 << 0) /* End of line: [\r\n] */ +#define CHAR_TYPE_EOL_EXT (1 << 1) /* End of line: [\r\n], JSON5 */ +#define CHAR_TYPE_ID_START (1 << 2) /* ID start: [_$A-Za-z\], U+0080+ */ +#define CHAR_TYPE_ID_NEXT (1 << 3) /* ID next: [_$A-Za-z0-9\], U+0080+ */ +#define CHAR_TYPE_ID_ASCII (1 << 4) /* ID next ASCII: [_$A-Za-z0-9] */ + +/* char_table3 */ +#define CHAR_TYPE_SIGN (1 << 0) /* [-+] */ +#define CHAR_TYPE_DIGIT (1 << 1) /* [0-9] */ +#define CHAR_TYPE_NONZERO (1 << 2) /* [1-9] */ +#define CHAR_TYPE_EXP (1 << 3) /* [eE] */ +#define CHAR_TYPE_DOT (1 << 4) /* [.] */ + +static const u8 char_table1[256] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x0C, 0x0C, 0x08, 0x08, 0x0C, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0F, 0x03, 0x02, 0x03, 0x03, 0x03, 0x03, 0x01, + 0x03, 0x03, 0x03, 0x13, 0x03, 0x13, 0x13, 0x23, + 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, + 0x13, 0x13, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x00, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static const u8 char_table2[256] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, + 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, + 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, + 0x1C, 0x1C, 0x1C, 0x00, 0x0C, 0x00, 0x00, 0x1C, + 0x00, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, + 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, + 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, + 0x1C, 0x1C, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C +}; + +static const u8 char_table3[256] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x10, 0x00, + 0x02, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, + 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +/** Match a whitespace: [ \t\n\r]. */ +static_inline bool char_is_space(u8 c) { + return !!(char_table1[c] & CHAR_TYPE_SPACE); +} + +/** Match an extended whitespace: [ \t\n\r\\v\\f], JSON5 whitespace. */ +static_inline bool char_is_space_ext(u8 c) { + return !!(char_table1[c] & CHAR_TYPE_SPACE_EXT); +} + +/** Match a JSON number: [.-+0-9]. */ +static_inline bool char_is_num(u8 c) { + return !!(char_table1[c] & CHAR_TYPE_NUM); +} + +/** Match an ASCII character in string: ["\], [0x00-0x1F, 0x80-0xFF]. */ +static_inline bool char_is_ascii_skip(u8 c) { + return !!(char_table1[c] & CHAR_TYPE_ASCII); +} + +/** Match an ASCII character single-quoted: ['\], [0x00-0x1F, 0x80-0xFF]. */ +static_inline bool char_is_ascii_skip_sq(u8 c) { + return !!(char_table1[c] & CHAR_TYPE_ASCII_SQ); +} + +/** Match a trivia character: extended whitespace or comment. */ +static_inline bool char_is_trivia(u8 c) { + return !!(char_table1[c] & (CHAR_TYPE_SPACE_EXT | CHAR_TYPE_COMMENT)); +} + +/** Match a line end character: [\r\n]. */ +static_inline bool char_is_eol(u8 c) { + return !!(char_table2[c] & CHAR_TYPE_EOL); +} + +/** Match an extended line end character: [\r\n], JSON5 line terminator. */ +static_inline bool char_is_eol_ext(u8 c) { + return !!(char_table2[c] & CHAR_TYPE_EOL_EXT); +} + +/** Match an identifier name start: [_$A-Za-z\], U+0080+. */ +static_inline bool char_is_id_start(u8 c) { + return !!(char_table2[c] & CHAR_TYPE_ID_START); +} + +/** Match an identifier name next: [_$A-Za-z0-9\], U+0080+. */ +static_inline bool char_is_id_next(u8 c) { + return !!(char_table2[c] & CHAR_TYPE_ID_NEXT); +} + +/** Match an identifier name ASCII: [_$A-Za-z0-9]. */ +static_inline bool char_is_id_ascii(u8 c) { + return !!(char_table2[c] & CHAR_TYPE_ID_ASCII); +} + +/** Match a sign: [+-] */ +static_inline bool char_is_sign(u8 d) { + return !!(char_table3[d] & CHAR_TYPE_SIGN); +} + +/** Match a none-zero digit: [1-9] */ +static_inline bool char_is_nonzero(u8 d) { + return !!(char_table3[d] & CHAR_TYPE_NONZERO); +} + +/** Match a digit: [0-9] */ +static_inline bool char_is_digit(u8 d) { + return !!(char_table3[d] & CHAR_TYPE_DIGIT); +} + +/** Match an exponent sign: [eE]. */ +static_inline bool char_is_exp(u8 d) { + return !!(char_table3[d] & CHAR_TYPE_EXP); +} + +/** Match a floating point indicator: [.eE]. */ +static_inline bool char_is_fp(u8 d) { + return !!(char_table3[d] & (CHAR_TYPE_DOT | CHAR_TYPE_EXP)); +} + +/** Match a digit or floating point indicator: [0-9.eE]. */ +static_inline bool char_is_digit_or_fp(u8 d) { + return !!(char_table3[d] & (CHAR_TYPE_DIGIT | CHAR_TYPE_DOT | + CHAR_TYPE_EXP)); +} + +/** Match a JSON container: `{` or `[`. */ +static_inline bool char_is_ctn(u8 c) { + return (c & 0xDF) == 0x5B; /* '[': 0x5B, '{': 0x7B */ +} + +/** Convert ASCII letter to lowercase; valid only for [A-Za-z]. */ +static_inline u8 char_to_lower(u8 c) { + return c | 0x20; +} + +/** Match UTF-8 byte order mask. */ +static_inline bool is_utf8_bom(const u8 *cur) { + return byte_load_3(cur) == byte_load_3("\xEF\xBB\xBF"); +} + +/** Match UTF-16 byte order mask. */ +static_inline bool is_utf16_bom(const u8 *cur) { + return byte_load_2(cur) == byte_load_2("\xFE\xFF") || + byte_load_2(cur) == byte_load_2("\xFF\xFE"); +} + +/** Match UTF-32 byte order mask, need length check to avoid zero padding. */ +static_inline bool is_utf32_bom(const u8 *cur) { + return byte_load_4(cur) == byte_load_4("\x00\x00\xFE\xFF") || + byte_load_4(cur) == byte_load_4("\xFF\xFE\x00\x00"); +} + +/** Get the extended line end length. Used with `char_is_eol_ext`. */ +static_inline usize ext_eol_len(const u8 *cur) { + if (cur[0] < 0x80) return 1; + if (cur[1] == 0x80 && (cur[2] == 0xA8 || cur[2] == 0xA9)) return 3; + return 0; +} + +/** Get the extended whitespace length. Used with `char_is_space_ext`. */ +static_inline usize ext_space_len(const u8 *cur) { + if (cur[0] < 0x80) { + return 1; + } else if (byte_load_2(cur) == byte_load_2("\xC2\xA0")) { + return 2; + } else if (byte_load_2(cur) == byte_load_2("\xE2\x80")) { + if (cur[2] >= 0x80 && cur[2] <= 0x8A) return 3; + if (cur[2] == 0xA8 || cur[2] == 0xA9 || cur[2] == 0xAF) return 3; + } else { + u32 uni = byte_load_3(cur); + if (uni == byte_load_3("\xE1\x9A\x80") || + uni == byte_load_3("\xE2\x81\x9F") || + uni == byte_load_3("\xE3\x80\x80") || + uni == byte_load_3("\xEF\xBB\xBF")) return 3; + } + return 0; +} + + + +/*============================================================================== + * MARK: - Hex Character Reader (Private) + * This function is used by JSON reader to read escaped characters. + *============================================================================*/ + +/** + This table is used to convert 4 hex character sequence to a number. + A valid hex character [0-9A-Fa-f] will mapped to it's raw number [0x00, 0x0F], + an invalid hex character will mapped to [0xF0]. + (generate with misc/make_tables.c) + */ +static const u8 hex_conv_table[256] = { + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0 +}; + +/** Load 4 hex characters to `u16`, return true on valid input. */ +static_inline bool hex_load_4(const u8 *src, u16 *dst) { + u16 c0 = hex_conv_table[src[0]]; + u16 c1 = hex_conv_table[src[1]]; + u16 c2 = hex_conv_table[src[2]]; + u16 c3 = hex_conv_table[src[3]]; + u16 t0 = (u16)((c0 << 8) | c2); + u16 t1 = (u16)((c1 << 8) | c3); + *dst = (u16)((t0 << 4) | t1); + return ((t0 | t1) & (u16)0xF0F0) == 0; +} + +/** Load 2 hex characters to `u8`, return true on valid input. */ +static_inline bool hex_load_2(const u8 *src, u8 *dst) { + u8 c0 = hex_conv_table[src[0]]; + u8 c1 = hex_conv_table[src[1]]; + *dst = (u8)((c0 << 4) | c1); + return ((c0 | c1) & 0xF0) == 0; +} + +/** Match a hexadecimal numeric character: [0-9a-fA-F]. */ +static_inline bool char_is_hex(u8 c) { + return hex_conv_table[c] != 0xF0; +} + + + +/*============================================================================== + * MARK: - UTF8 Validation (Private) + * Each Unicode code point is encoded using 1 to 4 bytes in UTF-8. + * Validation is performed using a 4-byte mask and pattern-based approach, + * which requires the input data to be padded with four zero bytes at the end. + *============================================================================*/ + +/* Macro for concatenating four u8 into a u32 and keeping the byte order. */ +#if YYJSON_ENDIAN == YYJSON_LITTLE_ENDIAN +# define utf8_seq_def(name, a, b, c, d) \ + static const u32 utf8_seq_##name = 0x##d##c##b##a##UL; +# define utf8_seq(name) utf8_seq_##name +#elif YYJSON_ENDIAN == YYJSON_BIG_ENDIAN +# define utf8_seq_def(name, a, b, c, d) \ + static const u32 utf8_seq_##name = 0x##a##b##c##d##UL; +# define utf8_seq(name) utf8_seq_##name +#else +# define utf8_seq_def(name, a, b, c, d) \ + static const v32_uni utf8_uni_##name = {{ 0x##a, 0x##b, 0x##c, 0x##d }}; +# define utf8_seq(name) utf8_uni_##name.u +#endif + +/* + 1-byte sequence (U+0000 to U+007F) + bit min [.......0] (U+0000) + bit max [.1111111] (U+007F) + bit mask [x.......] (80) + bit pattern [0.......] (00) + */ +utf8_seq_def(b1_mask, 80, 00, 00, 00) +utf8_seq_def(b1_patt, 00, 00, 00, 00) +#define is_utf8_seq1(uni) ( \ + ((uni & utf8_seq(b1_mask)) == utf8_seq(b1_patt)) ) + +/* + 2-byte sequence (U+0080 to U+07FF) + bit min [......10 ..000000] (U+0080) + bit max [...11111 ..111111] (U+07FF) + bit mask [xxx..... xx......] (E0 C0) + bit pattern [110..... 10......] (C0 80) + bit require [...xxxx. ........] (1E 00) + */ +utf8_seq_def(b2_mask, E0, C0, 00, 00) +utf8_seq_def(b2_patt, C0, 80, 00, 00) +utf8_seq_def(b2_requ, 1E, 00, 00, 00) +#define is_utf8_seq2(uni) ( \ + ((uni & utf8_seq(b2_mask)) == utf8_seq(b2_patt)) && \ + ((uni & utf8_seq(b2_requ))) ) + +/* + 3-byte sequence (U+0800 to U+FFFF) + bit min [........ ..100000 ..000000] (U+0800) + bit max [....1111 ..111111 ..111111] (U+FFFF) + bit mask [xxxx.... xx...... xx......] (F0 C0 C0) + bit pattern [1110.... 10...... 10......] (E0 80 80) + bit require [....xxxx ..x..... ........] (0F 20 00) + + 3-byte invalid sequence, reserved for surrogate halves (U+D800 to U+DFFF) + bit min [....1101 ..100000 ..000000] (U+D800) + bit max [....1101 ..111111 ..111111] (U+DFFF) + bit mask [....xxxx ..x..... ........] (0F 20 00) + bit pattern [....1101 ..1..... ........] (0D 20 00) + */ +utf8_seq_def(b3_mask, F0, C0, C0, 00) +utf8_seq_def(b3_patt, E0, 80, 80, 00) +utf8_seq_def(b3_requ, 0F, 20, 00, 00) +utf8_seq_def(b3_erro, 0D, 20, 00, 00) +#define is_utf8_seq3(uni) ( \ + ((uni & utf8_seq(b3_mask)) == utf8_seq(b3_patt)) && \ + ((tmp = (uni & utf8_seq(b3_requ)))) && \ + ((tmp != utf8_seq(b3_erro))) ) + +/* + 4-byte sequence (U+10000 to U+10FFFF) + bit min [........ ...10000 ..000000 ..000000] (U+10000) + bit max [.....100 ..001111 ..111111 ..111111] (U+10FFFF) + bit mask [xxxxx... xx...... xx...... xx......] (F8 C0 C0 C0) + bit pattern [11110... 10...... 10...... 10......] (F0 80 80 80) + bit require [.....xxx ..xx.... ........ ........] (07 30 00 00) + bit require 1 [.....x.. ........ ........ ........] (04 00 00 00) + bit require 2 [......xx ..xx.... ........ ........] (03 30 00 00) + */ +utf8_seq_def(b4_mask, F8, C0, C0, C0) +utf8_seq_def(b4_patt, F0, 80, 80, 80) +utf8_seq_def(b4_requ, 07, 30, 00, 00) +utf8_seq_def(b4_req1, 04, 00, 00, 00) +utf8_seq_def(b4_req2, 03, 30, 00, 00) +#define is_utf8_seq4(uni) ( \ + ((uni & utf8_seq(b4_mask)) == utf8_seq(b4_patt)) && \ + ((tmp = (uni & utf8_seq(b4_requ)))) && \ + ((tmp & utf8_seq(b4_req1)) == 0 || (tmp & utf8_seq(b4_req2)) == 0) ) + + + +/*============================================================================== + * MARK: - Power10 Lookup Table (Private) + * These data are used by the floating-point number reader and writer. + *============================================================================*/ + +#if !YYJSON_DISABLE_FAST_FP_CONV + +/** Maximum pow10 exponent that can be represented exactly as a float64. */ +#define F64_POW10_MAX_EXACT_EXP 22 + +/** Cached pow10 table. */ +static const f64 f64_pow10_table[F64_POW10_MAX_EXACT_EXP + 1] = { + 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, + 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22 +}; + +/** Maximum pow10 exponent that can be represented exactly as a uint64. */ +#define U64_POW10_MAX_EXACT_EXP 19 + +/** Table: [ 10^0, ..., 10^19 ] (generate with misc/make_tables.c) */ +static const u64 u64_pow10_table[U64_POW10_MAX_EXACT_EXP + 1] = { + U64(0x00000000, 0x00000001), U64(0x00000000, 0x0000000A), + U64(0x00000000, 0x00000064), U64(0x00000000, 0x000003E8), + U64(0x00000000, 0x00002710), U64(0x00000000, 0x000186A0), + U64(0x00000000, 0x000F4240), U64(0x00000000, 0x00989680), + U64(0x00000000, 0x05F5E100), U64(0x00000000, 0x3B9ACA00), + U64(0x00000002, 0x540BE400), U64(0x00000017, 0x4876E800), + U64(0x000000E8, 0xD4A51000), U64(0x00000918, 0x4E72A000), + U64(0x00005AF3, 0x107A4000), U64(0x00038D7E, 0xA4C68000), + U64(0x002386F2, 0x6FC10000), U64(0x01634578, 0x5D8A0000), + U64(0x0DE0B6B3, 0xA7640000), U64(0x8AC72304, 0x89E80000) +}; + +/** Minimum decimal exponent in pow10_sig_table. */ +#define POW10_SIG_TABLE_MIN_EXP -343 + +/** Maximum decimal exponent in pow10_sig_table. */ +#define POW10_SIG_TABLE_MAX_EXP 324 + +/** Minimum exact decimal exponent in pow10_sig_table */ +#define POW10_SIG_TABLE_MIN_EXACT_EXP 0 + +/** Maximum exact decimal exponent in pow10_sig_table */ +#define POW10_SIG_TABLE_MAX_EXACT_EXP 55 + +/** Normalized significant 128 bits of pow10, no rounded up (size: 10.4KB). + This lookup table is used by both the double number reader and writer. + (generate with misc/make_tables.c) */ +static const u64 pow10_sig_table[] = { + U64(0xBF29DCAB, 0xA82FDEAE), U64(0x7432EE87, 0x3880FC33), /* ~= 10^-343 */ + U64(0xEEF453D6, 0x923BD65A), U64(0x113FAA29, 0x06A13B3F), /* ~= 10^-342 */ + U64(0x9558B466, 0x1B6565F8), U64(0x4AC7CA59, 0xA424C507), /* ~= 10^-341 */ + U64(0xBAAEE17F, 0xA23EBF76), U64(0x5D79BCF0, 0x0D2DF649), /* ~= 10^-340 */ + U64(0xE95A99DF, 0x8ACE6F53), U64(0xF4D82C2C, 0x107973DC), /* ~= 10^-339 */ + U64(0x91D8A02B, 0xB6C10594), U64(0x79071B9B, 0x8A4BE869), /* ~= 10^-338 */ + U64(0xB64EC836, 0xA47146F9), U64(0x9748E282, 0x6CDEE284), /* ~= 10^-337 */ + U64(0xE3E27A44, 0x4D8D98B7), U64(0xFD1B1B23, 0x08169B25), /* ~= 10^-336 */ + U64(0x8E6D8C6A, 0xB0787F72), U64(0xFE30F0F5, 0xE50E20F7), /* ~= 10^-335 */ + U64(0xB208EF85, 0x5C969F4F), U64(0xBDBD2D33, 0x5E51A935), /* ~= 10^-334 */ + U64(0xDE8B2B66, 0xB3BC4723), U64(0xAD2C7880, 0x35E61382), /* ~= 10^-333 */ + U64(0x8B16FB20, 0x3055AC76), U64(0x4C3BCB50, 0x21AFCC31), /* ~= 10^-332 */ + U64(0xADDCB9E8, 0x3C6B1793), U64(0xDF4ABE24, 0x2A1BBF3D), /* ~= 10^-331 */ + U64(0xD953E862, 0x4B85DD78), U64(0xD71D6DAD, 0x34A2AF0D), /* ~= 10^-330 */ + U64(0x87D4713D, 0x6F33AA6B), U64(0x8672648C, 0x40E5AD68), /* ~= 10^-329 */ + U64(0xA9C98D8C, 0xCB009506), U64(0x680EFDAF, 0x511F18C2), /* ~= 10^-328 */ + U64(0xD43BF0EF, 0xFDC0BA48), U64(0x0212BD1B, 0x2566DEF2), /* ~= 10^-327 */ + U64(0x84A57695, 0xFE98746D), U64(0x014BB630, 0xF7604B57), /* ~= 10^-326 */ + U64(0xA5CED43B, 0x7E3E9188), U64(0x419EA3BD, 0x35385E2D), /* ~= 10^-325 */ + U64(0xCF42894A, 0x5DCE35EA), U64(0x52064CAC, 0x828675B9), /* ~= 10^-324 */ + U64(0x818995CE, 0x7AA0E1B2), U64(0x7343EFEB, 0xD1940993), /* ~= 10^-323 */ + U64(0xA1EBFB42, 0x19491A1F), U64(0x1014EBE6, 0xC5F90BF8), /* ~= 10^-322 */ + U64(0xCA66FA12, 0x9F9B60A6), U64(0xD41A26E0, 0x77774EF6), /* ~= 10^-321 */ + U64(0xFD00B897, 0x478238D0), U64(0x8920B098, 0x955522B4), /* ~= 10^-320 */ + U64(0x9E20735E, 0x8CB16382), U64(0x55B46E5F, 0x5D5535B0), /* ~= 10^-319 */ + U64(0xC5A89036, 0x2FDDBC62), U64(0xEB2189F7, 0x34AA831D), /* ~= 10^-318 */ + U64(0xF712B443, 0xBBD52B7B), U64(0xA5E9EC75, 0x01D523E4), /* ~= 10^-317 */ + U64(0x9A6BB0AA, 0x55653B2D), U64(0x47B233C9, 0x2125366E), /* ~= 10^-316 */ + U64(0xC1069CD4, 0xEABE89F8), U64(0x999EC0BB, 0x696E840A), /* ~= 10^-315 */ + U64(0xF148440A, 0x256E2C76), U64(0xC00670EA, 0x43CA250D), /* ~= 10^-314 */ + U64(0x96CD2A86, 0x5764DBCA), U64(0x38040692, 0x6A5E5728), /* ~= 10^-313 */ + U64(0xBC807527, 0xED3E12BC), U64(0xC6050837, 0x04F5ECF2), /* ~= 10^-312 */ + U64(0xEBA09271, 0xE88D976B), U64(0xF7864A44, 0xC633682E), /* ~= 10^-311 */ + U64(0x93445B87, 0x31587EA3), U64(0x7AB3EE6A, 0xFBE0211D), /* ~= 10^-310 */ + U64(0xB8157268, 0xFDAE9E4C), U64(0x5960EA05, 0xBAD82964), /* ~= 10^-309 */ + U64(0xE61ACF03, 0x3D1A45DF), U64(0x6FB92487, 0x298E33BD), /* ~= 10^-308 */ + U64(0x8FD0C162, 0x06306BAB), U64(0xA5D3B6D4, 0x79F8E056), /* ~= 10^-307 */ + U64(0xB3C4F1BA, 0x87BC8696), U64(0x8F48A489, 0x9877186C), /* ~= 10^-306 */ + U64(0xE0B62E29, 0x29ABA83C), U64(0x331ACDAB, 0xFE94DE87), /* ~= 10^-305 */ + U64(0x8C71DCD9, 0xBA0B4925), U64(0x9FF0C08B, 0x7F1D0B14), /* ~= 10^-304 */ + U64(0xAF8E5410, 0x288E1B6F), U64(0x07ECF0AE, 0x5EE44DD9), /* ~= 10^-303 */ + U64(0xDB71E914, 0x32B1A24A), U64(0xC9E82CD9, 0xF69D6150), /* ~= 10^-302 */ + U64(0x892731AC, 0x9FAF056E), U64(0xBE311C08, 0x3A225CD2), /* ~= 10^-301 */ + U64(0xAB70FE17, 0xC79AC6CA), U64(0x6DBD630A, 0x48AAF406), /* ~= 10^-300 */ + U64(0xD64D3D9D, 0xB981787D), U64(0x092CBBCC, 0xDAD5B108), /* ~= 10^-299 */ + U64(0x85F04682, 0x93F0EB4E), U64(0x25BBF560, 0x08C58EA5), /* ~= 10^-298 */ + U64(0xA76C5823, 0x38ED2621), U64(0xAF2AF2B8, 0x0AF6F24E), /* ~= 10^-297 */ + U64(0xD1476E2C, 0x07286FAA), U64(0x1AF5AF66, 0x0DB4AEE1), /* ~= 10^-296 */ + U64(0x82CCA4DB, 0x847945CA), U64(0x50D98D9F, 0xC890ED4D), /* ~= 10^-295 */ + U64(0xA37FCE12, 0x6597973C), U64(0xE50FF107, 0xBAB528A0), /* ~= 10^-294 */ + U64(0xCC5FC196, 0xFEFD7D0C), U64(0x1E53ED49, 0xA96272C8), /* ~= 10^-293 */ + U64(0xFF77B1FC, 0xBEBCDC4F), U64(0x25E8E89C, 0x13BB0F7A), /* ~= 10^-292 */ + U64(0x9FAACF3D, 0xF73609B1), U64(0x77B19161, 0x8C54E9AC), /* ~= 10^-291 */ + U64(0xC795830D, 0x75038C1D), U64(0xD59DF5B9, 0xEF6A2417), /* ~= 10^-290 */ + U64(0xF97AE3D0, 0xD2446F25), U64(0x4B057328, 0x6B44AD1D), /* ~= 10^-289 */ + U64(0x9BECCE62, 0x836AC577), U64(0x4EE367F9, 0x430AEC32), /* ~= 10^-288 */ + U64(0xC2E801FB, 0x244576D5), U64(0x229C41F7, 0x93CDA73F), /* ~= 10^-287 */ + U64(0xF3A20279, 0xED56D48A), U64(0x6B435275, 0x78C1110F), /* ~= 10^-286 */ + U64(0x9845418C, 0x345644D6), U64(0x830A1389, 0x6B78AAA9), /* ~= 10^-285 */ + U64(0xBE5691EF, 0x416BD60C), U64(0x23CC986B, 0xC656D553), /* ~= 10^-284 */ + U64(0xEDEC366B, 0x11C6CB8F), U64(0x2CBFBE86, 0xB7EC8AA8), /* ~= 10^-283 */ + U64(0x94B3A202, 0xEB1C3F39), U64(0x7BF7D714, 0x32F3D6A9), /* ~= 10^-282 */ + U64(0xB9E08A83, 0xA5E34F07), U64(0xDAF5CCD9, 0x3FB0CC53), /* ~= 10^-281 */ + U64(0xE858AD24, 0x8F5C22C9), U64(0xD1B3400F, 0x8F9CFF68), /* ~= 10^-280 */ + U64(0x91376C36, 0xD99995BE), U64(0x23100809, 0xB9C21FA1), /* ~= 10^-279 */ + U64(0xB5854744, 0x8FFFFB2D), U64(0xABD40A0C, 0x2832A78A), /* ~= 10^-278 */ + U64(0xE2E69915, 0xB3FFF9F9), U64(0x16C90C8F, 0x323F516C), /* ~= 10^-277 */ + U64(0x8DD01FAD, 0x907FFC3B), U64(0xAE3DA7D9, 0x7F6792E3), /* ~= 10^-276 */ + U64(0xB1442798, 0xF49FFB4A), U64(0x99CD11CF, 0xDF41779C), /* ~= 10^-275 */ + U64(0xDD95317F, 0x31C7FA1D), U64(0x40405643, 0xD711D583), /* ~= 10^-274 */ + U64(0x8A7D3EEF, 0x7F1CFC52), U64(0x482835EA, 0x666B2572), /* ~= 10^-273 */ + U64(0xAD1C8EAB, 0x5EE43B66), U64(0xDA324365, 0x0005EECF), /* ~= 10^-272 */ + U64(0xD863B256, 0x369D4A40), U64(0x90BED43E, 0x40076A82), /* ~= 10^-271 */ + U64(0x873E4F75, 0xE2224E68), U64(0x5A7744A6, 0xE804A291), /* ~= 10^-270 */ + U64(0xA90DE353, 0x5AAAE202), U64(0x711515D0, 0xA205CB36), /* ~= 10^-269 */ + U64(0xD3515C28, 0x31559A83), U64(0x0D5A5B44, 0xCA873E03), /* ~= 10^-268 */ + U64(0x8412D999, 0x1ED58091), U64(0xE858790A, 0xFE9486C2), /* ~= 10^-267 */ + U64(0xA5178FFF, 0x668AE0B6), U64(0x626E974D, 0xBE39A872), /* ~= 10^-266 */ + U64(0xCE5D73FF, 0x402D98E3), U64(0xFB0A3D21, 0x2DC8128F), /* ~= 10^-265 */ + U64(0x80FA687F, 0x881C7F8E), U64(0x7CE66634, 0xBC9D0B99), /* ~= 10^-264 */ + U64(0xA139029F, 0x6A239F72), U64(0x1C1FFFC1, 0xEBC44E80), /* ~= 10^-263 */ + U64(0xC9874347, 0x44AC874E), U64(0xA327FFB2, 0x66B56220), /* ~= 10^-262 */ + U64(0xFBE91419, 0x15D7A922), U64(0x4BF1FF9F, 0x0062BAA8), /* ~= 10^-261 */ + U64(0x9D71AC8F, 0xADA6C9B5), U64(0x6F773FC3, 0x603DB4A9), /* ~= 10^-260 */ + U64(0xC4CE17B3, 0x99107C22), U64(0xCB550FB4, 0x384D21D3), /* ~= 10^-259 */ + U64(0xF6019DA0, 0x7F549B2B), U64(0x7E2A53A1, 0x46606A48), /* ~= 10^-258 */ + U64(0x99C10284, 0x4F94E0FB), U64(0x2EDA7444, 0xCBFC426D), /* ~= 10^-257 */ + U64(0xC0314325, 0x637A1939), U64(0xFA911155, 0xFEFB5308), /* ~= 10^-256 */ + U64(0xF03D93EE, 0xBC589F88), U64(0x793555AB, 0x7EBA27CA), /* ~= 10^-255 */ + U64(0x96267C75, 0x35B763B5), U64(0x4BC1558B, 0x2F3458DE), /* ~= 10^-254 */ + U64(0xBBB01B92, 0x83253CA2), U64(0x9EB1AAED, 0xFB016F16), /* ~= 10^-253 */ + U64(0xEA9C2277, 0x23EE8BCB), U64(0x465E15A9, 0x79C1CADC), /* ~= 10^-252 */ + U64(0x92A1958A, 0x7675175F), U64(0x0BFACD89, 0xEC191EC9), /* ~= 10^-251 */ + U64(0xB749FAED, 0x14125D36), U64(0xCEF980EC, 0x671F667B), /* ~= 10^-250 */ + U64(0xE51C79A8, 0x5916F484), U64(0x82B7E127, 0x80E7401A), /* ~= 10^-249 */ + U64(0x8F31CC09, 0x37AE58D2), U64(0xD1B2ECB8, 0xB0908810), /* ~= 10^-248 */ + U64(0xB2FE3F0B, 0x8599EF07), U64(0x861FA7E6, 0xDCB4AA15), /* ~= 10^-247 */ + U64(0xDFBDCECE, 0x67006AC9), U64(0x67A791E0, 0x93E1D49A), /* ~= 10^-246 */ + U64(0x8BD6A141, 0x006042BD), U64(0xE0C8BB2C, 0x5C6D24E0), /* ~= 10^-245 */ + U64(0xAECC4991, 0x4078536D), U64(0x58FAE9F7, 0x73886E18), /* ~= 10^-244 */ + U64(0xDA7F5BF5, 0x90966848), U64(0xAF39A475, 0x506A899E), /* ~= 10^-243 */ + U64(0x888F9979, 0x7A5E012D), U64(0x6D8406C9, 0x52429603), /* ~= 10^-242 */ + U64(0xAAB37FD7, 0xD8F58178), U64(0xC8E5087B, 0xA6D33B83), /* ~= 10^-241 */ + U64(0xD5605FCD, 0xCF32E1D6), U64(0xFB1E4A9A, 0x90880A64), /* ~= 10^-240 */ + U64(0x855C3BE0, 0xA17FCD26), U64(0x5CF2EEA0, 0x9A55067F), /* ~= 10^-239 */ + U64(0xA6B34AD8, 0xC9DFC06F), U64(0xF42FAA48, 0xC0EA481E), /* ~= 10^-238 */ + U64(0xD0601D8E, 0xFC57B08B), U64(0xF13B94DA, 0xF124DA26), /* ~= 10^-237 */ + U64(0x823C1279, 0x5DB6CE57), U64(0x76C53D08, 0xD6B70858), /* ~= 10^-236 */ + U64(0xA2CB1717, 0xB52481ED), U64(0x54768C4B, 0x0C64CA6E), /* ~= 10^-235 */ + U64(0xCB7DDCDD, 0xA26DA268), U64(0xA9942F5D, 0xCF7DFD09), /* ~= 10^-234 */ + U64(0xFE5D5415, 0x0B090B02), U64(0xD3F93B35, 0x435D7C4C), /* ~= 10^-233 */ + U64(0x9EFA548D, 0x26E5A6E1), U64(0xC47BC501, 0x4A1A6DAF), /* ~= 10^-232 */ + U64(0xC6B8E9B0, 0x709F109A), U64(0x359AB641, 0x9CA1091B), /* ~= 10^-231 */ + U64(0xF867241C, 0x8CC6D4C0), U64(0xC30163D2, 0x03C94B62), /* ~= 10^-230 */ + U64(0x9B407691, 0xD7FC44F8), U64(0x79E0DE63, 0x425DCF1D), /* ~= 10^-229 */ + U64(0xC2109436, 0x4DFB5636), U64(0x985915FC, 0x12F542E4), /* ~= 10^-228 */ + U64(0xF294B943, 0xE17A2BC4), U64(0x3E6F5B7B, 0x17B2939D), /* ~= 10^-227 */ + U64(0x979CF3CA, 0x6CEC5B5A), U64(0xA705992C, 0xEECF9C42), /* ~= 10^-226 */ + U64(0xBD8430BD, 0x08277231), U64(0x50C6FF78, 0x2A838353), /* ~= 10^-225 */ + U64(0xECE53CEC, 0x4A314EBD), U64(0xA4F8BF56, 0x35246428), /* ~= 10^-224 */ + U64(0x940F4613, 0xAE5ED136), U64(0x871B7795, 0xE136BE99), /* ~= 10^-223 */ + U64(0xB9131798, 0x99F68584), U64(0x28E2557B, 0x59846E3F), /* ~= 10^-222 */ + U64(0xE757DD7E, 0xC07426E5), U64(0x331AEADA, 0x2FE589CF), /* ~= 10^-221 */ + U64(0x9096EA6F, 0x3848984F), U64(0x3FF0D2C8, 0x5DEF7621), /* ~= 10^-220 */ + U64(0xB4BCA50B, 0x065ABE63), U64(0x0FED077A, 0x756B53A9), /* ~= 10^-219 */ + U64(0xE1EBCE4D, 0xC7F16DFB), U64(0xD3E84959, 0x12C62894), /* ~= 10^-218 */ + U64(0x8D3360F0, 0x9CF6E4BD), U64(0x64712DD7, 0xABBBD95C), /* ~= 10^-217 */ + U64(0xB080392C, 0xC4349DEC), U64(0xBD8D794D, 0x96AACFB3), /* ~= 10^-216 */ + U64(0xDCA04777, 0xF541C567), U64(0xECF0D7A0, 0xFC5583A0), /* ~= 10^-215 */ + U64(0x89E42CAA, 0xF9491B60), U64(0xF41686C4, 0x9DB57244), /* ~= 10^-214 */ + U64(0xAC5D37D5, 0xB79B6239), U64(0x311C2875, 0xC522CED5), /* ~= 10^-213 */ + U64(0xD77485CB, 0x25823AC7), U64(0x7D633293, 0x366B828B), /* ~= 10^-212 */ + U64(0x86A8D39E, 0xF77164BC), U64(0xAE5DFF9C, 0x02033197), /* ~= 10^-211 */ + U64(0xA8530886, 0xB54DBDEB), U64(0xD9F57F83, 0x0283FDFC), /* ~= 10^-210 */ + U64(0xD267CAA8, 0x62A12D66), U64(0xD072DF63, 0xC324FD7B), /* ~= 10^-209 */ + U64(0x8380DEA9, 0x3DA4BC60), U64(0x4247CB9E, 0x59F71E6D), /* ~= 10^-208 */ + U64(0xA4611653, 0x8D0DEB78), U64(0x52D9BE85, 0xF074E608), /* ~= 10^-207 */ + U64(0xCD795BE8, 0x70516656), U64(0x67902E27, 0x6C921F8B), /* ~= 10^-206 */ + U64(0x806BD971, 0x4632DFF6), U64(0x00BA1CD8, 0xA3DB53B6), /* ~= 10^-205 */ + U64(0xA086CFCD, 0x97BF97F3), U64(0x80E8A40E, 0xCCD228A4), /* ~= 10^-204 */ + U64(0xC8A883C0, 0xFDAF7DF0), U64(0x6122CD12, 0x8006B2CD), /* ~= 10^-203 */ + U64(0xFAD2A4B1, 0x3D1B5D6C), U64(0x796B8057, 0x20085F81), /* ~= 10^-202 */ + U64(0x9CC3A6EE, 0xC6311A63), U64(0xCBE33036, 0x74053BB0), /* ~= 10^-201 */ + U64(0xC3F490AA, 0x77BD60FC), U64(0xBEDBFC44, 0x11068A9C), /* ~= 10^-200 */ + U64(0xF4F1B4D5, 0x15ACB93B), U64(0xEE92FB55, 0x15482D44), /* ~= 10^-199 */ + U64(0x99171105, 0x2D8BF3C5), U64(0x751BDD15, 0x2D4D1C4A), /* ~= 10^-198 */ + U64(0xBF5CD546, 0x78EEF0B6), U64(0xD262D45A, 0x78A0635D), /* ~= 10^-197 */ + U64(0xEF340A98, 0x172AACE4), U64(0x86FB8971, 0x16C87C34), /* ~= 10^-196 */ + U64(0x9580869F, 0x0E7AAC0E), U64(0xD45D35E6, 0xAE3D4DA0), /* ~= 10^-195 */ + U64(0xBAE0A846, 0xD2195712), U64(0x89748360, 0x59CCA109), /* ~= 10^-194 */ + U64(0xE998D258, 0x869FACD7), U64(0x2BD1A438, 0x703FC94B), /* ~= 10^-193 */ + U64(0x91FF8377, 0x5423CC06), U64(0x7B6306A3, 0x4627DDCF), /* ~= 10^-192 */ + U64(0xB67F6455, 0x292CBF08), U64(0x1A3BC84C, 0x17B1D542), /* ~= 10^-191 */ + U64(0xE41F3D6A, 0x7377EECA), U64(0x20CABA5F, 0x1D9E4A93), /* ~= 10^-190 */ + U64(0x8E938662, 0x882AF53E), U64(0x547EB47B, 0x7282EE9C), /* ~= 10^-189 */ + U64(0xB23867FB, 0x2A35B28D), U64(0xE99E619A, 0x4F23AA43), /* ~= 10^-188 */ + U64(0xDEC681F9, 0xF4C31F31), U64(0x6405FA00, 0xE2EC94D4), /* ~= 10^-187 */ + U64(0x8B3C113C, 0x38F9F37E), U64(0xDE83BC40, 0x8DD3DD04), /* ~= 10^-186 */ + U64(0xAE0B158B, 0x4738705E), U64(0x9624AB50, 0xB148D445), /* ~= 10^-185 */ + U64(0xD98DDAEE, 0x19068C76), U64(0x3BADD624, 0xDD9B0957), /* ~= 10^-184 */ + U64(0x87F8A8D4, 0xCFA417C9), U64(0xE54CA5D7, 0x0A80E5D6), /* ~= 10^-183 */ + U64(0xA9F6D30A, 0x038D1DBC), U64(0x5E9FCF4C, 0xCD211F4C), /* ~= 10^-182 */ + U64(0xD47487CC, 0x8470652B), U64(0x7647C320, 0x0069671F), /* ~= 10^-181 */ + U64(0x84C8D4DF, 0xD2C63F3B), U64(0x29ECD9F4, 0x0041E073), /* ~= 10^-180 */ + U64(0xA5FB0A17, 0xC777CF09), U64(0xF4681071, 0x00525890), /* ~= 10^-179 */ + U64(0xCF79CC9D, 0xB955C2CC), U64(0x7182148D, 0x4066EEB4), /* ~= 10^-178 */ + U64(0x81AC1FE2, 0x93D599BF), U64(0xC6F14CD8, 0x48405530), /* ~= 10^-177 */ + U64(0xA21727DB, 0x38CB002F), U64(0xB8ADA00E, 0x5A506A7C), /* ~= 10^-176 */ + U64(0xCA9CF1D2, 0x06FDC03B), U64(0xA6D90811, 0xF0E4851C), /* ~= 10^-175 */ + U64(0xFD442E46, 0x88BD304A), U64(0x908F4A16, 0x6D1DA663), /* ~= 10^-174 */ + U64(0x9E4A9CEC, 0x15763E2E), U64(0x9A598E4E, 0x043287FE), /* ~= 10^-173 */ + U64(0xC5DD4427, 0x1AD3CDBA), U64(0x40EFF1E1, 0x853F29FD), /* ~= 10^-172 */ + U64(0xF7549530, 0xE188C128), U64(0xD12BEE59, 0xE68EF47C), /* ~= 10^-171 */ + U64(0x9A94DD3E, 0x8CF578B9), U64(0x82BB74F8, 0x301958CE), /* ~= 10^-170 */ + U64(0xC13A148E, 0x3032D6E7), U64(0xE36A5236, 0x3C1FAF01), /* ~= 10^-169 */ + U64(0xF18899B1, 0xBC3F8CA1), U64(0xDC44E6C3, 0xCB279AC1), /* ~= 10^-168 */ + U64(0x96F5600F, 0x15A7B7E5), U64(0x29AB103A, 0x5EF8C0B9), /* ~= 10^-167 */ + U64(0xBCB2B812, 0xDB11A5DE), U64(0x7415D448, 0xF6B6F0E7), /* ~= 10^-166 */ + U64(0xEBDF6617, 0x91D60F56), U64(0x111B495B, 0x3464AD21), /* ~= 10^-165 */ + U64(0x936B9FCE, 0xBB25C995), U64(0xCAB10DD9, 0x00BEEC34), /* ~= 10^-164 */ + U64(0xB84687C2, 0x69EF3BFB), U64(0x3D5D514F, 0x40EEA742), /* ~= 10^-163 */ + U64(0xE65829B3, 0x046B0AFA), U64(0x0CB4A5A3, 0x112A5112), /* ~= 10^-162 */ + U64(0x8FF71A0F, 0xE2C2E6DC), U64(0x47F0E785, 0xEABA72AB), /* ~= 10^-161 */ + U64(0xB3F4E093, 0xDB73A093), U64(0x59ED2167, 0x65690F56), /* ~= 10^-160 */ + U64(0xE0F218B8, 0xD25088B8), U64(0x306869C1, 0x3EC3532C), /* ~= 10^-159 */ + U64(0x8C974F73, 0x83725573), U64(0x1E414218, 0xC73A13FB), /* ~= 10^-158 */ + U64(0xAFBD2350, 0x644EEACF), U64(0xE5D1929E, 0xF90898FA), /* ~= 10^-157 */ + U64(0xDBAC6C24, 0x7D62A583), U64(0xDF45F746, 0xB74ABF39), /* ~= 10^-156 */ + U64(0x894BC396, 0xCE5DA772), U64(0x6B8BBA8C, 0x328EB783), /* ~= 10^-155 */ + U64(0xAB9EB47C, 0x81F5114F), U64(0x066EA92F, 0x3F326564), /* ~= 10^-154 */ + U64(0xD686619B, 0xA27255A2), U64(0xC80A537B, 0x0EFEFEBD), /* ~= 10^-153 */ + U64(0x8613FD01, 0x45877585), U64(0xBD06742C, 0xE95F5F36), /* ~= 10^-152 */ + U64(0xA798FC41, 0x96E952E7), U64(0x2C481138, 0x23B73704), /* ~= 10^-151 */ + U64(0xD17F3B51, 0xFCA3A7A0), U64(0xF75A1586, 0x2CA504C5), /* ~= 10^-150 */ + U64(0x82EF8513, 0x3DE648C4), U64(0x9A984D73, 0xDBE722FB), /* ~= 10^-149 */ + U64(0xA3AB6658, 0x0D5FDAF5), U64(0xC13E60D0, 0xD2E0EBBA), /* ~= 10^-148 */ + U64(0xCC963FEE, 0x10B7D1B3), U64(0x318DF905, 0x079926A8), /* ~= 10^-147 */ + U64(0xFFBBCFE9, 0x94E5C61F), U64(0xFDF17746, 0x497F7052), /* ~= 10^-146 */ + U64(0x9FD561F1, 0xFD0F9BD3), U64(0xFEB6EA8B, 0xEDEFA633), /* ~= 10^-145 */ + U64(0xC7CABA6E, 0x7C5382C8), U64(0xFE64A52E, 0xE96B8FC0), /* ~= 10^-144 */ + U64(0xF9BD690A, 0x1B68637B), U64(0x3DFDCE7A, 0xA3C673B0), /* ~= 10^-143 */ + U64(0x9C1661A6, 0x51213E2D), U64(0x06BEA10C, 0xA65C084E), /* ~= 10^-142 */ + U64(0xC31BFA0F, 0xE5698DB8), U64(0x486E494F, 0xCFF30A62), /* ~= 10^-141 */ + U64(0xF3E2F893, 0xDEC3F126), U64(0x5A89DBA3, 0xC3EFCCFA), /* ~= 10^-140 */ + U64(0x986DDB5C, 0x6B3A76B7), U64(0xF8962946, 0x5A75E01C), /* ~= 10^-139 */ + U64(0xBE895233, 0x86091465), U64(0xF6BBB397, 0xF1135823), /* ~= 10^-138 */ + U64(0xEE2BA6C0, 0x678B597F), U64(0x746AA07D, 0xED582E2C), /* ~= 10^-137 */ + U64(0x94DB4838, 0x40B717EF), U64(0xA8C2A44E, 0xB4571CDC), /* ~= 10^-136 */ + U64(0xBA121A46, 0x50E4DDEB), U64(0x92F34D62, 0x616CE413), /* ~= 10^-135 */ + U64(0xE896A0D7, 0xE51E1566), U64(0x77B020BA, 0xF9C81D17), /* ~= 10^-134 */ + U64(0x915E2486, 0xEF32CD60), U64(0x0ACE1474, 0xDC1D122E), /* ~= 10^-133 */ + U64(0xB5B5ADA8, 0xAAFF80B8), U64(0x0D819992, 0x132456BA), /* ~= 10^-132 */ + U64(0xE3231912, 0xD5BF60E6), U64(0x10E1FFF6, 0x97ED6C69), /* ~= 10^-131 */ + U64(0x8DF5EFAB, 0xC5979C8F), U64(0xCA8D3FFA, 0x1EF463C1), /* ~= 10^-130 */ + U64(0xB1736B96, 0xB6FD83B3), U64(0xBD308FF8, 0xA6B17CB2), /* ~= 10^-129 */ + U64(0xDDD0467C, 0x64BCE4A0), U64(0xAC7CB3F6, 0xD05DDBDE), /* ~= 10^-128 */ + U64(0x8AA22C0D, 0xBEF60EE4), U64(0x6BCDF07A, 0x423AA96B), /* ~= 10^-127 */ + U64(0xAD4AB711, 0x2EB3929D), U64(0x86C16C98, 0xD2C953C6), /* ~= 10^-126 */ + U64(0xD89D64D5, 0x7A607744), U64(0xE871C7BF, 0x077BA8B7), /* ~= 10^-125 */ + U64(0x87625F05, 0x6C7C4A8B), U64(0x11471CD7, 0x64AD4972), /* ~= 10^-124 */ + U64(0xA93AF6C6, 0xC79B5D2D), U64(0xD598E40D, 0x3DD89BCF), /* ~= 10^-123 */ + U64(0xD389B478, 0x79823479), U64(0x4AFF1D10, 0x8D4EC2C3), /* ~= 10^-122 */ + U64(0x843610CB, 0x4BF160CB), U64(0xCEDF722A, 0x585139BA), /* ~= 10^-121 */ + U64(0xA54394FE, 0x1EEDB8FE), U64(0xC2974EB4, 0xEE658828), /* ~= 10^-120 */ + U64(0xCE947A3D, 0xA6A9273E), U64(0x733D2262, 0x29FEEA32), /* ~= 10^-119 */ + U64(0x811CCC66, 0x8829B887), U64(0x0806357D, 0x5A3F525F), /* ~= 10^-118 */ + U64(0xA163FF80, 0x2A3426A8), U64(0xCA07C2DC, 0xB0CF26F7), /* ~= 10^-117 */ + U64(0xC9BCFF60, 0x34C13052), U64(0xFC89B393, 0xDD02F0B5), /* ~= 10^-116 */ + U64(0xFC2C3F38, 0x41F17C67), U64(0xBBAC2078, 0xD443ACE2), /* ~= 10^-115 */ + U64(0x9D9BA783, 0x2936EDC0), U64(0xD54B944B, 0x84AA4C0D), /* ~= 10^-114 */ + U64(0xC5029163, 0xF384A931), U64(0x0A9E795E, 0x65D4DF11), /* ~= 10^-113 */ + U64(0xF64335BC, 0xF065D37D), U64(0x4D4617B5, 0xFF4A16D5), /* ~= 10^-112 */ + U64(0x99EA0196, 0x163FA42E), U64(0x504BCED1, 0xBF8E4E45), /* ~= 10^-111 */ + U64(0xC06481FB, 0x9BCF8D39), U64(0xE45EC286, 0x2F71E1D6), /* ~= 10^-110 */ + U64(0xF07DA27A, 0x82C37088), U64(0x5D767327, 0xBB4E5A4C), /* ~= 10^-109 */ + U64(0x964E858C, 0x91BA2655), U64(0x3A6A07F8, 0xD510F86F), /* ~= 10^-108 */ + U64(0xBBE226EF, 0xB628AFEA), U64(0x890489F7, 0x0A55368B), /* ~= 10^-107 */ + U64(0xEADAB0AB, 0xA3B2DBE5), U64(0x2B45AC74, 0xCCEA842E), /* ~= 10^-106 */ + U64(0x92C8AE6B, 0x464FC96F), U64(0x3B0B8BC9, 0x0012929D), /* ~= 10^-105 */ + U64(0xB77ADA06, 0x17E3BBCB), U64(0x09CE6EBB, 0x40173744), /* ~= 10^-104 */ + U64(0xE5599087, 0x9DDCAABD), U64(0xCC420A6A, 0x101D0515), /* ~= 10^-103 */ + U64(0x8F57FA54, 0xC2A9EAB6), U64(0x9FA94682, 0x4A12232D), /* ~= 10^-102 */ + U64(0xB32DF8E9, 0xF3546564), U64(0x47939822, 0xDC96ABF9), /* ~= 10^-101 */ + U64(0xDFF97724, 0x70297EBD), U64(0x59787E2B, 0x93BC56F7), /* ~= 10^-100 */ + U64(0x8BFBEA76, 0xC619EF36), U64(0x57EB4EDB, 0x3C55B65A), /* ~= 10^-99 */ + U64(0xAEFAE514, 0x77A06B03), U64(0xEDE62292, 0x0B6B23F1), /* ~= 10^-98 */ + U64(0xDAB99E59, 0x958885C4), U64(0xE95FAB36, 0x8E45ECED), /* ~= 10^-97 */ + U64(0x88B402F7, 0xFD75539B), U64(0x11DBCB02, 0x18EBB414), /* ~= 10^-96 */ + U64(0xAAE103B5, 0xFCD2A881), U64(0xD652BDC2, 0x9F26A119), /* ~= 10^-95 */ + U64(0xD59944A3, 0x7C0752A2), U64(0x4BE76D33, 0x46F0495F), /* ~= 10^-94 */ + U64(0x857FCAE6, 0x2D8493A5), U64(0x6F70A440, 0x0C562DDB), /* ~= 10^-93 */ + U64(0xA6DFBD9F, 0xB8E5B88E), U64(0xCB4CCD50, 0x0F6BB952), /* ~= 10^-92 */ + U64(0xD097AD07, 0xA71F26B2), U64(0x7E2000A4, 0x1346A7A7), /* ~= 10^-91 */ + U64(0x825ECC24, 0xC873782F), U64(0x8ED40066, 0x8C0C28C8), /* ~= 10^-90 */ + U64(0xA2F67F2D, 0xFA90563B), U64(0x72890080, 0x2F0F32FA), /* ~= 10^-89 */ + U64(0xCBB41EF9, 0x79346BCA), U64(0x4F2B40A0, 0x3AD2FFB9), /* ~= 10^-88 */ + U64(0xFEA126B7, 0xD78186BC), U64(0xE2F610C8, 0x4987BFA8), /* ~= 10^-87 */ + U64(0x9F24B832, 0xE6B0F436), U64(0x0DD9CA7D, 0x2DF4D7C9), /* ~= 10^-86 */ + U64(0xC6EDE63F, 0xA05D3143), U64(0x91503D1C, 0x79720DBB), /* ~= 10^-85 */ + U64(0xF8A95FCF, 0x88747D94), U64(0x75A44C63, 0x97CE912A), /* ~= 10^-84 */ + U64(0x9B69DBE1, 0xB548CE7C), U64(0xC986AFBE, 0x3EE11ABA), /* ~= 10^-83 */ + U64(0xC24452DA, 0x229B021B), U64(0xFBE85BAD, 0xCE996168), /* ~= 10^-82 */ + U64(0xF2D56790, 0xAB41C2A2), U64(0xFAE27299, 0x423FB9C3), /* ~= 10^-81 */ + U64(0x97C560BA, 0x6B0919A5), U64(0xDCCD879F, 0xC967D41A), /* ~= 10^-80 */ + U64(0xBDB6B8E9, 0x05CB600F), U64(0x5400E987, 0xBBC1C920), /* ~= 10^-79 */ + U64(0xED246723, 0x473E3813), U64(0x290123E9, 0xAAB23B68), /* ~= 10^-78 */ + U64(0x9436C076, 0x0C86E30B), U64(0xF9A0B672, 0x0AAF6521), /* ~= 10^-77 */ + U64(0xB9447093, 0x8FA89BCE), U64(0xF808E40E, 0x8D5B3E69), /* ~= 10^-76 */ + U64(0xE7958CB8, 0x7392C2C2), U64(0xB60B1D12, 0x30B20E04), /* ~= 10^-75 */ + U64(0x90BD77F3, 0x483BB9B9), U64(0xB1C6F22B, 0x5E6F48C2), /* ~= 10^-74 */ + U64(0xB4ECD5F0, 0x1A4AA828), U64(0x1E38AEB6, 0x360B1AF3), /* ~= 10^-73 */ + U64(0xE2280B6C, 0x20DD5232), U64(0x25C6DA63, 0xC38DE1B0), /* ~= 10^-72 */ + U64(0x8D590723, 0x948A535F), U64(0x579C487E, 0x5A38AD0E), /* ~= 10^-71 */ + U64(0xB0AF48EC, 0x79ACE837), U64(0x2D835A9D, 0xF0C6D851), /* ~= 10^-70 */ + U64(0xDCDB1B27, 0x98182244), U64(0xF8E43145, 0x6CF88E65), /* ~= 10^-69 */ + U64(0x8A08F0F8, 0xBF0F156B), U64(0x1B8E9ECB, 0x641B58FF), /* ~= 10^-68 */ + U64(0xAC8B2D36, 0xEED2DAC5), U64(0xE272467E, 0x3D222F3F), /* ~= 10^-67 */ + U64(0xD7ADF884, 0xAA879177), U64(0x5B0ED81D, 0xCC6ABB0F), /* ~= 10^-66 */ + U64(0x86CCBB52, 0xEA94BAEA), U64(0x98E94712, 0x9FC2B4E9), /* ~= 10^-65 */ + U64(0xA87FEA27, 0xA539E9A5), U64(0x3F2398D7, 0x47B36224), /* ~= 10^-64 */ + U64(0xD29FE4B1, 0x8E88640E), U64(0x8EEC7F0D, 0x19A03AAD), /* ~= 10^-63 */ + U64(0x83A3EEEE, 0xF9153E89), U64(0x1953CF68, 0x300424AC), /* ~= 10^-62 */ + U64(0xA48CEAAA, 0xB75A8E2B), U64(0x5FA8C342, 0x3C052DD7), /* ~= 10^-61 */ + U64(0xCDB02555, 0x653131B6), U64(0x3792F412, 0xCB06794D), /* ~= 10^-60 */ + U64(0x808E1755, 0x5F3EBF11), U64(0xE2BBD88B, 0xBEE40BD0), /* ~= 10^-59 */ + U64(0xA0B19D2A, 0xB70E6ED6), U64(0x5B6ACEAE, 0xAE9D0EC4), /* ~= 10^-58 */ + U64(0xC8DE0475, 0x64D20A8B), U64(0xF245825A, 0x5A445275), /* ~= 10^-57 */ + U64(0xFB158592, 0xBE068D2E), U64(0xEED6E2F0, 0xF0D56712), /* ~= 10^-56 */ + U64(0x9CED737B, 0xB6C4183D), U64(0x55464DD6, 0x9685606B), /* ~= 10^-55 */ + U64(0xC428D05A, 0xA4751E4C), U64(0xAA97E14C, 0x3C26B886), /* ~= 10^-54 */ + U64(0xF5330471, 0x4D9265DF), U64(0xD53DD99F, 0x4B3066A8), /* ~= 10^-53 */ + U64(0x993FE2C6, 0xD07B7FAB), U64(0xE546A803, 0x8EFE4029), /* ~= 10^-52 */ + U64(0xBF8FDB78, 0x849A5F96), U64(0xDE985204, 0x72BDD033), /* ~= 10^-51 */ + U64(0xEF73D256, 0xA5C0F77C), U64(0x963E6685, 0x8F6D4440), /* ~= 10^-50 */ + U64(0x95A86376, 0x27989AAD), U64(0xDDE70013, 0x79A44AA8), /* ~= 10^-49 */ + U64(0xBB127C53, 0xB17EC159), U64(0x5560C018, 0x580D5D52), /* ~= 10^-48 */ + U64(0xE9D71B68, 0x9DDE71AF), U64(0xAAB8F01E, 0x6E10B4A6), /* ~= 10^-47 */ + U64(0x92267121, 0x62AB070D), U64(0xCAB39613, 0x04CA70E8), /* ~= 10^-46 */ + U64(0xB6B00D69, 0xBB55C8D1), U64(0x3D607B97, 0xC5FD0D22), /* ~= 10^-45 */ + U64(0xE45C10C4, 0x2A2B3B05), U64(0x8CB89A7D, 0xB77C506A), /* ~= 10^-44 */ + U64(0x8EB98A7A, 0x9A5B04E3), U64(0x77F3608E, 0x92ADB242), /* ~= 10^-43 */ + U64(0xB267ED19, 0x40F1C61C), U64(0x55F038B2, 0x37591ED3), /* ~= 10^-42 */ + U64(0xDF01E85F, 0x912E37A3), U64(0x6B6C46DE, 0xC52F6688), /* ~= 10^-41 */ + U64(0x8B61313B, 0xBABCE2C6), U64(0x2323AC4B, 0x3B3DA015), /* ~= 10^-40 */ + U64(0xAE397D8A, 0xA96C1B77), U64(0xABEC975E, 0x0A0D081A), /* ~= 10^-39 */ + U64(0xD9C7DCED, 0x53C72255), U64(0x96E7BD35, 0x8C904A21), /* ~= 10^-38 */ + U64(0x881CEA14, 0x545C7575), U64(0x7E50D641, 0x77DA2E54), /* ~= 10^-37 */ + U64(0xAA242499, 0x697392D2), U64(0xDDE50BD1, 0xD5D0B9E9), /* ~= 10^-36 */ + U64(0xD4AD2DBF, 0xC3D07787), U64(0x955E4EC6, 0x4B44E864), /* ~= 10^-35 */ + U64(0x84EC3C97, 0xDA624AB4), U64(0xBD5AF13B, 0xEF0B113E), /* ~= 10^-34 */ + U64(0xA6274BBD, 0xD0FADD61), U64(0xECB1AD8A, 0xEACDD58E), /* ~= 10^-33 */ + U64(0xCFB11EAD, 0x453994BA), U64(0x67DE18ED, 0xA5814AF2), /* ~= 10^-32 */ + U64(0x81CEB32C, 0x4B43FCF4), U64(0x80EACF94, 0x8770CED7), /* ~= 10^-31 */ + U64(0xA2425FF7, 0x5E14FC31), U64(0xA1258379, 0xA94D028D), /* ~= 10^-30 */ + U64(0xCAD2F7F5, 0x359A3B3E), U64(0x096EE458, 0x13A04330), /* ~= 10^-29 */ + U64(0xFD87B5F2, 0x8300CA0D), U64(0x8BCA9D6E, 0x188853FC), /* ~= 10^-28 */ + U64(0x9E74D1B7, 0x91E07E48), U64(0x775EA264, 0xCF55347D), /* ~= 10^-27 */ + U64(0xC6120625, 0x76589DDA), U64(0x95364AFE, 0x032A819D), /* ~= 10^-26 */ + U64(0xF79687AE, 0xD3EEC551), U64(0x3A83DDBD, 0x83F52204), /* ~= 10^-25 */ + U64(0x9ABE14CD, 0x44753B52), U64(0xC4926A96, 0x72793542), /* ~= 10^-24 */ + U64(0xC16D9A00, 0x95928A27), U64(0x75B7053C, 0x0F178293), /* ~= 10^-23 */ + U64(0xF1C90080, 0xBAF72CB1), U64(0x5324C68B, 0x12DD6338), /* ~= 10^-22 */ + U64(0x971DA050, 0x74DA7BEE), U64(0xD3F6FC16, 0xEBCA5E03), /* ~= 10^-21 */ + U64(0xBCE50864, 0x92111AEA), U64(0x88F4BB1C, 0xA6BCF584), /* ~= 10^-20 */ + U64(0xEC1E4A7D, 0xB69561A5), U64(0x2B31E9E3, 0xD06C32E5), /* ~= 10^-19 */ + U64(0x9392EE8E, 0x921D5D07), U64(0x3AFF322E, 0x62439FCF), /* ~= 10^-18 */ + U64(0xB877AA32, 0x36A4B449), U64(0x09BEFEB9, 0xFAD487C2), /* ~= 10^-17 */ + U64(0xE69594BE, 0xC44DE15B), U64(0x4C2EBE68, 0x7989A9B3), /* ~= 10^-16 */ + U64(0x901D7CF7, 0x3AB0ACD9), U64(0x0F9D3701, 0x4BF60A10), /* ~= 10^-15 */ + U64(0xB424DC35, 0x095CD80F), U64(0x538484C1, 0x9EF38C94), /* ~= 10^-14 */ + U64(0xE12E1342, 0x4BB40E13), U64(0x2865A5F2, 0x06B06FB9), /* ~= 10^-13 */ + U64(0x8CBCCC09, 0x6F5088CB), U64(0xF93F87B7, 0x442E45D3), /* ~= 10^-12 */ + U64(0xAFEBFF0B, 0xCB24AAFE), U64(0xF78F69A5, 0x1539D748), /* ~= 10^-11 */ + U64(0xDBE6FECE, 0xBDEDD5BE), U64(0xB573440E, 0x5A884D1B), /* ~= 10^-10 */ + U64(0x89705F41, 0x36B4A597), U64(0x31680A88, 0xF8953030), /* ~= 10^-9 */ + U64(0xABCC7711, 0x8461CEFC), U64(0xFDC20D2B, 0x36BA7C3D), /* ~= 10^-8 */ + U64(0xD6BF94D5, 0xE57A42BC), U64(0x3D329076, 0x04691B4C), /* ~= 10^-7 */ + U64(0x8637BD05, 0xAF6C69B5), U64(0xA63F9A49, 0xC2C1B10F), /* ~= 10^-6 */ + U64(0xA7C5AC47, 0x1B478423), U64(0x0FCF80DC, 0x33721D53), /* ~= 10^-5 */ + U64(0xD1B71758, 0xE219652B), U64(0xD3C36113, 0x404EA4A8), /* ~= 10^-4 */ + U64(0x83126E97, 0x8D4FDF3B), U64(0x645A1CAC, 0x083126E9), /* ~= 10^-3 */ + U64(0xA3D70A3D, 0x70A3D70A), U64(0x3D70A3D7, 0x0A3D70A3), /* ~= 10^-2 */ + U64(0xCCCCCCCC, 0xCCCCCCCC), U64(0xCCCCCCCC, 0xCCCCCCCC), /* ~= 10^-1 */ + U64(0x80000000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^0 */ + U64(0xA0000000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^1 */ + U64(0xC8000000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^2 */ + U64(0xFA000000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^3 */ + U64(0x9C400000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^4 */ + U64(0xC3500000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^5 */ + U64(0xF4240000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^6 */ + U64(0x98968000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^7 */ + U64(0xBEBC2000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^8 */ + U64(0xEE6B2800, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^9 */ + U64(0x9502F900, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^10 */ + U64(0xBA43B740, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^11 */ + U64(0xE8D4A510, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^12 */ + U64(0x9184E72A, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^13 */ + U64(0xB5E620F4, 0x80000000), U64(0x00000000, 0x00000000), /* == 10^14 */ + U64(0xE35FA931, 0xA0000000), U64(0x00000000, 0x00000000), /* == 10^15 */ + U64(0x8E1BC9BF, 0x04000000), U64(0x00000000, 0x00000000), /* == 10^16 */ + U64(0xB1A2BC2E, 0xC5000000), U64(0x00000000, 0x00000000), /* == 10^17 */ + U64(0xDE0B6B3A, 0x76400000), U64(0x00000000, 0x00000000), /* == 10^18 */ + U64(0x8AC72304, 0x89E80000), U64(0x00000000, 0x00000000), /* == 10^19 */ + U64(0xAD78EBC5, 0xAC620000), U64(0x00000000, 0x00000000), /* == 10^20 */ + U64(0xD8D726B7, 0x177A8000), U64(0x00000000, 0x00000000), /* == 10^21 */ + U64(0x87867832, 0x6EAC9000), U64(0x00000000, 0x00000000), /* == 10^22 */ + U64(0xA968163F, 0x0A57B400), U64(0x00000000, 0x00000000), /* == 10^23 */ + U64(0xD3C21BCE, 0xCCEDA100), U64(0x00000000, 0x00000000), /* == 10^24 */ + U64(0x84595161, 0x401484A0), U64(0x00000000, 0x00000000), /* == 10^25 */ + U64(0xA56FA5B9, 0x9019A5C8), U64(0x00000000, 0x00000000), /* == 10^26 */ + U64(0xCECB8F27, 0xF4200F3A), U64(0x00000000, 0x00000000), /* == 10^27 */ + U64(0x813F3978, 0xF8940984), U64(0x40000000, 0x00000000), /* == 10^28 */ + U64(0xA18F07D7, 0x36B90BE5), U64(0x50000000, 0x00000000), /* == 10^29 */ + U64(0xC9F2C9CD, 0x04674EDE), U64(0xA4000000, 0x00000000), /* == 10^30 */ + U64(0xFC6F7C40, 0x45812296), U64(0x4D000000, 0x00000000), /* == 10^31 */ + U64(0x9DC5ADA8, 0x2B70B59D), U64(0xF0200000, 0x00000000), /* == 10^32 */ + U64(0xC5371912, 0x364CE305), U64(0x6C280000, 0x00000000), /* == 10^33 */ + U64(0xF684DF56, 0xC3E01BC6), U64(0xC7320000, 0x00000000), /* == 10^34 */ + U64(0x9A130B96, 0x3A6C115C), U64(0x3C7F4000, 0x00000000), /* == 10^35 */ + U64(0xC097CE7B, 0xC90715B3), U64(0x4B9F1000, 0x00000000), /* == 10^36 */ + U64(0xF0BDC21A, 0xBB48DB20), U64(0x1E86D400, 0x00000000), /* == 10^37 */ + U64(0x96769950, 0xB50D88F4), U64(0x13144480, 0x00000000), /* == 10^38 */ + U64(0xBC143FA4, 0xE250EB31), U64(0x17D955A0, 0x00000000), /* == 10^39 */ + U64(0xEB194F8E, 0x1AE525FD), U64(0x5DCFAB08, 0x00000000), /* == 10^40 */ + U64(0x92EFD1B8, 0xD0CF37BE), U64(0x5AA1CAE5, 0x00000000), /* == 10^41 */ + U64(0xB7ABC627, 0x050305AD), U64(0xF14A3D9E, 0x40000000), /* == 10^42 */ + U64(0xE596B7B0, 0xC643C719), U64(0x6D9CCD05, 0xD0000000), /* == 10^43 */ + U64(0x8F7E32CE, 0x7BEA5C6F), U64(0xE4820023, 0xA2000000), /* == 10^44 */ + U64(0xB35DBF82, 0x1AE4F38B), U64(0xDDA2802C, 0x8A800000), /* == 10^45 */ + U64(0xE0352F62, 0xA19E306E), U64(0xD50B2037, 0xAD200000), /* == 10^46 */ + U64(0x8C213D9D, 0xA502DE45), U64(0x4526F422, 0xCC340000), /* == 10^47 */ + U64(0xAF298D05, 0x0E4395D6), U64(0x9670B12B, 0x7F410000), /* == 10^48 */ + U64(0xDAF3F046, 0x51D47B4C), U64(0x3C0CDD76, 0x5F114000), /* == 10^49 */ + U64(0x88D8762B, 0xF324CD0F), U64(0xA5880A69, 0xFB6AC800), /* == 10^50 */ + U64(0xAB0E93B6, 0xEFEE0053), U64(0x8EEA0D04, 0x7A457A00), /* == 10^51 */ + U64(0xD5D238A4, 0xABE98068), U64(0x72A49045, 0x98D6D880), /* == 10^52 */ + U64(0x85A36366, 0xEB71F041), U64(0x47A6DA2B, 0x7F864750), /* == 10^53 */ + U64(0xA70C3C40, 0xA64E6C51), U64(0x999090B6, 0x5F67D924), /* == 10^54 */ + U64(0xD0CF4B50, 0xCFE20765), U64(0xFFF4B4E3, 0xF741CF6D), /* == 10^55 */ + U64(0x82818F12, 0x81ED449F), U64(0xBFF8F10E, 0x7A8921A4), /* ~= 10^56 */ + U64(0xA321F2D7, 0x226895C7), U64(0xAFF72D52, 0x192B6A0D), /* ~= 10^57 */ + U64(0xCBEA6F8C, 0xEB02BB39), U64(0x9BF4F8A6, 0x9F764490), /* ~= 10^58 */ + U64(0xFEE50B70, 0x25C36A08), U64(0x02F236D0, 0x4753D5B4), /* ~= 10^59 */ + U64(0x9F4F2726, 0x179A2245), U64(0x01D76242, 0x2C946590), /* ~= 10^60 */ + U64(0xC722F0EF, 0x9D80AAD6), U64(0x424D3AD2, 0xB7B97EF5), /* ~= 10^61 */ + U64(0xF8EBAD2B, 0x84E0D58B), U64(0xD2E08987, 0x65A7DEB2), /* ~= 10^62 */ + U64(0x9B934C3B, 0x330C8577), U64(0x63CC55F4, 0x9F88EB2F), /* ~= 10^63 */ + U64(0xC2781F49, 0xFFCFA6D5), U64(0x3CBF6B71, 0xC76B25FB), /* ~= 10^64 */ + U64(0xF316271C, 0x7FC3908A), U64(0x8BEF464E, 0x3945EF7A), /* ~= 10^65 */ + U64(0x97EDD871, 0xCFDA3A56), U64(0x97758BF0, 0xE3CBB5AC), /* ~= 10^66 */ + U64(0xBDE94E8E, 0x43D0C8EC), U64(0x3D52EEED, 0x1CBEA317), /* ~= 10^67 */ + U64(0xED63A231, 0xD4C4FB27), U64(0x4CA7AAA8, 0x63EE4BDD), /* ~= 10^68 */ + U64(0x945E455F, 0x24FB1CF8), U64(0x8FE8CAA9, 0x3E74EF6A), /* ~= 10^69 */ + U64(0xB975D6B6, 0xEE39E436), U64(0xB3E2FD53, 0x8E122B44), /* ~= 10^70 */ + U64(0xE7D34C64, 0xA9C85D44), U64(0x60DBBCA8, 0x7196B616), /* ~= 10^71 */ + U64(0x90E40FBE, 0xEA1D3A4A), U64(0xBC8955E9, 0x46FE31CD), /* ~= 10^72 */ + U64(0xB51D13AE, 0xA4A488DD), U64(0x6BABAB63, 0x98BDBE41), /* ~= 10^73 */ + U64(0xE264589A, 0x4DCDAB14), U64(0xC696963C, 0x7EED2DD1), /* ~= 10^74 */ + U64(0x8D7EB760, 0x70A08AEC), U64(0xFC1E1DE5, 0xCF543CA2), /* ~= 10^75 */ + U64(0xB0DE6538, 0x8CC8ADA8), U64(0x3B25A55F, 0x43294BCB), /* ~= 10^76 */ + U64(0xDD15FE86, 0xAFFAD912), U64(0x49EF0EB7, 0x13F39EBE), /* ~= 10^77 */ + U64(0x8A2DBF14, 0x2DFCC7AB), U64(0x6E356932, 0x6C784337), /* ~= 10^78 */ + U64(0xACB92ED9, 0x397BF996), U64(0x49C2C37F, 0x07965404), /* ~= 10^79 */ + U64(0xD7E77A8F, 0x87DAF7FB), U64(0xDC33745E, 0xC97BE906), /* ~= 10^80 */ + U64(0x86F0AC99, 0xB4E8DAFD), U64(0x69A028BB, 0x3DED71A3), /* ~= 10^81 */ + U64(0xA8ACD7C0, 0x222311BC), U64(0xC40832EA, 0x0D68CE0C), /* ~= 10^82 */ + U64(0xD2D80DB0, 0x2AABD62B), U64(0xF50A3FA4, 0x90C30190), /* ~= 10^83 */ + U64(0x83C7088E, 0x1AAB65DB), U64(0x792667C6, 0xDA79E0FA), /* ~= 10^84 */ + U64(0xA4B8CAB1, 0xA1563F52), U64(0x577001B8, 0x91185938), /* ~= 10^85 */ + U64(0xCDE6FD5E, 0x09ABCF26), U64(0xED4C0226, 0xB55E6F86), /* ~= 10^86 */ + U64(0x80B05E5A, 0xC60B6178), U64(0x544F8158, 0x315B05B4), /* ~= 10^87 */ + U64(0xA0DC75F1, 0x778E39D6), U64(0x696361AE, 0x3DB1C721), /* ~= 10^88 */ + U64(0xC913936D, 0xD571C84C), U64(0x03BC3A19, 0xCD1E38E9), /* ~= 10^89 */ + U64(0xFB587849, 0x4ACE3A5F), U64(0x04AB48A0, 0x4065C723), /* ~= 10^90 */ + U64(0x9D174B2D, 0xCEC0E47B), U64(0x62EB0D64, 0x283F9C76), /* ~= 10^91 */ + U64(0xC45D1DF9, 0x42711D9A), U64(0x3BA5D0BD, 0x324F8394), /* ~= 10^92 */ + U64(0xF5746577, 0x930D6500), U64(0xCA8F44EC, 0x7EE36479), /* ~= 10^93 */ + U64(0x9968BF6A, 0xBBE85F20), U64(0x7E998B13, 0xCF4E1ECB), /* ~= 10^94 */ + U64(0xBFC2EF45, 0x6AE276E8), U64(0x9E3FEDD8, 0xC321A67E), /* ~= 10^95 */ + U64(0xEFB3AB16, 0xC59B14A2), U64(0xC5CFE94E, 0xF3EA101E), /* ~= 10^96 */ + U64(0x95D04AEE, 0x3B80ECE5), U64(0xBBA1F1D1, 0x58724A12), /* ~= 10^97 */ + U64(0xBB445DA9, 0xCA61281F), U64(0x2A8A6E45, 0xAE8EDC97), /* ~= 10^98 */ + U64(0xEA157514, 0x3CF97226), U64(0xF52D09D7, 0x1A3293BD), /* ~= 10^99 */ + U64(0x924D692C, 0xA61BE758), U64(0x593C2626, 0x705F9C56), /* ~= 10^100 */ + U64(0xB6E0C377, 0xCFA2E12E), U64(0x6F8B2FB0, 0x0C77836C), /* ~= 10^101 */ + U64(0xE498F455, 0xC38B997A), U64(0x0B6DFB9C, 0x0F956447), /* ~= 10^102 */ + U64(0x8EDF98B5, 0x9A373FEC), U64(0x4724BD41, 0x89BD5EAC), /* ~= 10^103 */ + U64(0xB2977EE3, 0x00C50FE7), U64(0x58EDEC91, 0xEC2CB657), /* ~= 10^104 */ + U64(0xDF3D5E9B, 0xC0F653E1), U64(0x2F2967B6, 0x6737E3ED), /* ~= 10^105 */ + U64(0x8B865B21, 0x5899F46C), U64(0xBD79E0D2, 0x0082EE74), /* ~= 10^106 */ + U64(0xAE67F1E9, 0xAEC07187), U64(0xECD85906, 0x80A3AA11), /* ~= 10^107 */ + U64(0xDA01EE64, 0x1A708DE9), U64(0xE80E6F48, 0x20CC9495), /* ~= 10^108 */ + U64(0x884134FE, 0x908658B2), U64(0x3109058D, 0x147FDCDD), /* ~= 10^109 */ + U64(0xAA51823E, 0x34A7EEDE), U64(0xBD4B46F0, 0x599FD415), /* ~= 10^110 */ + U64(0xD4E5E2CD, 0xC1D1EA96), U64(0x6C9E18AC, 0x7007C91A), /* ~= 10^111 */ + U64(0x850FADC0, 0x9923329E), U64(0x03E2CF6B, 0xC604DDB0), /* ~= 10^112 */ + U64(0xA6539930, 0xBF6BFF45), U64(0x84DB8346, 0xB786151C), /* ~= 10^113 */ + U64(0xCFE87F7C, 0xEF46FF16), U64(0xE6126418, 0x65679A63), /* ~= 10^114 */ + U64(0x81F14FAE, 0x158C5F6E), U64(0x4FCB7E8F, 0x3F60C07E), /* ~= 10^115 */ + U64(0xA26DA399, 0x9AEF7749), U64(0xE3BE5E33, 0x0F38F09D), /* ~= 10^116 */ + U64(0xCB090C80, 0x01AB551C), U64(0x5CADF5BF, 0xD3072CC5), /* ~= 10^117 */ + U64(0xFDCB4FA0, 0x02162A63), U64(0x73D9732F, 0xC7C8F7F6), /* ~= 10^118 */ + U64(0x9E9F11C4, 0x014DDA7E), U64(0x2867E7FD, 0xDCDD9AFA), /* ~= 10^119 */ + U64(0xC646D635, 0x01A1511D), U64(0xB281E1FD, 0x541501B8), /* ~= 10^120 */ + U64(0xF7D88BC2, 0x4209A565), U64(0x1F225A7C, 0xA91A4226), /* ~= 10^121 */ + U64(0x9AE75759, 0x6946075F), U64(0x3375788D, 0xE9B06958), /* ~= 10^122 */ + U64(0xC1A12D2F, 0xC3978937), U64(0x0052D6B1, 0x641C83AE), /* ~= 10^123 */ + U64(0xF209787B, 0xB47D6B84), U64(0xC0678C5D, 0xBD23A49A), /* ~= 10^124 */ + U64(0x9745EB4D, 0x50CE6332), U64(0xF840B7BA, 0x963646E0), /* ~= 10^125 */ + U64(0xBD176620, 0xA501FBFF), U64(0xB650E5A9, 0x3BC3D898), /* ~= 10^126 */ + U64(0xEC5D3FA8, 0xCE427AFF), U64(0xA3E51F13, 0x8AB4CEBE), /* ~= 10^127 */ + U64(0x93BA47C9, 0x80E98CDF), U64(0xC66F336C, 0x36B10137), /* ~= 10^128 */ + U64(0xB8A8D9BB, 0xE123F017), U64(0xB80B0047, 0x445D4184), /* ~= 10^129 */ + U64(0xE6D3102A, 0xD96CEC1D), U64(0xA60DC059, 0x157491E5), /* ~= 10^130 */ + U64(0x9043EA1A, 0xC7E41392), U64(0x87C89837, 0xAD68DB2F), /* ~= 10^131 */ + U64(0xB454E4A1, 0x79DD1877), U64(0x29BABE45, 0x98C311FB), /* ~= 10^132 */ + U64(0xE16A1DC9, 0xD8545E94), U64(0xF4296DD6, 0xFEF3D67A), /* ~= 10^133 */ + U64(0x8CE2529E, 0x2734BB1D), U64(0x1899E4A6, 0x5F58660C), /* ~= 10^134 */ + U64(0xB01AE745, 0xB101E9E4), U64(0x5EC05DCF, 0xF72E7F8F), /* ~= 10^135 */ + U64(0xDC21A117, 0x1D42645D), U64(0x76707543, 0xF4FA1F73), /* ~= 10^136 */ + U64(0x899504AE, 0x72497EBA), U64(0x6A06494A, 0x791C53A8), /* ~= 10^137 */ + U64(0xABFA45DA, 0x0EDBDE69), U64(0x0487DB9D, 0x17636892), /* ~= 10^138 */ + U64(0xD6F8D750, 0x9292D603), U64(0x45A9D284, 0x5D3C42B6), /* ~= 10^139 */ + U64(0x865B8692, 0x5B9BC5C2), U64(0x0B8A2392, 0xBA45A9B2), /* ~= 10^140 */ + U64(0xA7F26836, 0xF282B732), U64(0x8E6CAC77, 0x68D7141E), /* ~= 10^141 */ + U64(0xD1EF0244, 0xAF2364FF), U64(0x3207D795, 0x430CD926), /* ~= 10^142 */ + U64(0x8335616A, 0xED761F1F), U64(0x7F44E6BD, 0x49E807B8), /* ~= 10^143 */ + U64(0xA402B9C5, 0xA8D3A6E7), U64(0x5F16206C, 0x9C6209A6), /* ~= 10^144 */ + U64(0xCD036837, 0x130890A1), U64(0x36DBA887, 0xC37A8C0F), /* ~= 10^145 */ + U64(0x80222122, 0x6BE55A64), U64(0xC2494954, 0xDA2C9789), /* ~= 10^146 */ + U64(0xA02AA96B, 0x06DEB0FD), U64(0xF2DB9BAA, 0x10B7BD6C), /* ~= 10^147 */ + U64(0xC83553C5, 0xC8965D3D), U64(0x6F928294, 0x94E5ACC7), /* ~= 10^148 */ + U64(0xFA42A8B7, 0x3ABBF48C), U64(0xCB772339, 0xBA1F17F9), /* ~= 10^149 */ + U64(0x9C69A972, 0x84B578D7), U64(0xFF2A7604, 0x14536EFB), /* ~= 10^150 */ + U64(0xC38413CF, 0x25E2D70D), U64(0xFEF51385, 0x19684ABA), /* ~= 10^151 */ + U64(0xF46518C2, 0xEF5B8CD1), U64(0x7EB25866, 0x5FC25D69), /* ~= 10^152 */ + U64(0x98BF2F79, 0xD5993802), U64(0xEF2F773F, 0xFBD97A61), /* ~= 10^153 */ + U64(0xBEEEFB58, 0x4AFF8603), U64(0xAAFB550F, 0xFACFD8FA), /* ~= 10^154 */ + U64(0xEEAABA2E, 0x5DBF6784), U64(0x95BA2A53, 0xF983CF38), /* ~= 10^155 */ + U64(0x952AB45C, 0xFA97A0B2), U64(0xDD945A74, 0x7BF26183), /* ~= 10^156 */ + U64(0xBA756174, 0x393D88DF), U64(0x94F97111, 0x9AEEF9E4), /* ~= 10^157 */ + U64(0xE912B9D1, 0x478CEB17), U64(0x7A37CD56, 0x01AAB85D), /* ~= 10^158 */ + U64(0x91ABB422, 0xCCB812EE), U64(0xAC62E055, 0xC10AB33A), /* ~= 10^159 */ + U64(0xB616A12B, 0x7FE617AA), U64(0x577B986B, 0x314D6009), /* ~= 10^160 */ + U64(0xE39C4976, 0x5FDF9D94), U64(0xED5A7E85, 0xFDA0B80B), /* ~= 10^161 */ + U64(0x8E41ADE9, 0xFBEBC27D), U64(0x14588F13, 0xBE847307), /* ~= 10^162 */ + U64(0xB1D21964, 0x7AE6B31C), U64(0x596EB2D8, 0xAE258FC8), /* ~= 10^163 */ + U64(0xDE469FBD, 0x99A05FE3), U64(0x6FCA5F8E, 0xD9AEF3BB), /* ~= 10^164 */ + U64(0x8AEC23D6, 0x80043BEE), U64(0x25DE7BB9, 0x480D5854), /* ~= 10^165 */ + U64(0xADA72CCC, 0x20054AE9), U64(0xAF561AA7, 0x9A10AE6A), /* ~= 10^166 */ + U64(0xD910F7FF, 0x28069DA4), U64(0x1B2BA151, 0x8094DA04), /* ~= 10^167 */ + U64(0x87AA9AFF, 0x79042286), U64(0x90FB44D2, 0xF05D0842), /* ~= 10^168 */ + U64(0xA99541BF, 0x57452B28), U64(0x353A1607, 0xAC744A53), /* ~= 10^169 */ + U64(0xD3FA922F, 0x2D1675F2), U64(0x42889B89, 0x97915CE8), /* ~= 10^170 */ + U64(0x847C9B5D, 0x7C2E09B7), U64(0x69956135, 0xFEBADA11), /* ~= 10^171 */ + U64(0xA59BC234, 0xDB398C25), U64(0x43FAB983, 0x7E699095), /* ~= 10^172 */ + U64(0xCF02B2C2, 0x1207EF2E), U64(0x94F967E4, 0x5E03F4BB), /* ~= 10^173 */ + U64(0x8161AFB9, 0x4B44F57D), U64(0x1D1BE0EE, 0xBAC278F5), /* ~= 10^174 */ + U64(0xA1BA1BA7, 0x9E1632DC), U64(0x6462D92A, 0x69731732), /* ~= 10^175 */ + U64(0xCA28A291, 0x859BBF93), U64(0x7D7B8F75, 0x03CFDCFE), /* ~= 10^176 */ + U64(0xFCB2CB35, 0xE702AF78), U64(0x5CDA7352, 0x44C3D43E), /* ~= 10^177 */ + U64(0x9DEFBF01, 0xB061ADAB), U64(0x3A088813, 0x6AFA64A7), /* ~= 10^178 */ + U64(0xC56BAEC2, 0x1C7A1916), U64(0x088AAA18, 0x45B8FDD0), /* ~= 10^179 */ + U64(0xF6C69A72, 0xA3989F5B), U64(0x8AAD549E, 0x57273D45), /* ~= 10^180 */ + U64(0x9A3C2087, 0xA63F6399), U64(0x36AC54E2, 0xF678864B), /* ~= 10^181 */ + U64(0xC0CB28A9, 0x8FCF3C7F), U64(0x84576A1B, 0xB416A7DD), /* ~= 10^182 */ + U64(0xF0FDF2D3, 0xF3C30B9F), U64(0x656D44A2, 0xA11C51D5), /* ~= 10^183 */ + U64(0x969EB7C4, 0x7859E743), U64(0x9F644AE5, 0xA4B1B325), /* ~= 10^184 */ + U64(0xBC4665B5, 0x96706114), U64(0x873D5D9F, 0x0DDE1FEE), /* ~= 10^185 */ + U64(0xEB57FF22, 0xFC0C7959), U64(0xA90CB506, 0xD155A7EA), /* ~= 10^186 */ + U64(0x9316FF75, 0xDD87CBD8), U64(0x09A7F124, 0x42D588F2), /* ~= 10^187 */ + U64(0xB7DCBF53, 0x54E9BECE), U64(0x0C11ED6D, 0x538AEB2F), /* ~= 10^188 */ + U64(0xE5D3EF28, 0x2A242E81), U64(0x8F1668C8, 0xA86DA5FA), /* ~= 10^189 */ + U64(0x8FA47579, 0x1A569D10), U64(0xF96E017D, 0x694487BC), /* ~= 10^190 */ + U64(0xB38D92D7, 0x60EC4455), U64(0x37C981DC, 0xC395A9AC), /* ~= 10^191 */ + U64(0xE070F78D, 0x3927556A), U64(0x85BBE253, 0xF47B1417), /* ~= 10^192 */ + U64(0x8C469AB8, 0x43B89562), U64(0x93956D74, 0x78CCEC8E), /* ~= 10^193 */ + U64(0xAF584166, 0x54A6BABB), U64(0x387AC8D1, 0x970027B2), /* ~= 10^194 */ + U64(0xDB2E51BF, 0xE9D0696A), U64(0x06997B05, 0xFCC0319E), /* ~= 10^195 */ + U64(0x88FCF317, 0xF22241E2), U64(0x441FECE3, 0xBDF81F03), /* ~= 10^196 */ + U64(0xAB3C2FDD, 0xEEAAD25A), U64(0xD527E81C, 0xAD7626C3), /* ~= 10^197 */ + U64(0xD60B3BD5, 0x6A5586F1), U64(0x8A71E223, 0xD8D3B074), /* ~= 10^198 */ + U64(0x85C70565, 0x62757456), U64(0xF6872D56, 0x67844E49), /* ~= 10^199 */ + U64(0xA738C6BE, 0xBB12D16C), U64(0xB428F8AC, 0x016561DB), /* ~= 10^200 */ + U64(0xD106F86E, 0x69D785C7), U64(0xE13336D7, 0x01BEBA52), /* ~= 10^201 */ + U64(0x82A45B45, 0x0226B39C), U64(0xECC00246, 0x61173473), /* ~= 10^202 */ + U64(0xA34D7216, 0x42B06084), U64(0x27F002D7, 0xF95D0190), /* ~= 10^203 */ + U64(0xCC20CE9B, 0xD35C78A5), U64(0x31EC038D, 0xF7B441F4), /* ~= 10^204 */ + U64(0xFF290242, 0xC83396CE), U64(0x7E670471, 0x75A15271), /* ~= 10^205 */ + U64(0x9F79A169, 0xBD203E41), U64(0x0F0062C6, 0xE984D386), /* ~= 10^206 */ + U64(0xC75809C4, 0x2C684DD1), U64(0x52C07B78, 0xA3E60868), /* ~= 10^207 */ + U64(0xF92E0C35, 0x37826145), U64(0xA7709A56, 0xCCDF8A82), /* ~= 10^208 */ + U64(0x9BBCC7A1, 0x42B17CCB), U64(0x88A66076, 0x400BB691), /* ~= 10^209 */ + U64(0xC2ABF989, 0x935DDBFE), U64(0x6ACFF893, 0xD00EA435), /* ~= 10^210 */ + U64(0xF356F7EB, 0xF83552FE), U64(0x0583F6B8, 0xC4124D43), /* ~= 10^211 */ + U64(0x98165AF3, 0x7B2153DE), U64(0xC3727A33, 0x7A8B704A), /* ~= 10^212 */ + U64(0xBE1BF1B0, 0x59E9A8D6), U64(0x744F18C0, 0x592E4C5C), /* ~= 10^213 */ + U64(0xEDA2EE1C, 0x7064130C), U64(0x1162DEF0, 0x6F79DF73), /* ~= 10^214 */ + U64(0x9485D4D1, 0xC63E8BE7), U64(0x8ADDCB56, 0x45AC2BA8), /* ~= 10^215 */ + U64(0xB9A74A06, 0x37CE2EE1), U64(0x6D953E2B, 0xD7173692), /* ~= 10^216 */ + U64(0xE8111C87, 0xC5C1BA99), U64(0xC8FA8DB6, 0xCCDD0437), /* ~= 10^217 */ + U64(0x910AB1D4, 0xDB9914A0), U64(0x1D9C9892, 0x400A22A2), /* ~= 10^218 */ + U64(0xB54D5E4A, 0x127F59C8), U64(0x2503BEB6, 0xD00CAB4B), /* ~= 10^219 */ + U64(0xE2A0B5DC, 0x971F303A), U64(0x2E44AE64, 0x840FD61D), /* ~= 10^220 */ + U64(0x8DA471A9, 0xDE737E24), U64(0x5CEAECFE, 0xD289E5D2), /* ~= 10^221 */ + U64(0xB10D8E14, 0x56105DAD), U64(0x7425A83E, 0x872C5F47), /* ~= 10^222 */ + U64(0xDD50F199, 0x6B947518), U64(0xD12F124E, 0x28F77719), /* ~= 10^223 */ + U64(0x8A5296FF, 0xE33CC92F), U64(0x82BD6B70, 0xD99AAA6F), /* ~= 10^224 */ + U64(0xACE73CBF, 0xDC0BFB7B), U64(0x636CC64D, 0x1001550B), /* ~= 10^225 */ + U64(0xD8210BEF, 0xD30EFA5A), U64(0x3C47F7E0, 0x5401AA4E), /* ~= 10^226 */ + U64(0x8714A775, 0xE3E95C78), U64(0x65ACFAEC, 0x34810A71), /* ~= 10^227 */ + U64(0xA8D9D153, 0x5CE3B396), U64(0x7F1839A7, 0x41A14D0D), /* ~= 10^228 */ + U64(0xD31045A8, 0x341CA07C), U64(0x1EDE4811, 0x1209A050), /* ~= 10^229 */ + U64(0x83EA2B89, 0x2091E44D), U64(0x934AED0A, 0xAB460432), /* ~= 10^230 */ + U64(0xA4E4B66B, 0x68B65D60), U64(0xF81DA84D, 0x5617853F), /* ~= 10^231 */ + U64(0xCE1DE406, 0x42E3F4B9), U64(0x36251260, 0xAB9D668E), /* ~= 10^232 */ + U64(0x80D2AE83, 0xE9CE78F3), U64(0xC1D72B7C, 0x6B426019), /* ~= 10^233 */ + U64(0xA1075A24, 0xE4421730), U64(0xB24CF65B, 0x8612F81F), /* ~= 10^234 */ + U64(0xC94930AE, 0x1D529CFC), U64(0xDEE033F2, 0x6797B627), /* ~= 10^235 */ + U64(0xFB9B7CD9, 0xA4A7443C), U64(0x169840EF, 0x017DA3B1), /* ~= 10^236 */ + U64(0x9D412E08, 0x06E88AA5), U64(0x8E1F2895, 0x60EE864E), /* ~= 10^237 */ + U64(0xC491798A, 0x08A2AD4E), U64(0xF1A6F2BA, 0xB92A27E2), /* ~= 10^238 */ + U64(0xF5B5D7EC, 0x8ACB58A2), U64(0xAE10AF69, 0x6774B1DB), /* ~= 10^239 */ + U64(0x9991A6F3, 0xD6BF1765), U64(0xACCA6DA1, 0xE0A8EF29), /* ~= 10^240 */ + U64(0xBFF610B0, 0xCC6EDD3F), U64(0x17FD090A, 0x58D32AF3), /* ~= 10^241 */ + U64(0xEFF394DC, 0xFF8A948E), U64(0xDDFC4B4C, 0xEF07F5B0), /* ~= 10^242 */ + U64(0x95F83D0A, 0x1FB69CD9), U64(0x4ABDAF10, 0x1564F98E), /* ~= 10^243 */ + U64(0xBB764C4C, 0xA7A4440F), U64(0x9D6D1AD4, 0x1ABE37F1), /* ~= 10^244 */ + U64(0xEA53DF5F, 0xD18D5513), U64(0x84C86189, 0x216DC5ED), /* ~= 10^245 */ + U64(0x92746B9B, 0xE2F8552C), U64(0x32FD3CF5, 0xB4E49BB4), /* ~= 10^246 */ + U64(0xB7118682, 0xDBB66A77), U64(0x3FBC8C33, 0x221DC2A1), /* ~= 10^247 */ + U64(0xE4D5E823, 0x92A40515), U64(0x0FABAF3F, 0xEAA5334A), /* ~= 10^248 */ + U64(0x8F05B116, 0x3BA6832D), U64(0x29CB4D87, 0xF2A7400E), /* ~= 10^249 */ + U64(0xB2C71D5B, 0xCA9023F8), U64(0x743E20E9, 0xEF511012), /* ~= 10^250 */ + U64(0xDF78E4B2, 0xBD342CF6), U64(0x914DA924, 0x6B255416), /* ~= 10^251 */ + U64(0x8BAB8EEF, 0xB6409C1A), U64(0x1AD089B6, 0xC2F7548E), /* ~= 10^252 */ + U64(0xAE9672AB, 0xA3D0C320), U64(0xA184AC24, 0x73B529B1), /* ~= 10^253 */ + U64(0xDA3C0F56, 0x8CC4F3E8), U64(0xC9E5D72D, 0x90A2741E), /* ~= 10^254 */ + U64(0x88658996, 0x17FB1871), U64(0x7E2FA67C, 0x7A658892), /* ~= 10^255 */ + U64(0xAA7EEBFB, 0x9DF9DE8D), U64(0xDDBB901B, 0x98FEEAB7), /* ~= 10^256 */ + U64(0xD51EA6FA, 0x85785631), U64(0x552A7422, 0x7F3EA565), /* ~= 10^257 */ + U64(0x8533285C, 0x936B35DE), U64(0xD53A8895, 0x8F87275F), /* ~= 10^258 */ + U64(0xA67FF273, 0xB8460356), U64(0x8A892ABA, 0xF368F137), /* ~= 10^259 */ + U64(0xD01FEF10, 0xA657842C), U64(0x2D2B7569, 0xB0432D85), /* ~= 10^260 */ + U64(0x8213F56A, 0x67F6B29B), U64(0x9C3B2962, 0x0E29FC73), /* ~= 10^261 */ + U64(0xA298F2C5, 0x01F45F42), U64(0x8349F3BA, 0x91B47B8F), /* ~= 10^262 */ + U64(0xCB3F2F76, 0x42717713), U64(0x241C70A9, 0x36219A73), /* ~= 10^263 */ + U64(0xFE0EFB53, 0xD30DD4D7), U64(0xED238CD3, 0x83AA0110), /* ~= 10^264 */ + U64(0x9EC95D14, 0x63E8A506), U64(0xF4363804, 0x324A40AA), /* ~= 10^265 */ + U64(0xC67BB459, 0x7CE2CE48), U64(0xB143C605, 0x3EDCD0D5), /* ~= 10^266 */ + U64(0xF81AA16F, 0xDC1B81DA), U64(0xDD94B786, 0x8E94050A), /* ~= 10^267 */ + U64(0x9B10A4E5, 0xE9913128), U64(0xCA7CF2B4, 0x191C8326), /* ~= 10^268 */ + U64(0xC1D4CE1F, 0x63F57D72), U64(0xFD1C2F61, 0x1F63A3F0), /* ~= 10^269 */ + U64(0xF24A01A7, 0x3CF2DCCF), U64(0xBC633B39, 0x673C8CEC), /* ~= 10^270 */ + U64(0x976E4108, 0x8617CA01), U64(0xD5BE0503, 0xE085D813), /* ~= 10^271 */ + U64(0xBD49D14A, 0xA79DBC82), U64(0x4B2D8644, 0xD8A74E18), /* ~= 10^272 */ + U64(0xEC9C459D, 0x51852BA2), U64(0xDDF8E7D6, 0x0ED1219E), /* ~= 10^273 */ + U64(0x93E1AB82, 0x52F33B45), U64(0xCABB90E5, 0xC942B503), /* ~= 10^274 */ + U64(0xB8DA1662, 0xE7B00A17), U64(0x3D6A751F, 0x3B936243), /* ~= 10^275 */ + U64(0xE7109BFB, 0xA19C0C9D), U64(0x0CC51267, 0x0A783AD4), /* ~= 10^276 */ + U64(0x906A617D, 0x450187E2), U64(0x27FB2B80, 0x668B24C5), /* ~= 10^277 */ + U64(0xB484F9DC, 0x9641E9DA), U64(0xB1F9F660, 0x802DEDF6), /* ~= 10^278 */ + U64(0xE1A63853, 0xBBD26451), U64(0x5E7873F8, 0xA0396973), /* ~= 10^279 */ + U64(0x8D07E334, 0x55637EB2), U64(0xDB0B487B, 0x6423E1E8), /* ~= 10^280 */ + U64(0xB049DC01, 0x6ABC5E5F), U64(0x91CE1A9A, 0x3D2CDA62), /* ~= 10^281 */ + U64(0xDC5C5301, 0xC56B75F7), U64(0x7641A140, 0xCC7810FB), /* ~= 10^282 */ + U64(0x89B9B3E1, 0x1B6329BA), U64(0xA9E904C8, 0x7FCB0A9D), /* ~= 10^283 */ + U64(0xAC2820D9, 0x623BF429), U64(0x546345FA, 0x9FBDCD44), /* ~= 10^284 */ + U64(0xD732290F, 0xBACAF133), U64(0xA97C1779, 0x47AD4095), /* ~= 10^285 */ + U64(0x867F59A9, 0xD4BED6C0), U64(0x49ED8EAB, 0xCCCC485D), /* ~= 10^286 */ + U64(0xA81F3014, 0x49EE8C70), U64(0x5C68F256, 0xBFFF5A74), /* ~= 10^287 */ + U64(0xD226FC19, 0x5C6A2F8C), U64(0x73832EEC, 0x6FFF3111), /* ~= 10^288 */ + U64(0x83585D8F, 0xD9C25DB7), U64(0xC831FD53, 0xC5FF7EAB), /* ~= 10^289 */ + U64(0xA42E74F3, 0xD032F525), U64(0xBA3E7CA8, 0xB77F5E55), /* ~= 10^290 */ + U64(0xCD3A1230, 0xC43FB26F), U64(0x28CE1BD2, 0xE55F35EB), /* ~= 10^291 */ + U64(0x80444B5E, 0x7AA7CF85), U64(0x7980D163, 0xCF5B81B3), /* ~= 10^292 */ + U64(0xA0555E36, 0x1951C366), U64(0xD7E105BC, 0xC332621F), /* ~= 10^293 */ + U64(0xC86AB5C3, 0x9FA63440), U64(0x8DD9472B, 0xF3FEFAA7), /* ~= 10^294 */ + U64(0xFA856334, 0x878FC150), U64(0xB14F98F6, 0xF0FEB951), /* ~= 10^295 */ + U64(0x9C935E00, 0xD4B9D8D2), U64(0x6ED1BF9A, 0x569F33D3), /* ~= 10^296 */ + U64(0xC3B83581, 0x09E84F07), U64(0x0A862F80, 0xEC4700C8), /* ~= 10^297 */ + U64(0xF4A642E1, 0x4C6262C8), U64(0xCD27BB61, 0x2758C0FA), /* ~= 10^298 */ + U64(0x98E7E9CC, 0xCFBD7DBD), U64(0x8038D51C, 0xB897789C), /* ~= 10^299 */ + U64(0xBF21E440, 0x03ACDD2C), U64(0xE0470A63, 0xE6BD56C3), /* ~= 10^300 */ + U64(0xEEEA5D50, 0x04981478), U64(0x1858CCFC, 0xE06CAC74), /* ~= 10^301 */ + U64(0x95527A52, 0x02DF0CCB), U64(0x0F37801E, 0x0C43EBC8), /* ~= 10^302 */ + U64(0xBAA718E6, 0x8396CFFD), U64(0xD3056025, 0x8F54E6BA), /* ~= 10^303 */ + U64(0xE950DF20, 0x247C83FD), U64(0x47C6B82E, 0xF32A2069), /* ~= 10^304 */ + U64(0x91D28B74, 0x16CDD27E), U64(0x4CDC331D, 0x57FA5441), /* ~= 10^305 */ + U64(0xB6472E51, 0x1C81471D), U64(0xE0133FE4, 0xADF8E952), /* ~= 10^306 */ + U64(0xE3D8F9E5, 0x63A198E5), U64(0x58180FDD, 0xD97723A6), /* ~= 10^307 */ + U64(0x8E679C2F, 0x5E44FF8F), U64(0x570F09EA, 0xA7EA7648), /* ~= 10^308 */ + U64(0xB201833B, 0x35D63F73), U64(0x2CD2CC65, 0x51E513DA), /* ~= 10^309 */ + U64(0xDE81E40A, 0x034BCF4F), U64(0xF8077F7E, 0xA65E58D1), /* ~= 10^310 */ + U64(0x8B112E86, 0x420F6191), U64(0xFB04AFAF, 0x27FAF782), /* ~= 10^311 */ + U64(0xADD57A27, 0xD29339F6), U64(0x79C5DB9A, 0xF1F9B563), /* ~= 10^312 */ + U64(0xD94AD8B1, 0xC7380874), U64(0x18375281, 0xAE7822BC), /* ~= 10^313 */ + U64(0x87CEC76F, 0x1C830548), U64(0x8F229391, 0x0D0B15B5), /* ~= 10^314 */ + U64(0xA9C2794A, 0xE3A3C69A), U64(0xB2EB3875, 0x504DDB22), /* ~= 10^315 */ + U64(0xD433179D, 0x9C8CB841), U64(0x5FA60692, 0xA46151EB), /* ~= 10^316 */ + U64(0x849FEEC2, 0x81D7F328), U64(0xDBC7C41B, 0xA6BCD333), /* ~= 10^317 */ + U64(0xA5C7EA73, 0x224DEFF3), U64(0x12B9B522, 0x906C0800), /* ~= 10^318 */ + U64(0xCF39E50F, 0xEAE16BEF), U64(0xD768226B, 0x34870A00), /* ~= 10^319 */ + U64(0x81842F29, 0xF2CCE375), U64(0xE6A11583, 0x00D46640), /* ~= 10^320 */ + U64(0xA1E53AF4, 0x6F801C53), U64(0x60495AE3, 0xC1097FD0), /* ~= 10^321 */ + U64(0xCA5E89B1, 0x8B602368), U64(0x385BB19C, 0xB14BDFC4), /* ~= 10^322 */ + U64(0xFCF62C1D, 0xEE382C42), U64(0x46729E03, 0xDD9ED7B5), /* ~= 10^323 */ + U64(0x9E19DB92, 0xB4E31BA9), U64(0x6C07A2C2, 0x6A8346D1) /* ~= 10^324 */ +}; + +/** + Get the cached pow10 value from `pow10_sig_table`. + @param exp10 The exponent of pow(10, e). This value must in range + `POW10_SIG_TABLE_MIN_EXP` to `POW10_SIG_TABLE_MAX_EXP`. + @param hi The highest 64 bits of pow(10, e). + @param lo The lower 64 bits after `hi`. + */ +static_inline void pow10_table_get_sig(i32 exp10, u64 *hi, u64 *lo) { + i32 idx = exp10 - (POW10_SIG_TABLE_MIN_EXP); + *hi = pow10_sig_table[idx * 2]; + *lo = pow10_sig_table[idx * 2 + 1]; +} + +/** + Get the exponent (base 2) for highest 64 bits significand in `pow10_sig_table`. + */ +static_inline void pow10_table_get_exp(i32 exp10, i32 *exp2) { + /* e2 = floor(log2(pow(10, e))) - 64 + 1 */ + /* = floor(e * log2(10) - 63) */ + *exp2 = (exp10 * 217706 - 4128768) >> 16; +} + +#endif + + + +/*============================================================================== + * MARK: - Number and Bit Utils (Private) + *============================================================================*/ + +/** Convert bits to double. */ +static_inline f64 f64_from_bits(u64 u) { + f64 f; + memcpy(&f, &u, sizeof(u)); + return f; +} + +/** Convert double to bits. */ +static_inline u64 f64_to_bits(f64 f) { + u64 u; + memcpy(&u, &f, sizeof(u)); + return u; +} + +/** Convert double to bits. */ +static_inline u32 f32_to_bits(f32 f) { + u32 u; + memcpy(&u, &f, sizeof(u)); + return u; +} + +/** Get 'infinity' bits with sign. */ +static_inline u64 f64_bits_inf(bool sign) { +#if YYJSON_HAS_IEEE_754 + return F64_BITS_INF | ((u64)sign << 63); +#elif defined(INFINITY) + return f64_to_bits(sign ? -INFINITY : INFINITY); +#else + return f64_to_bits(sign ? -HUGE_VAL : HUGE_VAL); +#endif +} + +/** Get 'nan' bits with sign. */ +static_inline u64 f64_bits_nan(bool sign) { +#if YYJSON_HAS_IEEE_754 + return F64_BITS_NAN | ((u64)sign << 63); +#elif defined(NAN) + return f64_to_bits(sign ? (f64)-NAN : (f64)NAN); +#else + return f64_to_bits((sign ? -0.0 : 0.0) / 0.0); +#endif +} + +/** Casting double to float, allow overflow. */ +#if yyjson_has_attribute(no_sanitize) +__attribute__((no_sanitize("undefined"))) +#elif yyjson_gcc_available(4, 9, 0) +__attribute__((__no_sanitize_undefined__)) +#endif +static_inline f32 f64_to_f32(f64 val) { + return (f32)val; +} + +/** Returns the number of leading 0-bits in value (input should not be 0). */ +static_inline u32 u64_lz_bits(u64 v) { +#if GCC_HAS_CLZLL + return (u32)__builtin_clzll(v); +#elif MSC_HAS_BIT_SCAN_64 + unsigned long r; + _BitScanReverse64(&r, v); + return (u32)63 - (u32)r; +#elif MSC_HAS_BIT_SCAN + unsigned long hi, lo; + bool hi_set = _BitScanReverse(&hi, (u32)(v >> 32)) != 0; + _BitScanReverse(&lo, (u32)v); + hi |= 32; + return (u32)63 - (u32)(hi_set ? hi : lo); +#else + /* branchless, use De Bruijn sequence */ + /* see: https://www.chessprogramming.org/BitScan */ + const u8 table[64] = { + 63, 16, 62, 7, 15, 36, 61, 3, 6, 14, 22, 26, 35, 47, 60, 2, + 9, 5, 28, 11, 13, 21, 42, 19, 25, 31, 34, 40, 46, 52, 59, 1, + 17, 8, 37, 4, 23, 27, 48, 10, 29, 12, 43, 20, 32, 41, 53, 18, + 38, 24, 49, 30, 44, 33, 54, 39, 50, 45, 55, 51, 56, 57, 58, 0 + }; + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + v |= v >> 32; + return table[(v * U64(0x03F79D71, 0xB4CB0A89)) >> 58]; +#endif +} + +/** Returns the number of trailing 0-bits in value (input should not be 0). */ +static_inline u32 u64_tz_bits(u64 v) { +#if GCC_HAS_CTZLL + return (u32)__builtin_ctzll(v); +#elif MSC_HAS_BIT_SCAN_64 + unsigned long r; + _BitScanForward64(&r, v); + return (u32)r; +#elif MSC_HAS_BIT_SCAN + unsigned long lo, hi; + bool lo_set = _BitScanForward(&lo, (u32)(v)) != 0; + _BitScanForward(&hi, (u32)(v >> 32)); + hi += 32; + return lo_set ? lo : hi; +#else + /* branchless, use De Bruijn sequence */ + /* see: https://www.chessprogramming.org/BitScan */ + const u8 table[64] = { + 0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28, + 62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11, + 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10, + 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12 + }; + return table[((v & (~v + 1)) * U64(0x022FDD63, 0xCC95386D)) >> 58]; +#endif +} + +/** Multiplies two 64-bit unsigned integers (a * b), + returns the 128-bit result as 'hi' and 'lo'. */ +static_inline void u128_mul(u64 a, u64 b, u64 *hi, u64 *lo) { +#if YYJSON_HAS_INT128 + u128 m = (u128)a * b; + *hi = (u64)(m >> 64); + *lo = (u64)(m); +#elif MSC_HAS_UMUL128 + *lo = _umul128(a, b, hi); +#else + u32 a0 = (u32)(a), a1 = (u32)(a >> 32); + u32 b0 = (u32)(b), b1 = (u32)(b >> 32); + u64 p00 = (u64)a0 * b0, p01 = (u64)a0 * b1; + u64 p10 = (u64)a1 * b0, p11 = (u64)a1 * b1; + u64 m0 = p01 + (p00 >> 32); + u32 m00 = (u32)(m0), m01 = (u32)(m0 >> 32); + u64 m1 = p10 + m00; + u32 m10 = (u32)(m1), m11 = (u32)(m1 >> 32); + *hi = p11 + m01 + m11; + *lo = ((u64)m10 << 32) | (u32)p00; +#endif +} + +/** Multiplies two 64-bit unsigned integers and add a value (a * b + c), + returns the 128-bit result as 'hi' and 'lo'. */ +static_inline void u128_mul_add(u64 a, u64 b, u64 c, u64 *hi, u64 *lo) { +#if YYJSON_HAS_INT128 + u128 m = (u128)a * b + c; + *hi = (u64)(m >> 64); + *lo = (u64)(m); +#else + u64 h, l, t; + u128_mul(a, b, &h, &l); + t = l + c; + h += (u64)(((t < l) | (t < c))); + *hi = h; + *lo = t; +#endif +} + + + +/*============================================================================== + * MARK: - File Utils (Private) + * These functions are used to read and write JSON files. + *============================================================================*/ + +#define YYJSON_FOPEN_E +#if !defined(_MSC_VER) && defined(__GLIBC__) && defined(__GLIBC_PREREQ) +# if __GLIBC_PREREQ(2, 7) +# undef YYJSON_FOPEN_E +# define YYJSON_FOPEN_E "e" /* glibc extension to enable O_CLOEXEC */ +# endif +#endif + +static_inline FILE *fopen_safe(const char *path, const char *mode) { +#if YYJSON_MSC_VER >= 1400 + FILE *file = NULL; + if (fopen_s(&file, path, mode) != 0) return NULL; + return file; +#else + return fopen(path, mode); +#endif +} + +static_inline FILE *fopen_readonly(const char *path) { + return fopen_safe(path, "rb" YYJSON_FOPEN_E); +} + +static_inline FILE *fopen_writeonly(const char *path) { + return fopen_safe(path, "wb" YYJSON_FOPEN_E); +} + +static_inline usize fread_safe(void *buf, usize size, FILE *file) { +#if YYJSON_MSC_VER >= 1400 + return fread_s(buf, size, 1, size, file); +#else + return fread(buf, 1, size, file); +#endif +} + + + +/*============================================================================== + * MARK: - Size Utils (Private) + * These functions are used for memory allocation. + *============================================================================*/ + +/** Returns whether the size is overflow after increment. */ +static_inline bool size_add_is_overflow(usize size, usize add) { + return size > (size + add); +} + +/** Returns whether the size is power of 2 (size should not be 0). */ +static_inline bool size_is_pow2(usize size) { + return (size & (size - 1)) == 0; +} + +/** Align size upwards (may overflow). */ +static_inline usize size_align_up(usize size, usize align) { + if (size_is_pow2(align)) { + return (size + (align - 1)) & ~(align - 1); + } else { + return size + align - (size + align - 1) % align - 1; + } +} + +/** Align size downwards. */ +static_inline usize size_align_down(usize size, usize align) { + if (size_is_pow2(align)) { + return size & ~(align - 1); + } else { + return size - (size % align); + } +} + +/** Align address upwards (may overflow). */ +static_inline void *mem_align_up(void *mem, usize align) { + usize size; + memcpy(&size, &mem, sizeof(usize)); + size = size_align_up(size, align); + memcpy(&mem, &size, sizeof(usize)); + return mem; +} + + + +/*============================================================================== + * MARK: - Default Memory Allocator (Private) + * This is a simple libc memory allocator wrapper. + *============================================================================*/ + +static void *default_malloc(void *ctx, usize size) { + return malloc(size); +} + +static void *default_realloc(void *ctx, void *ptr, usize old_size, usize size) { + return realloc(ptr, size); +} + +static void default_free(void *ctx, void *ptr) { + free(ptr); +} + +static const yyjson_alc YYJSON_DEFAULT_ALC = { + default_malloc, default_realloc, default_free, NULL +}; + + + +/*============================================================================== + * MARK: - Null Memory Allocator (Private) + * This allocator is just a placeholder to ensure that the internal + * malloc/realloc/free function pointers are not null. + *============================================================================*/ + +static void *null_malloc(void *ctx, usize size) { + return NULL; +} + +static void *null_realloc(void *ctx, void *ptr, usize old_size, usize size) { + return NULL; +} + +static void null_free(void *ctx, void *ptr) { + return; +} + +static const yyjson_alc YYJSON_NULL_ALC = { + null_malloc, null_realloc, null_free, NULL +}; + + + +/*============================================================================== + * MARK: - Pool Memory Allocator (Public) + * This allocator is initialized with a fixed-size buffer. + * The buffer is split into multiple memory chunks for memory allocation. + *============================================================================*/ + +/** memory chunk header */ +typedef struct pool_chunk { + usize size; /* chunk memory size, include chunk header */ + struct pool_chunk *next; /* linked list, nullable */ + /* char mem[]; flexible array member */ +} pool_chunk; + +/** allocator ctx header */ +typedef struct pool_ctx { + usize size; /* total memory size, include ctx header */ + pool_chunk *free_list; /* linked list, nullable */ + /* pool_chunk chunks[]; flexible array member */ +} pool_ctx; + +/** align up the input size to chunk size */ +static_inline void pool_size_align(usize *size) { + *size = size_align_up(*size, sizeof(pool_chunk)) + sizeof(pool_chunk); +} + +static void *pool_malloc(void *ctx_ptr, usize size) { + /* assert(size != 0) */ + pool_ctx *ctx = (pool_ctx *)ctx_ptr; + pool_chunk *next, *prev = NULL, *cur = ctx->free_list; + + if (unlikely(size >= ctx->size)) return NULL; + pool_size_align(&size); + + while (cur) { + if (cur->size < size) { + /* not enough space, try next chunk */ + prev = cur; + cur = cur->next; + continue; + } + if (cur->size >= size + sizeof(pool_chunk) * 2) { + /* too much space, split this chunk */ + next = (pool_chunk *)(void *)((u8 *)cur + size); + next->size = cur->size - size; + next->next = cur->next; + cur->size = size; + } else { + /* just enough space, use whole chunk */ + next = cur->next; + } + if (prev) prev->next = next; + else ctx->free_list = next; + return (void *)(cur + 1); + } + return NULL; +} + +static void pool_free(void *ctx_ptr, void *ptr) { + /* assert(ptr != NULL) */ + pool_ctx *ctx = (pool_ctx *)ctx_ptr; + pool_chunk *cur = ((pool_chunk *)ptr) - 1; + pool_chunk *prev = NULL, *next = ctx->free_list; + + while (next && next < cur) { + prev = next; + next = next->next; + } + if (prev) prev->next = cur; + else ctx->free_list = cur; + cur->next = next; + + if (next && ((u8 *)cur + cur->size) == (u8 *)next) { + /* merge cur to higher chunk */ + cur->size += next->size; + cur->next = next->next; + } + if (prev && ((u8 *)prev + prev->size) == (u8 *)cur) { + /* merge cur to lower chunk */ + prev->size += cur->size; + prev->next = cur->next; + } +} + +static void *pool_realloc(void *ctx_ptr, void *ptr, + usize old_size, usize size) { + /* assert(ptr != NULL && size != 0 && old_size < size) */ + pool_ctx *ctx = (pool_ctx *)ctx_ptr; + pool_chunk *cur = ((pool_chunk *)ptr) - 1, *prev, *next, *tmp; + + /* check size */ + if (unlikely(size >= ctx->size)) return NULL; + pool_size_align(&old_size); + pool_size_align(&size); + if (unlikely(old_size == size)) return ptr; + + /* find next and prev chunk */ + prev = NULL; + next = ctx->free_list; + while (next && next < cur) { + prev = next; + next = next->next; + } + + if ((u8 *)cur + cur->size == (u8 *)next && cur->size + next->size >= size) { + /* merge to higher chunk if they are contiguous */ + usize free_size = cur->size + next->size - size; + if (free_size > sizeof(pool_chunk) * 2) { + tmp = (pool_chunk *)(void *)((u8 *)cur + size); + if (prev) prev->next = tmp; + else ctx->free_list = tmp; + tmp->next = next->next; + tmp->size = free_size; + cur->size = size; + } else { + if (prev) prev->next = next->next; + else ctx->free_list = next->next; + cur->size += next->size; + } + return ptr; + } else { + /* fallback to malloc and memcpy */ + void *new_ptr = pool_malloc(ctx_ptr, size - sizeof(pool_chunk)); + if (new_ptr) { + memcpy(new_ptr, ptr, cur->size - sizeof(pool_chunk)); + pool_free(ctx_ptr, ptr); + } + return new_ptr; + } +} + +bool yyjson_alc_pool_init(yyjson_alc *alc, void *buf, usize size) { + pool_chunk *chunk; + pool_ctx *ctx; + + if (unlikely(!alc)) return false; + *alc = YYJSON_NULL_ALC; + if (size < sizeof(pool_ctx) * 4) return false; + ctx = (pool_ctx *)mem_align_up(buf, sizeof(pool_ctx)); + if (unlikely(!ctx)) return false; + size -= (usize)((u8 *)ctx - (u8 *)buf); + size = size_align_down(size, sizeof(pool_ctx)); + + chunk = (pool_chunk *)(ctx + 1); + chunk->size = size - sizeof(pool_ctx); + chunk->next = NULL; + ctx->size = size; + ctx->free_list = chunk; + + alc->malloc = pool_malloc; + alc->realloc = pool_realloc; + alc->free = pool_free; + alc->ctx = (void *)ctx; + return true; +} + + + +/*============================================================================== + * MARK: - Dynamic Memory Allocator (Public) + * This allocator allocates memory on demand and does not immediately release + * unused memory. Instead, it places the unused memory into a freelist for + * potential reuse in the future. It is only when the entire allocator is + * destroyed that all previously allocated memory is released at once. + *============================================================================*/ + +/** memory chunk header */ +typedef struct dyn_chunk { + usize size; /* chunk size, include header */ + struct dyn_chunk *next; + /* char mem[]; flexible array member */ +} dyn_chunk; + +/** allocator ctx header */ +typedef struct { + dyn_chunk free_list; /* dummy header, sorted from small to large */ + dyn_chunk used_list; /* dummy header */ +} dyn_ctx; + +/** align up the input size to chunk size */ +static_inline bool dyn_size_align(usize *size) { + usize alc_size = *size + sizeof(dyn_chunk); + alc_size = size_align_up(alc_size, YYJSON_ALC_DYN_MIN_SIZE); + if (unlikely(alc_size < *size)) return false; /* overflow */ + *size = alc_size; + return true; +} + +/** remove a chunk from list (the chunk must already be in the list) */ +static_inline void dyn_chunk_list_remove(dyn_chunk *list, dyn_chunk *chunk) { + dyn_chunk *prev = list, *cur; + for (cur = prev->next; cur; cur = cur->next) { + if (cur == chunk) { + prev->next = cur->next; + cur->next = NULL; + return; + } + prev = cur; + } +} + +/** add a chunk to list header (the chunk must not be in the list) */ +static_inline void dyn_chunk_list_add(dyn_chunk *list, dyn_chunk *chunk) { + chunk->next = list->next; + list->next = chunk; +} + +static void *dyn_malloc(void *ctx_ptr, usize size) { + /* assert(size != 0) */ + const yyjson_alc def = YYJSON_DEFAULT_ALC; + dyn_ctx *ctx = (dyn_ctx *)ctx_ptr; + dyn_chunk *chunk, *prev; + if (unlikely(!dyn_size_align(&size))) return NULL; + + /* freelist is empty, create new chunk */ + if (!ctx->free_list.next) { + chunk = (dyn_chunk *)def.malloc(def.ctx, size); + if (unlikely(!chunk)) return NULL; + chunk->size = size; + chunk->next = NULL; + dyn_chunk_list_add(&ctx->used_list, chunk); + return (void *)(chunk + 1); + } + + /* find a large enough chunk, or resize the largest chunk */ + prev = &ctx->free_list; + while (true) { + chunk = prev->next; + if (chunk->size >= size) { /* enough size, reuse this chunk */ + prev->next = chunk->next; + dyn_chunk_list_add(&ctx->used_list, chunk); + return (void *)(chunk + 1); + } + if (!chunk->next) { /* resize the largest chunk */ + chunk = (dyn_chunk *)def.realloc(def.ctx, chunk, chunk->size, size); + if (unlikely(!chunk)) return NULL; + prev->next = NULL; + chunk->size = size; + dyn_chunk_list_add(&ctx->used_list, chunk); + return (void *)(chunk + 1); + } + prev = chunk; + } +} + +static void *dyn_realloc(void *ctx_ptr, void *ptr, + usize old_size, usize size) { + /* assert(ptr != NULL && size != 0 && old_size < size) */ + const yyjson_alc def = YYJSON_DEFAULT_ALC; + dyn_ctx *ctx = (dyn_ctx *)ctx_ptr; + dyn_chunk *new_chunk, *chunk = (dyn_chunk *)ptr - 1; + if (unlikely(!dyn_size_align(&size))) return NULL; + if (chunk->size >= size) return ptr; + + dyn_chunk_list_remove(&ctx->used_list, chunk); + new_chunk = (dyn_chunk *)def.realloc(def.ctx, chunk, chunk->size, size); + if (likely(new_chunk)) { + new_chunk->size = size; + chunk = new_chunk; + } + dyn_chunk_list_add(&ctx->used_list, chunk); + return new_chunk ? (void *)(new_chunk + 1) : NULL; +} + +static void dyn_free(void *ctx_ptr, void *ptr) { + /* assert(ptr != NULL) */ + dyn_ctx *ctx = (dyn_ctx *)ctx_ptr; + dyn_chunk *chunk = (dyn_chunk *)ptr - 1, *prev; + + dyn_chunk_list_remove(&ctx->used_list, chunk); + for (prev = &ctx->free_list; prev; prev = prev->next) { + if (!prev->next || prev->next->size >= chunk->size) { + chunk->next = prev->next; + prev->next = chunk; + break; + } + } +} + +yyjson_alc *yyjson_alc_dyn_new(void) { + const yyjson_alc def = YYJSON_DEFAULT_ALC; + usize hdr_len = sizeof(yyjson_alc) + sizeof(dyn_ctx); + yyjson_alc *alc = (yyjson_alc *)def.malloc(def.ctx, hdr_len); + dyn_ctx *ctx = (dyn_ctx *)(void *)(alc + 1); + if (unlikely(!alc)) return NULL; + alc->malloc = dyn_malloc; + alc->realloc = dyn_realloc; + alc->free = dyn_free; + alc->ctx = alc + 1; + memset(ctx, 0, sizeof(*ctx)); + return alc; +} + +void yyjson_alc_dyn_free(yyjson_alc *alc) { + const yyjson_alc def = YYJSON_DEFAULT_ALC; + dyn_ctx *ctx = (dyn_ctx *)(void *)(alc + 1); + dyn_chunk *chunk, *next; + if (unlikely(!alc)) return; + for (chunk = ctx->free_list.next; chunk; chunk = next) { + next = chunk->next; + def.free(def.ctx, chunk); + } + for (chunk = ctx->used_list.next; chunk; chunk = next) { + next = chunk->next; + def.free(def.ctx, chunk); + } + def.free(def.ctx, alc); +} + + + +/*============================================================================== + * MARK: - JSON Struct Utils (Public) + * These functions are used for creating, copying, releasing, and comparing + * JSON documents and values. They are widely used throughout this library. + *============================================================================*/ + +static_inline void unsafe_yyjson_str_pool_release(yyjson_str_pool *pool, + yyjson_alc *alc) { + yyjson_str_chunk *chunk = pool->chunks, *next; + while (chunk) { + next = chunk->next; + alc->free(alc->ctx, chunk); + chunk = next; + } +} + +static_inline void unsafe_yyjson_val_pool_release(yyjson_val_pool *pool, + yyjson_alc *alc) { + yyjson_val_chunk *chunk = pool->chunks, *next; + while (chunk) { + next = chunk->next; + alc->free(alc->ctx, chunk); + chunk = next; + } +} + +bool unsafe_yyjson_str_pool_grow(yyjson_str_pool *pool, + const yyjson_alc *alc, usize len) { + yyjson_str_chunk *chunk; + usize size, max_len; + + /* create a new chunk */ + max_len = USIZE_MAX - sizeof(yyjson_str_chunk); + if (unlikely(len > max_len)) return false; + size = len + sizeof(yyjson_str_chunk); + size = yyjson_max(pool->chunk_size, size); + chunk = (yyjson_str_chunk *)alc->malloc(alc->ctx, size); + if (unlikely(!chunk)) return false; + + /* insert the new chunk as the head of the linked list */ + chunk->next = pool->chunks; + chunk->chunk_size = size; + pool->chunks = chunk; + pool->cur = (char *)chunk + sizeof(yyjson_str_chunk); + pool->end = (char *)chunk + size; + + /* the next chunk is twice the size of the current one */ + size = yyjson_min(pool->chunk_size * 2, pool->chunk_size_max); + if (size < pool->chunk_size) size = pool->chunk_size_max; /* overflow */ + pool->chunk_size = size; + return true; +} + +bool unsafe_yyjson_val_pool_grow(yyjson_val_pool *pool, + const yyjson_alc *alc, usize count) { + yyjson_val_chunk *chunk; + usize size, max_count; + + /* create a new chunk */ + max_count = USIZE_MAX / sizeof(yyjson_mut_val) - 1; + if (unlikely(count > max_count)) return false; + size = (count + 1) * sizeof(yyjson_mut_val); + size = yyjson_max(pool->chunk_size, size); + chunk = (yyjson_val_chunk *)alc->malloc(alc->ctx, size); + if (unlikely(!chunk)) return false; + + /* insert the new chunk as the head of the linked list */ + chunk->next = pool->chunks; + chunk->chunk_size = size; + pool->chunks = chunk; + pool->cur = (yyjson_mut_val *)(void *)((u8 *)chunk) + 1; + pool->end = (yyjson_mut_val *)(void *)((u8 *)chunk + size); + + /* the next chunk is twice the size of the current one */ + size = yyjson_min(pool->chunk_size * 2, pool->chunk_size_max); + if (size < pool->chunk_size) size = pool->chunk_size_max; /* overflow */ + pool->chunk_size = size; + return true; +} + +bool yyjson_mut_doc_set_str_pool_size(yyjson_mut_doc *doc, size_t len) { + usize max_size = USIZE_MAX - sizeof(yyjson_str_chunk); + if (!doc || !len || len > max_size) return false; + doc->str_pool.chunk_size = len + sizeof(yyjson_str_chunk); + return true; +} + +bool yyjson_mut_doc_set_val_pool_size(yyjson_mut_doc *doc, size_t count) { + usize max_count = USIZE_MAX / sizeof(yyjson_mut_val) - 1; + if (!doc || !count || count > max_count) return false; + doc->val_pool.chunk_size = (count + 1) * sizeof(yyjson_mut_val); + return true; +} + +void yyjson_mut_doc_free(yyjson_mut_doc *doc) { + if (doc) { + yyjson_alc alc = doc->alc; + memset(&doc->alc, 0, sizeof(alc)); + unsafe_yyjson_str_pool_release(&doc->str_pool, &alc); + unsafe_yyjson_val_pool_release(&doc->val_pool, &alc); + alc.free(alc.ctx, doc); + } +} + +yyjson_mut_doc *yyjson_mut_doc_new(const yyjson_alc *alc) { + yyjson_mut_doc *doc; + if (!alc) alc = &YYJSON_DEFAULT_ALC; + doc = (yyjson_mut_doc *)alc->malloc(alc->ctx, sizeof(yyjson_mut_doc)); + if (!doc) return NULL; + memset(doc, 0, sizeof(yyjson_mut_doc)); + + doc->alc = *alc; + doc->str_pool.chunk_size = YYJSON_MUT_DOC_STR_POOL_INIT_SIZE; + doc->str_pool.chunk_size_max = YYJSON_MUT_DOC_STR_POOL_MAX_SIZE; + doc->val_pool.chunk_size = YYJSON_MUT_DOC_VAL_POOL_INIT_SIZE; + doc->val_pool.chunk_size_max = YYJSON_MUT_DOC_VAL_POOL_MAX_SIZE; + return doc; +} + +yyjson_mut_doc *yyjson_doc_mut_copy(yyjson_doc *doc, const yyjson_alc *alc) { + yyjson_mut_doc *m_doc; + yyjson_mut_val *m_val; + + if (!doc || !doc->root) return NULL; + m_doc = yyjson_mut_doc_new(alc); + if (!m_doc) return NULL; + m_val = yyjson_val_mut_copy(m_doc, doc->root); + if (!m_val) { + yyjson_mut_doc_free(m_doc); + return NULL; + } + yyjson_mut_doc_set_root(m_doc, m_val); + return m_doc; +} + +yyjson_mut_doc *yyjson_mut_doc_mut_copy(yyjson_mut_doc *doc, + const yyjson_alc *alc) { + yyjson_mut_doc *m_doc; + yyjson_mut_val *m_val; + + if (!doc) return NULL; + if (!doc->root) return yyjson_mut_doc_new(alc); + + m_doc = yyjson_mut_doc_new(alc); + if (!m_doc) return NULL; + m_val = yyjson_mut_val_mut_copy(m_doc, doc->root); + if (!m_val) { + yyjson_mut_doc_free(m_doc); + return NULL; + } + yyjson_mut_doc_set_root(m_doc, m_val); + return m_doc; +} + +yyjson_mut_val *yyjson_val_mut_copy(yyjson_mut_doc *m_doc, + yyjson_val *i_vals) { + /* + The immutable object or array stores all sub-values in a contiguous memory, + We copy them to another contiguous memory as mutable values, + then reconnect the mutable values with the original relationship. + */ + usize i_vals_len; + yyjson_mut_val *m_vals, *m_val; + yyjson_val *i_val, *i_end; + + if (!m_doc || !i_vals) return NULL; + i_end = unsafe_yyjson_get_next(i_vals); + i_vals_len = (usize)(unsafe_yyjson_get_next(i_vals) - i_vals); + m_vals = unsafe_yyjson_mut_val(m_doc, i_vals_len); + if (!m_vals) return NULL; + i_val = i_vals; + m_val = m_vals; + + for (; i_val < i_end; i_val++, m_val++) { + yyjson_type type = unsafe_yyjson_get_type(i_val); + m_val->tag = i_val->tag; + m_val->uni.u64 = i_val->uni.u64; + if (type == YYJSON_TYPE_STR || type == YYJSON_TYPE_RAW) { + const char *str = i_val->uni.str; + usize str_len = unsafe_yyjson_get_len(i_val); + m_val->uni.str = unsafe_yyjson_mut_strncpy(m_doc, str, str_len); + if (!m_val->uni.str) return NULL; + } else if (type == YYJSON_TYPE_ARR) { + usize len = unsafe_yyjson_get_len(i_val); + if (len > 0) { + yyjson_val *ii_val = i_val + 1, *ii_next; + yyjson_mut_val *mm_val = m_val + 1, *mm_ctn = m_val, *mm_next; + while (len-- > 1) { + ii_next = unsafe_yyjson_get_next(ii_val); + mm_next = mm_val + (ii_next - ii_val); + mm_val->next = mm_next; + ii_val = ii_next; + mm_val = mm_next; + } + mm_val->next = mm_ctn + 1; + mm_ctn->uni.ptr = mm_val; + } + } else if (type == YYJSON_TYPE_OBJ) { + usize len = unsafe_yyjson_get_len(i_val); + if (len > 0) { + yyjson_val *ii_key = i_val + 1, *ii_nextkey; + yyjson_mut_val *mm_key = m_val + 1, *mm_ctn = m_val; + yyjson_mut_val *mm_nextkey; + while (len-- > 1) { + ii_nextkey = unsafe_yyjson_get_next(ii_key + 1); + mm_nextkey = mm_key + (ii_nextkey - ii_key); + mm_key->next = mm_key + 1; + mm_key->next->next = mm_nextkey; + ii_key = ii_nextkey; + mm_key = mm_nextkey; + } + mm_key->next = mm_key + 1; + mm_key->next->next = mm_ctn + 1; + mm_ctn->uni.ptr = mm_key; + } + } + } + return m_vals; +} + +static yyjson_mut_val *unsafe_yyjson_mut_val_mut_copy(yyjson_mut_doc *m_doc, + yyjson_mut_val *m_vals) { + /* + The mutable object or array stores all sub-values in a circular linked + list, so we can traverse them in the same loop. The traversal starts from + the last item, continues with the first item in a list, and ends with the + second to last item, which needs to be linked to the last item to close the + circle. + */ + yyjson_mut_val *m_val = unsafe_yyjson_mut_val(m_doc, 1); + if (unlikely(!m_val)) return NULL; + m_val->tag = m_vals->tag; + + switch (unsafe_yyjson_get_type(m_vals)) { + case YYJSON_TYPE_OBJ: + case YYJSON_TYPE_ARR: + if (unsafe_yyjson_get_len(m_vals) > 0) { + yyjson_mut_val *last = (yyjson_mut_val *)m_vals->uni.ptr; + yyjson_mut_val *next = last->next, *prev; + prev = unsafe_yyjson_mut_val_mut_copy(m_doc, last); + if (!prev) return NULL; + m_val->uni.ptr = (void *)prev; + while (next != last) { + prev->next = unsafe_yyjson_mut_val_mut_copy(m_doc, next); + if (!prev->next) return NULL; + prev = prev->next; + next = next->next; + } + prev->next = (yyjson_mut_val *)m_val->uni.ptr; + } + break; + case YYJSON_TYPE_RAW: + case YYJSON_TYPE_STR: { + const char *str = m_vals->uni.str; + usize str_len = unsafe_yyjson_get_len(m_vals); + m_val->uni.str = unsafe_yyjson_mut_strncpy(m_doc, str, str_len); + if (!m_val->uni.str) return NULL; + break; + } + default: + m_val->uni = m_vals->uni; + break; + } + return m_val; +} + +yyjson_mut_val *yyjson_mut_val_mut_copy(yyjson_mut_doc *doc, + yyjson_mut_val *val) { + if (doc && val) return unsafe_yyjson_mut_val_mut_copy(doc, val); + return NULL; +} + +/* Count the number of values and the total length of the strings. */ +static void yyjson_mut_stat(yyjson_mut_val *val, + usize *val_sum, usize *str_sum) { + yyjson_type type = unsafe_yyjson_get_type(val); + *val_sum += 1; + if (type == YYJSON_TYPE_ARR || type == YYJSON_TYPE_OBJ) { + yyjson_mut_val *child = (yyjson_mut_val *)val->uni.ptr; + usize len = unsafe_yyjson_get_len(val), i; + len <<= (u8)(type == YYJSON_TYPE_OBJ); + *val_sum += len; + for (i = 0; i < len; i++) { + yyjson_type stype = unsafe_yyjson_get_type(child); + if (stype == YYJSON_TYPE_STR || stype == YYJSON_TYPE_RAW) { + *str_sum += unsafe_yyjson_get_len(child) + 1; + } else if (stype == YYJSON_TYPE_ARR || stype == YYJSON_TYPE_OBJ) { + yyjson_mut_stat(child, val_sum, str_sum); + *val_sum -= 1; + } + child = child->next; + } + } else if (type == YYJSON_TYPE_STR || type == YYJSON_TYPE_RAW) { + *str_sum += unsafe_yyjson_get_len(val) + 1; + } +} + +/* Copy mutable values to immutable value pool. */ +static usize yyjson_imut_copy(yyjson_val **val_ptr, char **buf_ptr, + yyjson_mut_val *mval) { + yyjson_val *val = *val_ptr; + yyjson_type type = unsafe_yyjson_get_type(mval); + if (type == YYJSON_TYPE_ARR || type == YYJSON_TYPE_OBJ) { + yyjson_mut_val *child = (yyjson_mut_val *)mval->uni.ptr; + usize len = unsafe_yyjson_get_len(mval), i; + usize val_sum = 1; + if (type == YYJSON_TYPE_OBJ) { + if (len) child = child->next->next; + len <<= 1; + } else { + if (len) child = child->next; + } + *val_ptr = val + 1; + for (i = 0; i < len; i++) { + val_sum += yyjson_imut_copy(val_ptr, buf_ptr, child); + child = child->next; + } + val->tag = mval->tag; + val->uni.ofs = val_sum * sizeof(yyjson_val); + return val_sum; + } else if (type == YYJSON_TYPE_STR || type == YYJSON_TYPE_RAW) { + char *buf = *buf_ptr; + usize len = unsafe_yyjson_get_len(mval); + memcpy((void *)buf, (const void *)mval->uni.str, len); + buf[len] = '\0'; + val->tag = mval->tag; + val->uni.str = buf; + *val_ptr = val + 1; + *buf_ptr = buf + len + 1; + return 1; + } else { + val->tag = mval->tag; + val->uni = mval->uni; + *val_ptr = val + 1; + return 1; + } +} + +yyjson_doc *yyjson_mut_doc_imut_copy(yyjson_mut_doc *mdoc, + const yyjson_alc *alc) { + if (!mdoc) return NULL; + return yyjson_mut_val_imut_copy(mdoc->root, alc); +} + +yyjson_doc *yyjson_mut_val_imut_copy(yyjson_mut_val *mval, + const yyjson_alc *alc) { + usize val_num = 0, str_sum = 0, hdr_size, buf_size; + yyjson_doc *doc = NULL; + yyjson_val *val_hdr = NULL; + + /* This value should be NULL here. Setting a non-null value suppresses + warning from the clang analyzer. */ + char *str_hdr = (char *)(void *)&str_sum; + if (!mval) return NULL; + if (!alc) alc = &YYJSON_DEFAULT_ALC; + + /* traverse the input value to get pool size */ + yyjson_mut_stat(mval, &val_num, &str_sum); + + /* create doc and val pool */ + hdr_size = size_align_up(sizeof(yyjson_doc), sizeof(yyjson_val)); + buf_size = hdr_size + val_num * sizeof(yyjson_val); + doc = (yyjson_doc *)alc->malloc(alc->ctx, buf_size); + if (!doc) return NULL; + memset(doc, 0, sizeof(yyjson_doc)); + val_hdr = (yyjson_val *)(void *)((char *)(void *)doc + hdr_size); + doc->root = val_hdr; + doc->alc = *alc; + + /* create str pool */ + if (str_sum > 0) { + str_hdr = (char *)alc->malloc(alc->ctx, str_sum); + doc->str_pool = str_hdr; + if (!str_hdr) { + alc->free(alc->ctx, (void *)doc); + return NULL; + } + } + + /* copy vals and strs */ + doc->val_read = yyjson_imut_copy(&val_hdr, &str_hdr, mval); + doc->dat_read = str_sum + 1; + return doc; +} + +static_inline bool unsafe_yyjson_num_equals(void *lhs, void *rhs) { + yyjson_val_uni *luni = &((yyjson_val *)lhs)->uni; + yyjson_val_uni *runi = &((yyjson_val *)rhs)->uni; + yyjson_subtype lt = unsafe_yyjson_get_subtype(lhs); + yyjson_subtype rt = unsafe_yyjson_get_subtype(rhs); + if (lt == rt) return luni->u64 == runi->u64; + if (lt == YYJSON_SUBTYPE_SINT && rt == YYJSON_SUBTYPE_UINT) { + return luni->i64 >= 0 && luni->u64 == runi->u64; + } + if (lt == YYJSON_SUBTYPE_UINT && rt == YYJSON_SUBTYPE_SINT) { + return runi->i64 >= 0 && luni->u64 == runi->u64; + } + return false; +} + +static_inline bool unsafe_yyjson_str_equals(void *lhs, void *rhs) { + usize len = unsafe_yyjson_get_len(lhs); + if (len != unsafe_yyjson_get_len(rhs)) return false; + return !memcmp(unsafe_yyjson_get_str(lhs), + unsafe_yyjson_get_str(rhs), len); +} + +bool unsafe_yyjson_equals(yyjson_val *lhs, yyjson_val *rhs) { + yyjson_type type = unsafe_yyjson_get_type(lhs); + if (type != unsafe_yyjson_get_type(rhs)) return false; + + switch (type) { + case YYJSON_TYPE_OBJ: { + usize len = unsafe_yyjson_get_len(lhs); + if (len != unsafe_yyjson_get_len(rhs)) return false; + if (len > 0) { + yyjson_obj_iter iter; + yyjson_obj_iter_init(rhs, &iter); + lhs = unsafe_yyjson_get_first(lhs); + while (len-- > 0) { + rhs = yyjson_obj_iter_getn(&iter, lhs->uni.str, + unsafe_yyjson_get_len(lhs)); + if (!rhs) return false; + if (!unsafe_yyjson_equals(lhs + 1, rhs)) return false; + lhs = unsafe_yyjson_get_next(lhs + 1); + } + } + /* yyjson allows duplicate keys, so the check may be inaccurate */ + return true; + } + + case YYJSON_TYPE_ARR: { + usize len = unsafe_yyjson_get_len(lhs); + if (len != unsafe_yyjson_get_len(rhs)) return false; + if (len > 0) { + lhs = unsafe_yyjson_get_first(lhs); + rhs = unsafe_yyjson_get_first(rhs); + while (len-- > 0) { + if (!unsafe_yyjson_equals(lhs, rhs)) return false; + lhs = unsafe_yyjson_get_next(lhs); + rhs = unsafe_yyjson_get_next(rhs); + } + } + return true; + } + + case YYJSON_TYPE_NUM: + return unsafe_yyjson_num_equals(lhs, rhs); + + case YYJSON_TYPE_RAW: + case YYJSON_TYPE_STR: + return unsafe_yyjson_str_equals(lhs, rhs); + + case YYJSON_TYPE_NULL: + case YYJSON_TYPE_BOOL: + return lhs->tag == rhs->tag; + + default: + return false; + } +} + +bool unsafe_yyjson_mut_equals(yyjson_mut_val *lhs, yyjson_mut_val *rhs) { + yyjson_type type = unsafe_yyjson_get_type(lhs); + if (type != unsafe_yyjson_get_type(rhs)) return false; + + switch (type) { + case YYJSON_TYPE_OBJ: { + usize len = unsafe_yyjson_get_len(lhs); + if (len != unsafe_yyjson_get_len(rhs)) return false; + if (len > 0) { + yyjson_mut_obj_iter iter; + yyjson_mut_obj_iter_init(rhs, &iter); + lhs = (yyjson_mut_val *)lhs->uni.ptr; + while (len-- > 0) { + rhs = yyjson_mut_obj_iter_getn(&iter, lhs->uni.str, + unsafe_yyjson_get_len(lhs)); + if (!rhs) return false; + if (!unsafe_yyjson_mut_equals(lhs->next, rhs)) return false; + lhs = lhs->next->next; + } + } + /* yyjson allows duplicate keys, so the check may be inaccurate */ + return true; + } + + case YYJSON_TYPE_ARR: { + usize len = unsafe_yyjson_get_len(lhs); + if (len != unsafe_yyjson_get_len(rhs)) return false; + if (len > 0) { + lhs = (yyjson_mut_val *)lhs->uni.ptr; + rhs = (yyjson_mut_val *)rhs->uni.ptr; + while (len-- > 0) { + if (!unsafe_yyjson_mut_equals(lhs, rhs)) return false; + lhs = lhs->next; + rhs = rhs->next; + } + } + return true; + } + + case YYJSON_TYPE_NUM: + return unsafe_yyjson_num_equals(lhs, rhs); + + case YYJSON_TYPE_RAW: + case YYJSON_TYPE_STR: + return unsafe_yyjson_str_equals(lhs, rhs); + + case YYJSON_TYPE_NULL: + case YYJSON_TYPE_BOOL: + return lhs->tag == rhs->tag; + + default: + return false; + } +} + +bool yyjson_locate_pos(const char *str, size_t len, size_t pos, + size_t *line, size_t *col, size_t *chr) { + usize line_sum = 0, line_pos = 0, chr_sum = 0; + const u8 *cur = (const u8 *)str; + const u8 *end = cur + pos; + + if (!str || pos > len) { + if (line) *line = 0; + if (col) *col = 0; + if (chr) *chr = 0; + return false; + } + + if (pos >= 3 && is_utf8_bom(cur)) cur += 3; /* don't count BOM */ + while (cur < end) { + u8 c = *cur; + chr_sum += 1; + if (likely(c < 0x80)) { /* 0xxxxxxx (0x00-0x7F) ASCII */ + if (c == '\n') { + line_sum += 1; + line_pos = chr_sum; + } + cur += 1; + } + else if (c < 0xC0) cur += 1; /* 10xxxxxx (0x80-0xBF) Invalid */ + else if (c < 0xE0) cur += 2; /* 110xxxxx (0xC0-0xDF) 2-byte UTF-8 */ + else if (c < 0xF0) cur += 3; /* 1110xxxx (0xE0-0xEF) 3-byte UTF-8 */ + else if (c < 0xF8) cur += 4; /* 11110xxx (0xF0-0xF7) 4-byte UTF-8 */ + else cur += 1; /* 11111xxx (0xF8-0xFF) Invalid */ + } + if (line) *line = line_sum + 1; + if (col) *col = chr_sum - line_pos + 1; + if (chr) *chr = chr_sum; + return true; +} + + + +#if !YYJSON_DISABLE_READER /* reader begin */ + +/* Check read flag, avoids `always false` warning when disabled. */ +#define has_flg(_flg) unlikely(has_rflag(flg, YYJSON_READ_##_flg, 0)) +#define has_allow(_flg) unlikely(has_rflag(flg, YYJSON_READ_ALLOW_##_flg, 1)) +#define YYJSON_READ_ALLOW_TRIVIA (YYJSON_READ_ALLOW_COMMENTS | \ + YYJSON_READ_ALLOW_EXT_WHITESPACE) +static_inline bool has_rflag(yyjson_read_flag flg, yyjson_read_flag chk, + bool non_standard) { +#if YYJSON_DISABLE_NON_STANDARD + if (non_standard) return false; +#endif + return (flg & chk) != 0; +} + + + +/*============================================================================== + * MARK: - JSON Reader Utils (Private) + * These functions are used by JSON reader to read literals and comments. + *============================================================================*/ + +/** Read `true` literal, `*ptr[0]` should be `t`. */ +static_inline bool read_true(u8 **ptr, yyjson_val *val) { + u8 *cur = *ptr; + if (likely(byte_match_4(cur, "true"))) { + val->tag = YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_TRUE; + *ptr = cur + 4; + return true; + } + return false; +} + +/** Read `false` literal, `*ptr[0]` should be `f`. */ +static_inline bool read_false(u8 **ptr, yyjson_val *val) { + u8 *cur = *ptr; + if (likely(byte_match_4(cur + 1, "alse"))) { + val->tag = YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_FALSE; + *ptr = cur + 5; + return true; + } + return false; +} + +/** Read `null` literal, `*ptr[0]` should be `n`. */ +static_inline bool read_null(u8 **ptr, yyjson_val *val) { + u8 *cur = *ptr; + if (likely(byte_match_4(cur, "null"))) { + val->tag = YYJSON_TYPE_NULL; + *ptr = cur + 4; + return true; + } + return false; +} + +/** Read `Inf` or `Infinity` literal (ignoring case). */ +static_inline bool read_inf(u8 **ptr, u8 **pre, + yyjson_read_flag flg, yyjson_val *val) { + u8 *hdr = *ptr; + u8 *cur = *ptr; + u8 **end = ptr; + bool sign = (*cur == '-'); + if (*cur == '+' && !has_allow(EXT_NUMBER)) return false; + cur += char_is_sign(*cur); + if (char_to_lower(cur[0]) == 'i' && + char_to_lower(cur[1]) == 'n' && + char_to_lower(cur[2]) == 'f') { + if (char_to_lower(cur[3]) == 'i') { + if (char_to_lower(cur[4]) == 'n' && + char_to_lower(cur[5]) == 'i' && + char_to_lower(cur[6]) == 't' && + char_to_lower(cur[7]) == 'y') { + cur += 8; + } else { + return false; + } + } else { + cur += 3; + } + *end = cur; + if (has_flg(NUMBER_AS_RAW)) { + **pre = '\0'; /* add null-terminator for previous raw string */ + *pre = cur; /* save end position for current raw string */ + val->tag = ((u64)(cur - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW; + val->uni.str = (const char *)hdr; + } else { + val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; + val->uni.u64 = f64_bits_inf(sign); + } + return true; + } + return false; +} + +/** Read `NaN` literal (ignoring case). */ +static_inline bool read_nan(u8 **ptr, u8 **pre, + yyjson_read_flag flg, yyjson_val *val) { + u8 *hdr = *ptr; + u8 *cur = *ptr; + u8 **end = ptr; + bool sign = (*cur == '-'); + if (*cur == '+' && !has_allow(EXT_NUMBER)) return false; + cur += char_is_sign(*cur); + if (char_to_lower(cur[0]) == 'n' && + char_to_lower(cur[1]) == 'a' && + char_to_lower(cur[2]) == 'n') { + cur += 3; + *end = cur; + if (has_flg(NUMBER_AS_RAW)) { + **pre = '\0'; /* add null-terminator for previous raw string */ + *pre = cur; /* save end position for current raw string */ + val->tag = ((u64)(cur - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW; + val->uni.str = (const char *)hdr; + } else { + val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; + val->uni.u64 = f64_bits_nan(sign); + } + return true; + } + return false; +} + +/** Read `Inf`, `Infinity` or `NaN` literal (ignoring case). */ +static_inline bool read_inf_or_nan(u8 **ptr, u8 **pre, + yyjson_read_flag flg, yyjson_val *val) { + if (read_inf(ptr, pre, flg, val)) return true; + if (read_nan(ptr, pre, flg, val)) return true; + return false; +} + +/** Read a JSON number as raw string. */ +static_noinline bool read_num_raw(u8 **ptr, u8 **pre, yyjson_read_flag flg, + yyjson_val *val, const char **msg) { +#define return_err(_pos, _msg) do { \ + *msg = _msg; *end = _pos; return false; \ +} while (false) + +#define return_raw() do { \ + val->tag = ((u64)(cur - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW; \ + val->uni.str = (const char *)hdr; \ + **pre = '\0'; *pre = cur; *end = cur; return true; \ +} while (false) + + u8 *hdr = *ptr; + u8 *cur = *ptr; + u8 **end = ptr; + + /* skip sign */ + cur += (*cur == '-'); + + /* read first digit, check leading zero */ + while (unlikely(!char_is_digit(*cur))) { + if (has_allow(EXT_NUMBER)) { + if (*cur == '+' && cur == hdr) { /* leading `+` sign */ + cur++; + continue; + } + if (*cur == '.' && char_is_digit(cur[1])) { /* e.g. '.123' */ + goto read_double; + } + } + if (has_allow(INF_AND_NAN)) { + if (read_inf_or_nan(ptr, pre, flg, val)) return true; + } + return_err(cur, "no digit after sign"); + } + + /* read integral part */ + if (*cur == '0') { + cur++; + if (unlikely(char_is_digit(*cur))) { + return_err(cur - 1, "number with leading zero is not allowed"); + } + if (!char_is_fp(*cur)) { + if (has_allow(EXT_NUMBER) && char_to_lower(*cur) == 'x') { /* hex */ + if (!char_is_hex(*++cur)) return_err(cur, "invalid hex number"); + while(char_is_hex(*cur)) cur++; + } + return_raw(); + } + } else { + while (char_is_digit(*cur)) cur++; + if (!char_is_fp(*cur)) return_raw(); + } + +read_double: + /* read fraction part */ + if (*cur == '.') { + cur++; + if (!char_is_digit(*cur)) { + if (has_allow(EXT_NUMBER)) { + if (!char_is_exp(*cur)) return_raw(); + } else { + return_err(cur, "no digit after decimal point"); + } + } + while (char_is_digit(*cur)) cur++; + } + + /* read exponent part */ + if (char_is_exp(*cur)) { + cur += 1 + char_is_sign(cur[1]); + if (!char_is_digit(*cur++)) { + return_err(cur, "no digit after exponent sign"); + } + while (char_is_digit(*cur)) cur++; + } + + return_raw(); + +#undef return_err +#undef return_raw +} + +/** Read a hex number. */ +static_noinline bool read_num_hex(u8 **ptr, u8 **pre, yyjson_read_flag flg, + yyjson_val *val, const char **msg) { + u8 *hdr = *ptr; + u8 *cur = *ptr; + u8 **end = ptr; + u64 sig = 0, i = 0; + bool sign; + + /* skip sign and '0x' */ + sign = (*cur == '-'); + cur += (*cur == '-' || *cur == '+') + 2; + + /* read hex */ + for(; i < 16; i++) { + u8 c = hex_conv_table[cur[i]]; + if (c == 0xF0) break; + sig <<= 4; + sig |= c; + } + + /* check error */ + if (unlikely(i == 0)) { + *msg = "invalid hex number"; + return false; + } + + /* check overflow */ + if (unlikely(i == 16)) { + if (char_is_hex(cur[16]) || (sign && sig > ((u64)1 << 63))) { + if (!has_flg(BIGNUM_AS_RAW)) { + *msg = "hex number overflow"; + return false; + } + cur += 16; + while (char_is_hex(*cur)) cur++; + **pre = '\0'; + val->tag = ((u64)(cur - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW; + val->uni.str = (const char *)hdr; + *pre = cur; *end = cur; + return true; + } + } + + val->tag = YYJSON_TYPE_NUM | (u64)((u8)sign << 3); + val->uni.u64 = (u64)(sign ? (u64)(~(sig) + 1) : (u64)(sig)); + *end = cur + i; + return true; +} + +/** + Skip trivia (whitespace and comments). + This function should be used only when `char_is_trivia()` returns true. + @param ptr (inout) Input current position, output end position. + @param eof JSON end position. + @param flg JSON read flags. + @return true if at least one character was skipped. + false if no characters were skipped, + or if a multi-line comment is unterminated; + in the latter case, `ptr` will be set to `eof`. + */ +static_noinline bool skip_trivia(u8 **ptr, u8 *eof, yyjson_read_flag flg) { + u8 *hdr = *ptr, *cur = *ptr; + usize len; + + while (cur < eof) { + u8 *loop_begin = cur; + + /* skip standard whitespace */ + while(char_is_space(*cur)) cur++; + + /* skip extended whitespace */ + if (has_allow(EXT_WHITESPACE)) { + while (char_is_space_ext(*cur)) { + cur += (len = ext_space_len(cur)); + if (!len) break; + } + } + + /* skip comment, do not validate encoding */ + if (has_allow(COMMENTS) && cur[0] == '/') { + if (cur[1] == '/') { /* single-line comment */ + cur += 2; + if (has_allow(EXT_WHITESPACE)) { + while (cur < eof) { + if (char_is_eol_ext(*cur)) { + cur += (len = ext_eol_len(cur)); + if (len) break; + } + cur++; + } + } else { + while (cur < eof && !char_is_eol(*cur)) cur++; + } + } else if (cur[1] == '*') { /* multi-line comment */ + cur += 2; + while (!byte_match_2(cur, "*/") && cur < eof) cur++; + if (cur == eof) { + *ptr = eof; + return false; /* unclosed comment */ + } + cur += 2; + } + } + if (cur == loop_begin) break; + } + *ptr = cur; + return cur > hdr; +} + +/** + Check truncated UTF-8 character. + Return true if `cur` starts a valid UTF-8 sequence that is truncated. + */ +static bool is_truncated_utf8(u8 *cur, u8 *eof) { + u8 c0, c1, c2; + usize len = (usize)(eof - cur); + if (cur >= eof || len >= 4) return false; + c0 = cur[0]; c1 = cur[1]; c2 = cur[2]; + /* 1-byte UTF-8, not truncated */ + if (c0 < 0x80) return false; + if (len == 1) { + /* 2-byte UTF-8, truncated */ + if ((c0 & 0xE0) == 0xC0 && (c0 & 0x1E) != 0x00) return true; + /* 3-byte UTF-8, truncated */ + if ((c0 & 0xF0) == 0xE0) return true; + /* 4-byte UTF-8, truncated */ + if ((c0 & 0xF8) == 0xF0 && (c0 & 0x07) <= 0x04) return true; + } else if (len == 2) { + /* 3-byte UTF-8, truncated */ + if ((c0 & 0xF0) == 0xE0 && (c1 & 0xC0) == 0x80) { + u8 t = (u8)(((c0 & 0x0F) << 1) | ((c1 & 0x20) >> 5)); + return 0x01 <= t && t != 0x1B; + } + /* 4-byte UTF-8, truncated */ + if ((c0 & 0xF8) == 0xF0 && (c1 & 0xC0) == 0x80) { + u8 t = (u8)(((c0 & 0x07) << 2) | ((c1 & 0x30) >> 4)); + return 0x01 <= t && t <= 0x10; + } + } else if (len == 3) { + /* 4 bytes UTF-8, truncated */ + if ((c0 & 0xF8) == 0xF0 && (c1 & 0xC0) == 0x80 && (c2 & 0xC0) == 0x80) { + u8 t = (u8)(((c0 & 0x07) << 2) | ((c1 & 0x30) >> 4)); + return 0x01 <= t && t <= 0x10; + } + } + return false; +} + +/** + Check truncated string. + Returns true if `cur` match `str` but is truncated. + The `str` should be lowercase ASCII letters. + */ +static bool is_truncated_str(u8 *cur, u8 *eof, const char *str, + bool case_sensitive) { + usize len = strlen(str); + if (cur + len <= eof || eof <= cur) return false; + if (case_sensitive) { + return memcmp(cur, str, (usize)(eof - cur)) == 0; + } + for (; cur < eof; cur++, str++) { + if (char_to_lower(*cur) != *(const u8 *)str) return false; + } + return true; +} + +/** + Check truncated JSON on parsing errors. + Returns true if the input is valid but truncated. + */ +static_noinline bool is_truncated_end(u8 *hdr, u8 *cur, u8 *eof, + yyjson_read_code code, + yyjson_read_flag flg) { + if (cur >= eof) return true; + if (code == YYJSON_READ_ERROR_LITERAL) { + if (is_truncated_str(cur, eof, "true", true) || + is_truncated_str(cur, eof, "false", true) || + is_truncated_str(cur, eof, "null", true)) { + return true; + } + } + if (code == YYJSON_READ_ERROR_UNEXPECTED_CHARACTER || + code == YYJSON_READ_ERROR_INVALID_NUMBER || + code == YYJSON_READ_ERROR_LITERAL) { + if (has_allow(INF_AND_NAN)) { + if (*cur == '-') cur++; + if (is_truncated_str(cur, eof, "infinity", false) || + is_truncated_str(cur, eof, "nan", false)) { + return true; + } + } + } + if (code == YYJSON_READ_ERROR_UNEXPECTED_CONTENT) { + if (has_allow(INF_AND_NAN)) { + if (hdr + 3 <= cur && + is_truncated_str(cur - 3, eof, "infinity", false)) { + return true; /* e.g. infin would be read as inf + in */ + } + } + } + if (code == YYJSON_READ_ERROR_INVALID_STRING) { + usize len = (usize)(eof - cur); + + /* unicode escape sequence */ + if (*cur == '\\') { + if (len == 1) return true; + if (len <= 5) { + if (*++cur != 'u') return false; + for (++cur; cur < eof; cur++) { + if (!char_is_hex(*cur)) return false; + } + return true; + } else if (len <= 11) { + /* incomplete surrogate pair? */ + u16 hi; + if (*++cur != 'u') return false; + if (!hex_load_4(++cur, &hi)) return false; + if ((hi & 0xF800) != 0xD800) return false; + cur += 4; + if (cur >= eof) return true; + /* valid low surrogate is DC00...DFFF */ + if (*cur != '\\') return false; + if (++cur >= eof) return true; + if (*cur != 'u') return false; + if (++cur >= eof) return true; + if (*cur != 'd' && *cur != 'D') return false; + if (++cur >= eof) return true; + if ((*cur < 'c' || *cur > 'f') && (*cur < 'C' || *cur > 'F')) + return false; + if (++cur >= eof) return true; + if (!char_is_hex(*cur)) return false; + return true; + } + return false; + } + + /* 2 to 4 bytes UTF-8 */ + if (is_truncated_utf8(cur, eof)) { + return true; + } + } + if (has_allow(COMMENTS)) { + if (code == YYJSON_READ_ERROR_INVALID_COMMENT) { + /* unclosed multiline comment */ + return true; + } + if (code == YYJSON_READ_ERROR_UNEXPECTED_CHARACTER && + *cur == '/' && cur + 1 == eof) { + /* truncated beginning of comment */ + return true; + } + } + if (code == YYJSON_READ_ERROR_UNEXPECTED_CHARACTER && + has_allow(BOM)) { + /* truncated UTF-8 BOM */ + usize len = (usize)(eof - cur); + if (cur == hdr && len < 3 && !memcmp(hdr, "\xEF\xBB\xBF", len)) { + return true; + } + } + return false; +} + + + +#if !YYJSON_DISABLE_FAST_FP_CONV /* FP_READER */ + +/*============================================================================== + * MARK: - BigInt For Floating Point Number Reader (Private) + * + * The bigint algorithm is used by floating-point number reader to get correctly + * rounded result for numbers with lots of digits. This part of code is rarely + * used for common numbers. + *============================================================================*/ + +/** Unsigned arbitrarily large integer */ +typedef struct bigint { + u32 used; /* used chunks count, should not be 0 */ + u64 bits[64]; /* chunks (58 is enough here) */ +} bigint; + +/** + Evaluate 'big += val'. + @param big A big number (can be 0). + @param val An unsigned integer (can be 0). + */ +static_inline void bigint_add_u64(bigint *big, u64 val) { + u32 idx, max; + u64 num = big->bits[0]; + u64 add = num + val; + big->bits[0] = add; + if (likely((add >= num) || (add >= val))) return; + for ((void)(idx = 1), max = big->used; idx < max; idx++) { + if (likely(big->bits[idx] != U64_MAX)) { + big->bits[idx] += 1; + return; + } + big->bits[idx] = 0; + } + big->bits[big->used++] = 1; +} + +/** + Evaluate 'big *= val'. + @param big A big number (can be 0). + @param val An unsigned integer (cannot be 0). + */ +static_inline void bigint_mul_u64(bigint *big, u64 val) { + u32 idx = 0, max = big->used; + u64 hi, lo, carry = 0; + for (; idx < max; idx++) { + if (big->bits[idx]) break; + } + for (; idx < max; idx++) { + u128_mul_add(big->bits[idx], val, carry, &hi, &lo); + big->bits[idx] = lo; + carry = hi; + } + if (carry) big->bits[big->used++] = carry; +} + +/** + Evaluate 'big *= 2^exp'. + @param big A big number (can be 0). + @param exp An exponent integer (can be 0). + */ +static_inline void bigint_mul_pow2(bigint *big, u32 exp) { + u32 shft = exp % 64; + u32 move = exp / 64; + u32 idx = big->used; + if (unlikely(shft == 0)) { + for (; idx > 0; idx--) { + big->bits[idx + move - 1] = big->bits[idx - 1]; + } + big->used += move; + while (move) big->bits[--move] = 0; + } else { + big->bits[idx] = 0; + for (; idx > 0; idx--) { + u64 num = big->bits[idx] << shft; + num |= big->bits[idx - 1] >> (64 - shft); + big->bits[idx + move] = num; + } + big->bits[move] = big->bits[0] << shft; + big->used += move + (big->bits[big->used + move] > 0); + while (move) big->bits[--move] = 0; + } +} + +/** + Evaluate 'big *= 10^exp'. + @param big A big number (can be 0). + @param exp An exponent integer (cannot be 0). + */ +static_inline void bigint_mul_pow10(bigint *big, i32 exp) { + for (; exp >= U64_POW10_MAX_EXACT_EXP; exp -= U64_POW10_MAX_EXACT_EXP) { + bigint_mul_u64(big, u64_pow10_table[U64_POW10_MAX_EXACT_EXP]); + } + if (exp) { + bigint_mul_u64(big, u64_pow10_table[exp]); + } +} + +/** + Compare two bigint. + @return -1 if 'a < b', +1 if 'a > b', 0 if 'a == b'. + */ +static_inline i32 bigint_cmp(bigint *a, bigint *b) { + u32 idx = a->used; + if (a->used < b->used) return -1; + if (a->used > b->used) return +1; + while (idx-- > 0) { + u64 av = a->bits[idx]; + u64 bv = b->bits[idx]; + if (av < bv) return -1; + if (av > bv) return +1; + } + return 0; +} + +/** + Evaluate 'big = val'. + @param big A big number (can be 0). + @param val An unsigned integer (can be 0). + */ +static_inline void bigint_set_u64(bigint *big, u64 val) { + big->used = 1; + big->bits[0] = val; +} + +/** Set a bigint with floating point number string. */ +static_noinline void bigint_set_buf(bigint *big, u64 sig, i32 *exp, + u8 *sig_cut, u8 *sig_end, u8 *dot_pos) { + + if (unlikely(!sig_cut)) { + /* no digit cut, set significant part only */ + bigint_set_u64(big, sig); + return; + + } else { + /* some digits were cut, read them from 'sig_cut' to 'sig_end' */ + u8 *hdr = sig_cut; + u8 *cur = hdr; + u32 len = 0; + u64 val = 0; + bool dig_big_cut = false; + bool has_dot = (hdr < dot_pos) & (dot_pos < sig_end); + u32 dig_len_total = U64_SAFE_DIG + (u32)(sig_end - hdr) - has_dot; + + sig -= (*sig_cut >= '5'); /* sig was rounded before */ + if (dig_len_total > F64_MAX_DEC_DIG) { + dig_big_cut = true; + sig_end -= dig_len_total - (F64_MAX_DEC_DIG + 1); + sig_end -= (dot_pos + 1 == sig_end); + dig_len_total = (F64_MAX_DEC_DIG + 1); + } + *exp -= (i32)dig_len_total - U64_SAFE_DIG; + + big->used = 1; + big->bits[0] = sig; + while (cur < sig_end) { + if (likely(cur != dot_pos)) { + val = val * 10 + (u8)(*cur++ - '0'); + len++; + if (unlikely(cur == sig_end && dig_big_cut)) { + /* The last digit must be non-zero, */ + /* set it to '1' for correct rounding. */ + val = val - (val % 10) + 1; + } + if (len == U64_SAFE_DIG || cur == sig_end) { + bigint_mul_pow10(big, (i32)len); + bigint_add_u64(big, val); + val = 0; + len = 0; + } + } else { + cur++; + } + } + } +} + + + +/*============================================================================== + * MARK: - Diy Floating Point (Private) + *============================================================================*/ + +/** "Do It Yourself Floating Point" struct. */ +typedef struct diy_fp { + u64 sig; /* significand */ + i32 exp; /* exponent, base 2 */ + i32 pad; /* padding, useless */ +} diy_fp; + +/** Get cached rounded diy_fp with pow(10, e) The input value must in range + [POW10_SIG_TABLE_MIN_EXP, POW10_SIG_TABLE_MAX_EXP]. */ +static_inline diy_fp diy_fp_get_cached_pow10(i32 exp10) { + diy_fp fp; + u64 sig_ext; + pow10_table_get_sig(exp10, &fp.sig, &sig_ext); + pow10_table_get_exp(exp10, &fp.exp); + fp.sig += (sig_ext >> 63); + return fp; +} + +/** Returns fp * fp2. */ +static_inline diy_fp diy_fp_mul(diy_fp fp, diy_fp fp2) { + u64 hi, lo; + u128_mul(fp.sig, fp2.sig, &hi, &lo); + fp.sig = hi + (lo >> 63); + fp.exp += fp2.exp + 64; + return fp; +} + +/** Convert diy_fp to IEEE-754 raw value. */ +static_inline u64 diy_fp_to_ieee_raw(diy_fp fp) { + u64 sig = fp.sig; + i32 exp = fp.exp; + u32 lz_bits; + if (unlikely(fp.sig == 0)) return 0; + + lz_bits = u64_lz_bits(sig); + sig <<= lz_bits; + sig >>= F64_BITS - F64_SIG_FULL_BITS; + exp -= (i32)lz_bits; + exp += F64_BITS - F64_SIG_FULL_BITS; + exp += F64_SIG_BITS; + + if (unlikely(exp >= F64_MAX_BIN_EXP)) { + /* overflow */ + return F64_BITS_INF; + } else if (likely(exp >= F64_MIN_BIN_EXP - 1)) { + /* normal */ + exp += F64_EXP_BIAS; + return ((u64)exp << F64_SIG_BITS) | (sig & F64_SIG_MASK); + } else if (likely(exp >= F64_MIN_BIN_EXP - F64_SIG_FULL_BITS)) { + /* subnormal */ + return sig >> (F64_MIN_BIN_EXP - exp - 1); + } else { + /* underflow */ + return 0; + } +} + + + +/*============================================================================== + * MARK: - Number Reader (Private) + *============================================================================*/ + +/** + Read a JSON number. + + 1. This function assume that the floating-point number is in IEEE-754 format. + 2. This function support uint64/int64/double number. If an integer number + cannot fit in uint64/int64, it will returns as a double number. If a double + number is infinite, the return value is based on flag. + 3. This function (with inline attribute) may generate a lot of instructions. + */ +static_inline bool read_num(u8 **ptr, u8 **pre, yyjson_read_flag flg, + yyjson_val *val, const char **msg) { +#define return_err(_pos, _msg) do { \ + *msg = _msg; \ + *end = _pos; \ + return false; \ +} while (false) + +#define return_0() do { \ + val->tag = YYJSON_TYPE_NUM | (u8)((u8)sign << 3); \ + val->uni.u64 = 0; \ + *end = cur; return true; \ +} while (false) + +#define return_i64(_v) do { \ + val->tag = YYJSON_TYPE_NUM | (u8)((u8)sign << 3); \ + val->uni.u64 = (u64)(sign ? (u64)(~(_v) + 1) : (u64)(_v)); \ + *end = cur; return true; \ +} while (false) + +#define return_f64(_v) do { \ + val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; \ + val->uni.f64 = sign ? -(f64)(_v) : (f64)(_v); \ + *end = cur; return true; \ +} while (false) + +#define return_f64_bin(_v) do { \ + val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; \ + val->uni.u64 = ((u64)sign << 63) | (u64)(_v); \ + *end = cur; return true; \ +} while (false) + +#define return_inf() do { \ + if (has_flg(BIGNUM_AS_RAW)) return_raw(); \ + if (has_allow(INF_AND_NAN)) return_f64_bin(F64_BITS_INF); \ + else return_err(hdr, "number is infinity when parsed as double"); \ +} while (false) + +#define return_raw() do { \ + **pre = '\0'; /* add null-terminator for previous raw string */ \ + val->tag = ((u64)(cur - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW; \ + val->uni.str = (const char *)hdr; \ + *pre = cur; *end = cur; return true; \ +} while (false) + + u8 *sig_cut = NULL; /* significant part cutting position for long number */ + u8 *sig_end = NULL; /* significant part ending position */ + u8 *dot_pos = NULL; /* decimal point position */ + + u64 sig = 0; /* significant part of the number */ + i32 exp = 0; /* exponent part of the number */ + + bool exp_sign; /* temporary exponent sign from literal part */ + i64 exp_sig = 0; /* temporary exponent number from significant part */ + i64 exp_lit = 0; /* temporary exponent number from exponent literal part */ + u64 num; /* temporary number for reading */ + u8 *tmp; /* temporary cursor for reading */ + + u8 *hdr = *ptr; + u8 *cur = *ptr; + u8 **end = ptr; + bool sign; + + /* read number as raw string if has `YYJSON_READ_NUMBER_AS_RAW` flag */ + if (has_flg(NUMBER_AS_RAW)) { + return read_num_raw(ptr, pre, flg, val, msg); + } + + sign = (*hdr == '-'); + cur += sign; + + /* begin with a leading zero or non-digit */ + while (unlikely(!char_is_nonzero(*cur))) { /* 0 or non-digit char */ + if (unlikely(*cur != '0')) { /* non-digit char */ + if (has_allow(EXT_NUMBER)) { + if (*cur == '+' && cur == hdr) { /* leading `+` sign */ + cur++; + continue; + } + if (*cur == '.' && char_is_digit(cur[1])) { /* e.g. '.123' */ + goto leading_dot; + } + } + if (has_allow(INF_AND_NAN)) { + if (read_inf_or_nan(ptr, pre, flg, val)) return true; + } + return_err(cur, "no digit after sign"); + } + /* begin with 0 */ + if (likely(!char_is_digit_or_fp(*++cur))) { + if (has_allow(EXT_NUMBER) && char_to_lower(*cur) == 'x') { /* hex */ + return read_num_hex(ptr, pre, flg, val, msg); + } + return_0(); + } + if (likely(*cur == '.')) { +leading_dot: + dot_pos = cur++; + if (unlikely(!char_is_digit(*cur))) { + if (has_allow(EXT_NUMBER)) { + if (char_is_exp(*cur)) { + goto digi_exp_more; + } else { + return_f64_bin(0); + } + } + return_err(cur, "no digit after decimal point"); + } + while (unlikely(*cur == '0')) cur++; + if (likely(char_is_digit(*cur))) { + /* first non-zero digit after decimal point */ + sig = (u64)(*cur - '0'); /* read first digit */ + cur--; + goto digi_frac_1; /* continue read fraction part */ + } + } + if (unlikely(char_is_digit(*cur))) { + return_err(cur - 1, "number with leading zero is not allowed"); + } + if (unlikely(char_is_exp(*cur))) { /* 0 with any exponent is still 0 */ + cur += (usize)1 + char_is_sign(cur[1]); + if (unlikely(!char_is_digit(*cur))) { + return_err(cur, "no digit after exponent sign"); + } + while (char_is_digit(*++cur)); + } + return_f64_bin(0); + } + + /* begin with non-zero digit */ + sig = (u64)(*cur - '0'); + + /* + Read integral part, same as the following code. + + for (int i = 1; i <= 18; i++) { + num = cur[i] - '0'; + if (num <= 9) sig = num + sig * 10; + else goto digi_sepr_i; + } + */ +#define expr_intg(i) \ + if (likely((num = (u64)(cur[i] - (u8)'0')) <= 9)) sig = num + sig * 10; \ + else { goto digi_sepr_##i; } + repeat_in_1_18(expr_intg) +#undef expr_intg + + + cur += 19; /* skip continuous 19 digits */ + if (!char_is_digit_or_fp(*cur)) { + /* this number is an integer consisting of 19 digits */ + if (sign && (sig > ((u64)1 << 63))) { /* overflow */ + if (has_flg(BIGNUM_AS_RAW)) return_raw(); + return_f64(unsafe_yyjson_u64_to_f64(sig)); + } + return_i64(sig); + } + goto digi_intg_more; /* read more digits in integral part */ + + + /* process first non-digit character */ +#define expr_sepr(i) \ + digi_sepr_##i: \ + if (likely(!char_is_fp(cur[i]))) { cur += i; return_i64(sig); } \ + dot_pos = cur + i; \ + if (likely(cur[i] == '.')) goto digi_frac_##i; \ + cur += i; sig_end = cur; goto digi_exp_more; + repeat_in_1_18(expr_sepr) +#undef expr_sepr + + + /* read fraction part */ +#define expr_frac(i) \ + digi_frac_##i: \ + if (likely((num = (u64)(cur[i + 1] - (u8)'0')) <= 9)) \ + sig = num + sig * 10; \ + else { goto digi_stop_##i; } + repeat_in_1_18(expr_frac) +#undef expr_frac + + cur += 20; /* skip 19 digits and 1 decimal point */ + if (!char_is_digit(*cur)) goto digi_frac_end; /* fraction part end */ + goto digi_frac_more; /* read more digits in fraction part */ + + + /* significant part end */ +#define expr_stop(i) \ + digi_stop_##i: \ + cur += i + 1; \ + goto digi_frac_end; + repeat_in_1_18(expr_stop) +#undef expr_stop + + + /* read more digits in integral part */ +digi_intg_more: + if (char_is_digit(*cur)) { + if (!char_is_digit_or_fp(cur[1])) { + /* this number is an integer consisting of 20 digits */ + num = (u64)(*cur - '0'); + if ((sig < (U64_MAX / 10)) || + (sig == (U64_MAX / 10) && num <= (U64_MAX % 10))) { + sig = num + sig * 10; + cur++; + /* convert to double if overflow */ + if (sign) { + if (has_flg(BIGNUM_AS_RAW)) return_raw(); + return_f64(unsafe_yyjson_u64_to_f64(sig)); + } + return_i64(sig); + } + } + } + + if (char_is_exp(*cur)) { + dot_pos = cur; + goto digi_exp_more; + } + + if (*cur == '.') { + dot_pos = cur++; + if (unlikely(!char_is_digit(*cur))) { + if (has_allow(EXT_NUMBER)) { + goto digi_frac_end; + } + return_err(cur, "no digit after decimal point"); + } + } + + + /* read more digits in fraction part */ +digi_frac_more: + sig_cut = cur; /* too large to fit in u64, excess digits need to be cut */ + sig += (*cur >= '5'); /* round */ + while (char_is_digit(*++cur)); + if (!dot_pos) { + if (!char_is_fp(*cur) && has_flg(BIGNUM_AS_RAW)) { + return_raw(); /* it's a large integer */ + } + dot_pos = cur; + if (*cur == '.') { + if (unlikely(!char_is_digit(*++cur))) { + if (!has_allow(EXT_NUMBER)) { + return_err(cur, "no digit after decimal point"); + } + } + while (char_is_digit(*cur)) cur++; + } + } + exp_sig = (i64)(dot_pos - sig_cut); + exp_sig += (dot_pos < sig_cut); + + /* ignore trailing zeros */ + tmp = cur - 1; + while ((*tmp == '0' || *tmp == '.') && tmp > hdr) tmp--; + if (tmp < sig_cut) { + sig_cut = NULL; + } else { + sig_end = cur; + } + + if (char_is_exp(*cur)) goto digi_exp_more; + goto digi_exp_finish; + + + /* fraction part end */ +digi_frac_end: + if (unlikely(dot_pos + 1 == cur)) { + if (!has_allow(EXT_NUMBER)) { + return_err(cur, "no digit after decimal point"); + } + } + sig_end = cur; + exp_sig = -(i64)((u64)(cur - dot_pos) - 1); + if (likely(!char_is_exp(*cur))) { + if (unlikely(exp_sig < F64_MIN_DEC_EXP - 19)) { + return_f64_bin(0); /* underflow */ + } + exp = (i32)exp_sig; + goto digi_finish; + } else { + goto digi_exp_more; + } + + + /* read exponent part */ +digi_exp_more: + exp_sign = (*++cur == '-'); + cur += char_is_sign(*cur); + if (unlikely(!char_is_digit(*cur))) { + return_err(cur, "no digit after exponent sign"); + } + while (*cur == '0') cur++; + + /* read exponent literal */ + tmp = cur; + while (char_is_digit(*cur)) { + exp_lit = (i64)((u8)(*cur++ - '0') + (u64)exp_lit * 10); + } + if (unlikely(cur - tmp >= U64_SAFE_DIG)) { + if (exp_sign) { + return_f64_bin(0); /* underflow */ + } else { + return_inf(); /* overflow */ + } + } + exp_sig += exp_sign ? -exp_lit : exp_lit; + + + /* validate exponent value */ +digi_exp_finish: + if (unlikely(exp_sig < F64_MIN_DEC_EXP - 19)) { + return_f64_bin(0); /* underflow */ + } + if (unlikely(exp_sig > F64_MAX_DEC_EXP)) { + return_inf(); /* overflow */ + } + exp = (i32)exp_sig; + + + /* all digit read finished */ +digi_finish: + + /* + Fast path 1: + + 1. The floating-point number calculation should be accurate, see the + comments of macro `YYJSON_DOUBLE_MATH_CORRECT`. + 2. Correct rounding should be performed (fegetround() == FE_TONEAREST). + 3. The input of floating point number calculation does not lose precision, + which means: 64 - leading_zero(input) - trailing_zero(input) < 53. + + We don't check all available inputs here, because that would make the code + more complicated, and not friendly to branch predictor. + */ +#if YYJSON_DOUBLE_MATH_CORRECT + if (sig < ((u64)1 << 53) && + exp >= -F64_POW10_MAX_EXACT_EXP && + exp <= +F64_POW10_MAX_EXACT_EXP) { + f64 dbl = (f64)sig; + if (exp < 0) { + dbl /= f64_pow10_table[-exp]; + } else { + dbl *= f64_pow10_table[+exp]; + } + return_f64(dbl); + } +#endif + + /* + Fast path 2: + + To keep it simple, we only accept normal number here, + let the slow path to handle subnormal and infinity number. + */ + if (likely(!sig_cut && + exp > -F64_MAX_DEC_EXP + 1 && + exp < +F64_MAX_DEC_EXP - 20)) { + /* + The result value is exactly equal to (sig * 10^exp), + the exponent part (10^exp) can be converted to (sig2 * 2^exp2). + + The sig2 can be an infinite length number, only the highest 128 bits + is cached in the pow10_sig_table. + + Now we have these bits: + sig1 (normalized 64bit) : aaaaaaaa + sig2 (higher 64bit) : bbbbbbbb + sig2_ext (lower 64bit) : cccccccc + sig2_cut (extra unknown bits) : dddddddddddd.... + + And the calculation process is: + ---------------------------------------- + aaaaaaaa * + bbbbbbbbccccccccdddddddddddd.... + ---------------------------------------- + abababababababab + + acacacacacacacac + + adadadadadadadadadad.... + ---------------------------------------- + [hi____][lo____] + + [hi2___][lo2___] + + [unknown___________....] + ---------------------------------------- + + The addition with carry may affect higher bits, but if there is a 0 + in higher bits, the bits higher than 0 will not be affected. + + `lo2` + `unknown` may get a carry bit and may affect `hi2`, the max + value of `hi2` is 0xFFFFFFFFFFFFFFFE, so `hi2` will not overflow. + + `lo` + `hi2` may also get a carry bit and may affect `hi`, but only + the highest significant 53 bits of `hi` is needed. If there is a 0 + in the lower bits of `hi`, then all the following bits can be dropped. + + To convert the result to IEEE-754 double number, we need to perform + correct rounding: + 1. if bit 54 is 0, round down, + 2. if bit 54 is 1 and any bit beyond bit 54 is 1, round up, + 3. if bit 54 is 1 and all bits beyond bit 54 are 0, round to even, + as the extra bits is unknown, this case will not be handled here. + */ + + u64 raw; + u64 sig1, sig2, sig2_ext, hi, lo, hi2, lo2, add, bits; + i32 exp2; + u32 lz; + bool exact = false, carry, round_up; + + /* convert (10^exp) to (sig2 * 2^exp2) */ + pow10_table_get_sig(exp, &sig2, &sig2_ext); + pow10_table_get_exp(exp, &exp2); + + /* normalize and multiply */ + lz = u64_lz_bits(sig); + sig1 = sig << lz; + exp2 -= (i32)lz; + u128_mul(sig1, sig2, &hi, &lo); + + /* + The `hi` is in range [0x4000000000000000, 0xFFFFFFFFFFFFFFFE], + To get normalized value, `hi` should be shifted to the left by 0 or 1. + + The highest significant 53 bits is used by IEEE-754 double number, + and the bit 54 is used to detect rounding direction. + + The lowest (64 - 54 - 1) bits is used to check whether it contains 0. + */ + bits = hi & (((u64)1 << (64 - 54 - 1)) - 1); + if (bits - 1 < (((u64)1 << (64 - 54 - 1)) - 2)) { + /* + (bits != 0 && bits != 0x1FF) => (bits - 1 < 0x1FF - 1) + The `bits` is not zero, so we don't need to check `round to even` + case. The `bits` contains bit `0`, so we can drop the extra bits + after `0`. + */ + exact = true; + + } else { + /* + (bits == 0 || bits == 0x1FF) + The `bits` is filled with all `0` or all `1`, so we need to check + lower bits with another 64-bit multiplication. + */ + u128_mul(sig1, sig2_ext, &hi2, &lo2); + + add = lo + hi2; + if (add + 1 > (u64)1) { + /* + (add != 0 && add != U64_MAX) => (add + 1 > 1) + The `add` is not zero, so we don't need to check `round to + even` case. The `add` contains bit `0`, so we can drop the + extra bits after `0`. The `hi` cannot be U64_MAX, so it will + not overflow. + */ + carry = add < lo || add < hi2; + hi += carry; + exact = true; + } + } + + if (exact) { + /* normalize */ + lz = hi < ((u64)1 << 63); + hi <<= lz; + exp2 -= (i32)lz; + exp2 += 64; + + /* test the bit 54 and get rounding direction */ + round_up = (hi & ((u64)1 << (64 - 54))) > (u64)0; + hi += (round_up ? ((u64)1 << (64 - 54)) : (u64)0); + + /* test overflow */ + if (hi < ((u64)1 << (64 - 54))) { + hi = ((u64)1 << 63); + exp2 += 1; + } + + /* This is a normal number, convert it to IEEE-754 format. */ + hi >>= F64_BITS - F64_SIG_FULL_BITS; + exp2 += F64_BITS - F64_SIG_FULL_BITS + F64_SIG_BITS; + exp2 += F64_EXP_BIAS; + raw = ((u64)exp2 << F64_SIG_BITS) | (hi & F64_SIG_MASK); + return_f64_bin(raw); + } + } + + /* + Slow path: read double number exactly with diyfp. + 1. Use cached diyfp to get an approximation value. + 2. Use bigcomp to check the approximation value if needed. + + This algorithm refers to google's double-conversion project: + https://github.com/google/double-conversion + */ + { + const i32 ERR_ULP_LOG = 3; + const i32 ERR_ULP = 1 << ERR_ULP_LOG; + const i32 ERR_CACHED_POW = ERR_ULP / 2; + const i32 ERR_MUL_FIXED = ERR_ULP / 2; + const i32 DIY_SIG_BITS = 64; + const i32 EXP_BIAS = F64_EXP_BIAS + F64_SIG_BITS; + const i32 EXP_SUBNORMAL = -EXP_BIAS + 1; + + u64 fp_err; + u32 bits; + i32 order_of_magnitude; + i32 effective_significand_size; + i32 precision_digits_count; + u64 precision_bits; + u64 half_way; + + u64 raw; + diy_fp fp, fp_upper; + bigint big_full, big_comp; + i32 cmp; + + fp.sig = sig; + fp.exp = 0; + fp_err = sig_cut ? (u64)(ERR_ULP / 2) : (u64)0; + + /* normalize */ + bits = u64_lz_bits(fp.sig); + fp.sig <<= bits; + fp.exp -= (i32)bits; + fp_err <<= bits; + + /* multiply and add error */ + fp = diy_fp_mul(fp, diy_fp_get_cached_pow10(exp)); + fp_err += (u64)ERR_CACHED_POW + (fp_err != 0) + (u64)ERR_MUL_FIXED; + + /* normalize */ + bits = u64_lz_bits(fp.sig); + fp.sig <<= bits; + fp.exp -= (i32)bits; + fp_err <<= bits; + + /* effective significand */ + order_of_magnitude = DIY_SIG_BITS + fp.exp; + if (likely(order_of_magnitude >= EXP_SUBNORMAL + F64_SIG_FULL_BITS)) { + effective_significand_size = F64_SIG_FULL_BITS; + } else if (order_of_magnitude <= EXP_SUBNORMAL) { + effective_significand_size = 0; + } else { + effective_significand_size = order_of_magnitude - EXP_SUBNORMAL; + } + + /* precision digits count */ + precision_digits_count = DIY_SIG_BITS - effective_significand_size; + if (unlikely(precision_digits_count + ERR_ULP_LOG >= DIY_SIG_BITS)) { + i32 shr = (precision_digits_count + ERR_ULP_LOG) - DIY_SIG_BITS + 1; + fp.sig >>= shr; + fp.exp += shr; + fp_err = (fp_err >> shr) + 1 + (u32)ERR_ULP; + precision_digits_count -= shr; + } + + /* half way */ + precision_bits = fp.sig & (((u64)1 << precision_digits_count) - 1); + precision_bits *= (u32)ERR_ULP; + half_way = (u64)1 << (precision_digits_count - 1); + half_way *= (u32)ERR_ULP; + + /* rounding */ + fp.sig >>= precision_digits_count; + fp.sig += (precision_bits >= half_way + fp_err); + fp.exp += precision_digits_count; + + /* get IEEE double raw value */ + raw = diy_fp_to_ieee_raw(fp); + if (unlikely(raw == F64_BITS_INF)) return_inf(); + if (likely(precision_bits <= half_way - fp_err || + precision_bits >= half_way + fp_err)) { + return_f64_bin(raw); /* number is accurate */ + } + /* now the number is the correct value, or the next lower value */ + + /* upper boundary */ + if (raw & F64_EXP_MASK) { + fp_upper.sig = (raw & F64_SIG_MASK) + ((u64)1 << F64_SIG_BITS); + fp_upper.exp = (i32)((raw & F64_EXP_MASK) >> F64_SIG_BITS); + } else { + fp_upper.sig = (raw & F64_SIG_MASK); + fp_upper.exp = 1; + } + fp_upper.exp -= F64_EXP_BIAS + F64_SIG_BITS; + fp_upper.sig <<= 1; + fp_upper.exp -= 1; + fp_upper.sig += 1; /* add half ulp */ + + /* compare with bigint */ + bigint_set_buf(&big_full, sig, &exp, sig_cut, sig_end, dot_pos); + bigint_set_u64(&big_comp, fp_upper.sig); + if (exp >= 0) { + bigint_mul_pow10(&big_full, +exp); + } else { + bigint_mul_pow10(&big_comp, -exp); + } + if (fp_upper.exp > 0) { + bigint_mul_pow2(&big_comp, (u32)+fp_upper.exp); + } else { + bigint_mul_pow2(&big_full, (u32)-fp_upper.exp); + } + cmp = bigint_cmp(&big_full, &big_comp); + if (likely(cmp != 0)) { + /* round down or round up */ + raw += (cmp > 0); + } else { + /* falls midway, round to even */ + raw += (raw & 1); + } + + if (unlikely(raw == F64_BITS_INF)) return_inf(); + return_f64_bin(raw); + } + +#undef return_err +#undef return_inf +#undef return_0 +#undef return_i64 +#undef return_f64 +#undef return_f64_bin +#undef return_raw +} + + + +#else /* FP_READER */ + +/** + Read a JSON number. + This is a fallback function if the custom number reader is disabled. + This function use libc's strtod() to read floating-point number. + */ +static_inline bool read_num(u8 **ptr, u8 **pre, yyjson_read_flag flg, + yyjson_val *val, const char **msg) { +#define return_err(_pos, _msg) do { \ + *msg = _msg; \ + *end = _pos; \ + return false; \ +} while (false) + +#define return_0() do { \ + val->tag = YYJSON_TYPE_NUM | (u64)((u8)sign << 3); \ + val->uni.u64 = 0; \ + *end = cur; return true; \ +} while (false) + +#define return_i64(_v) do { \ + val->tag = YYJSON_TYPE_NUM | (u64)((u8)sign << 3); \ + val->uni.u64 = (u64)(sign ? (u64)(~(_v) + 1) : (u64)(_v)); \ + *end = cur; return true; \ +} while (false) + +#define return_f64(_v) do { \ + val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; \ + val->uni.f64 = sign ? -(f64)(_v) : (f64)(_v); \ + *end = cur; return true; \ +} while (false) + +#define return_f64_bin(_v) do { \ + val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; \ + val->uni.u64 = ((u64)sign << 63) | (u64)(_v); \ + *end = cur; return true; \ +} while (false) + +#define return_inf() do { \ + if (has_flg(BIGNUM_AS_RAW)) return_raw(); \ + if (has_allow(INF_AND_NAN)) return_f64_bin(F64_BITS_INF); \ + else return_err(hdr, "number is infinity when parsed as double"); \ +} while (false) + +#define return_raw() do { \ + val->tag = ((u64)(cur - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW; \ + val->uni.str = (const char *)hdr; \ + **pre = '\0'; *pre = cur; *end = cur; return true; \ +} while (false) + + u64 sig, num; + u8 *hdr = *ptr; + u8 *cur = *ptr; + u8 **end = ptr; + u8 *dot = NULL; + u8 *f64_end = NULL; + bool sign; + + /* read number as raw string if has `YYJSON_READ_NUMBER_AS_RAW` flag */ + if (has_flg(NUMBER_AS_RAW)) { + return read_num_raw(ptr, pre, flg, val, msg); + } + + sign = (*hdr == '-'); + cur += sign; + sig = (u8)(*cur - '0'); + + /* read first digit, check leading zero */ + while (unlikely(!char_is_digit(*cur))) { + if (has_allow(EXT_NUMBER)) { + if (*cur == '+' && cur == hdr) { /* leading `+` sign */ + cur++; + sig = (u8)(*cur - '0'); + continue; + } + if (*cur == '.' && char_is_num(cur[1])) { /* no integer part */ + goto read_double; /* e.g. '.123' */ + } + } + if (has_allow(INF_AND_NAN)) { + if (read_inf_or_nan(ptr, pre, flg, val)) return true; + } + return_err(cur, "no digit after sign"); + } + if (*cur == '0') { + cur++; + if (unlikely(char_is_digit(*cur))) { + return_err(cur - 1, "number with leading zero is not allowed"); + } + if (!char_is_fp(*cur)) { + if (has_allow(EXT_NUMBER) && + (*cur == 'x' || *cur == 'X')) { /* hex integer */ + return read_num_hex(ptr, pre, flg, val, msg); + } + return_0(); + } + goto read_double; + } + + /* read continuous digits, up to 19 characters */ +#define expr_intg(i) \ + if (likely((num = (u64)(cur[i] - (u8)'0')) <= 9)) sig = num + sig * 10; \ + else { cur += i; goto intg_end; } + repeat_in_1_18(expr_intg) +#undef expr_intg + + /* here are 19 continuous digits, skip them */ + cur += 19; + if (char_is_digit(cur[0]) && !char_is_digit_or_fp(cur[1])) { + /* this number is an integer consisting of 20 digits */ + num = (u8)(*cur - '0'); + if ((sig < (U64_MAX / 10)) || + (sig == (U64_MAX / 10) && num <= (U64_MAX % 10))) { + sig = num + sig * 10; + cur++; + if (sign) { + if (has_flg(BIGNUM_AS_RAW)) return_raw(); + return_f64(unsafe_yyjson_u64_to_f64(sig)); + } + return_i64(sig); + } + } + +intg_end: + /* continuous digits ended */ + if (!char_is_digit_or_fp(*cur)) { + /* this number is an integer consisting of 1 to 19 digits */ + if (sign && (sig > ((u64)1 << 63))) { + if (has_flg(BIGNUM_AS_RAW)) return_raw(); + return_f64(unsafe_yyjson_u64_to_f64(sig)); + } + return_i64(sig); + } + +read_double: + /* this number should be read as double */ + while (char_is_digit(*cur)) cur++; + if (!char_is_fp(*cur) && has_flg(BIGNUM_AS_RAW)) { + return_raw(); /* it's a large integer */ + } + while (*cur == '.') { + /* skip fraction part */ + dot = cur; + cur++; + if (!char_is_digit(*cur)) { + if (has_allow(EXT_NUMBER)) { + break; + } else { + return_err(cur, "no digit after decimal point"); + } + } + cur++; + while (char_is_digit(*cur)) cur++; + break; + } + if (char_is_exp(*cur)) { + /* skip exponent part */ + cur += 1 + char_is_sign(cur[1]); + if (!char_is_digit(*cur)) { + return_err(cur, "no digit after exponent sign"); + } + cur++; + while (char_is_digit(*cur)) cur++; + } + + /* + libc's strtod() is used to parse the floating-point number. + + Note that the decimal point character used by strtod() is locale-dependent, + and the rounding direction may affected by fesetround(). + + For currently known locales, (en, zh, ja, ko, am, he, hi) use '.' as the + decimal point, while other locales use ',' as the decimal point. + + Here strtod() is called twice for different locales, but if another thread + happens calls setlocale() between two strtod(), parsing may still fail. + */ + val->uni.f64 = strtod((const char *)hdr, (char **)&f64_end); + if (unlikely(f64_end != cur)) { + /* replace '.' with ',' for locale */ + bool cut = (*cur == ','); + if (cut) *cur = ' '; + if (dot) *dot = ','; + val->uni.f64 = strtod((const char *)hdr, (char **)&f64_end); + /* restore ',' to '.' */ + if (cut) *cur = ','; + if (dot) *dot = '.'; + if (unlikely(f64_end != cur)) { + return_err(hdr, "strtod() failed to parse the number"); + } + } + if (unlikely(val->uni.f64 >= HUGE_VAL || val->uni.f64 <= -HUGE_VAL)) { + return_inf(); + } + val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; + *end = cur; + return true; + +#undef return_err +#undef return_0 +#undef return_i64 +#undef return_f64 +#undef return_f64_bin +#undef return_inf +#undef return_raw +} + +#endif /* FP_READER */ + + + +/*============================================================================== + * MARK: - String Reader (Private) + *============================================================================*/ + +/** Read unicode escape sequence. */ +static_inline bool read_uni_esc(u8 **src_ptr, u8 **dst_ptr, const char **msg) { +#define return_err(_end, _msg) *msg = _msg; *src_ptr = _end; return false + + u8 *src = *src_ptr; + u8 *dst = *dst_ptr; + u16 hi, lo; + u32 uni; + + src += 2; /* skip `\u` */ + if (unlikely(!hex_load_4(src, &hi))) { + return_err(src - 2, "invalid escaped sequence in string"); + } + src += 4; /* skip hex */ + if (likely((hi & 0xF800) != 0xD800)) { + /* a BMP character */ + if (hi >= 0x800) { + *dst++ = (u8)(0xE0 | (hi >> 12)); + *dst++ = (u8)(0x80 | ((hi >> 6) & 0x3F)); + *dst++ = (u8)(0x80 | (hi & 0x3F)); + } else if (hi >= 0x80) { + *dst++ = (u8)(0xC0 | (hi >> 6)); + *dst++ = (u8)(0x80 | (hi & 0x3F)); + } else { + *dst++ = (u8)hi; + } + } else { + /* a non-BMP character, represented as a surrogate pair */ + if (unlikely((hi & 0xFC00) != 0xD800)) { + return_err(src - 6, "invalid high surrogate in string"); + } + if (unlikely(!byte_match_2(src, "\\u"))) { + return_err(src - 6, "no low surrogate in string"); + } + if (unlikely(!hex_load_4(src + 2, &lo))) { + return_err(src - 6, "invalid escape in string"); + } + if (unlikely((lo & 0xFC00) != 0xDC00)) { + return_err(src - 6, "invalid low surrogate in string"); + } + uni = ((((u32)hi - 0xD800) << 10) | + ((u32)lo - 0xDC00)) + 0x10000; + *dst++ = (u8)(0xF0 | (uni >> 18)); + *dst++ = (u8)(0x80 | ((uni >> 12) & 0x3F)); + *dst++ = (u8)(0x80 | ((uni >> 6) & 0x3F)); + *dst++ = (u8)(0x80 | (uni & 0x3F)); + src += 6; + } + *src_ptr = src; + *dst_ptr = dst; + return true; +#undef return_err +} + +/** + Read a JSON string. + @param quo The quote character (single quote or double quote). + @param ptr The head pointer of string before quote (inout). + @param eof JSON end position. + @param flg JSON read flag. + @param val The string value to be written. + @param msg The error message pointer. + @param con Continuation for incremental parsing. + @return Whether success. + */ +static_inline bool read_str_opt(u8 quo, u8 **ptr, u8 *eof, yyjson_read_flag flg, + yyjson_val *val, const char **msg, u8 *con[2]) { + /* + GCC may sometimes load variables into registers too early, causing + unnecessary instructions and performance degradation. This inline assembly + serves as a hint to GCC: 'This variable will be modified, so avoid loading + it too early.' Other compilers like MSVC, Clang, and ICC can generate the + expected instructions without needing this hint. + + Check out this example: https://godbolt.org/z/YG6a5W5Ec + */ +#define return_err(_end, _msg) do { \ + *msg = _msg; \ + *end = _end; \ + if (con) { con[0] = _end; con[1] = dst; } \ + return false; \ +} while (false) + + u8 *hdr = *ptr + 1; + u8 **end = ptr; + u8 *src = hdr, *dst = NULL, *pos; + u16 hi, lo; + u32 uni, tmp; + + /* Resume incremental parsing. */ + if (con && unlikely(con[0])) { + src = con[0]; + dst = con[1]; + if (dst) goto copy_ascii; + } + +skip_ascii: + /* + Most strings have no escaped characters, so we can jump them quickly. + + We want to make loop unrolling, as shown in the following code. Some + compiler may not generate instructions as expected, so we rewrite it with + explicit goto statements. We hope the compiler can generate instructions + like this: https://godbolt.org/z/8vjsYq + + while (true) repeat16({ + if (likely((char_is_ascii_skip(*src)))) src++; + else break; + }) + */ + if (quo == '"') { +#define expr_jump(i) \ + if (likely(char_is_ascii_skip(src[i]))) {} \ + else goto skip_ascii_stop##i; + +#define expr_stop(i) \ + skip_ascii_stop##i: \ + src += i; \ + goto skip_ascii_end; + + repeat16_incr(expr_jump) + src += 16; + goto skip_ascii; + repeat16_incr(expr_stop) + +#undef expr_jump +#undef expr_stop + } else { +#define expr_jump(i) \ + if (likely(char_is_ascii_skip_sq(src[i]))) {} \ + else goto skip_ascii_stop_sq##i; + +#define expr_stop(i) \ + skip_ascii_stop_sq##i: \ + src += i; \ + goto skip_ascii_end; + + repeat16_incr(expr_jump) + src += 16; + goto skip_ascii; + repeat16_incr(expr_stop) + +#undef expr_jump +#undef expr_stop + } + +skip_ascii_end: + gcc_store_barrier(*src); + if (likely(*src == quo)) { + val->tag = ((u64)(src - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_STR | + (quo == '"' ? YYJSON_SUBTYPE_NOESC : 0); + val->uni.str = (const char *)hdr; + *src = '\0'; + *end = src + 1; + if (con) con[0] = con[1] = NULL; + return true; + } + +skip_utf8: + if (*src & 0x80) { /* non-ASCII character */ + /* + Non-ASCII character appears here, which means that the text is likely + to be written in non-English or emoticons. According to some common + data set statistics, byte sequences of the same length may appear + consecutively. We process the byte sequences of the same length in each + loop, which is more friendly to branch prediction. + */ + pos = src; +#if YYJSON_DISABLE_UTF8_VALIDATION + while (true) repeat8({ + if (likely((*src & 0xF0) == 0xE0)) src += 3; + else break; + }) + if (*src < 0x80) goto skip_ascii; + while (true) repeat8({ + if (likely((*src & 0xE0) == 0xC0)) src += 2; + else break; + }) + while (true) repeat8({ + if (likely((*src & 0xF8) == 0xF0)) src += 4; + else break; + }) +#else + uni = byte_load_4(src); + while (is_utf8_seq3(uni)) { + src += 3; + uni = byte_load_4(src); + } + if (is_utf8_seq1(uni)) goto skip_ascii; + while (is_utf8_seq2(uni)) { + src += 2; + uni = byte_load_4(src); + } + while (is_utf8_seq4(uni)) { + src += 4; + uni = byte_load_4(src); + } +#endif + if (unlikely(pos == src)) { + if (has_allow(INVALID_UNICODE)) ++src; + else return_err(src, "invalid UTF-8 encoding in string"); + } + goto skip_ascii; + } + + /* The escape character appears, we need to copy it. */ + dst = src; +copy_escape: + if (likely(*src == '\\')) { + switch (*++src) { + case '"': *dst++ = '"'; src++; break; + case '\\': *dst++ = '\\'; src++; break; + case '/': *dst++ = '/'; src++; break; + case 'b': *dst++ = '\b'; src++; break; + case 'f': *dst++ = '\f'; src++; break; + case 'n': *dst++ = '\n'; src++; break; + case 'r': *dst++ = '\r'; src++; break; + case 't': *dst++ = '\t'; src++; break; + case 'u': + src--; + if (!read_uni_esc(&src, &dst, msg)) return_err(src, *msg); + break; + default: { + if (has_allow(EXT_ESCAPE)) { + /* read extended escape (non-standard) */ + switch (*src) { + case '\'': *dst++ = '\''; src++; break; + case 'a': *dst++ = '\a'; src++; break; + case 'v': *dst++ = '\v'; src++; break; + case '?': *dst++ = '\?'; src++; break; + case 'e': *dst++ = 0x1B; src++; break; + case '0': + if (!char_is_digit(src[1])) { + *dst++ = '\0'; src++; break; + } + return_err(src - 1, "octal escape is not allowed"); + case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + return_err(src - 1, "invalid number escape"); + case 'x': { + u8 c; + if (hex_load_2(src + 1, &c)) { + src += 3; + if (c <= 0x7F) { /* 1-byte ASCII */ + *dst++ = c; + } else { /* 2-byte UTF-8 */ + *dst++ = (u8)(0xC0 | (c >> 6)); + *dst++ = (u8)(0x80 | (c & 0x3F)); + } + break; + } + return_err(src - 1, "invalid hex escape"); + } + case '\n': src++; break; + case '\r': src++; src += (*src == '\n'); break; + case 0xE2: /* Line terminator: U+2028, U+2029 */ + if ((src[1] == 0x80 && src[2] == 0xA8) || + (src[1] == 0x80 && src[2] == 0xA9)) { + src += 3; + } + break; + default: + break; /* skip */ + } + } else if (quo == '\'' && *src == '\'') { + *dst++ = '\''; src++; break; + } else { + return_err(src - 1, "invalid escaped sequence in string"); + } + } + } + } else if (likely(*src == quo)) { + val->tag = ((u64)(dst - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; + val->uni.str = (const char *)hdr; + *dst = '\0'; + *end = src + 1; + if (con) con[0] = con[1] = NULL; + return true; + } else { + if (!has_allow(INVALID_UNICODE)) { + return_err(src, "unexpected control character in string"); + } + if (src >= eof) return_err(src, "unclosed string"); + *dst++ = *src++; + } + +copy_ascii: + /* + Copy continuous ASCII, loop unrolling, same as the following code: + + while (true) repeat16({ + if (char_is_ascii_skip(*src)) *dst++ = *src++; + else break; + }) + */ + if (quo == '"') { +#define expr_jump(i) \ + if (likely((char_is_ascii_skip(src[i])))) {} \ + else { gcc_store_barrier(src[i]); goto copy_ascii_stop_##i; } + repeat16_incr(expr_jump) +#undef expr_jump + } else { +#define expr_jump(i) \ + if (likely((char_is_ascii_skip_sq(src[i])))) {} \ + else { gcc_store_barrier(src[i]); goto copy_ascii_stop_##i; } + repeat16_incr(expr_jump) +#undef expr_jump + } + + byte_move_16(dst, src); + dst += 16; src += 16; + goto copy_ascii; + + /* + The memory is copied forward since `dst < src`. + So it's safe to move one extra byte to reduce instruction count. + */ +#define expr_jump(i) \ + copy_ascii_stop_##i: \ + byte_move_forward(dst, src, i); \ + dst += i; src += i; \ + goto copy_utf8; + repeat16_incr(expr_jump) +#undef expr_jump + +copy_utf8: + if (*src & 0x80) { /* non-ASCII character */ + pos = src; + uni = byte_load_4(src); +#if YYJSON_DISABLE_UTF8_VALIDATION + while (true) repeat4({ + if ((uni & utf8_seq(b3_mask)) == utf8_seq(b3_patt)) { + byte_copy_4(dst, &uni); + dst += 3; src += 3; + uni = byte_load_4(src); + } else break; + }) + if ((uni & utf8_seq(b1_mask)) == utf8_seq(b1_patt)) goto copy_ascii; + while (true) repeat4({ + if ((uni & utf8_seq(b2_mask)) == utf8_seq(b2_patt)) { + byte_copy_2(dst, &uni); + dst += 2; src += 2; + uni = byte_load_4(src); + } else break; + }) + while (true) repeat4({ + if ((uni & utf8_seq(b4_mask)) == utf8_seq(b4_patt)) { + byte_copy_4(dst, &uni); + dst += 4; src += 4; + uni = byte_load_4(src); + } else break; + }) +#else + while (is_utf8_seq3(uni)) { + byte_copy_4(dst, &uni); + dst += 3; src += 3; + uni = byte_load_4(src); + } + if (is_utf8_seq1(uni)) goto copy_ascii; + while (is_utf8_seq2(uni)) { + byte_copy_2(dst, &uni); + dst += 2; src += 2; + uni = byte_load_4(src); + } + while (is_utf8_seq4(uni)) { + byte_copy_4(dst, &uni); + dst += 4; src += 4; + uni = byte_load_4(src); + } +#endif + if (unlikely(pos == src)) { + if (!has_allow(INVALID_UNICODE)) { + return_err(src, MSG_ERR_UTF8); + } + goto copy_ascii_stop_1; + } + goto copy_ascii; + } + goto copy_escape; + +#undef return_err +} + +static_inline bool read_str(u8 **ptr, u8 *eof, yyjson_read_flag flg, + yyjson_val *val, const char **msg) { + return read_str_opt('\"', ptr, eof, flg, val, msg, NULL); +} + +static_inline bool read_str_con(u8 **ptr, u8 *eof, yyjson_read_flag flg, + yyjson_val *val, const char **msg, u8 **con) { + return read_str_opt('\"', ptr, eof, flg, val, msg, con); +} + +static_noinline bool read_str_sq(u8 **ptr, u8 *eof, yyjson_read_flag flg, + yyjson_val *val, const char **msg) { + return read_str_opt('\'', ptr, eof, flg, val, msg, NULL); +} + +/** Read unquoted key (identifier name). */ +static_noinline bool read_str_id(u8 **ptr, u8 *eof, yyjson_read_flag flg, + u8 **pre, yyjson_val *val, const char **msg) { +#define return_err(_end, _msg) do { \ + *msg = _msg; \ + *end = _end; \ + return false; \ +} while (false) + +#define return_suc(_str_end, _cur_end) do { \ + val->tag = ((u64)(_str_end - hdr) << YYJSON_TAG_BIT) | \ + (u64)(YYJSON_TYPE_STR); \ + val->uni.str = (const char *)hdr; \ + *pre = _str_end; *end = _cur_end; \ + return true; \ +} while (false) + + u8 *hdr = *ptr; + u8 **end = ptr; + u8 *src = hdr, *dst = NULL; + u16 hi, lo; + u32 uni, tmp; + + /* add null-terminator for previous raw string */ + **pre = '\0'; + +skip_ascii: +#define expr_jump(i) \ + if (likely(char_is_id_ascii(src[i]))) {} \ + else goto skip_ascii_stop##i; + +#define expr_stop(i) \ + skip_ascii_stop##i: \ + src += i; \ + goto skip_ascii_end; + + repeat16_incr(expr_jump) + src += 16; + goto skip_ascii; + repeat16_incr(expr_stop) + +#undef expr_jump +#undef expr_stop + +skip_ascii_end: + gcc_store_barrier(*src); + if (likely(!char_is_id_next(*src))) { + return_suc(src, src); + } + +skip_utf8: + while (*src >= 0x80) { + if (has_allow(EXT_WHITESPACE)) { + if (char_is_space_ext(*src) && ext_space_len(src)) { + return_suc(src, src); + } + } + uni = byte_load_4(src); + if (is_utf8_seq2(uni)) { + src += 2; + } else if (is_utf8_seq3(uni)) { + src += 3; + } else if (is_utf8_seq4(uni)) { + src += 4; + } else { +#if !YYJSON_DISABLE_UTF8_VALIDATION + if (!has_allow(INVALID_UNICODE)) return_err(src, MSG_ERR_UTF8); +#endif + src += 1; + } + } + if (char_is_id_ascii(*src)) goto skip_ascii; + + /* The escape character appears, we need to copy it. */ + dst = src; +copy_escape: + if (byte_match_2(src, "\\u")) { + if (!read_uni_esc(&src, &dst, msg)) return_err(src, *msg); + } else { + if (!char_is_id_next(*src)) return_suc(dst, src); + return_err(src, "unexpected character in key"); + } + +copy_ascii: + /* + Copy continuous ASCII, loop unrolling, same as the following code: + + while (true) repeat16({ + if (char_is_ascii_skip(*src)) *dst++ = *src++; + else break; + }) + */ +#define expr_jump(i) \ + if (likely((char_is_id_ascii(src[i])))) {} \ + else { gcc_store_barrier(src[i]); goto copy_ascii_stop_##i; } + repeat16_incr(expr_jump) +#undef expr_jump + + byte_move_16(dst, src); + dst += 16; src += 16; + goto copy_ascii; + +#define expr_jump(i) \ + copy_ascii_stop_##i: \ + byte_move_forward(dst, src, i); \ + dst += i; src += i; \ + goto copy_utf8; + repeat16_incr(expr_jump) +#undef expr_jump + +copy_utf8: + while (*src >= 0x80) { /* non-ASCII character */ + if (has_allow(EXT_WHITESPACE)) { + if (char_is_space_ext(*src) && ext_space_len(src)) { + return_suc(dst, src); + } + } + uni = byte_load_4(src); + if (is_utf8_seq2(uni)) { + byte_copy_2(dst, &uni); + dst += 2; src += 2; + } else if (is_utf8_seq3(uni)) { + byte_copy_4(dst, &uni); + dst += 3; src += 3; + } else if (is_utf8_seq4(uni)) { + byte_copy_4(dst, &uni); + dst += 4; src += 4; + } else { +#if !YYJSON_DISABLE_UTF8_VALIDATION + if (!has_allow(INVALID_UNICODE)) return_err(src, MSG_ERR_UTF8); +#endif + *dst = *src; + dst += 1; src += 1; + } + } + if (char_is_id_ascii(*src)) goto copy_ascii; + goto copy_escape; + +#undef return_err +#undef return_suc +} + + + +/*============================================================================== + * MARK: - JSON Reader Implementation (Private) + * + * We use goto statements to build the finite state machine (FSM). + * The FSM's state was held by program counter (PC) and the 'goto' make the + * state transitions. + *============================================================================*/ + +/** Read single value JSON document. */ +static_noinline yyjson_doc *read_root_single(u8 *hdr, u8 *cur, u8 *eof, + yyjson_alc alc, + yyjson_read_flag flg, + yyjson_read_err *err) { +#define return_err(_pos, _code, _msg) do { \ + if (is_truncated_end(hdr, _pos, eof, YYJSON_READ_ERROR_##_code, flg)) { \ + err->pos = (usize)(eof - hdr); \ + err->code = YYJSON_READ_ERROR_UNEXPECTED_END; \ + err->msg = MSG_NOT_END; \ + } else { \ + err->pos = (usize)(_pos - hdr); \ + err->code = YYJSON_READ_ERROR_##_code; \ + err->msg = _msg; \ + } \ + if (val_hdr) alc.free(alc.ctx, val_hdr); \ + return NULL; \ +} while (false) + + usize hdr_len; /* value count used by doc */ + usize alc_num; /* value count capacity */ + yyjson_val *val_hdr; /* the head of allocated values */ + yyjson_val *val; /* current value */ + yyjson_doc *doc; /* the JSON document, equals to val_hdr */ + const char *msg; /* error message */ + + u8 raw_end[1]; /* raw end for null-terminator */ + u8 *raw_ptr = raw_end; + u8 **pre = &raw_ptr; /* previous raw end pointer */ + + hdr_len = sizeof(yyjson_doc) / sizeof(yyjson_val); + hdr_len += (sizeof(yyjson_doc) % sizeof(yyjson_val)) > 0; + alc_num = hdr_len + 1; /* single value */ + + val_hdr = (yyjson_val *)alc.malloc(alc.ctx, alc_num * sizeof(yyjson_val)); + if (unlikely(!val_hdr)) goto fail_alloc; + val = val_hdr + hdr_len; + + if (char_is_num(*cur)) { + if (likely(read_num(&cur, pre, flg, val, &msg))) goto doc_end; + goto fail_number; + } + if (*cur == '"') { + if (likely(read_str(&cur, eof, flg, val, &msg))) goto doc_end; + goto fail_string; + } + if (*cur == 't') { + if (likely(read_true(&cur, val))) goto doc_end; + goto fail_literal_true; + } + if (*cur == 'f') { + if (likely(read_false(&cur, val))) goto doc_end; + goto fail_literal_false; + } + if (*cur == 'n') { + if (likely(read_null(&cur, val))) goto doc_end; + if (has_allow(INF_AND_NAN)) { + if (read_nan(&cur, pre, flg, val)) goto doc_end; + } + goto fail_literal_null; + } + if (has_allow(INF_AND_NAN)) { + if (read_inf_or_nan(&cur, pre, flg, val)) goto doc_end; + } + if (has_allow(SINGLE_QUOTED_STR) && *cur == '\'') { + if (likely(read_str_sq(&cur, eof, flg, val, &msg))) goto doc_end; + goto fail_string; + } + goto fail_character; + +doc_end: + /* check invalid contents after json document */ + if (unlikely(cur < eof) && !has_flg(STOP_WHEN_DONE)) { + while (char_is_space(*cur)) cur++; + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (!skip_trivia(&cur, eof, flg) && cur == eof) { + goto fail_comment; + } + } + if (unlikely(cur < eof)) goto fail_garbage; + } + + **pre = '\0'; + doc = (yyjson_doc *)val_hdr; + doc->root = val_hdr + hdr_len; + doc->alc = alc; + doc->dat_read = (usize)(cur - hdr); + doc->val_read = 1; + doc->str_pool = has_flg(INSITU) ? NULL : (char *)hdr; + return doc; + +fail_string: return_err(cur, INVALID_STRING, msg); +fail_number: return_err(cur, INVALID_NUMBER, msg); +fail_alloc: return_err(cur, MEMORY_ALLOCATION, MSG_MALLOC); +fail_literal_true: return_err(cur, LITERAL, MSG_CHAR_T); +fail_literal_false: return_err(cur, LITERAL, MSG_CHAR_F); +fail_literal_null: return_err(cur, LITERAL, MSG_CHAR_N); +fail_character: return_err(cur, UNEXPECTED_CHARACTER, MSG_CHAR); +fail_comment: return_err(cur, INVALID_COMMENT, MSG_COMMENT); +fail_garbage: return_err(cur, UNEXPECTED_CONTENT, MSG_GARBAGE); + +#undef return_err +} + +/** Read JSON document (accept all style, but optimized for minify). */ +static_inline yyjson_doc *read_root_minify(u8 *hdr, u8 *cur, u8 *eof, + yyjson_alc alc, + yyjson_read_flag flg, + yyjson_read_err *err) { +#define return_err(_pos, _code, _msg) do { \ + if (is_truncated_end(hdr, _pos, eof, YYJSON_READ_ERROR_##_code, flg)) { \ + err->pos = (usize)(eof - hdr); \ + err->code = YYJSON_READ_ERROR_UNEXPECTED_END; \ + err->msg = MSG_NOT_END; \ + } else { \ + err->pos = (usize)(_pos - hdr); \ + err->code = YYJSON_READ_ERROR_##_code; \ + err->msg = _msg; \ + } \ + if (val_hdr) alc.free(alc.ctx, val_hdr); \ + return NULL; \ +} while (false) + +#define val_incr() do { \ + val++; \ + if (unlikely(val >= val_end)) { \ + usize alc_old = alc_len; \ + usize val_ofs = (usize)(val - val_hdr); \ + usize ctn_ofs = (usize)(ctn - val_hdr); \ + alc_len += alc_len / 2; \ + if ((sizeof(usize) < 8) && (alc_len >= alc_max)) goto fail_alloc; \ + val_tmp = (yyjson_val *)alc.realloc(alc.ctx, (void *)val_hdr, \ + alc_old * sizeof(yyjson_val), \ + alc_len * sizeof(yyjson_val)); \ + if ((!val_tmp)) goto fail_alloc; \ + val = val_tmp + val_ofs; \ + ctn = val_tmp + ctn_ofs; \ + val_hdr = val_tmp; \ + val_end = val_tmp + (alc_len - 2); \ + } \ +} while (false) + + usize dat_len; /* data length in bytes, hint for allocator */ + usize hdr_len; /* value count used by yyjson_doc */ + usize alc_len; /* value count allocated */ + usize alc_max; /* maximum value count for allocator */ + usize ctn_len; /* the number of elements in current container */ + yyjson_val *val_hdr; /* the head of allocated values */ + yyjson_val *val_end; /* the end of allocated values */ + yyjson_val *val_tmp; /* temporary pointer for realloc */ + yyjson_val *val; /* current JSON value */ + yyjson_val *ctn; /* current container */ + yyjson_val *ctn_parent; /* parent of current container */ + yyjson_doc *doc; /* the JSON document, equals to val_hdr */ + const char *msg; /* error message */ + + u8 raw_end[1]; /* raw end for null-terminator */ + u8 *raw_ptr = raw_end; + u8 **pre = &raw_ptr; /* previous raw end pointer */ + + dat_len = has_flg(STOP_WHEN_DONE) ? 256 : (usize)(eof - cur); + hdr_len = sizeof(yyjson_doc) / sizeof(yyjson_val); + hdr_len += (sizeof(yyjson_doc) % sizeof(yyjson_val)) > 0; + alc_max = USIZE_MAX / sizeof(yyjson_val); + alc_len = hdr_len + (dat_len / YYJSON_READER_ESTIMATED_MINIFY_RATIO) + 4; + alc_len = yyjson_min(alc_len, alc_max); + + val_hdr = (yyjson_val *)alc.malloc(alc.ctx, alc_len * sizeof(yyjson_val)); + if (unlikely(!val_hdr)) goto fail_alloc; + val_end = val_hdr + (alc_len - 2); /* padding for key-value pair reading */ + val = val_hdr + hdr_len; + ctn = val; + ctn_len = 0; + + if (*cur++ == '{') { + ctn->tag = YYJSON_TYPE_OBJ; + ctn->uni.ofs = 0; + goto obj_key_begin; + } else { + ctn->tag = YYJSON_TYPE_ARR; + ctn->uni.ofs = 0; + goto arr_val_begin; + } + +arr_begin: + /* save current container */ + ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) | + (ctn->tag & YYJSON_TAG_MASK); + + /* create a new array value, save parent container offset */ + val_incr(); + val->tag = YYJSON_TYPE_ARR; + val->uni.ofs = (usize)((u8 *)val - (u8 *)ctn); + + /* push the new array value as current container */ + ctn = val; + ctn_len = 0; + +arr_val_begin: + if (*cur == '{') { + cur++; + goto obj_begin; + } + if (*cur == '[') { + cur++; + goto arr_begin; + } + if (char_is_num(*cur)) { + val_incr(); + ctn_len++; + if (likely(read_num(&cur, pre, flg, val, &msg))) goto arr_val_end; + goto fail_number; + } + if (*cur == '"') { + val_incr(); + ctn_len++; + if (likely(read_str(&cur, eof, flg, val, &msg))) goto arr_val_end; + goto fail_string; + } + if (*cur == 't') { + val_incr(); + ctn_len++; + if (likely(read_true(&cur, val))) goto arr_val_end; + goto fail_literal_true; + } + if (*cur == 'f') { + val_incr(); + ctn_len++; + if (likely(read_false(&cur, val))) goto arr_val_end; + goto fail_literal_false; + } + if (*cur == 'n') { + val_incr(); + ctn_len++; + if (likely(read_null(&cur, val))) goto arr_val_end; + if (has_allow(INF_AND_NAN)) { + if (read_nan(&cur, pre, flg, val)) goto arr_val_end; + } + goto fail_literal_null; + } + if (*cur == ']') { + cur++; + if (likely(ctn_len == 0)) goto arr_end; + if (has_allow(TRAILING_COMMAS)) goto arr_end; + while (*cur != ',') cur--; + goto fail_trailing_comma; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto arr_val_begin; + } + if (has_allow(INF_AND_NAN) && + (*cur == 'i' || *cur == 'I' || *cur == 'N')) { + val_incr(); + ctn_len++; + if (read_inf_or_nan(&cur, pre, flg, val)) goto arr_val_end; + goto fail_character_val; + } + if (has_allow(SINGLE_QUOTED_STR) && *cur == '\'') { + val_incr(); + ctn_len++; + if (likely(read_str_sq(&cur, eof, flg, val, &msg))) goto arr_val_end; + goto fail_string; + } + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (skip_trivia(&cur, eof, flg)) goto arr_val_begin; + if (cur == eof) goto fail_comment; + } + goto fail_character_val; + +arr_val_end: + if (*cur == ',') { + cur++; + goto arr_val_begin; + } + if (*cur == ']') { + cur++; + goto arr_end; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto arr_val_end; + } + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (skip_trivia(&cur, eof, flg)) goto arr_val_end; + if (cur == eof) goto fail_comment; + } + goto fail_character_arr_end; + +arr_end: + /* get parent container */ + ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs); + + /* save the next sibling value offset */ + ctn->uni.ofs = (usize)((u8 *)val - (u8 *)ctn) + sizeof(yyjson_val); + ctn->tag = ((ctn_len) << YYJSON_TAG_BIT) | YYJSON_TYPE_ARR; + if (unlikely(ctn == ctn_parent)) goto doc_end; + + /* pop parent as current container */ + ctn = ctn_parent; + ctn_len = (usize)(ctn->tag >> YYJSON_TAG_BIT); + if ((ctn->tag & YYJSON_TYPE_MASK) == YYJSON_TYPE_OBJ) { + goto obj_val_end; + } else { + goto arr_val_end; + } + +obj_begin: + /* push container */ + ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) | + (ctn->tag & YYJSON_TAG_MASK); + val_incr(); + val->tag = YYJSON_TYPE_OBJ; + /* offset to the parent */ + val->uni.ofs = (usize)((u8 *)val - (u8 *)ctn); + ctn = val; + ctn_len = 0; + +obj_key_begin: + if (likely(*cur == '"')) { + val_incr(); + ctn_len++; + if (likely(read_str(&cur, eof, flg, val, &msg))) goto obj_key_end; + goto fail_string; + } + if (likely(*cur == '}')) { + cur++; + if (likely(ctn_len == 0)) goto obj_end; + if (has_allow(TRAILING_COMMAS)) goto obj_end; + while (*cur != ',') cur--; + goto fail_trailing_comma; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto obj_key_begin; + } + if (has_allow(SINGLE_QUOTED_STR) && *cur == '\'') { + val_incr(); + ctn_len++; + if (likely(read_str_sq(&cur, eof, flg, val, &msg))) goto obj_key_end; + goto fail_string; + } + if (has_allow(UNQUOTED_KEY) && char_is_id_start(*cur)) { + val_incr(); + ctn_len++; + if (read_str_id(&cur, eof, flg, pre, val, &msg)) goto obj_key_end; + goto fail_string; + } + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (skip_trivia(&cur, eof, flg)) goto obj_key_begin; + if (cur == eof) goto fail_comment; + } + goto fail_character_obj_key; + +obj_key_end: + if (*cur == ':') { + cur++; + goto obj_val_begin; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto obj_key_end; + } + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (skip_trivia(&cur, eof, flg)) goto obj_key_end; + if (cur == eof) goto fail_comment; + } + goto fail_character_obj_sep; + +obj_val_begin: + if (*cur == '"') { + val++; + ctn_len++; + if (likely(read_str(&cur, eof, flg, val, &msg))) goto obj_val_end; + goto fail_string; + } + if (char_is_num(*cur)) { + val++; + ctn_len++; + if (likely(read_num(&cur, pre, flg, val, &msg))) goto obj_val_end; + goto fail_number; + } + if (*cur == '{') { + cur++; + goto obj_begin; + } + if (*cur == '[') { + cur++; + goto arr_begin; + } + if (*cur == 't') { + val++; + ctn_len++; + if (likely(read_true(&cur, val))) goto obj_val_end; + goto fail_literal_true; + } + if (*cur == 'f') { + val++; + ctn_len++; + if (likely(read_false(&cur, val))) goto obj_val_end; + goto fail_literal_false; + } + if (*cur == 'n') { + val++; + ctn_len++; + if (likely(read_null(&cur, val))) goto obj_val_end; + if (has_allow(INF_AND_NAN)) { + if (read_nan(&cur, pre, flg, val)) goto obj_val_end; + } + goto fail_literal_null; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto obj_val_begin; + } + if (has_allow(INF_AND_NAN) && + (*cur == 'i' || *cur == 'I' || *cur == 'N')) { + val++; + ctn_len++; + if (read_inf_or_nan(&cur, pre, flg, val)) goto obj_val_end; + goto fail_character_val; + } + if (has_allow(SINGLE_QUOTED_STR) && *cur == '\'') { + val++; + ctn_len++; + if (likely(read_str_sq(&cur, eof, flg, val, &msg))) goto obj_val_end; + goto fail_string; + } + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (skip_trivia(&cur, eof, flg)) goto obj_val_begin; + if (cur == eof) goto fail_comment; + } + goto fail_character_val; + +obj_val_end: + if (likely(*cur == ',')) { + cur++; + goto obj_key_begin; + } + if (likely(*cur == '}')) { + cur++; + goto obj_end; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto obj_val_end; + } + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (skip_trivia(&cur, eof, flg)) goto obj_val_end; + if (cur == eof) goto fail_comment; + } + goto fail_character_obj_end; + +obj_end: + /* pop container */ + ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs); + /* point to the next value */ + ctn->uni.ofs = (usize)((u8 *)val - (u8 *)ctn) + sizeof(yyjson_val); + ctn->tag = (ctn_len << (YYJSON_TAG_BIT - 1)) | YYJSON_TYPE_OBJ; + if (unlikely(ctn == ctn_parent)) goto doc_end; + ctn = ctn_parent; + ctn_len = (usize)(ctn->tag >> YYJSON_TAG_BIT); + if ((ctn->tag & YYJSON_TYPE_MASK) == YYJSON_TYPE_OBJ) { + goto obj_val_end; + } else { + goto arr_val_end; + } + +doc_end: + /* check invalid contents after json document */ + if (unlikely(cur < eof) && !has_flg(STOP_WHEN_DONE)) { + while (char_is_space(*cur)) cur++; + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (!skip_trivia(&cur, eof, flg) && cur == eof) { + goto fail_comment; + } + } + if (unlikely(cur < eof)) goto fail_garbage; + } + + **pre = '\0'; + doc = (yyjson_doc *)val_hdr; + doc->root = val_hdr + hdr_len; + doc->alc = alc; + doc->dat_read = (usize)(cur - hdr); + doc->val_read = (usize)((val - doc->root) + 1); + doc->str_pool = has_flg(INSITU) ? NULL : (char *)hdr; + return doc; + +fail_string: return_err(cur, INVALID_STRING, msg); +fail_number: return_err(cur, INVALID_NUMBER, msg); +fail_alloc: return_err(cur, MEMORY_ALLOCATION, MSG_MALLOC); +fail_trailing_comma: return_err(cur, JSON_STRUCTURE, MSG_COMMA); +fail_literal_true: return_err(cur, LITERAL, MSG_CHAR_T); +fail_literal_false: return_err(cur, LITERAL, MSG_CHAR_F); +fail_literal_null: return_err(cur, LITERAL, MSG_CHAR_N); +fail_character_val: return_err(cur, UNEXPECTED_CHARACTER, MSG_CHAR); +fail_character_arr_end: return_err(cur, UNEXPECTED_CHARACTER, MSG_ARR_END); +fail_character_obj_key: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_KEY); +fail_character_obj_sep: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_SEP); +fail_character_obj_end: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_END); +fail_comment: return_err(cur, INVALID_COMMENT, MSG_COMMENT); +fail_garbage: return_err(cur, UNEXPECTED_CONTENT, MSG_GARBAGE); + +#undef val_incr +#undef return_err +} + +/** Read JSON document (accept all style, but optimized for pretty). */ +static_inline yyjson_doc *read_root_pretty(u8 *hdr, u8 *cur, u8 *eof, + yyjson_alc alc, + yyjson_read_flag flg, + yyjson_read_err *err) { +#define return_err(_pos, _code, _msg) do { \ + if (is_truncated_end(hdr, _pos, eof, YYJSON_READ_ERROR_##_code, flg)) { \ + err->pos = (usize)(eof - hdr); \ + err->code = YYJSON_READ_ERROR_UNEXPECTED_END; \ + err->msg = MSG_NOT_END; \ + } else { \ + err->pos = (usize)(_pos - hdr); \ + err->code = YYJSON_READ_ERROR_##_code; \ + err->msg = _msg; \ + } \ + if (val_hdr) alc.free(alc.ctx, val_hdr); \ + return NULL; \ +} while (false) + +#define val_incr() do { \ + val++; \ + if (unlikely(val >= val_end)) { \ + usize alc_old = alc_len; \ + usize val_ofs = (usize)(val - val_hdr); \ + usize ctn_ofs = (usize)(ctn - val_hdr); \ + alc_len += alc_len / 2; \ + if ((sizeof(usize) < 8) && (alc_len >= alc_max)) goto fail_alloc; \ + val_tmp = (yyjson_val *)alc.realloc(alc.ctx, (void *)val_hdr, \ + alc_old * sizeof(yyjson_val), \ + alc_len * sizeof(yyjson_val)); \ + if ((!val_tmp)) goto fail_alloc; \ + val = val_tmp + val_ofs; \ + ctn = val_tmp + ctn_ofs; \ + val_hdr = val_tmp; \ + val_end = val_tmp + (alc_len - 2); \ + } \ +} while (false) + + usize dat_len; /* data length in bytes, hint for allocator */ + usize hdr_len; /* value count used by yyjson_doc */ + usize alc_len; /* value count allocated */ + usize alc_max; /* maximum value count for allocator */ + usize ctn_len; /* the number of elements in current container */ + yyjson_val *val_hdr; /* the head of allocated values */ + yyjson_val *val_end; /* the end of allocated values */ + yyjson_val *val_tmp; /* temporary pointer for realloc */ + yyjson_val *val; /* current JSON value */ + yyjson_val *ctn; /* current container */ + yyjson_val *ctn_parent; /* parent of current container */ + yyjson_doc *doc; /* the JSON document, equals to val_hdr */ + const char *msg; /* error message */ + + u8 raw_end[1]; /* raw end for null-terminator */ + u8 *raw_ptr = raw_end; + u8 **pre = &raw_ptr; /* previous raw end pointer */ + + dat_len = has_flg(STOP_WHEN_DONE) ? 256 : (usize)(eof - cur); + hdr_len = sizeof(yyjson_doc) / sizeof(yyjson_val); + hdr_len += (sizeof(yyjson_doc) % sizeof(yyjson_val)) > 0; + alc_max = USIZE_MAX / sizeof(yyjson_val); + alc_len = hdr_len + (dat_len / YYJSON_READER_ESTIMATED_PRETTY_RATIO) + 4; + alc_len = yyjson_min(alc_len, alc_max); + + val_hdr = (yyjson_val *)alc.malloc(alc.ctx, alc_len * sizeof(yyjson_val)); + if (unlikely(!val_hdr)) goto fail_alloc; + val_end = val_hdr + (alc_len - 2); /* padding for key-value pair reading */ + val = val_hdr + hdr_len; + ctn = val; + ctn_len = 0; + + if (*cur++ == '{') { + ctn->tag = YYJSON_TYPE_OBJ; + ctn->uni.ofs = 0; + if (*cur == '\n') cur++; + goto obj_key_begin; + } else { + ctn->tag = YYJSON_TYPE_ARR; + ctn->uni.ofs = 0; + if (*cur == '\n') cur++; + goto arr_val_begin; + } + +arr_begin: + /* save current container */ + ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) | + (ctn->tag & YYJSON_TAG_MASK); + + /* create a new array value, save parent container offset */ + val_incr(); + val->tag = YYJSON_TYPE_ARR; + val->uni.ofs = (usize)((u8 *)val - (u8 *)ctn); + + /* push the new array value as current container */ + ctn = val; + ctn_len = 0; + if (*cur == '\n') cur++; + +arr_val_begin: +#if YYJSON_IS_REAL_GCC + while (true) repeat16({ + if (byte_match_2(cur, " ")) cur += 2; + else break; + }) +#else + while (true) repeat16({ + if (likely(byte_match_2(cur, " "))) cur += 2; + else break; + }) +#endif + + if (*cur == '{') { + cur++; + goto obj_begin; + } + if (*cur == '[') { + cur++; + goto arr_begin; + } + if (char_is_num(*cur)) { + val_incr(); + ctn_len++; + if (likely(read_num(&cur, pre, flg, val, &msg))) goto arr_val_end; + goto fail_number; + } + if (*cur == '"') { + val_incr(); + ctn_len++; + if (likely(read_str(&cur, eof, flg, val, &msg))) goto arr_val_end; + goto fail_string; + } + if (*cur == 't') { + val_incr(); + ctn_len++; + if (likely(read_true(&cur, val))) goto arr_val_end; + goto fail_literal_true; + } + if (*cur == 'f') { + val_incr(); + ctn_len++; + if (likely(read_false(&cur, val))) goto arr_val_end; + goto fail_literal_false; + } + if (*cur == 'n') { + val_incr(); + ctn_len++; + if (likely(read_null(&cur, val))) goto arr_val_end; + if (has_allow(INF_AND_NAN)) { + if (read_nan(&cur, pre, flg, val)) goto arr_val_end; + } + goto fail_literal_null; + } + if (*cur == ']') { + cur++; + if (likely(ctn_len == 0)) goto arr_end; + if (has_allow(TRAILING_COMMAS)) goto arr_end; + while (*cur != ',') cur--; + goto fail_trailing_comma; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto arr_val_begin; + } + if (has_allow(INF_AND_NAN) && + (*cur == 'i' || *cur == 'I' || *cur == 'N')) { + val_incr(); + ctn_len++; + if (read_inf_or_nan(&cur, pre, flg, val)) goto arr_val_end; + goto fail_character_val; + } + if (has_allow(SINGLE_QUOTED_STR) && *cur == '\'') { + val_incr(); + ctn_len++; + if (likely(read_str_sq(&cur, eof, flg, val, &msg))) goto arr_val_end; + goto fail_string; + } + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (skip_trivia(&cur, eof, flg)) goto arr_val_begin; + if (cur == eof) goto fail_comment; + } + goto fail_character_val; + +arr_val_end: + if (byte_match_2(cur, ",\n")) { + cur += 2; + goto arr_val_begin; + } + if (*cur == ',') { + cur++; + goto arr_val_begin; + } + if (*cur == ']') { + cur++; + goto arr_end; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto arr_val_end; + } + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (skip_trivia(&cur, eof, flg)) goto arr_val_end; + if (cur == eof) goto fail_comment; + } + goto fail_character_arr_end; + +arr_end: + /* get parent container */ + ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs); + + /* save the next sibling value offset */ + ctn->uni.ofs = (usize)((u8 *)val - (u8 *)ctn) + sizeof(yyjson_val); + ctn->tag = ((ctn_len) << YYJSON_TAG_BIT) | YYJSON_TYPE_ARR; + if (unlikely(ctn == ctn_parent)) goto doc_end; + + /* pop parent as current container */ + ctn = ctn_parent; + ctn_len = (usize)(ctn->tag >> YYJSON_TAG_BIT); + if (*cur == '\n') cur++; + if ((ctn->tag & YYJSON_TYPE_MASK) == YYJSON_TYPE_OBJ) { + goto obj_val_end; + } else { + goto arr_val_end; + } + +obj_begin: + /* push container */ + ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) | + (ctn->tag & YYJSON_TAG_MASK); + val_incr(); + val->tag = YYJSON_TYPE_OBJ; + /* offset to the parent */ + val->uni.ofs = (usize)((u8 *)val - (u8 *)ctn); + ctn = val; + ctn_len = 0; + if (*cur == '\n') cur++; + +obj_key_begin: +#if YYJSON_IS_REAL_GCC + while (true) repeat16({ + if (byte_match_2(cur, " ")) cur += 2; + else break; + }) +#else + while (true) repeat16({ + if (likely(byte_match_2(cur, " "))) cur += 2; + else break; + }) +#endif + if (likely(*cur == '"')) { + val_incr(); + ctn_len++; + if (likely(read_str(&cur, eof, flg, val, &msg))) goto obj_key_end; + goto fail_string; + } + if (likely(*cur == '}')) { + cur++; + if (likely(ctn_len == 0)) goto obj_end; + if (has_allow(TRAILING_COMMAS)) goto obj_end; + while (*cur != ',') cur--; + goto fail_trailing_comma; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto obj_key_begin; + } + if (has_allow(SINGLE_QUOTED_STR) && *cur == '\'') { + val_incr(); + ctn_len++; + if (likely(read_str_sq(&cur, eof, flg, val, &msg))) goto obj_key_end; + goto fail_string; + } + if (has_allow(UNQUOTED_KEY) && char_is_id_start(*cur)) { + val_incr(); + ctn_len++; + if (read_str_id(&cur, eof, flg, pre, val, &msg)) goto obj_key_end; + goto fail_string; + } + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (skip_trivia(&cur, eof, flg)) goto obj_key_begin; + if (cur == eof) goto fail_comment; + } + goto fail_character_obj_key; + +obj_key_end: + if (byte_match_2(cur, ": ")) { + cur += 2; + goto obj_val_begin; + } + if (*cur == ':') { + cur++; + goto obj_val_begin; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto obj_key_end; + } + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (skip_trivia(&cur, eof, flg)) goto obj_key_end; + if (cur == eof) goto fail_comment; + } + goto fail_character_obj_sep; + +obj_val_begin: + if (*cur == '"') { + val++; + ctn_len++; + if (likely(read_str(&cur, eof, flg, val, &msg))) goto obj_val_end; + goto fail_string; + } + if (char_is_num(*cur)) { + val++; + ctn_len++; + if (likely(read_num(&cur, pre, flg, val, &msg))) goto obj_val_end; + goto fail_number; + } + if (*cur == '{') { + cur++; + goto obj_begin; + } + if (*cur == '[') { + cur++; + goto arr_begin; + } + if (*cur == 't') { + val++; + ctn_len++; + if (likely(read_true(&cur, val))) goto obj_val_end; + goto fail_literal_true; + } + if (*cur == 'f') { + val++; + ctn_len++; + if (likely(read_false(&cur, val))) goto obj_val_end; + goto fail_literal_false; + } + if (*cur == 'n') { + val++; + ctn_len++; + if (likely(read_null(&cur, val))) goto obj_val_end; + if (has_allow(INF_AND_NAN)) { + if (read_nan(&cur, pre, flg, val)) goto obj_val_end; + } + goto fail_literal_null; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto obj_val_begin; + } + if (has_allow(INF_AND_NAN) && + (*cur == 'i' || *cur == 'I' || *cur == 'N')) { + val++; + ctn_len++; + if (read_inf_or_nan(&cur, pre, flg, val)) goto obj_val_end; + goto fail_character_val; + } + if (has_allow(SINGLE_QUOTED_STR) && *cur == '\'') { + val++; + ctn_len++; + if (likely(read_str_sq(&cur, eof, flg, val, &msg))) goto obj_val_end; + goto fail_string; + } + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (skip_trivia(&cur, eof, flg)) goto obj_val_begin; + if (cur == eof) goto fail_comment; + } + goto fail_character_val; + +obj_val_end: + if (byte_match_2(cur, ",\n")) { + cur += 2; + goto obj_key_begin; + } + if (likely(*cur == ',')) { + cur++; + goto obj_key_begin; + } + if (likely(*cur == '}')) { + cur++; + goto obj_end; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto obj_val_end; + } + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (skip_trivia(&cur, eof, flg)) goto obj_val_end; + if (cur == eof) goto fail_comment; + } + goto fail_character_obj_end; + +obj_end: + /* pop container */ + ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs); + /* point to the next value */ + ctn->uni.ofs = (usize)((u8 *)val - (u8 *)ctn) + sizeof(yyjson_val); + ctn->tag = (ctn_len << (YYJSON_TAG_BIT - 1)) | YYJSON_TYPE_OBJ; + if (unlikely(ctn == ctn_parent)) goto doc_end; + ctn = ctn_parent; + ctn_len = (usize)(ctn->tag >> YYJSON_TAG_BIT); + if (*cur == '\n') cur++; + if ((ctn->tag & YYJSON_TYPE_MASK) == YYJSON_TYPE_OBJ) { + goto obj_val_end; + } else { + goto arr_val_end; + } + +doc_end: + /* check invalid contents after json document */ + if (unlikely(cur < eof) && !has_flg(STOP_WHEN_DONE)) { + while (char_is_space(*cur)) cur++; + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (!skip_trivia(&cur, eof, flg) && cur == eof) { + goto fail_comment; + } + } + if (unlikely(cur < eof)) goto fail_garbage; + } + + **pre = '\0'; + doc = (yyjson_doc *)val_hdr; + doc->root = val_hdr + hdr_len; + doc->alc = alc; + doc->dat_read = (usize)(cur - hdr); + doc->val_read = (usize)((val - doc->root) + 1); + doc->str_pool = has_flg(INSITU) ? NULL : (char *)hdr; + return doc; + +fail_string: return_err(cur, INVALID_STRING, msg); +fail_number: return_err(cur, INVALID_NUMBER, msg); +fail_alloc: return_err(cur, MEMORY_ALLOCATION, MSG_MALLOC); +fail_trailing_comma: return_err(cur, JSON_STRUCTURE, MSG_COMMA); +fail_literal_true: return_err(cur, LITERAL, MSG_CHAR_T); +fail_literal_false: return_err(cur, LITERAL, MSG_CHAR_F); +fail_literal_null: return_err(cur, LITERAL, MSG_CHAR_N); +fail_character_val: return_err(cur, UNEXPECTED_CHARACTER, MSG_CHAR); +fail_character_arr_end: return_err(cur, UNEXPECTED_CHARACTER, MSG_ARR_END); +fail_character_obj_key: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_KEY); +fail_character_obj_sep: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_SEP); +fail_character_obj_end: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_END); +fail_comment: return_err(cur, INVALID_COMMENT, MSG_COMMENT); +fail_garbage: return_err(cur, UNEXPECTED_CONTENT, MSG_GARBAGE); + +#undef val_incr +#undef return_err +} + + + +/*============================================================================== + * MARK: - JSON Reader (Public) + *============================================================================*/ + +yyjson_doc *yyjson_read_opts(char *dat, usize len, + yyjson_read_flag flg, + const yyjson_alc *alc_ptr, + yyjson_read_err *err) { +#define return_err(_pos, _code, _msg) do { \ + err->pos = (usize)(_pos); \ + err->msg = _msg; \ + err->code = YYJSON_READ_ERROR_##_code; \ + if (!has_flg(INSITU) && hdr) alc.free(alc.ctx, (void *)hdr); \ + return NULL; \ +} while (false) + + yyjson_read_err tmp_err; + yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC; + yyjson_doc *doc; + u8 *hdr = NULL, *eof, *cur; + + /* validate input parameters */ + if (!err) err = &tmp_err; + if (unlikely(!dat)) return_err(0, INVALID_PARAMETER, "input data is NULL"); + if (unlikely(!len)) return_err(0, INVALID_PARAMETER, "input length is 0"); + + /* add 4-byte zero padding for input data if necessary */ + if (has_flg(INSITU)) { + hdr = (u8 *)dat; + eof = (u8 *)dat + len; + cur = (u8 *)dat; + } else { + if (unlikely(len >= USIZE_MAX - YYJSON_PADDING_SIZE)) { + return_err(0, MEMORY_ALLOCATION, MSG_MALLOC); + } + hdr = (u8 *)alc.malloc(alc.ctx, len + YYJSON_PADDING_SIZE); + if (unlikely(!hdr)) { + return_err(0, MEMORY_ALLOCATION, MSG_MALLOC); + } + eof = hdr + len; + cur = hdr; + memcpy(hdr, dat, len); + } + memset(eof, 0, YYJSON_PADDING_SIZE); + + if (has_allow(BOM)) { + if (len >= 3 && is_utf8_bom(cur)) cur += 3; + } + + /* skip empty contents before json document */ + if (unlikely(!char_is_ctn(*cur))) { + while (char_is_space(*cur)) cur++; + if (unlikely(!char_is_ctn(*cur))) { + if (has_allow(TRIVIA) && char_is_trivia(*cur)) { + if (!skip_trivia(&cur, eof, flg) && cur == eof) { + return_err(cur - hdr, INVALID_COMMENT, MSG_COMMENT); + } + } + } + if (unlikely(cur >= eof)) { + return_err(0, EMPTY_CONTENT, "input data is empty"); + } + } + + /* read json document */ + if (likely(char_is_ctn(*cur))) { + if (char_is_space(cur[1]) && char_is_space(cur[2])) { + doc = read_root_pretty(hdr, cur, eof, alc, flg, err); + } else { + doc = read_root_minify(hdr, cur, eof, alc, flg, err); + } + } else { + doc = read_root_single(hdr, cur, eof, alc, flg, err); + } + + /* check result */ + if (likely(doc)) { + memset(err, 0, sizeof(yyjson_read_err)); + } else { + /* RFC 8259: JSON text MUST be encoded using UTF-8 */ + if (err->pos == 0 && err->code != YYJSON_READ_ERROR_MEMORY_ALLOCATION) { + if (is_utf8_bom(hdr)) err->msg = MSG_ERR_BOM; + else if (len >= 4 && is_utf32_bom(hdr)) err->msg = MSG_ERR_UTF32; + else if (len >= 2 && is_utf16_bom(hdr)) err->msg = MSG_ERR_UTF16; + } + if (!has_flg(INSITU)) alc.free(alc.ctx, hdr); + } + return doc; + +#undef return_err +} + +yyjson_doc *yyjson_read_file(const char *path, + yyjson_read_flag flg, + const yyjson_alc *alc_ptr, + yyjson_read_err *err) { +#define return_err(_code, _msg) do { \ + err->pos = 0; \ + err->msg = _msg; \ + err->code = YYJSON_READ_ERROR_##_code; \ + return NULL; \ +} while (false) + + yyjson_read_err tmp_err; + yyjson_doc *doc; + FILE *file; + + if (!err) err = &tmp_err; + if (unlikely(!path)) return_err(INVALID_PARAMETER, "input path is NULL"); + + file = fopen_readonly(path); + if (unlikely(!file)) return_err(FILE_OPEN, MSG_FREAD); + + doc = yyjson_read_fp(file, flg, alc_ptr, err); + fclose(file); + return doc; + +#undef return_err +} + +yyjson_doc *yyjson_read_fp(FILE *file, + yyjson_read_flag flg, + const yyjson_alc *alc_ptr, + yyjson_read_err *err) { +#define return_err(_code, _msg) do { \ + err->pos = 0; \ + err->msg = _msg; \ + err->code = YYJSON_READ_ERROR_##_code; \ + if (buf) alc.free(alc.ctx, buf); \ + return NULL; \ +} while (false) + + yyjson_read_err tmp_err; + yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC; + yyjson_doc *doc; + + long file_size = 0, file_pos; + void *buf = NULL; + usize buf_size = 0; + + /* validate input parameters */ + if (!err) err = &tmp_err; + if (unlikely(!file)) return_err(INVALID_PARAMETER, "input file is NULL"); + + /* get current position */ + file_pos = ftell(file); + if (file_pos != -1) { + /* get total file size, may fail */ + if (fseek(file, 0, SEEK_END) == 0) file_size = ftell(file); + /* reset to original position, may fail */ + if (fseek(file, file_pos, SEEK_SET) != 0) file_size = 0; + /* get file size from current postion to end */ + if (file_size > 0) file_size -= file_pos; + } + + /* read file */ + if (file_size > 0) { + /* read the entire file in one call */ + buf_size = (usize)file_size + YYJSON_PADDING_SIZE; + buf = alc.malloc(alc.ctx, buf_size); + if (buf == NULL) { + return_err(MEMORY_ALLOCATION, MSG_MALLOC); + } + if (fread_safe(buf, (usize)file_size, file) != (usize)file_size) { + return_err(FILE_READ, MSG_FREAD); + } + } else { + /* failed to get file size, read it as a stream */ + usize chunk_min = (usize)64; + usize chunk_max = (usize)512 * 1024 * 1024; + usize chunk_now = chunk_min; + usize read_size; + void *tmp; + + buf_size = YYJSON_PADDING_SIZE; + while (true) { + if (buf_size + chunk_now < buf_size) { /* overflow */ + return_err(MEMORY_ALLOCATION, MSG_MALLOC); + } + buf_size += chunk_now; + if (!buf) { + buf = alc.malloc(alc.ctx, buf_size); + if (!buf) return_err(MEMORY_ALLOCATION, MSG_MALLOC); + } else { + tmp = alc.realloc(alc.ctx, buf, buf_size - chunk_now, buf_size); + if (!tmp) return_err(MEMORY_ALLOCATION, MSG_MALLOC); + buf = tmp; + } + tmp = ((u8 *)buf) + buf_size - YYJSON_PADDING_SIZE - chunk_now; + read_size = fread_safe(tmp, chunk_now, file); + file_size += (long)read_size; + if (read_size != chunk_now) break; + + chunk_now *= 2; + if (chunk_now > chunk_max) chunk_now = chunk_max; + } + } + + /* read JSON */ + memset((u8 *)buf + file_size, 0, YYJSON_PADDING_SIZE); + flg |= YYJSON_READ_INSITU; + doc = yyjson_read_opts((char *)buf, (usize)file_size, flg, &alc, err); + if (doc) { + doc->str_pool = (char *)buf; + return doc; + } else { + alc.free(alc.ctx, buf); + return NULL; + } + +#undef return_err +} + +const char *yyjson_read_number(const char *dat, + yyjson_val *val, + yyjson_read_flag flg, + const yyjson_alc *alc, + yyjson_read_err *err) { +#define return_err(_pos, _code, _msg) do { \ + err->pos = _pos > hdr ? (usize)(_pos - hdr) : 0; \ + err->msg = _msg; \ + err->code = YYJSON_READ_ERROR_##_code; \ + return NULL; \ +} while (false) + + u8 *hdr = constcast(u8 *)dat, *cur = hdr; + u8 raw_end[1]; /* raw end for null-terminator */ + u8 *raw_ptr = raw_end; + u8 **pre = &raw_ptr; /* previous raw end pointer */ + const char *msg; + yyjson_read_err tmp_err; + +#if YYJSON_DISABLE_FAST_FP_CONV + u8 buf[128]; + usize dat_len; +#endif + + if (!err) err = &tmp_err; + if (unlikely(!dat)) { + return_err(cur, INVALID_PARAMETER, "input data is NULL"); + } + if (unlikely(!val)) { + return_err(cur, INVALID_PARAMETER, "output value is NULL"); + } + +#if YYJSON_DISABLE_FAST_FP_CONV + if (!alc) alc = &YYJSON_DEFAULT_ALC; + dat_len = strlen(dat); + if (dat_len < sizeof(buf)) { + memcpy(buf, dat, dat_len + 1); + hdr = buf; + cur = hdr; + } else { + hdr = (u8 *)alc->malloc(alc->ctx, dat_len + 1); + cur = hdr; + if (unlikely(!hdr)) { + return_err(cur, MEMORY_ALLOCATION, MSG_MALLOC); + } + memcpy(hdr, dat, dat_len + 1); + } + hdr[dat_len] = 0; +#endif + +#if YYJSON_DISABLE_FAST_FP_CONV + if (!read_num(&cur, pre, flg, val, &msg)) { + if (dat_len >= sizeof(buf)) alc->free(alc->ctx, hdr); + return_err(cur, INVALID_NUMBER, msg); + } + if (dat_len >= sizeof(buf)) alc->free(alc->ctx, hdr); + if (yyjson_is_raw(val)) val->uni.str = dat; + return dat + (cur - hdr); +#else + if (!read_num(&cur, pre, flg, val, &msg)) { + return_err(cur, INVALID_NUMBER, msg); + } + return (const char *)cur; +#endif + +#undef return_err +} + + + +/*============================================================================== + * MARK: - Incremental JSON Reader (Public) + *============================================================================*/ + +#if !YYJSON_DISABLE_INCR_READER + +/* labels within yyjson_incr_read() to resume incremental parsing */ +#define LABEL_doc_begin 0 +#define LABEL_arr_val_begin 1 +#define LABEL_arr_val_end 2 +#define LABEL_obj_key_begin 3 +#define LABEL_obj_key_end 4 +#define LABEL_obj_val_begin 5 +#define LABEL_obj_val_end 6 +#define LABEL_doc_end 7 + +/** State for incremental JSON reader, opaque in the API. */ +struct yyjson_incr_state { + u32 label; /* current parser goto label */ + yyjson_alc alc; /* allocator */ + yyjson_read_flag flg; /* read flags */ + u8 *hdr; /* JSON data header */ + u8 *cur; /* current position in JSON data */ + usize buf_len; /* total buffer length (without padding) */ + usize hdr_len; /* value count used by yyjson_doc */ + usize alc_len; /* value count allocated */ + usize ctn_len; /* the number of elements in current container */ + yyjson_val *val_hdr; /* the head of allocated values */ + yyjson_val *val_end; /* the end of allocated values */ + yyjson_val *val; /* current JSON value */ + yyjson_val *ctn; /* current container */ + u8 *str_con[2]; /* string parser incremental state */ +}; + +yyjson_incr_state *yyjson_incr_new(char *buf, size_t buf_len, + yyjson_read_flag flg, + const yyjson_alc *alc_ptr) { + yyjson_incr_state *state = NULL; + yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC; + + /* remove non-standard flags */ + flg &= ~YYJSON_READ_JSON5; + flg &= ~YYJSON_READ_ALLOW_BOM; + flg &= ~YYJSON_READ_ALLOW_INVALID_UNICODE; + + if (unlikely(!buf)) return NULL; + if (unlikely(buf_len >= USIZE_MAX - YYJSON_PADDING_SIZE)) return NULL; + state = (yyjson_incr_state *)alc.malloc(alc.ctx, sizeof(*state)); + if (!state) return NULL; + memset(state, 0, sizeof(yyjson_incr_state)); + state->alc = alc; + state->flg = flg; + state->buf_len = buf_len; + + /* add 4-byte zero padding for input data if necessary */ + if (has_flg(INSITU)) { + state->hdr = (u8 *)buf; + } else { + state->hdr = (u8 *)alc.malloc(alc.ctx, buf_len + YYJSON_PADDING_SIZE); + if (unlikely(!state->hdr)) { + alc.free(alc.ctx, state); + return NULL; + } + memcpy(state->hdr, buf, buf_len); + } + memset(state->hdr + buf_len, 0, YYJSON_PADDING_SIZE); + state->cur = state->hdr; + state->label = LABEL_doc_begin; + return state; +} + +void yyjson_incr_free(yyjson_incr_state *state) { + if (state) { + yyjson_alc alc = state->alc; + memset(&state->alc, 0, sizeof(alc)); + if (state->val_hdr) { + alc.free(alc.ctx, (void *)state->val_hdr); + } + if (state->hdr && !(state->flg & YYJSON_READ_INSITU)) { + alc.free(alc.ctx, state->hdr); + } + alc.free(alc.ctx, state); + } +} + +yyjson_doc *yyjson_incr_read(yyjson_incr_state *state, size_t len, + yyjson_read_err *err) { +#define return_err_inv_param(_msg) do { \ + err->pos = 0; \ + err->msg = _msg; \ + err->code = YYJSON_READ_ERROR_INVALID_PARAMETER; \ + return NULL; \ +} while (false) + +#define return_err(_pos, _code, _msg) do { \ + if (is_truncated_end(hdr, _pos, end, YYJSON_READ_ERROR_##_code, flg)) { \ + goto unexpected_end; \ + } else { \ + err->pos = (usize)(_pos - hdr); \ + err->code = YYJSON_READ_ERROR_##_code; \ + err->msg = _msg; \ + } \ + return NULL; \ +} while (false) + +#define val_incr() do { \ + val++; \ + if (unlikely(val >= val_end)) { \ + usize alc_old = alc_len; \ + alc_len += alc_len / 2; \ + if ((sizeof(usize) < 8) && (alc_len >= alc_max)) goto fail_alloc; \ + val_tmp = (yyjson_val *)alc.realloc(alc.ctx, (void *)val_hdr, \ + alc_old * sizeof(yyjson_val), \ + alc_len * sizeof(yyjson_val)); \ + if ((!val_tmp)) goto fail_alloc; \ + val = val_tmp + (usize)(val - val_hdr); \ + ctn = val_tmp + (usize)(ctn - val_hdr); \ + state->val = val_tmp + (usize)(state->val - val_hdr); \ + state->val_hdr = val_hdr = val_tmp; \ + val_end = val_tmp + (alc_len - 2); \ + state->val_end = val_end; \ + } \ +} while (false) + + /* save position where it's possible to resume incremental parsing */ +#define save_incr_state(_label) do { \ + state->label = LABEL_##_label; \ + state->cur = cur; \ + state->val = val; \ + state->ctn_len = ctn_len; \ + state->hdr_len = hdr_len; \ + if (unlikely(cur >= end)) goto unexpected_end; \ +} while (false) + +#define check_maybe_truncated_number() do { \ + if (unlikely(cur >= end)) { \ + if (unlikely(cur > state->cur + INCR_NUM_MAX_LEN)) { \ + msg = "number too long"; \ + goto fail_number; \ + } \ + goto unexpected_end; \ + } \ +} while (false) + + u8 *hdr = NULL, *end = NULL, *cur = NULL; + yyjson_read_flag flg; + yyjson_alc alc; + usize dat_len; /* data length in bytes, hint for allocator */ + usize hdr_len; /* value count used by yyjson_doc */ + usize alc_len; /* value count allocated */ + usize alc_max; /* maximum value count for allocator */ + usize ctn_len; /* the number of elements in current container */ + yyjson_val *val_hdr; /* the head of allocated values */ + yyjson_val *val_end; /* the end of allocated values */ + yyjson_val *val_tmp; /* temporary pointer for realloc */ + yyjson_val *val; /* current JSON value */ + yyjson_val *ctn; /* current container */ + yyjson_val *ctn_parent; /* parent of current container */ + yyjson_doc *doc; /* the JSON document, equals to val_hdr */ + const char *msg; /* error message */ + + yyjson_read_err tmp_err; + u8 raw_end[1]; /* raw end for null-terminator */ + u8 *raw_ptr = raw_end; + u8 **pre = &raw_ptr; /* previous raw end pointer */ + u8 **con = NULL; /* for incremental string parsing */ + u8 saved_end = '\0'; /* saved end char */ + + /* validate input parameters */ + if (!err) err = &tmp_err; + if (unlikely(!state)) { + return_err_inv_param("input state is NULL"); + } + if (unlikely(!len)) { + return_err_inv_param("input length is 0"); + } + if (unlikely(len > state->buf_len)) { + return_err_inv_param("length is greater than total input length"); + } + + /* restore state saved from the previous call */ + hdr = state->hdr; + end = state->hdr + len; + cur = state->cur; + flg = state->flg; + alc = state->alc; + ctn_len = state->ctn_len; + hdr_len = state->hdr_len; + alc_len = state->alc_len; + val = state->val; + val_hdr = state->val_hdr; + val_end = state->val_end; + ctn = state->ctn; + con = state->str_con; + alc_max = USIZE_MAX / sizeof(yyjson_val); + + /* insert null terminator to make us stop at the specified end, even if + the data contains more valid JSON */ + saved_end = *end; + *end = '\0'; + + /* resume parsing from the last save point */ + switch (state->label) { + case LABEL_doc_begin: goto doc_begin; + case LABEL_arr_val_begin: goto arr_val_begin; + case LABEL_arr_val_end: goto arr_val_end; + case LABEL_obj_key_begin: goto obj_key_begin; + case LABEL_obj_key_end: goto obj_key_end; + case LABEL_obj_val_begin: goto obj_val_begin; + case LABEL_obj_val_end: goto obj_val_end; + case LABEL_doc_end: goto doc_end; + default: return_err_inv_param("invalid incremental state"); + } + +doc_begin: + /* skip empty contents before json document */ + if (unlikely(!char_is_ctn(*cur))) { + while (char_is_space(*cur)) cur++; + if (unlikely(cur >= end)) goto unexpected_end; /* input data is empty */ + } + + /* allocate memory for document */ + if (!val_hdr) { + hdr_len = sizeof(yyjson_doc) / sizeof(yyjson_val); + hdr_len += (sizeof(yyjson_doc) % sizeof(yyjson_val)) > 0; + if (likely(char_is_ctn(*cur))) { + dat_len = has_flg(STOP_WHEN_DONE) ? 256 : state->buf_len; + alc_len = hdr_len + + (dat_len / YYJSON_READER_ESTIMATED_MINIFY_RATIO) + 4; + alc_len = yyjson_min(alc_len, alc_max); + } else { + alc_len = hdr_len + 1; /* single value */ + } + val_hdr = (yyjson_val *)alc.malloc(alc.ctx, + alc_len * sizeof(yyjson_val)); + if (unlikely(!val_hdr)) goto fail_alloc; + val_end = val_hdr + (alc_len - 2); /* padding for kv pair reading */ + val = val_hdr + hdr_len; + ctn = val; + ctn_len = 0; + state->val_hdr = val_hdr; + state->val_end = val_end; + save_incr_state(doc_begin); + } + + /* read json document */ + if (*cur == '{') { + cur++; + ctn->tag = YYJSON_TYPE_OBJ; + ctn->uni.ofs = 0; + goto obj_key_begin; + } + if (*cur == '[') { + cur++; + ctn->tag = YYJSON_TYPE_ARR; + ctn->uni.ofs = 0; + goto arr_val_begin; + } + if (char_is_num(*cur)) { + if (likely(read_num(&cur, pre, flg, val, &msg))) goto doc_end; + goto fail_number; + } + if (*cur == '"') { + if (likely(read_str_con(&cur, end, flg, val, &msg, con))) goto doc_end; + goto fail_string; + } + if (*cur == 't') { + if (likely(read_true(&cur, val))) goto doc_end; + goto fail_literal_true; + } + if (*cur == 'f') { + if (likely(read_false(&cur, val))) goto doc_end; + goto fail_literal_false; + } + if (*cur == 'n') { + if (likely(read_null(&cur, val))) goto doc_end; + goto fail_literal_null; + } + + msg = "unexpected character, expected a valid root value"; + if (cur == hdr) { + /* RFC 8259: JSON text MUST be encoded using UTF-8 */ + if (is_utf8_bom(hdr)) msg = MSG_ERR_BOM; + else if (len >= 4 && is_utf32_bom(hdr)) msg = MSG_ERR_UTF32; + else if (len >= 2 && is_utf16_bom(hdr)) msg = MSG_ERR_UTF16; + } + return_err(cur, UNEXPECTED_CHARACTER, msg); + +arr_begin: + /* save current container */ + ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) | + (ctn->tag & YYJSON_TAG_MASK); + + /* create a new array value, save parent container offset */ + val_incr(); + val->tag = YYJSON_TYPE_ARR; + val->uni.ofs = (usize)((u8 *)val - (u8 *)ctn); + + /* push the new array value as current container */ + ctn = val; + ctn_len = 0; + +arr_val_begin: + save_incr_state(arr_val_begin); +arr_val_continue: + if (*cur == '{') { + cur++; + goto obj_begin; + } + if (*cur == '[') { + cur++; + goto arr_begin; + } + if (char_is_num(*cur)) { + val_incr(); + ctn_len++; + if (likely(read_num(&cur, pre, flg, val, &msg))) goto arr_val_maybe_end; + goto fail_number; + } + if (*cur == '"') { + val_incr(); + ctn_len++; + if (likely(read_str_con(&cur, end, flg, val, &msg, con))) + goto arr_val_end; + goto fail_string; + } + if (*cur == 't') { + val_incr(); + ctn_len++; + if (likely(read_true(&cur, val))) goto arr_val_end; + goto fail_literal_true; + } + if (*cur == 'f') { + val_incr(); + ctn_len++; + if (likely(read_false(&cur, val))) goto arr_val_end; + goto fail_literal_false; + } + if (*cur == 'n') { + val_incr(); + ctn_len++; + if (likely(read_null(&cur, val))) goto arr_val_end; + goto fail_literal_null; + } + if (*cur == ']') { + cur++; + if (likely(ctn_len == 0)) goto arr_end; + while (*cur != ',') cur--; + goto fail_trailing_comma; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto arr_val_continue; + } + goto fail_character_val; + +arr_val_maybe_end: + /* if incremental parsing stops in the middle of a number, it may continue + with more digits, so arr val maybe didn't end yet */ + check_maybe_truncated_number(); + +arr_val_end: + save_incr_state(arr_val_end); + if (*cur == ',') { + cur++; + goto arr_val_begin; + } + if (*cur == ']') { + cur++; + goto arr_end; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto arr_val_end; + } + goto fail_character_arr_end; + +arr_end: + /* get parent container */ + ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs); + + /* save the next sibling value offset */ + ctn->uni.ofs = (usize)((u8 *)val - (u8 *)ctn) + sizeof(yyjson_val); + ctn->tag = ((ctn_len) << YYJSON_TAG_BIT) | YYJSON_TYPE_ARR; + if (unlikely(ctn == ctn_parent)) goto doc_end; + + /* pop parent as current container */ + ctn = ctn_parent; + ctn_len = (usize)(ctn->tag >> YYJSON_TAG_BIT); + if ((ctn->tag & YYJSON_TYPE_MASK) == YYJSON_TYPE_OBJ) { + goto obj_val_end; + } else { + goto arr_val_end; + } + +obj_begin: + /* push container */ + ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) | + (ctn->tag & YYJSON_TAG_MASK); + val_incr(); + val->tag = YYJSON_TYPE_OBJ; + /* offset to the parent */ + val->uni.ofs = (usize)((u8 *)val - (u8 *)ctn); + ctn = val; + ctn_len = 0; + +obj_key_begin: + save_incr_state(obj_key_begin); +obj_key_continue: + if (likely(*cur == '"')) { + val_incr(); + ctn_len++; + if (likely(read_str_con(&cur, end, flg, val, &msg, con))) + goto obj_key_end; + goto fail_string; + } + if (likely(*cur == '}')) { + cur++; + if (likely(ctn_len == 0)) goto obj_end; + while (*cur != ',') cur--; + goto fail_trailing_comma; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto obj_key_continue; + } + goto fail_character_obj_key; + +obj_key_end: + save_incr_state(obj_key_end); + if (*cur == ':') { + cur++; + goto obj_val_begin; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto obj_key_end; + } + goto fail_character_obj_sep; + +obj_val_begin: + save_incr_state(obj_val_begin); +obj_val_continue: + if (*cur == '"') { + val++; + ctn_len++; + if (likely(read_str_con(&cur, end, flg, val, &msg, con))) + goto obj_val_end; + goto fail_string; + } + if (char_is_num(*cur)) { + val++; + ctn_len++; + if (likely(read_num(&cur, pre, flg, val, &msg))) goto obj_val_maybe_end; + goto fail_number; + } + if (*cur == '{') { + cur++; + goto obj_begin; + } + if (*cur == '[') { + cur++; + goto arr_begin; + } + if (*cur == 't') { + val++; + ctn_len++; + if (likely(read_true(&cur, val))) goto obj_val_end; + goto fail_literal_true; + } + if (*cur == 'f') { + val++; + ctn_len++; + if (likely(read_false(&cur, val))) goto obj_val_end; + goto fail_literal_false; + } + if (*cur == 'n') { + val++; + ctn_len++; + if (likely(read_null(&cur, val))) goto obj_val_end; + goto fail_literal_null; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto obj_val_continue; + } + goto fail_character_val; + +obj_val_maybe_end: + /* if incremental parsing stops in the middle of a number, it may continue + with more digits, so obj val maybe didn't end yet */ + check_maybe_truncated_number(); + +obj_val_end: + save_incr_state(obj_val_end); + if (likely(*cur == ',')) { + cur++; + goto obj_key_begin; + } + if (likely(*cur == '}')) { + cur++; + goto obj_end; + } + if (char_is_space(*cur)) { + while (char_is_space(*++cur)); + goto obj_val_end; + } + goto fail_character_obj_end; + +obj_end: + /* pop container */ + ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs); + /* point to the next value */ + ctn->uni.ofs = (usize)((u8 *)val - (u8 *)ctn) + sizeof(yyjson_val); + ctn->tag = (ctn_len << (YYJSON_TAG_BIT - 1)) | YYJSON_TYPE_OBJ; + if (unlikely(ctn == ctn_parent)) goto doc_end; + ctn = ctn_parent; + ctn_len = (usize)(ctn->tag >> YYJSON_TAG_BIT); + if ((ctn->tag & YYJSON_TYPE_MASK) == YYJSON_TYPE_OBJ) { + goto obj_val_end; + } else { + goto arr_val_end; + } + +doc_end: + /* check invalid contents after json document */ + if (unlikely(cur < end) && !has_flg(STOP_WHEN_DONE)) { + save_incr_state(doc_end); + while (char_is_space(*cur)) cur++; + if (unlikely(cur < end)) goto fail_garbage; + } + + **pre = '\0'; + doc = (yyjson_doc *)val_hdr; + doc->root = val_hdr + hdr_len; + doc->alc = alc; + doc->dat_read = (usize)(cur - hdr); + doc->val_read = (usize)((val - doc->root) + 1); + doc->str_pool = has_flg(INSITU) ? NULL : (char *)hdr; + state->hdr = NULL; + state->val_hdr = NULL; + memset(err, 0, sizeof(yyjson_read_err)); + return doc; + +unexpected_end: + err->pos = len; + /* if no nore data, stop the incr read */ + if (unlikely(len >= state->buf_len)) { + err->code = YYJSON_READ_ERROR_UNEXPECTED_END; + err->msg = MSG_NOT_END; + return NULL; + } + /* save parser state in extended error struct, in addition to what was + * stored in the last save_incr_state */ + err->code = YYJSON_READ_ERROR_MORE; + err->msg = "need more data"; + state->val_end = val_end; + state->ctn = ctn; + state->alc_len = alc_len; + /* restore the end where we've inserted a null terminator */ + *end = saved_end; + return NULL; + +fail_string: return_err(cur, INVALID_STRING, msg); +fail_number: return_err(cur, INVALID_NUMBER, msg); +fail_alloc: return_err(cur, MEMORY_ALLOCATION, MSG_MALLOC); +fail_trailing_comma: return_err(cur, JSON_STRUCTURE, MSG_COMMA); +fail_literal_true: return_err(cur, LITERAL, MSG_CHAR_T); +fail_literal_false: return_err(cur, LITERAL, MSG_CHAR_F); +fail_literal_null: return_err(cur, LITERAL, MSG_CHAR_N); +fail_character_val: return_err(cur, UNEXPECTED_CHARACTER, MSG_CHAR); +fail_character_arr_end: return_err(cur, UNEXPECTED_CHARACTER, MSG_ARR_END); +fail_character_obj_key: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_KEY); +fail_character_obj_sep: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_SEP); +fail_character_obj_end: return_err(cur, UNEXPECTED_CHARACTER, MSG_OBJ_END); +fail_garbage: return_err(cur, UNEXPECTED_CONTENT, MSG_GARBAGE); + +#undef val_incr +#undef return_err +#undef return_err_inv_param +#undef save_incr_state +#undef check_maybe_truncated_number +} + +#endif /* YYJSON_DISABLE_INCR_READER */ + +#undef has_flg +#undef has_allow +#endif /* YYJSON_DISABLE_READER */ + + + +#if !YYJSON_DISABLE_WRITER /* writer begin */ + +/* Check write flag, avoids `always false` warning when disabled. */ +#define has_flg(_flg) unlikely(has_wflag(flg, YYJSON_WRITE_##_flg, 0)) +#define has_allow(_flg) unlikely(has_wflag(flg, YYJSON_WRITE_ALLOW_##_flg, 1)) +static_inline bool has_wflag(yyjson_write_flag flg, yyjson_write_flag chk, + bool non_standard) { +#if YYJSON_DISABLE_NON_STANDARD + if (non_standard) return false; +#endif + return (flg & chk) != 0; +} + +/*============================================================================== + * MARK: - Integer Writer (Private) + * + * The maximum value of uint32_t is 4294967295 (10 digits), + * these digits are named as 'aabbccddee' here. + * + * Although most compilers may convert the "division by constant value" into + * "multiply and shift", manual conversion can still help some compilers + * generate fewer and better instructions. + * + * Reference: + * Division by Invariant Integers using Multiplication, 1994. + * https://gmplib.org/~tege/divcnst-pldi94.pdf + * Improved division by invariant integers, 2011. + * https://gmplib.org/~tege/division-paper.pdf + *============================================================================*/ + +/** Digit table from 00 to 99. */ +yyjson_align(2) +static const char digit_table[200] = { + '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', + '0', '5', '0', '6', '0', '7', '0', '8', '0', '9', + '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', + '1', '5', '1', '6', '1', '7', '1', '8', '1', '9', + '2', '0', '2', '1', '2', '2', '2', '3', '2', '4', + '2', '5', '2', '6', '2', '7', '2', '8', '2', '9', + '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', + '3', '5', '3', '6', '3', '7', '3', '8', '3', '9', + '4', '0', '4', '1', '4', '2', '4', '3', '4', '4', + '4', '5', '4', '6', '4', '7', '4', '8', '4', '9', + '5', '0', '5', '1', '5', '2', '5', '3', '5', '4', + '5', '5', '5', '6', '5', '7', '5', '8', '5', '9', + '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', + '6', '5', '6', '6', '6', '7', '6', '8', '6', '9', + '7', '0', '7', '1', '7', '2', '7', '3', '7', '4', + '7', '5', '7', '6', '7', '7', '7', '8', '7', '9', + '8', '0', '8', '1', '8', '2', '8', '3', '8', '4', + '8', '5', '8', '6', '8', '7', '8', '8', '8', '9', + '9', '0', '9', '1', '9', '2', '9', '3', '9', '4', + '9', '5', '9', '6', '9', '7', '9', '8', '9', '9' +}; + +static_inline u8 *write_u32_len_8(u32 val, u8 *buf) { + u32 aa, bb, cc, dd, aabb, ccdd; /* 8 digits: aabbccdd */ + aabb = (u32)(((u64)val * 109951163) >> 40); /* (val / 10000) */ + ccdd = val - aabb * 10000; /* (val % 10000) */ + aa = (aabb * 5243) >> 19; /* (aabb / 100) */ + cc = (ccdd * 5243) >> 19; /* (ccdd / 100) */ + bb = aabb - aa * 100; /* (aabb % 100) */ + dd = ccdd - cc * 100; /* (ccdd % 100) */ + byte_copy_2(buf + 0, digit_table + aa * 2); + byte_copy_2(buf + 2, digit_table + bb * 2); + byte_copy_2(buf + 4, digit_table + cc * 2); + byte_copy_2(buf + 6, digit_table + dd * 2); + return buf + 8; +} + +static_inline u8 *write_u32_len_4(u32 val, u8 *buf) { + u32 aa, bb; /* 4 digits: aabb */ + aa = (val * 5243) >> 19; /* (val / 100) */ + bb = val - aa * 100; /* (val % 100) */ + byte_copy_2(buf + 0, digit_table + aa * 2); + byte_copy_2(buf + 2, digit_table + bb * 2); + return buf + 4; +} + +static_inline u8 *write_u32_len_1_to_8(u32 val, u8 *buf) { + u32 aa, bb, cc, dd, aabb, bbcc, ccdd, lz; + + if (val < 100) { /* 1-2 digits: aa */ + lz = val < 10; /* leading zero: 0 or 1 */ + byte_copy_2(buf + 0, digit_table + val * 2 + lz); + buf -= lz; + return buf + 2; + + } else if (val < 10000) { /* 3-4 digits: aabb */ + aa = (val * 5243) >> 19; /* (val / 100) */ + bb = val - aa * 100; /* (val % 100) */ + lz = aa < 10; /* leading zero: 0 or 1 */ + byte_copy_2(buf + 0, digit_table + aa * 2 + lz); + buf -= lz; + byte_copy_2(buf + 2, digit_table + bb * 2); + return buf + 4; + + } else if (val < 1000000) { /* 5-6 digits: aabbcc */ + aa = (u32)(((u64)val * 429497) >> 32); /* (val / 10000) */ + bbcc = val - aa * 10000; /* (val % 10000) */ + bb = (bbcc * 5243) >> 19; /* (bbcc / 100) */ + cc = bbcc - bb * 100; /* (bbcc % 100) */ + lz = aa < 10; /* leading zero: 0 or 1 */ + byte_copy_2(buf + 0, digit_table + aa * 2 + lz); + buf -= lz; + byte_copy_2(buf + 2, digit_table + bb * 2); + byte_copy_2(buf + 4, digit_table + cc * 2); + return buf + 6; + + } else { /* 7-8 digits: aabbccdd */ + aabb = (u32)(((u64)val * 109951163) >> 40); /* (val / 10000) */ + ccdd = val - aabb * 10000; /* (val % 10000) */ + aa = (aabb * 5243) >> 19; /* (aabb / 100) */ + cc = (ccdd * 5243) >> 19; /* (ccdd / 100) */ + bb = aabb - aa * 100; /* (aabb % 100) */ + dd = ccdd - cc * 100; /* (ccdd % 100) */ + lz = aa < 10; /* leading zero: 0 or 1 */ + byte_copy_2(buf + 0, digit_table + aa * 2 + lz); + buf -= lz; + byte_copy_2(buf + 2, digit_table + bb * 2); + byte_copy_2(buf + 4, digit_table + cc * 2); + byte_copy_2(buf + 6, digit_table + dd * 2); + return buf + 8; + } +} + +static_inline u8 *write_u32_len_5_to_8(u32 val, u8 *buf) { + u32 aa, bb, cc, dd, aabb, bbcc, ccdd, lz; + + if (val < 1000000) { /* 5-6 digits: aabbcc */ + aa = (u32)(((u64)val * 429497) >> 32); /* (val / 10000) */ + bbcc = val - aa * 10000; /* (val % 10000) */ + bb = (bbcc * 5243) >> 19; /* (bbcc / 100) */ + cc = bbcc - bb * 100; /* (bbcc % 100) */ + lz = aa < 10; /* leading zero: 0 or 1 */ + byte_copy_2(buf + 0, digit_table + aa * 2 + lz); + buf -= lz; + byte_copy_2(buf + 2, digit_table + bb * 2); + byte_copy_2(buf + 4, digit_table + cc * 2); + return buf + 6; + + } else { /* 7-8 digits: aabbccdd */ + aabb = (u32)(((u64)val * 109951163) >> 40); /* (val / 10000) */ + ccdd = val - aabb * 10000; /* (val % 10000) */ + aa = (aabb * 5243) >> 19; /* (aabb / 100) */ + cc = (ccdd * 5243) >> 19; /* (ccdd / 100) */ + bb = aabb - aa * 100; /* (aabb % 100) */ + dd = ccdd - cc * 100; /* (ccdd % 100) */ + lz = aa < 10; /* leading zero: 0 or 1 */ + byte_copy_2(buf + 0, digit_table + aa * 2 + lz); + buf -= lz; + byte_copy_2(buf + 2, digit_table + bb * 2); + byte_copy_2(buf + 4, digit_table + cc * 2); + byte_copy_2(buf + 6, digit_table + dd * 2); + return buf + 8; + } +} + +static_inline u8 *write_u64(u64 val, u8 *buf) { + u64 tmp, hgh; + u32 mid, low; + + if (val < 100000000) { /* 1-8 digits */ + buf = write_u32_len_1_to_8((u32)val, buf); + return buf; + + } else if (val < (u64)100000000 * 100000000) { /* 9-16 digits */ + hgh = val / 100000000; /* (val / 100000000) */ + low = (u32)(val - hgh * 100000000); /* (val % 100000000) */ + buf = write_u32_len_1_to_8((u32)hgh, buf); + buf = write_u32_len_8(low, buf); + return buf; + + } else { /* 17-20 digits */ + tmp = val / 100000000; /* (val / 100000000) */ + low = (u32)(val - tmp * 100000000); /* (val % 100000000) */ + hgh = (u32)(tmp / 10000); /* (tmp / 10000) */ + mid = (u32)(tmp - hgh * 10000); /* (tmp % 10000) */ + buf = write_u32_len_5_to_8((u32)hgh, buf); + buf = write_u32_len_4(mid, buf); + buf = write_u32_len_8(low, buf); + return buf; + } +} + + + +/*============================================================================== + * MARK: - Number Writer (Private) + *============================================================================*/ + +#if !YYJSON_DISABLE_FAST_FP_CONV /* FP_WRITER */ + +/** Trailing zero count table for number 0 to 99. + (generate with misc/make_tables.c) */ +static const u8 dec_trailing_zero_table[] = { + 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +static_inline u8 *write_u64_len_1_to_16(u64 val, u8 *buf) { + u64 hgh; + u32 low; + if (val < 100000000) { /* 1-8 digits */ + buf = write_u32_len_1_to_8((u32)val, buf); + return buf; + } else { /* 9-16 digits */ + hgh = val / 100000000; /* (val / 100000000) */ + low = (u32)(val - hgh * 100000000); /* (val % 100000000) */ + buf = write_u32_len_1_to_8((u32)hgh, buf); + buf = write_u32_len_8(low, buf); + return buf; + } +} + +static_inline u8 *write_u64_len_1_to_17(u64 val, u8 *buf) { + u64 hgh; + u32 mid, low, one; + if (val >= (u64)100000000 * 10000000) { /* len: 16 to 17 */ + hgh = val / 100000000; /* (val / 100000000) */ + low = (u32)(val - hgh * 100000000); /* (val % 100000000) */ + one = (u32)(hgh / 100000000); /* (hgh / 100000000) */ + mid = (u32)(hgh - (u64)one * 100000000); /* (hgh % 100000000) */ + *buf = (u8)((u8)one + (u8)'0'); + buf += one > 0; + buf = write_u32_len_8(mid, buf); + buf = write_u32_len_8(low, buf); + return buf; + } else if (val >= (u64)100000000){ /* len: 9 to 15 */ + hgh = val / 100000000; /* (val / 100000000) */ + low = (u32)(val - hgh * 100000000); /* (val % 100000000) */ + buf = write_u32_len_1_to_8((u32)hgh, buf); + buf = write_u32_len_8(low, buf); + return buf; + } else { /* len: 1 to 8 */ + buf = write_u32_len_1_to_8((u32)val, buf); + return buf; + } +} + +/** + Write an unsigned integer with a length of 7 to 9 with trailing zero trimmed. + These digits are named as "abbccddee" here. + For example, input 123456000, output "123456". + */ +static_inline u8 *write_u32_len_7_to_9_trim(u32 val, u8 *buf) { + bool lz; + u32 tz, tz1, tz2; + + u32 abbcc = val / 10000; /* (abbccddee / 10000) */ + u32 ddee = val - abbcc * 10000; /* (abbccddee % 10000) */ + u32 abb = (u32)(((u64)abbcc * 167773) >> 24); /* (abbcc / 100) */ + u32 a = (abb * 41) >> 12; /* (abb / 100) */ + u32 bb = abb - a * 100; /* (abb % 100) */ + u32 cc = abbcc - abb * 100; /* (abbcc % 100) */ + + /* write abbcc */ + buf[0] = (u8)(a + '0'); + buf += a > 0; + lz = bb < 10 && a == 0; + byte_copy_2(buf + 0, digit_table + bb * 2 + lz); + buf -= lz; + byte_copy_2(buf + 2, digit_table + cc * 2); + + if (ddee) { + u32 dd = (ddee * 5243) >> 19; /* (ddee / 100) */ + u32 ee = ddee - dd * 100; /* (ddee % 100) */ + byte_copy_2(buf + 4, digit_table + dd * 2); + byte_copy_2(buf + 6, digit_table + ee * 2); + tz1 = dec_trailing_zero_table[dd]; + tz2 = dec_trailing_zero_table[ee]; + tz = ee ? tz2 : (tz1 + 2); + buf += 8 - tz; + return buf; + } else { + tz1 = dec_trailing_zero_table[bb]; + tz2 = dec_trailing_zero_table[cc]; + tz = cc ? tz2 : (tz1 + tz2); + buf += 4 - tz; + return buf; + } +} + +/** + Write an unsigned integer with a length of 16 or 17 with trailing zero trimmed. + These digits are named as "abbccddeeffgghhii" here. + For example, input 1234567890123000, output "1234567890123". + */ +static_inline u8 *write_u64_len_16_to_17_trim(u64 val, u8 *buf) { + u32 tz, tz1, tz2; + + u32 abbccddee = (u32)(val / 100000000); + u32 ffgghhii = (u32)(val - (u64)abbccddee * 100000000); + u32 abbcc = abbccddee / 10000; + u32 ddee = abbccddee - abbcc * 10000; + u32 abb = (u32)(((u64)abbcc * 167773) >> 24); /* (abbcc / 100) */ + u32 a = (abb * 41) >> 12; /* (abb / 100) */ + u32 bb = abb - a * 100; /* (abb % 100) */ + u32 cc = abbcc - abb * 100; /* (abbcc % 100) */ + buf[0] = (u8)(a + '0'); + buf += a > 0; + byte_copy_2(buf + 0, digit_table + bb * 2); + byte_copy_2(buf + 2, digit_table + cc * 2); + + if (ffgghhii) { + u32 dd = (ddee * 5243) >> 19; /* (ddee / 100) */ + u32 ee = ddee - dd * 100; /* (ddee % 100) */ + u32 ffgg = (u32)(((u64)ffgghhii * 109951163) >> 40); /* (val / 10000) */ + u32 hhii = ffgghhii - ffgg * 10000; /* (val % 10000) */ + u32 ff = (ffgg * 5243) >> 19; /* (aabb / 100) */ + u32 gg = ffgg - ff * 100; /* (aabb % 100) */ + byte_copy_2(buf + 4, digit_table + dd * 2); + byte_copy_2(buf + 6, digit_table + ee * 2); + byte_copy_2(buf + 8, digit_table + ff * 2); + byte_copy_2(buf + 10, digit_table + gg * 2); + if (hhii) { + u32 hh = (hhii * 5243) >> 19; /* (ccdd / 100) */ + u32 ii = hhii - hh * 100; /* (ccdd % 100) */ + byte_copy_2(buf + 12, digit_table + hh * 2); + byte_copy_2(buf + 14, digit_table + ii * 2); + tz1 = dec_trailing_zero_table[hh]; + tz2 = dec_trailing_zero_table[ii]; + tz = ii ? tz2 : (tz1 + 2); + return buf + 16 - tz; + } else { + tz1 = dec_trailing_zero_table[ff]; + tz2 = dec_trailing_zero_table[gg]; + tz = gg ? tz2 : (tz1 + 2); + return buf + 12 - tz; + } + } else { + if (ddee) { + u32 dd = (ddee * 5243) >> 19; /* (ddee / 100) */ + u32 ee = ddee - dd * 100; /* (ddee % 100) */ + byte_copy_2(buf + 4, digit_table + dd * 2); + byte_copy_2(buf + 6, digit_table + ee * 2); + tz1 = dec_trailing_zero_table[dd]; + tz2 = dec_trailing_zero_table[ee]; + tz = ee ? tz2 : (tz1 + 2); + return buf + 8 - tz; + } else { + tz1 = dec_trailing_zero_table[bb]; + tz2 = dec_trailing_zero_table[cc]; + tz = cc ? tz2 : (tz1 + tz2); + return buf + 4 - tz; + } + } +} + +/** Write exponent part in range `e-45` to `e38`. */ +static_inline u8 *write_f32_exp(i32 exp, u8 *buf) { + bool lz; + byte_copy_2(buf, "e-"); + buf += 2 - (exp >= 0); + exp = exp < 0 ? -exp : exp; + lz = exp < 10; + byte_copy_2(buf + 0, digit_table + (u32)exp * 2 + lz); + return buf + 2 - lz; +} + +/** Write exponent part in range `e-324` to `e308`. */ +static_inline u8 *write_f64_exp(i32 exp, u8 *buf) { + byte_copy_2(buf, "e-"); + buf += 2 - (exp >= 0); + exp = exp < 0 ? -exp : exp; + if (exp < 100) { + bool lz = exp < 10; + byte_copy_2(buf + 0, digit_table + (u32)exp * 2 + lz); + return buf + 2 - lz; + } else { + u32 hi = ((u32)exp * 656) >> 16; /* exp / 100 */ + u32 lo = (u32)exp - hi * 100; /* exp % 100 */ + buf[0] = (u8)((u8)hi + (u8)'0'); + byte_copy_2(buf + 1, digit_table + lo * 2); + return buf + 3; + } +} + +/** Magic number for fast `divide by power of 10`. */ +typedef struct { + u64 p10, mul; + u32 shr1, shr2; +} div_pow10_magic; + +/** Generated with llvm, see https://github.com/llvm/llvm-project/ + blob/main/llvm/lib/Support/DivisionByConstantInfo.cpp */ +static const div_pow10_magic div_pow10_table[] = { + { U64(0x00000000, 0x00000001), U64(0x00000000, 0x00000000), 0, 0 }, + { U64(0x00000000, 0x0000000A), U64(0xCCCCCCCC, 0xCCCCCCCD), 0, 3 }, + { U64(0x00000000, 0x00000064), U64(0x28F5C28F, 0x5C28F5C3), 2, 2 }, + { U64(0x00000000, 0x000003E8), U64(0x20C49BA5, 0xE353F7CF), 3, 4 }, + { U64(0x00000000, 0x00002710), U64(0x346DC5D6, 0x3886594B), 0, 11 }, + { U64(0x00000000, 0x000186A0), U64(0x0A7C5AC4, 0x71B47843), 5, 7 }, + { U64(0x00000000, 0x000F4240), U64(0x431BDE82, 0xD7B634DB), 0, 18 }, + { U64(0x00000000, 0x00989680), U64(0xD6BF94D5, 0xE57A42BD), 0, 23 }, + { U64(0x00000000, 0x05F5E100), U64(0xABCC7711, 0x8461CEFD), 0, 26 }, + { U64(0x00000000, 0x3B9ACA00), U64(0x0044B82F, 0xA09B5A53), 9, 11 }, + { U64(0x00000002, 0x540BE400), U64(0xDBE6FECE, 0xBDEDD5BF), 0, 33 }, + { U64(0x00000017, 0x4876E800), U64(0xAFEBFF0B, 0xCB24AAFF), 0, 36 }, + { U64(0x000000E8, 0xD4A51000), U64(0x232F3302, 0x5BD42233), 0, 37 }, + { U64(0x00000918, 0x4E72A000), U64(0x384B84D0, 0x92ED0385), 0, 41 }, + { U64(0x00005AF3, 0x107A4000), U64(0x0B424DC3, 0x5095CD81), 0, 42 }, + { U64(0x00038D7E, 0xA4C68000), U64(0x00024075, 0xF3DCEAC3), 15, 20 }, + { U64(0x002386F2, 0x6FC10000), U64(0x39A5652F, 0xB1137857), 0, 51 }, + { U64(0x01634578, 0x5D8A0000), U64(0x00005C3B, 0xD5191B53), 17, 22 }, + { U64(0x0DE0B6B3, 0xA7640000), U64(0x000049C9, 0x7747490F), 18, 24 }, + { U64(0x8AC72304, 0x89E80000), U64(0x760F253E, 0xDB4AB0d3), 0, 62 }, +}; + +/** Divide a number by power of 10. */ +static_inline void div_pow10(u64 num, u32 exp, u64 *div, u64 *mod, u64 *p10) { + u64 hi, lo; + div_pow10_magic m = div_pow10_table[exp]; + u128_mul(num >> m.shr1, m.mul, &hi, &lo); + *div = hi >> m.shr2; + *mod = num - (*div * m.p10); + *p10 = m.p10; +} + +/** Multiplies 64-bit integer and returns highest 64-bit rounded value. */ +static_inline u32 u64_round_to_odd(u64 u, u32 cp) { + u64 hi, lo; + u32 y_hi, y_lo; + u128_mul(cp, u, &hi, &lo); + y_hi = (u32)hi; + y_lo = (u32)(lo >> 32); + return y_hi | (y_lo > 1); +} + +/** Multiplies 128-bit integer and returns highest 64-bit rounded value. */ +static_inline u64 u128_round_to_odd(u64 hi, u64 lo, u64 cp) { + u64 x_hi, x_lo, y_hi, y_lo; + u128_mul(cp, lo, &x_hi, &x_lo); + u128_mul_add(cp, hi, x_hi, &y_hi, &y_lo); + return y_hi | (y_lo > 1); +} + +/** Convert f32 from binary to decimal (shortest but may have trailing zeros). + The input should not be 0, inf or nan. */ +static_inline void f32_bin_to_dec(u32 sig_raw, u32 exp_raw, + u32 sig_bin, i32 exp_bin, + u32 *sig_dec, i32 *exp_dec) { + + bool is_even, irregular, round_up, trim; + bool u0_inside, u1_inside, w0_inside, w1_inside; + u64 p10_hi, p10_lo, hi, lo; + u32 s, sp, cb, cbl, cbr, vb, vbl, vbr, upper, lower, mid; + i32 k, h; + + /* Fast path, see f64_bin_to_dec(). */ + while (likely(sig_raw)) { + u32 mod, dec, add_1, add_10, s_hi, s_lo; + u32 c, half_ulp, t0, t1; + + /* k = floor(exp_bin * log10(2)); */ + /* h = exp_bin + floor(log2(10) * -k); (h = 0/1/2/3) */ + k = (i32)(exp_bin * 315653) >> 20; + h = exp_bin + ((-k * 217707) >> 16); + pow10_table_get_sig(-k, &p10_hi, &p10_lo); + + /* sig_bin << (1/2/3/4) */ + cb = sig_bin << (h + 1); + u128_mul(cb, p10_hi, &hi, &lo); + s_hi = (u32)(hi); + s_lo = (u32)(lo >> 32); + mod = s_hi % 10; + dec = s_hi - mod; + + /* right shift 4 to fit in u32 */ + c = (mod << (32 - 4)) | (s_lo >> 4); + half_ulp = (u32)(p10_hi >> (32 + 4 - h)); + + /* check w1, u0, w0 range */ + w1_inside = (s_lo >= ((u32)1 << 31)); + if (unlikely(s_lo == ((u32)1 << 31))) break; + u0_inside = (half_ulp >= c); + if (unlikely(half_ulp == c)) break; + t0 = (u32)10 << (32 - 4); + t1 = c + half_ulp; + w0_inside = (t1 >= t0); + if (unlikely(t0 - t1 <= (u32)1)) break; + + trim = (u0_inside | w0_inside); + add_10 = (w0_inside ? 10 : 0); + add_1 = mod + w1_inside; + *sig_dec = dec + (trim ? add_10 : add_1); + *exp_dec = k; + return; + } + + /* Schubfach algorithm, see f64_bin_to_dec(). */ + irregular = (sig_raw == 0 && exp_raw > 1); + is_even = !(sig_bin & 1); + cbl = 4 * sig_bin - 2 + irregular; + cb = 4 * sig_bin; + cbr = 4 * sig_bin + 2; + + /* k = floor(exp_bin * log10(2) + (irregular ? log10(3.0 / 4.0) : 0)); */ + /* h = exp_bin + floor(log2(10) * -k) + 1; (h = 1/2/3/4) */ + k = (i32)(exp_bin * 315653 - (irregular ? 131237 : 0)) >> 20; + h = exp_bin + ((-k * 217707) >> 16) + 1; + pow10_table_get_sig(-k, &p10_hi, &p10_lo); + p10_hi += 1; + + vbl = u64_round_to_odd(p10_hi, cbl << h); + vb = u64_round_to_odd(p10_hi, cb << h); + vbr = u64_round_to_odd(p10_hi, cbr << h); + lower = vbl + !is_even; + upper = vbr - !is_even; + + s = vb / 4; + if (s >= 10) { + sp = s / 10; + u0_inside = (lower <= 40 * sp); + w0_inside = (upper >= 40 * sp + 40); + if (u0_inside != w0_inside) { + *sig_dec = sp * 10 + (w0_inside ? 10 : 0); + *exp_dec = k; + return; + } + } + u1_inside = (lower <= 4 * s); + w1_inside = (upper >= 4 * s + 4); + mid = 4 * s + 2; + round_up = (vb > mid) || (vb == mid && (s & 1) != 0); + *sig_dec = s + ((u1_inside != w1_inside) ? w1_inside : round_up); + *exp_dec = k; +} + +/** Convert f64 from binary to decimal (shortest but may have trailing zeros). + The input should not be 0, inf or nan. */ +static_inline void f64_bin_to_dec(u64 sig_raw, u32 exp_raw, + u64 sig_bin, i32 exp_bin, + u64 *sig_dec, i32 *exp_dec) { + + bool is_even, irregular, round_up, trim; + bool u0_inside, u1_inside, w0_inside, w1_inside; + u64 s, sp, cb, cbl, cbr, vb, vbl, vbr, p10_hi, p10_lo, upper, lower, mid; + i32 k, h; + + /* + Fast path: + For regular spacing significand 'c', there are 4 candidates: + + u0 u1 c w1 w0 + ----|----|----|----|----|-*--|----|----|----|----|----|----|----|---- + 9 0 1 2 3 4 5 6 7 8 9 0 1 + |___________________|___________________| + 1ulp + + The `1ulp` is in the range [1.0, 10.0). + If (c - 0.5ulp < u0), trim the last digit and round down. + If (c + 0.5ulp > w0), trim the last digit and round up. + If (c - 0.5ulp < u1), round down. + If (c + 0.5ulp > w1), round up. + */ + while (likely(sig_raw)) { + u64 mod, dec, add_1, add_10, s_hi, s_lo; + u64 c, half_ulp, t0, t1; + + /* k = floor(exp_bin * log10(2)); */ + /* h = exp_bin + floor(log2(10) * -k); (h = 0/1/2/3) */ + k = (i32)(exp_bin * 315653) >> 20; + h = exp_bin + ((-k * 217707) >> 16); + pow10_table_get_sig(-k, &p10_hi, &p10_lo); + + /* sig_bin << (1/2/3/4) */ + cb = sig_bin << (h + 1); + u128_mul(cb, p10_lo, &s_hi, &s_lo); + u128_mul_add(cb, p10_hi, s_hi, &s_hi, &s_lo); + mod = s_hi % 10; + dec = s_hi - mod; + + /* right shift 4 to fit in u64 */ + c = (mod << (64 - 4)) | (s_lo >> 4); + half_ulp = p10_hi >> (4 - h); + + /* check w1, u0, w0 range */ + w1_inside = (s_lo >= ((u64)1 << 63)); + if (unlikely(s_lo == ((u64)1 << 63))) break; + u0_inside = (half_ulp >= c); + if (unlikely(half_ulp == c)) break; + t0 = ((u64)10 << (64 - 4)); + t1 = c + half_ulp; + w0_inside = (t1 >= t0); + if (unlikely(t0 - t1 <= (u64)1)) break; + + trim = (u0_inside | w0_inside); + add_10 = (w0_inside ? 10 : 0); + add_1 = mod + w1_inside; + *sig_dec = dec + (trim ? add_10 : add_1); + *exp_dec = k; + return; + } + + /* + Schubfach algorithm: + Raffaello Giulietti, The Schubfach way to render doubles, 2022. + https://drive.google.com/file/d/1gp5xv4CAa78SVgCeWfGqqI4FfYYYuNFb (Paper) + https://github.com/openjdk/jdk/pull/3402 (Java implementation) + https://github.com/abolz/Drachennest (C++ implementation) + */ + irregular = (sig_raw == 0 && exp_raw > 1); + is_even = !(sig_bin & 1); + cbl = 4 * sig_bin - 2 + irregular; + cb = 4 * sig_bin; + cbr = 4 * sig_bin + 2; + + /* k = floor(exp_bin * log10(2) + (irregular ? log10(3.0 / 4.0) : 0)); */ + /* h = exp_bin + floor(log2(10) * -k) + 1; (h = 1/2/3/4) */ + k = (i32)(exp_bin * 315653 - (irregular ? 131237 : 0)) >> 20; + h = exp_bin + ((-k * 217707) >> 16) + 1; + pow10_table_get_sig(-k, &p10_hi, &p10_lo); + p10_lo += 1; + + vbl = u128_round_to_odd(p10_hi, p10_lo, cbl << h); + vb = u128_round_to_odd(p10_hi, p10_lo, cb << h); + vbr = u128_round_to_odd(p10_hi, p10_lo, cbr << h); + lower = vbl + !is_even; + upper = vbr - !is_even; + + s = vb / 4; + if (s >= 10) { + sp = s / 10; + u0_inside = (lower <= 40 * sp); + w0_inside = (upper >= 40 * sp + 40); + if (u0_inside != w0_inside) { + *sig_dec = sp * 10 + (w0_inside ? 10 : 0); + *exp_dec = k; + return; + } + } + u1_inside = (lower <= 4 * s); + w1_inside = (upper >= 4 * s + 4); + mid = 4 * s + 2; + round_up = (vb > mid) || (vb == mid && (s & 1) != 0); + *sig_dec = s + ((u1_inside != w1_inside) ? w1_inside : round_up); + *exp_dec = k; +} + +/** Convert f64 from binary to decimal (fast but not the shortest). + The input should not be 0, inf, nan. */ +static_inline void f64_bin_to_dec_fast(u64 sig_raw, u32 exp_raw, + u64 sig_bin, i32 exp_bin, + u64 *sig_dec, i32 *exp_dec, + bool *round_up) { + u64 cb, p10_hi, p10_lo, s_hi, s_lo; + i32 k, h; + bool irregular, u; + + irregular = (sig_raw == 0 && exp_raw > 1); + + /* k = floor(exp_bin * log10(2) + (irregular ? log10(3.0 / 4.0) : 0)); */ + /* h = exp_bin + floor(log2(10) * -k) + 1; (h = 1/2/3/4) */ + k = (i32)(exp_bin * 315653 - (irregular ? 131237 : 0)) >> 20; + h = exp_bin + ((-k * 217707) >> 16); + pow10_table_get_sig(-k, &p10_hi, &p10_lo); + + /* sig_bin << (1/2/3/4) */ + cb = sig_bin << (h + 1); + u128_mul(cb, p10_lo, &s_hi, &s_lo); + u128_mul_add(cb, p10_hi, s_hi, &s_hi, &s_lo); + + /* round up */ + u = s_lo >= (irregular ? U64(0x55555555, 0x55555555) : ((u64)1 << 63)); + + *sig_dec = s_hi + u; + *exp_dec = k; + *round_up = u; + return; +} + +/** Write inf/nan if allowed. */ +static_inline u8 *write_inf_or_nan(u8 *buf, yyjson_write_flag flg, + u64 sig_raw, bool sign) { + if (has_flg(INF_AND_NAN_AS_NULL)) { + byte_copy_4(buf, "null"); + return buf + 4; + } + if (has_allow(INF_AND_NAN)) { + if (sig_raw == 0) { + buf[0] = '-'; + buf += sign; + byte_copy_8(buf, "Infinity"); + return buf + 8; + } else { + byte_copy_4(buf, "NaN"); + return buf + 3; + } + } + return NULL; +} + +/** + Write a float number (requires 40 bytes buffer). + We follow the ECMAScript specification for printing floating-point numbers, + similar to `Number.prototype.toString()`, but with the following changes: + 1. Keep the negative sign of `-0.0` to preserve input information. + 2. Keep decimal point to indicate the number is floating point. + 3. Remove positive sign in the exponent part. + */ +static_noinline u8 *write_f32_raw(u8 *buf, u64 raw_f64, + yyjson_write_flag flg) { + u32 sig_bin, sig_dec, sig_raw; + i32 exp_bin, exp_dec, sig_len, dot_ofs; + u32 exp_raw, raw; + u8 *end; + bool sign; + + /* cast double to float */ + raw = f32_to_bits(f64_to_f32(f64_from_bits(raw_f64))); + + /* decode raw bytes from IEEE-754 double format. */ + sign = (bool)(raw >> (F32_BITS - 1)); + sig_raw = raw & F32_SIG_MASK; + exp_raw = (raw & F32_EXP_MASK) >> F32_SIG_BITS; + + /* return inf or nan */ + if (unlikely(exp_raw == ((u32)1 << F32_EXP_BITS) - 1)) { + return write_inf_or_nan(buf, flg, sig_raw, sign); + } + + /* add sign for all finite number */ + buf[0] = '-'; + buf += sign; + + /* return zero */ + if ((raw << 1) == 0) { + byte_copy_4(buf, "0.0"); + return buf + 3; + } + + if (likely(exp_raw != 0)) { + /* normal number */ + sig_bin = sig_raw | ((u32)1 << F32_SIG_BITS); + exp_bin = (i32)exp_raw - F32_EXP_BIAS - F32_SIG_BITS; + + /* fast path for small integer number without fraction */ + if ((-F32_SIG_BITS <= exp_bin && exp_bin <= 0) && + (u64_tz_bits(sig_bin) >= (u32)-exp_bin)) { + sig_dec = sig_bin >> -exp_bin; /* range: [1, 0xFFFFFF] */ + buf = write_u32_len_1_to_8(sig_dec, buf); + byte_copy_2(buf, ".0"); + return buf + 2; + } + + /* binary to decimal */ + f32_bin_to_dec(sig_raw, exp_raw, sig_bin, exp_bin, &sig_dec, &exp_dec); + + /* the sig length is 7 or 9 */ + sig_len = 7 + (sig_dec >= (u32)10000000) + (sig_dec >= (u32)100000000); + + /* the decimal point offset relative to the first digit */ + dot_ofs = sig_len + exp_dec; + + if (-6 < dot_ofs && dot_ofs <= 21) { + i32 num_sep_pos, dot_set_pos, pre_ofs; + u8 *num_hdr, *num_end, *num_sep, *dot_end; + bool no_pre_zero; + + /* fill zeros */ + memset(buf, '0', 32); + + /* not prefixed with zero, e.g. 1.234, 1234.0 */ + no_pre_zero = (dot_ofs > 0); + + /* write the number as digits */ + pre_ofs = no_pre_zero ? 0 : (2 - dot_ofs); + num_hdr = buf + pre_ofs; + num_end = write_u32_len_7_to_9_trim(sig_dec, num_hdr); + + /* seperate these digits to leave a space for dot */ + num_sep_pos = no_pre_zero ? dot_ofs : 0; + num_sep = num_hdr + num_sep_pos; + byte_move_8(num_sep + no_pre_zero, num_sep); + num_end += no_pre_zero; + + /* write the dot */ + dot_set_pos = yyjson_max(dot_ofs, 1); + buf[dot_set_pos] = '.'; + + /* return the ending */ + dot_end = buf + dot_ofs + 2; + return yyjson_max(dot_end, num_end); + + } else { + /* write with scientific notation, e.g. 1.234e56 */ + end = write_u32_len_7_to_9_trim(sig_dec, buf + 1); + end -= (end == buf + 2); /* remove '.0', e.g. 2.0e34 -> 2e34 */ + exp_dec += sig_len - 1; + buf[0] = buf[1]; + buf[1] = '.'; + return write_f32_exp(exp_dec, end); + } + + } else { + /* subnormal number */ + sig_bin = sig_raw; + exp_bin = 1 - F32_EXP_BIAS - F32_SIG_BITS; + + /* binary to decimal */ + f32_bin_to_dec(sig_raw, exp_raw, sig_bin, exp_bin, &sig_dec, &exp_dec); + + /* write significand part */ + end = write_u32_len_1_to_8(sig_dec, buf + 1); + buf[0] = buf[1]; + buf[1] = '.'; + exp_dec += (i32)(end - buf) - 2; + + /* trim trailing zeros */ + end -= *(end - 1) == '0'; /* branchless for last zero */ + end -= *(end - 1) == '0'; /* branchless for second last zero */ + while (*(end - 1) == '0') end--; /* for unlikely more zeros */ + end -= *(end - 1) == '.'; /* remove dot, e.g. 2.e-321 -> 2e-321 */ + + /* write exponent part */ + return write_f32_exp(exp_dec, end); + } +} + +/** + Write a double number (requires 40 bytes buffer). + We follow the ECMAScript specification for printing floating-point numbers, + similar to `Number.prototype.toString()`, but with the following changes: + 1. Keep the negative sign of `-0.0` to preserve input information. + 2. Keep decimal point to indicate the number is floating point. + 3. Remove positive sign in the exponent part. + */ +static_noinline u8 *write_f64_raw(u8 *buf, u64 raw, yyjson_write_flag flg) { + u64 sig_bin, sig_dec, sig_raw; + i32 exp_bin, exp_dec, sig_len, dot_ofs; + u32 exp_raw; + u8 *end; + bool sign; + + /* decode raw bytes from IEEE-754 double format. */ + sign = (bool)(raw >> (F64_BITS - 1)); + sig_raw = raw & F64_SIG_MASK; + exp_raw = (u32)((raw & F64_EXP_MASK) >> F64_SIG_BITS); + + /* return inf or nan */ + if (unlikely(exp_raw == ((u32)1 << F64_EXP_BITS) - 1)) { + return write_inf_or_nan(buf, flg, sig_raw, sign); + } + + /* add sign for all finite number */ + buf[0] = '-'; + buf += sign; + + /* return zero */ + if ((raw << 1) == 0) { + byte_copy_4(buf, "0.0"); + return buf + 3; + } + + if (likely(exp_raw != 0)) { + /* normal number */ + sig_bin = sig_raw | ((u64)1 << F64_SIG_BITS); + exp_bin = (i32)exp_raw - F64_EXP_BIAS - F64_SIG_BITS; + + /* fast path for small integer number without fraction */ + if ((-F64_SIG_BITS <= exp_bin && exp_bin <= 0) && + (u64_tz_bits(sig_bin) >= (u32)-exp_bin)) { + sig_dec = sig_bin >> -exp_bin; /* range: [1, 0x1FFFFFFFFFFFFF] */ + buf = write_u64_len_1_to_16(sig_dec, buf); + byte_copy_2(buf, ".0"); + return buf + 2; + } + + /* binary to decimal */ + f64_bin_to_dec(sig_raw, exp_raw, sig_bin, exp_bin, &sig_dec, &exp_dec); + + /* the sig length is 16 or 17 */ + sig_len = 16 + (sig_dec >= (u64)100000000 * 100000000); + + /* the decimal point offset relative to the first digit */ + dot_ofs = sig_len + exp_dec; + + if (-6 < dot_ofs && dot_ofs <= 21) { + i32 num_sep_pos, dot_set_pos, pre_ofs; + u8 *num_hdr, *num_end, *num_sep, *dot_end; + bool no_pre_zero; + + /* fill zeros */ + memset(buf, '0', 32); + + /* not prefixed with zero, e.g. 1.234, 1234.0 */ + no_pre_zero = (dot_ofs > 0); + + /* write the number as digits */ + pre_ofs = no_pre_zero ? 0 : (2 - dot_ofs); + num_hdr = buf + pre_ofs; + num_end = write_u64_len_16_to_17_trim(sig_dec, num_hdr); + + /* seperate these digits to leave a space for dot */ + num_sep_pos = no_pre_zero ? dot_ofs : 0; + num_sep = num_hdr + num_sep_pos; + byte_move_16(num_sep + no_pre_zero, num_sep); + num_end += no_pre_zero; + + /* write the dot */ + dot_set_pos = yyjson_max(dot_ofs, 1); + buf[dot_set_pos] = '.'; + + /* return the ending */ + dot_end = buf + dot_ofs + 2; + return yyjson_max(dot_end, num_end); + + } else { + /* write with scientific notation, e.g. 1.234e56 */ + end = write_u64_len_16_to_17_trim(sig_dec, buf + 1); + end -= (end == buf + 2); /* remove '.0', e.g. 2.0e34 -> 2e34 */ + exp_dec += sig_len - 1; + buf[0] = buf[1]; + buf[1] = '.'; + return write_f64_exp(exp_dec, end); + } + + } else { + /* subnormal number */ + sig_bin = sig_raw; + exp_bin = 1 - F64_EXP_BIAS - F64_SIG_BITS; + + /* binary to decimal */ + f64_bin_to_dec(sig_raw, exp_raw, sig_bin, exp_bin, &sig_dec, &exp_dec); + + /* write significand part */ + end = write_u64_len_1_to_17(sig_dec, buf + 1); + buf[0] = buf[1]; + buf[1] = '.'; + exp_dec += (i32)(end - buf) - 2; + + /* trim trailing zeros */ + end -= *(end - 1) == '0'; /* branchless for last zero */ + end -= *(end - 1) == '0'; /* branchless for second last zero */ + while (*(end - 1) == '0') end--; /* for unlikely more zeros */ + end -= *(end - 1) == '.'; /* remove dot, e.g. 2.e-321 -> 2e-321 */ + + /* write exponent part */ + return write_f64_exp(exp_dec, end); + } +} + +/** + Write a double number using fixed-point notation (requires 40 bytes buffer). + + We follow the ECMAScript specification for printing floating-point numbers, + similar to `Number.prototype.toFixed(prec)`, but with the following changes: + 1. Keep the negative sign of `-0.0` to preserve input information. + 2. Keep decimal point to indicate the number is floating point. + 3. Remove positive sign in the exponent part. + 4. Remove trailing zeros and reduce unnecessary precision. + */ +static_noinline u8 *write_f64_raw_fixed(u8 *buf, u64 raw, yyjson_write_flag flg, + u32 prec) { + u64 sig_bin, sig_dec, sig_raw; + i32 exp_bin, exp_dec, sig_len, dot_ofs; + u32 exp_raw; + u8 *end; + bool sign; + + /* decode raw bytes from IEEE-754 double format. */ + sign = (bool)(raw >> (F64_BITS - 1)); + sig_raw = raw & F64_SIG_MASK; + exp_raw = (u32)((raw & F64_EXP_MASK) >> F64_SIG_BITS); + + /* return inf or nan */ + if (unlikely(exp_raw == ((u32)1 << F64_EXP_BITS) - 1)) { + return write_inf_or_nan(buf, flg, sig_raw, sign); + } + + /* add sign for all finite number */ + buf[0] = '-'; + buf += sign; + + /* return zero */ + if ((raw << 1) == 0) { + byte_copy_4(buf, "0.0"); + return buf + 3; + } + + if (likely(exp_raw != 0)) { + /* normal number */ + sig_bin = sig_raw | ((u64)1 << F64_SIG_BITS); + exp_bin = (i32)exp_raw - F64_EXP_BIAS - F64_SIG_BITS; + + /* fast path for small integer number without fraction */ + if ((-F64_SIG_BITS <= exp_bin && exp_bin <= 0) && + (u64_tz_bits(sig_bin) >= (u32)-exp_bin)) { + sig_dec = sig_bin >> -exp_bin; /* range: [1, 0x1FFFFFFFFFFFFF] */ + buf = write_u64_len_1_to_16(sig_dec, buf); + byte_copy_2(buf, ".0"); + return buf + 2; + } + + /* only `fabs(num) < 1e21` are processed here. */ + if ((raw << 1) < (U64(0x444B1AE4, 0xD6E2EF50) << 1)) { + i32 num_sep_pos, dot_set_pos, pre_ofs; + u8 *num_hdr, *num_end, *num_sep; + bool round_up, no_pre_zero; + + /* binary to decimal */ + f64_bin_to_dec_fast(sig_raw, exp_raw, sig_bin, exp_bin, + &sig_dec, &exp_dec, &round_up); + + /* the sig length is 16 or 17 */ + sig_len = 16 + (sig_dec >= (u64)100000000 * 100000000); + + /* limit the length of digits after the decimal point */ + if (exp_dec < -1) { + i32 sig_len_cut = -exp_dec - (i32)prec; + if (sig_len_cut > sig_len) { + byte_copy_4(buf, "0.0"); + return buf + 3; + } + if (sig_len_cut > 0) { + u64 div, mod, p10; + + /* remove round up */ + sig_dec -= round_up; + sig_len = 16 + (sig_dec >= (u64)100000000 * 100000000); + + /* cut off some digits */ + div_pow10(sig_dec, (u32)sig_len_cut, &div, &mod, &p10); + + /* add round up */ + sig_dec = div + (mod >= p10 / 2); + + /* update exp and sig length */ + exp_dec += sig_len_cut; + sig_len -= sig_len_cut; + sig_len += (sig_len >= 0) && + (sig_dec >= div_pow10_table[sig_len].p10); + } + if (sig_len <= 0) { + byte_copy_4(buf, "0.0"); + return buf + 3; + } + } + + /* fill zeros */ + memset(buf, '0', 32); + + /* the decimal point offset relative to the first digit */ + dot_ofs = sig_len + exp_dec; + + /* not prefixed with zero, e.g. 1.234, 1234.0 */ + no_pre_zero = (dot_ofs > 0); + + /* write the number as digits */ + pre_ofs = no_pre_zero ? 0 : (1 - dot_ofs); + num_hdr = buf + pre_ofs; + num_end = write_u64_len_1_to_17(sig_dec, num_hdr); + + /* seperate these digits to leave a space for dot */ + num_sep_pos = no_pre_zero ? dot_ofs : -dot_ofs; + num_sep = buf + num_sep_pos; + byte_move_16(num_sep + 1, num_sep); + num_end += (exp_dec < 0); + + /* write the dot */ + dot_set_pos = yyjson_max(dot_ofs, 1); + buf[dot_set_pos] = '.'; + + /* remove trailing zeros */ + buf += dot_set_pos + 2; + buf = yyjson_max(buf, num_end); + buf -= *(buf - 1) == '0'; /* branchless for last zero */ + buf -= *(buf - 1) == '0'; /* branchless for second last zero */ + while (*(buf - 1) == '0') buf--; /* for unlikely more zeros */ + buf += *(buf - 1) == '.'; /* keep a zero after dot */ + return buf; + + } else { + /* binary to decimal */ + f64_bin_to_dec(sig_raw, exp_raw, sig_bin, exp_bin, + &sig_dec, &exp_dec); + + /* the sig length is 16 or 17 */ + sig_len = 16 + (sig_dec >= (u64)100000000 * 100000000); + + /* write with scientific notation, e.g. 1.234e56 */ + end = write_u64_len_16_to_17_trim(sig_dec, buf + 1); + end -= (end == buf + 2); /* remove '.0', e.g. 2.0e34 -> 2e34 */ + exp_dec += sig_len - 1; + buf[0] = buf[1]; + buf[1] = '.'; + return write_f64_exp(exp_dec, end); + } + } else { + /* subnormal number */ + byte_copy_4(buf, "0.0"); + return buf + 3; + } +} + +#else /* FP_WRITER */ + +#if YYJSON_MSC_VER >= 1400 +#define snprintf_num(buf, len, fmt, dig, val) \ + sprintf_s((char *)buf, len, fmt, dig, val) +#elif defined(snprintf) || (YYJSON_STDC_VER >= 199901L) +#define snprintf_num(buf, len, fmt, dig, val) \ + snprintf((char *)buf, len, fmt, dig, val) +#else +#define snprintf_num(buf, len, fmt, dig, val) \ + sprintf((char *)buf, fmt, dig, val) +#endif + +static_noinline u8 *write_fp_reformat(u8 *buf, int len, + yyjson_write_flag flg, bool fixed) { + u8 *cur = buf; + if (unlikely(len < 1)) return NULL; + cur += (*cur == '-'); + if (unlikely(!char_is_digit(*cur))) { + /* nan, inf, or bad output */ + if (has_flg(INF_AND_NAN_AS_NULL)) { + byte_copy_4(buf, "null"); + return buf + 4; + } else if (has_allow(INF_AND_NAN)) { + if (*cur == 'i') { + byte_copy_8(cur, "Infinity"); + return cur + 8; + } else if (*cur == 'n') { + byte_copy_4(buf, "NaN"); + return buf + 3; + } + } + return NULL; + } else { + /* finite number */ + u8 *end = buf + len, *dot = NULL, *exp = NULL; + + /* + The snprintf() function is locale-dependent. For currently known + locales, (en, zh, ja, ko, am, he, hi) use '.' as the decimal point, + while other locales use ',' as the decimal point. we need to replace + ',' with '.' to avoid the locale setting. + */ + for (; cur < end; cur++) { + switch (*cur) { + case ',': *cur = '.'; /* fallthrough */ + case '.': dot = cur; break; + case 'e': exp = cur; break; + default: break; + } + } + if (fixed) { + /* remove trailing zeros */ + while (*(end - 1) == '0') end--; + end += *(end - 1) == '.'; + } else { + if (!dot && !exp) { + /* add decimal point, e.g. 123 -> 123.0 */ + byte_copy_2(end, ".0"); + end += 2; + } else if (exp) { + cur = exp + 1; + /* remove positive sign in the exponent part */ + if (*cur == '+') { + memmove(cur, cur + 1, (usize)(end - cur - 1)); + end--; + } + cur += (*cur == '-'); + /* remove leading zeros in the exponent part */ + if (*cur == '0') { + u8 *hdr = cur++; + while (*cur == '0') cur++; + memmove(hdr, cur, (usize)(end - cur)); + end -= (usize)(cur - hdr); + } + } + } + return end; + } +} + +/** Write a double number (requires 40 bytes buffer). */ +static_noinline u8 *write_f64_raw(u8 *buf, u64 raw, yyjson_write_flag flg) { +#if defined(DBL_DECIMAL_DIG) && DBL_DECIMAL_DIG < F64_DEC_DIG + int dig = DBL_DECIMAL_DIG; +#else + int dig = F64_DEC_DIG; +#endif + f64 val = f64_from_bits(raw); + int len = snprintf_num(buf, FP_BUF_LEN, "%.*g", dig, val); + return write_fp_reformat(buf, len, flg, false); +} + +/** Write a double number (requires 40 bytes buffer). */ +static_noinline u8 *write_f32_raw(u8 *buf, u64 raw, yyjson_write_flag flg) { +#if defined(FLT_DECIMAL_DIG) && FLT_DECIMAL_DIG < F32_DEC_DIG + int dig = FLT_DECIMAL_DIG; +#else + int dig = F32_DEC_DIG; +#endif + f64 val = (f64)f64_to_f32(f64_from_bits(raw)); + int len = snprintf_num(buf, FP_BUF_LEN, "%.*g", dig, val); + return write_fp_reformat(buf, len, flg, false); +} + +/** Write a double number (requires 40 bytes buffer). */ +static_noinline u8 *write_f64_raw_fixed(u8 *buf, u64 raw, + yyjson_write_flag flg, u32 prec) { + f64 val = (f64)f64_from_bits(raw); + if (-1e21 < val && val < 1e21) { + int len = snprintf_num(buf, FP_BUF_LEN, "%.*f", (int)prec, val); + return write_fp_reformat(buf, len, flg, true); + } else { + return write_f64_raw(buf, raw, flg); + } +} + +#endif /* FP_WRITER */ + +/** Write a JSON number (requires 40 bytes buffer). */ +static_inline u8 *write_num(u8 *cur, yyjson_val *val, yyjson_write_flag flg) { + if (!(val->tag & YYJSON_SUBTYPE_REAL)) { + u64 pos = val->uni.u64; + u64 neg = ~pos + 1; + usize sign = ((val->tag & YYJSON_SUBTYPE_SINT) > 0) & ((i64)pos < 0); + *cur = '-'; + return write_u64(sign ? neg : pos, cur + sign); + } else { + u64 raw = val->uni.u64; + u32 val_fmt = (u32)(val->tag >> 32); + u32 all_fmt = flg; + u32 fmt = val_fmt | all_fmt; + if (likely(!(fmt >> (32 - YYJSON_WRITE_FP_FLAG_BITS)))) { + /* double to shortest */ + return write_f64_raw(cur, raw, flg); + } else if (fmt >> (32 - YYJSON_WRITE_FP_PREC_BITS)) { + /* double to fixed */ + u32 val_prec = val_fmt >> (32 - YYJSON_WRITE_FP_PREC_BITS); + u32 all_prec = all_fmt >> (32 - YYJSON_WRITE_FP_PREC_BITS); + u32 prec = val_prec ? val_prec : all_prec; + return write_f64_raw_fixed(cur, raw, flg, prec); + } else { + if (fmt & YYJSON_WRITE_FP_TO_FLOAT) { + /* float to shortest */ + return write_f32_raw(cur, raw, flg); + } else { + /* double to shortest */ + return write_f64_raw(cur, raw, flg); + } + } + } +} + +char *yyjson_write_number(const yyjson_val *val, char *buf) { + if (unlikely(!val || !buf)) return NULL; + switch (val->tag & YYJSON_TAG_MASK) { + case YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT: { + buf = (char *)write_u64(val->uni.u64, (u8 *)buf); + *buf = '\0'; + return buf; + } + case YYJSON_TYPE_NUM | YYJSON_SUBTYPE_SINT: { + u64 pos = val->uni.u64; + u64 neg = ~pos + 1; + usize sign = ((i64)pos < 0); + *buf = '-'; + buf = (char *)write_u64(sign ? neg : pos, (u8 *)buf + sign); + *buf = '\0'; + return buf; + } + case YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL: { + u64 raw = val->uni.u64; + u32 fmt = (u32)(val->tag >> 32); + u32 flg = YYJSON_WRITE_ALLOW_INF_AND_NAN; + if (likely(!(fmt >> (32 - YYJSON_WRITE_FP_FLAG_BITS)))) { + buf = (char *)write_f64_raw((u8 *)buf, raw, flg); + } else if (fmt >> (32 - YYJSON_WRITE_FP_PREC_BITS)) { + u32 prec = fmt >> (32 - YYJSON_WRITE_FP_PREC_BITS); + buf = (char *)write_f64_raw_fixed((u8 *)buf, raw, flg, prec); + } else { + if (fmt & YYJSON_WRITE_FP_TO_FLOAT) { + buf = (char *)write_f32_raw((u8 *)buf, raw, flg); + } else { + buf = (char *)write_f64_raw((u8 *)buf, raw, flg); + } + } + if (buf) *buf = '\0'; + return buf; + } + default: return NULL; + } +} + + + +/*============================================================================== + * MARK: - String Writer (Private) + *============================================================================*/ + +/** Character encode type, if (type > CHAR_ENC_ERR_1) bytes = type / 2; */ +typedef u8 char_enc_type; +#define CHAR_ENC_CPY_1 0 /* 1-byte UTF-8, copy. */ +#define CHAR_ENC_ERR_1 1 /* 1-byte UTF-8, error. */ +#define CHAR_ENC_ESC_A 2 /* 1-byte ASCII, escaped as '\x'. */ +#define CHAR_ENC_ESC_1 3 /* 1-byte UTF-8, escaped as '\uXXXX'. */ +#define CHAR_ENC_CPY_2 4 /* 2-byte UTF-8, copy. */ +#define CHAR_ENC_ESC_2 5 /* 2-byte UTF-8, escaped as '\uXXXX'. */ +#define CHAR_ENC_CPY_3 6 /* 3-byte UTF-8, copy. */ +#define CHAR_ENC_ESC_3 7 /* 3-byte UTF-8, escaped as '\uXXXX'. */ +#define CHAR_ENC_CPY_4 8 /* 4-byte UTF-8, copy. */ +#define CHAR_ENC_ESC_4 9 /* 4-byte UTF-8, escaped as '\uXXXX\uXXXX'. */ + +/** Character encode type table: don't escape unicode, don't escape '/'. + (generate with misc/make_tables.c) */ +static const char_enc_type enc_table_cpy[256] = { + 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 3, 2, 2, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 8, 8, 8, 8, 8, 8, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1 +}; + +/** Character encode type table: don't escape unicode, escape '/'. + (generate with misc/make_tables.c) */ +static const char_enc_type enc_table_cpy_slash[256] = { + 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 3, 2, 2, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 8, 8, 8, 8, 8, 8, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1 +}; + +/** Character encode type table: escape unicode, don't escape '/'. + (generate with misc/make_tables.c) */ +static const char_enc_type enc_table_esc[256] = { + 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 3, 2, 2, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 9, 9, 9, 9, 9, 9, 9, 9, 1, 1, 1, 1, 1, 1, 1, 1 +}; + +/** Character encode type table: escape unicode, escape '/'. + (generate with misc/make_tables.c) */ +static const char_enc_type enc_table_esc_slash[256] = { + 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 3, 2, 2, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 9, 9, 9, 9, 9, 9, 9, 9, 1, 1, 1, 1, 1, 1, 1, 1 +}; + +/** Escaped hex character table: ["00" "01" "02" ... "FD" "FE" "FF"]. + (generate with misc/make_tables.c) */ +yyjson_align(2) +static const u8 esc_hex_char_table[512] = { + '0', '0', '0', '1', '0', '2', '0', '3', + '0', '4', '0', '5', '0', '6', '0', '7', + '0', '8', '0', '9', '0', 'A', '0', 'B', + '0', 'C', '0', 'D', '0', 'E', '0', 'F', + '1', '0', '1', '1', '1', '2', '1', '3', + '1', '4', '1', '5', '1', '6', '1', '7', + '1', '8', '1', '9', '1', 'A', '1', 'B', + '1', 'C', '1', 'D', '1', 'E', '1', 'F', + '2', '0', '2', '1', '2', '2', '2', '3', + '2', '4', '2', '5', '2', '6', '2', '7', + '2', '8', '2', '9', '2', 'A', '2', 'B', + '2', 'C', '2', 'D', '2', 'E', '2', 'F', + '3', '0', '3', '1', '3', '2', '3', '3', + '3', '4', '3', '5', '3', '6', '3', '7', + '3', '8', '3', '9', '3', 'A', '3', 'B', + '3', 'C', '3', 'D', '3', 'E', '3', 'F', + '4', '0', '4', '1', '4', '2', '4', '3', + '4', '4', '4', '5', '4', '6', '4', '7', + '4', '8', '4', '9', '4', 'A', '4', 'B', + '4', 'C', '4', 'D', '4', 'E', '4', 'F', + '5', '0', '5', '1', '5', '2', '5', '3', + '5', '4', '5', '5', '5', '6', '5', '7', + '5', '8', '5', '9', '5', 'A', '5', 'B', + '5', 'C', '5', 'D', '5', 'E', '5', 'F', + '6', '0', '6', '1', '6', '2', '6', '3', + '6', '4', '6', '5', '6', '6', '6', '7', + '6', '8', '6', '9', '6', 'A', '6', 'B', + '6', 'C', '6', 'D', '6', 'E', '6', 'F', + '7', '0', '7', '1', '7', '2', '7', '3', + '7', '4', '7', '5', '7', '6', '7', '7', + '7', '8', '7', '9', '7', 'A', '7', 'B', + '7', 'C', '7', 'D', '7', 'E', '7', 'F', + '8', '0', '8', '1', '8', '2', '8', '3', + '8', '4', '8', '5', '8', '6', '8', '7', + '8', '8', '8', '9', '8', 'A', '8', 'B', + '8', 'C', '8', 'D', '8', 'E', '8', 'F', + '9', '0', '9', '1', '9', '2', '9', '3', + '9', '4', '9', '5', '9', '6', '9', '7', + '9', '8', '9', '9', '9', 'A', '9', 'B', + '9', 'C', '9', 'D', '9', 'E', '9', 'F', + 'A', '0', 'A', '1', 'A', '2', 'A', '3', + 'A', '4', 'A', '5', 'A', '6', 'A', '7', + 'A', '8', 'A', '9', 'A', 'A', 'A', 'B', + 'A', 'C', 'A', 'D', 'A', 'E', 'A', 'F', + 'B', '0', 'B', '1', 'B', '2', 'B', '3', + 'B', '4', 'B', '5', 'B', '6', 'B', '7', + 'B', '8', 'B', '9', 'B', 'A', 'B', 'B', + 'B', 'C', 'B', 'D', 'B', 'E', 'B', 'F', + 'C', '0', 'C', '1', 'C', '2', 'C', '3', + 'C', '4', 'C', '5', 'C', '6', 'C', '7', + 'C', '8', 'C', '9', 'C', 'A', 'C', 'B', + 'C', 'C', 'C', 'D', 'C', 'E', 'C', 'F', + 'D', '0', 'D', '1', 'D', '2', 'D', '3', + 'D', '4', 'D', '5', 'D', '6', 'D', '7', + 'D', '8', 'D', '9', 'D', 'A', 'D', 'B', + 'D', 'C', 'D', 'D', 'D', 'E', 'D', 'F', + 'E', '0', 'E', '1', 'E', '2', 'E', '3', + 'E', '4', 'E', '5', 'E', '6', 'E', '7', + 'E', '8', 'E', '9', 'E', 'A', 'E', 'B', + 'E', 'C', 'E', 'D', 'E', 'E', 'E', 'F', + 'F', '0', 'F', '1', 'F', '2', 'F', '3', + 'F', '4', 'F', '5', 'F', '6', 'F', '7', + 'F', '8', 'F', '9', 'F', 'A', 'F', 'B', + 'F', 'C', 'F', 'D', 'F', 'E', 'F', 'F' +}; + +/** Escaped single character table. (generate with misc/make_tables.c) */ +yyjson_align(2) +static const u8 esc_single_char_table[512] = { + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + '\\', 'b', '\\', 't', '\\', 'n', ' ', ' ', + '\\', 'f', '\\', 'r', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', '\\', '"', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', '\\', '/', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + '\\', '\\', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' +}; + +/** Returns the encode table with options. */ +static_inline const char_enc_type *get_enc_table_with_flag( + yyjson_write_flag flg) { + if (has_flg(ESCAPE_UNICODE)) { + if (has_flg(ESCAPE_SLASHES)) { + return enc_table_esc_slash; + } else { + return enc_table_esc; + } + } else { + if (has_flg(ESCAPE_SLASHES)) { + return enc_table_cpy_slash; + } else { + return enc_table_cpy; + } + } +} + +/** Write raw string. */ +static_inline u8 *write_raw(u8 *cur, const u8 *raw, usize raw_len) { + memcpy(cur, raw, raw_len); + return cur + raw_len; +} + +/** + Write string no-escape. + @param cur Buffer cursor. + @param str A UTF-8 string, null-terminator is not required. + @param str_len Length of string in bytes. + @return The buffer cursor after string. + */ +static_inline u8 *write_str_noesc(u8 *cur, const u8 *str, usize str_len) { + *cur++ = '"'; + while (str_len >= 16) { + byte_copy_16(cur, str); + cur += 16; + str += 16; + str_len -= 16; + } + while (str_len >= 4) { + byte_copy_4(cur, str); + cur += 4; + str += 4; + str_len -= 4; + } + while (str_len) { + *cur++ = *str++; + str_len -= 1; + } + *cur++ = '"'; + return cur; +} + +/** + Write UTF-8 string (requires len * 6 + 2 bytes buffer). + @param cur Buffer cursor. + @param esc Escape unicode. + @param inv Allow invalid unicode. + @param str A UTF-8 string, null-terminator is not required. + @param str_len Length of string in bytes. + @param enc_table Encode type table for character. + @return The buffer cursor after string, or NULL on invalid unicode. + */ +static_inline u8 *write_str(u8 *cur, bool esc, bool inv, + const u8 *str, usize str_len, + const char_enc_type *enc_table) { + /* The replacement character U+FFFD, used to indicate invalid character. */ + const v32 rep = {{ 'F', 'F', 'F', 'D' }}; + const v32 pre = {{ '\\', 'u', '0', '0' }}; + + const u8 *src = str; + const u8 *end = str + str_len; + *cur++ = '"'; + +copy_ascii: + /* + Copy continuous ASCII, loop unrolling, same as the following code: + + while (end > src) ( + if (unlikely(enc_table[*src])) break; + *cur++ = *src++; + ); + */ +#define expr_jump(i) \ + if (unlikely(enc_table[src[i]])) goto stop_char_##i; + +#define expr_stop(i) \ + stop_char_##i: \ + memcpy(cur, src, i); \ + cur += i; src += i; goto copy_utf8; + + while (end - src >= 16) { + repeat16_incr(expr_jump) + byte_copy_16(cur, src); + cur += 16; src += 16; + } + + while (end - src >= 4) { + repeat4_incr(expr_jump) + byte_copy_4(cur, src); + cur += 4; src += 4; + } + + while (end > src) { + expr_jump(0) + *cur++ = *src++; + } + + *cur++ = '"'; + return cur; + + repeat16_incr(expr_stop) + +#undef expr_jump +#undef expr_stop + +copy_utf8: + if (unlikely(src + 4 > end)) { + if (end == src) goto copy_end; + if (end - src < enc_table[*src] / 2) goto err_one; + } + switch (enc_table[*src]) { + case CHAR_ENC_CPY_1: { + *cur++ = *src++; + goto copy_ascii; + } + case CHAR_ENC_CPY_2: { +#if YYJSON_DISABLE_UTF8_VALIDATION + byte_copy_2(cur, src); +#else + u32 uni = 0; + byte_copy_2(&uni, src); + if (unlikely(!is_utf8_seq2(uni))) goto err_cpy; + byte_copy_2(cur, &uni); +#endif + cur += 2; + src += 2; + goto copy_utf8; + } + case CHAR_ENC_CPY_3: { +#if YYJSON_DISABLE_UTF8_VALIDATION + if (likely(src + 4 <= end)) { + byte_copy_4(cur, src); + } else { + byte_copy_2(cur, src); + cur[2] = src[2]; + } +#else + u32 uni, tmp; + if (likely(src + 4 <= end)) { + uni = byte_load_4(src); + if (unlikely(!is_utf8_seq3(uni))) goto err_cpy; + byte_copy_4(cur, src); + } else { + uni = byte_load_3(src); + if (unlikely(!is_utf8_seq3(uni))) goto err_cpy; + byte_copy_4(cur, &uni); + } +#endif + cur += 3; + src += 3; + goto copy_utf8; + } + case CHAR_ENC_CPY_4: { +#if YYJSON_DISABLE_UTF8_VALIDATION + byte_copy_4(cur, src); +#else + u32 uni, tmp; + uni = byte_load_4(src); + if (unlikely(!is_utf8_seq4(uni))) goto err_cpy; + byte_copy_4(cur, src); +#endif + cur += 4; + src += 4; + goto copy_utf8; + } + case CHAR_ENC_ESC_A: { + byte_copy_2(cur, &esc_single_char_table[*src * 2]); + cur += 2; + src += 1; + goto copy_utf8; + } + case CHAR_ENC_ESC_1: { + byte_copy_4(cur + 0, &pre); + byte_copy_2(cur + 4, &esc_hex_char_table[*src * 2]); + cur += 6; + src += 1; + goto copy_utf8; + } + case CHAR_ENC_ESC_2: { + u16 u; +#if !YYJSON_DISABLE_UTF8_VALIDATION + u32 v4 = 0; + u16 v2 = byte_load_2(src); + byte_copy_2(&v4, &v2); + if (unlikely(!is_utf8_seq2(v4))) goto err_esc; +#endif + u = (u16)(((u16)(src[0] & 0x1F) << 6) | + ((u16)(src[1] & 0x3F) << 0)); + byte_copy_2(cur + 0, &pre); + byte_copy_2(cur + 2, &esc_hex_char_table[(u >> 8) * 2]); + byte_copy_2(cur + 4, &esc_hex_char_table[(u & 0xFF) * 2]); + cur += 6; + src += 2; + goto copy_utf8; + } + case CHAR_ENC_ESC_3: { + u16 u; + u32 v, tmp; +#if !YYJSON_DISABLE_UTF8_VALIDATION + v = byte_load_3(src); + if (unlikely(!is_utf8_seq3(v))) goto err_esc; +#endif + u = (u16)(((u16)(src[0] & 0x0F) << 12) | + ((u16)(src[1] & 0x3F) << 6) | + ((u16)(src[2] & 0x3F) << 0)); + byte_copy_2(cur + 0, &pre); + byte_copy_2(cur + 2, &esc_hex_char_table[(u >> 8) * 2]); + byte_copy_2(cur + 4, &esc_hex_char_table[(u & 0xFF) * 2]); + cur += 6; + src += 3; + goto copy_utf8; + } + case CHAR_ENC_ESC_4: { + u32 hi, lo, u, v, tmp; +#if !YYJSON_DISABLE_UTF8_VALIDATION + v = byte_load_4(src); + if (unlikely(!is_utf8_seq4(v))) goto err_esc; +#endif + u = ((u32)(src[0] & 0x07) << 18) | + ((u32)(src[1] & 0x3F) << 12) | + ((u32)(src[2] & 0x3F) << 6) | + ((u32)(src[3] & 0x3F) << 0); + u -= 0x10000; + hi = (u >> 10) + 0xD800; + lo = (u & 0x3FF) + 0xDC00; + byte_copy_2(cur + 0, &pre); + byte_copy_2(cur + 2, &esc_hex_char_table[(hi >> 8) * 2]); + byte_copy_2(cur + 4, &esc_hex_char_table[(hi & 0xFF) * 2]); + byte_copy_2(cur + 6, &pre); + byte_copy_2(cur + 8, &esc_hex_char_table[(lo >> 8) * 2]); + byte_copy_2(cur + 10, &esc_hex_char_table[(lo & 0xFF) * 2]); + cur += 12; + src += 4; + goto copy_utf8; + } + case CHAR_ENC_ERR_1: { + goto err_one; + } + default: break; /* unreachable */ + } + +copy_end: + *cur++ = '"'; + return cur; + +err_one: + if (esc) goto err_esc; + else goto err_cpy; + +err_cpy: + if (!inv) return NULL; + *cur++ = *src++; + goto copy_utf8; + +err_esc: + if (!inv) return NULL; + byte_copy_2(cur + 0, &pre); + byte_copy_4(cur + 2, &rep); + cur += 6; + src += 1; + goto copy_utf8; +} + + + +/*============================================================================== + * MARK: - JSON Writer Utilities (Private) + *============================================================================*/ + +/** Write null (requires 8 bytes buffer). */ +static_inline u8 *write_null(u8 *cur) { + v64 v = {{ 'n', 'u', 'l', 'l', ',', '\n', 0, 0 }}; + byte_copy_8(cur, &v); + return cur + 4; +} + +/** Write bool (requires 8 bytes buffer). */ +static_inline u8 *write_bool(u8 *cur, bool val) { + v64 v0 = {{ 'f', 'a', 'l', 's', 'e', ',', '\n', 0 }}; + v64 v1 = {{ 't', 'r', 'u', 'e', ',', '\n', 0, 0 }}; + if (val) { + byte_copy_8(cur, &v1); + } else { + byte_copy_8(cur, &v0); + } + return cur + 5 - val; +} + +/** Write indent (requires level x 4 bytes buffer). + Param spaces should not larger than 4. */ +static_inline u8 *write_indent(u8 *cur, usize level, usize spaces) { + while (level-- > 0) { + byte_copy_4(cur, " "); + cur += spaces; + } + return cur; +} + +/** Write data to file pointer. */ +static bool write_dat_to_fp(FILE *fp, u8 *dat, usize len, + yyjson_write_err *err) { + if (fwrite(dat, len, 1, fp) != 1) { + err->msg = "file writing failed"; + err->code = YYJSON_WRITE_ERROR_FILE_WRITE; + return false; + } + return true; +} + +/** Write data to file. */ +static bool write_dat_to_file(const char *path, u8 *dat, usize len, + yyjson_write_err *err) { +#define return_err(_code, _msg) do { \ + err->msg = _msg; \ + err->code = YYJSON_WRITE_ERROR_##_code; \ + if (file) fclose(file); \ + return false; \ +} while (false) + + FILE *file = fopen_writeonly(path); + if (file == NULL) { + return_err(FILE_OPEN, MSG_FOPEN); + } + if (fwrite(dat, len, 1, file) != 1) { + return_err(FILE_WRITE, MSG_FWRITE); + } + if (fclose(file) != 0) { + file = NULL; + return_err(FILE_WRITE, MSG_FCLOSE); + } + return true; + +#undef return_err +} + + + +/*============================================================================== + * MARK: - JSON Writer Implementation (Private) + *============================================================================*/ + +typedef struct yyjson_write_ctx { + usize tag; +} yyjson_write_ctx; + +static_inline void yyjson_write_ctx_set(yyjson_write_ctx *ctx, + usize size, bool is_obj) { + ctx->tag = (size << 1) | (usize)is_obj; +} + +static_inline void yyjson_write_ctx_get(yyjson_write_ctx *ctx, + usize *size, bool *is_obj) { + usize tag = ctx->tag; + *size = tag >> 1; + *is_obj = (bool)(tag & 1); +} + +/** Write single JSON value. */ +static_inline u8 *yyjson_write_single(yyjson_val *val, + yyjson_write_flag flg, + yyjson_alc alc, + usize *dat_len, + yyjson_write_err *err) { +#define return_err(_code, _msg) do { \ + if (hdr) alc.free(alc.ctx, (void *)hdr); \ + *dat_len = 0; \ + err->code = YYJSON_WRITE_ERROR_##_code; \ + err->msg = _msg; \ + return NULL; \ +} while (false) + +#define incr_len(_len) do { \ + hdr = (u8 *)alc.malloc(alc.ctx, _len); \ + if (!hdr) goto fail_alloc; \ + cur = hdr; \ +} while (false) + +#define check_str_len(_len) do { \ + if ((sizeof(usize) < 8) && (_len >= (USIZE_MAX - 16) / 6)) \ + goto fail_alloc; \ +} while (false) + + u8 *hdr = NULL, *cur; + usize str_len; + const u8 *str_ptr; + const char_enc_type *enc_table = get_enc_table_with_flag(flg); + bool cpy = (enc_table == enc_table_cpy); + bool esc = has_flg(ESCAPE_UNICODE) != 0; + bool inv = has_allow(INVALID_UNICODE) != 0; + bool newline = has_flg(NEWLINE_AT_END) != 0; + const usize end_len = 2; /* '\n' and '\0' */ + + switch (unsafe_yyjson_get_type(val)) { + case YYJSON_TYPE_RAW: + str_len = unsafe_yyjson_get_len(val); + str_ptr = (const u8 *)unsafe_yyjson_get_str(val); + check_str_len(str_len); + incr_len(str_len + end_len); + cur = write_raw(cur, str_ptr, str_len); + break; + + case YYJSON_TYPE_STR: + str_len = unsafe_yyjson_get_len(val); + str_ptr = (const u8 *)unsafe_yyjson_get_str(val); + check_str_len(str_len); + incr_len(str_len * 6 + 2 + end_len); + if (likely(cpy) && unsafe_yyjson_get_subtype(val)) { + cur = write_str_noesc(cur, str_ptr, str_len); + } else { + cur = write_str(cur, esc, inv, str_ptr, str_len, enc_table); + if (unlikely(!cur)) goto fail_str; + } + break; + + case YYJSON_TYPE_NUM: + incr_len(FP_BUF_LEN + end_len); + cur = write_num(cur, val, flg); + if (unlikely(!cur)) goto fail_num; + break; + + case YYJSON_TYPE_BOOL: + incr_len(8); + cur = write_bool(cur, unsafe_yyjson_get_bool(val)); + break; + + case YYJSON_TYPE_NULL: + incr_len(8); + cur = write_null(cur); + break; + + case YYJSON_TYPE_ARR: + incr_len(2 + end_len); + byte_copy_2(cur, "[]"); + cur += 2; + break; + + case YYJSON_TYPE_OBJ: + incr_len(2 + end_len); + byte_copy_2(cur, "{}"); + cur += 2; + break; + + default: + goto fail_type; + } + + if (newline) *cur++ = '\n'; + *cur = '\0'; + *dat_len = (usize)(cur - hdr); + memset(err, 0, sizeof(yyjson_write_err)); + return hdr; + +fail_alloc: return_err(MEMORY_ALLOCATION, MSG_MALLOC); +fail_type: return_err(INVALID_VALUE_TYPE, MSG_ERR_TYPE); +fail_num: return_err(NAN_OR_INF, MSG_NAN_INF); +fail_str: return_err(INVALID_STRING, MSG_ERR_UTF8); + +#undef return_err +#undef check_str_len +#undef incr_len +} + +/** Write JSON document minify. + The root of this document should be a non-empty container. */ +static_inline u8 *yyjson_write_minify(const yyjson_val *root, + const yyjson_write_flag flg, + const yyjson_alc alc, + usize *dat_len, + yyjson_write_err *err) { +#define return_err(_code, _msg) do { \ + *dat_len = 0; \ + err->code = YYJSON_WRITE_ERROR_##_code; \ + err->msg = _msg; \ + if (hdr) alc.free(alc.ctx, hdr); \ + return NULL; \ +} while (false) + +#define incr_len(_len) do { \ + ext_len = (usize)(_len); \ + if (unlikely((u8 *)(cur + ext_len) >= (u8 *)ctx)) { \ + usize ctx_pos = (usize)((u8 *)ctx - hdr); \ + usize cur_pos = (usize)(cur - hdr); \ + ctx_len = (usize)(end - (u8 *)ctx); \ + alc_inc = yyjson_max(alc_len / 2, ext_len); \ + alc_inc = size_align_up(alc_inc, sizeof(yyjson_write_ctx)); \ + if ((sizeof(usize) < 8) && size_add_is_overflow(alc_len, alc_inc)) \ + goto fail_alloc; \ + alc_len += alc_inc; \ + tmp = (u8 *)alc.realloc(alc.ctx, hdr, alc_len - alc_inc, alc_len); \ + if (unlikely(!tmp)) goto fail_alloc; \ + ctx_tmp = (yyjson_write_ctx *)(void *)(tmp + (alc_len - ctx_len)); \ + memmove((void *)ctx_tmp, (void *)(tmp + ctx_pos), ctx_len); \ + ctx = ctx_tmp; \ + cur = tmp + cur_pos; \ + end = tmp + alc_len; \ + hdr = tmp; \ + } \ +} while (false) + +#define check_str_len(_len) do { \ + if ((sizeof(usize) < 8) && (_len >= (USIZE_MAX - 16) / 6)) \ + goto fail_alloc; \ +} while (false) + + yyjson_val *val; + yyjson_type val_type; + usize ctn_len, ctn_len_tmp; + bool ctn_obj, ctn_obj_tmp, is_key; + u8 *hdr, *cur, *end, *tmp; + yyjson_write_ctx *ctx, *ctx_tmp; + usize alc_len, alc_inc, ctx_len, ext_len, str_len; + const u8 *str_ptr; + const char_enc_type *enc_table = get_enc_table_with_flag(flg); + bool cpy = (enc_table == enc_table_cpy); + bool esc = has_flg(ESCAPE_UNICODE) != 0; + bool inv = has_allow(INVALID_UNICODE) != 0; + bool newline = has_flg(NEWLINE_AT_END) != 0; + + alc_len = root->uni.ofs / sizeof(yyjson_val); + alc_len = alc_len * YYJSON_WRITER_ESTIMATED_MINIFY_RATIO + 64; + alc_len = size_align_up(alc_len, sizeof(yyjson_write_ctx)); + hdr = (u8 *)alc.malloc(alc.ctx, alc_len); + if (!hdr) goto fail_alloc; + cur = hdr; + end = hdr + alc_len; + ctx = (yyjson_write_ctx *)(void *)end; + +doc_begin: + val = constcast(yyjson_val *)root; + val_type = unsafe_yyjson_get_type(val); + ctn_obj = (val_type == YYJSON_TYPE_OBJ); + ctn_len = unsafe_yyjson_get_len(val) << (u8)ctn_obj; + *cur++ = (u8)('[' | ((u8)ctn_obj << 5)); + val++; + +val_begin: + val_type = unsafe_yyjson_get_type(val); + if (val_type == YYJSON_TYPE_STR) { + is_key = ((u8)ctn_obj & (u8)~ctn_len); + str_len = unsafe_yyjson_get_len(val); + str_ptr = (const u8 *)unsafe_yyjson_get_str(val); + check_str_len(str_len); + incr_len(str_len * 6 + 16); + if (likely(cpy) && unsafe_yyjson_get_subtype(val)) { + cur = write_str_noesc(cur, str_ptr, str_len); + } else { + cur = write_str(cur, esc, inv, str_ptr, str_len, enc_table); + if (unlikely(!cur)) goto fail_str; + } + *cur++ = is_key ? ':' : ','; + goto val_end; + } + if (val_type == YYJSON_TYPE_NUM) { + incr_len(FP_BUF_LEN); + cur = write_num(cur, val, flg); + if (unlikely(!cur)) goto fail_num; + *cur++ = ','; + goto val_end; + } + if ((val_type & (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) == + (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) { + ctn_len_tmp = unsafe_yyjson_get_len(val); + ctn_obj_tmp = (val_type == YYJSON_TYPE_OBJ); + incr_len(16); + if (unlikely(ctn_len_tmp == 0)) { + /* write empty container */ + *cur++ = (u8)('[' | ((u8)ctn_obj_tmp << 5)); + *cur++ = (u8)(']' | ((u8)ctn_obj_tmp << 5)); + *cur++ = ','; + goto val_end; + } else { + /* push context, setup new container */ + yyjson_write_ctx_set(--ctx, ctn_len, ctn_obj); + ctn_len = ctn_len_tmp << (u8)ctn_obj_tmp; + ctn_obj = ctn_obj_tmp; + *cur++ = (u8)('[' | ((u8)ctn_obj << 5)); + val++; + goto val_begin; + } + } + if (val_type == YYJSON_TYPE_BOOL) { + incr_len(16); + cur = write_bool(cur, unsafe_yyjson_get_bool(val)); + cur++; + goto val_end; + } + if (val_type == YYJSON_TYPE_NULL) { + incr_len(16); + cur = write_null(cur); + cur++; + goto val_end; + } + if (val_type == YYJSON_TYPE_RAW) { + str_len = unsafe_yyjson_get_len(val); + str_ptr = (const u8 *)unsafe_yyjson_get_str(val); + check_str_len(str_len); + incr_len(str_len + 2); + cur = write_raw(cur, str_ptr, str_len); + *cur++ = ','; + goto val_end; + } + goto fail_type; + +val_end: + val++; + ctn_len--; + if (unlikely(ctn_len == 0)) goto ctn_end; + goto val_begin; + +ctn_end: + cur--; + *cur++ = (u8)(']' | ((u8)ctn_obj << 5)); + *cur++ = ','; + if (unlikely((u8 *)ctx >= end)) goto doc_end; + yyjson_write_ctx_get(ctx++, &ctn_len, &ctn_obj); + ctn_len--; + if (likely(ctn_len > 0)) { + goto val_begin; + } else { + goto ctn_end; + } + +doc_end: + if (newline) { + incr_len(2); + *(cur - 1) = '\n'; + cur++; + } + *--cur = '\0'; + *dat_len = (usize)(cur - hdr); + memset(err, 0, sizeof(yyjson_write_err)); + return hdr; + +fail_alloc: return_err(MEMORY_ALLOCATION, MSG_MALLOC); +fail_type: return_err(INVALID_VALUE_TYPE, MSG_ERR_TYPE); +fail_num: return_err(NAN_OR_INF, MSG_NAN_INF); +fail_str: return_err(INVALID_STRING, MSG_ERR_UTF8); + +#undef return_err +#undef incr_len +#undef check_str_len +} + +/** Write JSON document pretty. + The root of this document should be a non-empty container. */ +static_inline u8 *yyjson_write_pretty(const yyjson_val *root, + const yyjson_write_flag flg, + const yyjson_alc alc, + usize *dat_len, + yyjson_write_err *err) { +#define return_err(_code, _msg) do { \ + *dat_len = 0; \ + err->code = YYJSON_WRITE_ERROR_##_code; \ + err->msg = _msg; \ + if (hdr) alc.free(alc.ctx, hdr); \ + return NULL; \ +} while (false) + +#define incr_len(_len) do { \ + ext_len = (usize)(_len); \ + if (unlikely((u8 *)(cur + ext_len) >= (u8 *)ctx)) { \ + usize ctx_pos = (usize)((u8 *)ctx - hdr); \ + usize cur_pos = (usize)(cur - hdr); \ + ctx_len = (usize)(end - (u8 *)ctx); \ + alc_inc = yyjson_max(alc_len / 2, ext_len); \ + alc_inc = size_align_up(alc_inc, sizeof(yyjson_write_ctx)); \ + if ((sizeof(usize) < 8) && size_add_is_overflow(alc_len, alc_inc)) \ + goto fail_alloc; \ + alc_len += alc_inc; \ + tmp = (u8 *)alc.realloc(alc.ctx, hdr, alc_len - alc_inc, alc_len); \ + if (unlikely(!tmp)) goto fail_alloc; \ + ctx_tmp = (yyjson_write_ctx *)(void *)(tmp + (alc_len - ctx_len)); \ + memmove((void *)ctx_tmp, (void *)(tmp + ctx_pos), ctx_len); \ + ctx = ctx_tmp; \ + cur = tmp + cur_pos; \ + end = tmp + alc_len; \ + hdr = tmp; \ + } \ +} while (false) + +#define check_str_len(_len) do { \ + if ((sizeof(usize) < 8) && (_len >= (USIZE_MAX - 16) / 6)) \ + goto fail_alloc; \ +} while (false) + + yyjson_val *val; + yyjson_type val_type; + usize ctn_len, ctn_len_tmp; + bool ctn_obj, ctn_obj_tmp, is_key, no_indent; + u8 *hdr, *cur, *end, *tmp; + yyjson_write_ctx *ctx, *ctx_tmp; + usize alc_len, alc_inc, ctx_len, ext_len, str_len, level; + const u8 *str_ptr; + const char_enc_type *enc_table = get_enc_table_with_flag(flg); + bool cpy = (enc_table == enc_table_cpy); + bool esc = has_flg(ESCAPE_UNICODE) != 0; + bool inv = has_allow(INVALID_UNICODE) != 0; + usize spaces = has_flg(PRETTY_TWO_SPACES) ? 2 : 4; + bool newline = has_flg(NEWLINE_AT_END) != 0; + + alc_len = root->uni.ofs / sizeof(yyjson_val); + alc_len = alc_len * YYJSON_WRITER_ESTIMATED_PRETTY_RATIO + 64; + alc_len = size_align_up(alc_len, sizeof(yyjson_write_ctx)); + hdr = (u8 *)alc.malloc(alc.ctx, alc_len); + if (!hdr) goto fail_alloc; + cur = hdr; + end = hdr + alc_len; + ctx = (yyjson_write_ctx *)(void *)end; + +doc_begin: + val = constcast(yyjson_val *)root; + val_type = unsafe_yyjson_get_type(val); + ctn_obj = (val_type == YYJSON_TYPE_OBJ); + ctn_len = unsafe_yyjson_get_len(val) << (u8)ctn_obj; + *cur++ = (u8)('[' | ((u8)ctn_obj << 5)); + *cur++ = '\n'; + val++; + level = 1; + +val_begin: + val_type = unsafe_yyjson_get_type(val); + if (val_type == YYJSON_TYPE_STR) { + is_key = (bool)((u8)ctn_obj & (u8)~ctn_len); + no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); + str_len = unsafe_yyjson_get_len(val); + str_ptr = (const u8 *)unsafe_yyjson_get_str(val); + check_str_len(str_len); + incr_len(str_len * 6 + 16 + (no_indent ? 0 : level * 4)); + cur = write_indent(cur, no_indent ? 0 : level, spaces); + if (likely(cpy) && unsafe_yyjson_get_subtype(val)) { + cur = write_str_noesc(cur, str_ptr, str_len); + } else { + cur = write_str(cur, esc, inv, str_ptr, str_len, enc_table); + if (unlikely(!cur)) goto fail_str; + } + *cur++ = is_key ? ':' : ','; + *cur++ = is_key ? ' ' : '\n'; + goto val_end; + } + if (val_type == YYJSON_TYPE_NUM) { + no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); + incr_len(FP_BUF_LEN + (no_indent ? 0 : level * 4)); + cur = write_indent(cur, no_indent ? 0 : level, spaces); + cur = write_num(cur, val, flg); + if (unlikely(!cur)) goto fail_num; + *cur++ = ','; + *cur++ = '\n'; + goto val_end; + } + if ((val_type & (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) == + (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) { + no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); + ctn_len_tmp = unsafe_yyjson_get_len(val); + ctn_obj_tmp = (val_type == YYJSON_TYPE_OBJ); + if (unlikely(ctn_len_tmp == 0)) { + /* write empty container */ + incr_len(16 + (no_indent ? 0 : level * 4)); + cur = write_indent(cur, no_indent ? 0 : level, spaces); + *cur++ = (u8)('[' | ((u8)ctn_obj_tmp << 5)); + *cur++ = (u8)(']' | ((u8)ctn_obj_tmp << 5)); + *cur++ = ','; + *cur++ = '\n'; + goto val_end; + } else { + /* push context, setup new container */ + incr_len(32 + (no_indent ? 0 : level * 4)); + yyjson_write_ctx_set(--ctx, ctn_len, ctn_obj); + ctn_len = ctn_len_tmp << (u8)ctn_obj_tmp; + ctn_obj = ctn_obj_tmp; + cur = write_indent(cur, no_indent ? 0 : level, spaces); + level++; + *cur++ = (u8)('[' | ((u8)ctn_obj << 5)); + *cur++ = '\n'; + val++; + goto val_begin; + } + } + if (val_type == YYJSON_TYPE_BOOL) { + no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); + incr_len(16 + (no_indent ? 0 : level * 4)); + cur = write_indent(cur, no_indent ? 0 : level, spaces); + cur = write_bool(cur, unsafe_yyjson_get_bool(val)); + cur += 2; + goto val_end; + } + if (val_type == YYJSON_TYPE_NULL) { + no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); + incr_len(16 + (no_indent ? 0 : level * 4)); + cur = write_indent(cur, no_indent ? 0 : level, spaces); + cur = write_null(cur); + cur += 2; + goto val_end; + } + if (val_type == YYJSON_TYPE_RAW) { + no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); + str_len = unsafe_yyjson_get_len(val); + str_ptr = (const u8 *)unsafe_yyjson_get_str(val); + check_str_len(str_len); + incr_len(str_len + 3 + (no_indent ? 0 : level * 4)); + cur = write_indent(cur, no_indent ? 0 : level, spaces); + cur = write_raw(cur, str_ptr, str_len); + *cur++ = ','; + *cur++ = '\n'; + goto val_end; + } + goto fail_type; + +val_end: + val++; + ctn_len--; + if (unlikely(ctn_len == 0)) goto ctn_end; + goto val_begin; + +ctn_end: + cur -= 2; + *cur++ = '\n'; + incr_len(level * 4); + cur = write_indent(cur, --level, spaces); + *cur++ = (u8)(']' | ((u8)ctn_obj << 5)); + if (unlikely((u8 *)ctx >= end)) goto doc_end; + yyjson_write_ctx_get(ctx++, &ctn_len, &ctn_obj); + ctn_len--; + *cur++ = ','; + *cur++ = '\n'; + if (likely(ctn_len > 0)) { + goto val_begin; + } else { + goto ctn_end; + } + +doc_end: + if (newline) { + incr_len(2); + *cur++ = '\n'; + } + *cur = '\0'; + *dat_len = (usize)(cur - hdr); + memset(err, 0, sizeof(yyjson_write_err)); + return hdr; + +fail_alloc: return_err(MEMORY_ALLOCATION, MSG_MALLOC); +fail_type: return_err(INVALID_VALUE_TYPE, MSG_ERR_TYPE); +fail_num: return_err(NAN_OR_INF, MSG_NAN_INF); +fail_str: return_err(INVALID_STRING, MSG_ERR_UTF8); + +#undef return_err +#undef incr_len +#undef check_str_len +} + + + +/*============================================================================== + * MARK: - JSON Writer (Public) + *============================================================================*/ + +char *yyjson_val_write_opts(const yyjson_val *val, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + usize *dat_len, + yyjson_write_err *err) { + yyjson_write_err tmp_err; + usize tmp_dat_len; + yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC; + yyjson_val *root = constcast(yyjson_val *)val; + + if (!err) err = &tmp_err; + if (!dat_len) dat_len = &tmp_dat_len; + + if (unlikely(!root)) { + *dat_len = 0; + err->msg = "input JSON is NULL"; + err->code = YYJSON_READ_ERROR_INVALID_PARAMETER; + return NULL; + } + + if (!unsafe_yyjson_is_ctn(root) || unsafe_yyjson_get_len(root) == 0) { + return (char *)yyjson_write_single(root, flg, alc, dat_len, err); + } else if (flg & (YYJSON_WRITE_PRETTY | YYJSON_WRITE_PRETTY_TWO_SPACES)) { + return (char *)yyjson_write_pretty(root, flg, alc, dat_len, err); + } else { + return (char *)yyjson_write_minify(root, flg, alc, dat_len, err); + } +} + +char *yyjson_write_opts(const yyjson_doc *doc, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + usize *dat_len, + yyjson_write_err *err) { + yyjson_val *root = doc ? doc->root : NULL; + return yyjson_val_write_opts(root, flg, alc_ptr, dat_len, err); +} + +bool yyjson_val_write_file(const char *path, + const yyjson_val *val, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + yyjson_write_err *err) { + yyjson_write_err tmp_err; + yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC; + u8 *dat; + usize dat_len = 0; + yyjson_val *root = constcast(yyjson_val *)val; + bool suc; + + if (!err) err = &tmp_err; + if (unlikely(!path || !*path)) { + err->msg = "input path is invalid"; + err->code = YYJSON_READ_ERROR_INVALID_PARAMETER; + return false; + } + + dat = (u8 *)yyjson_val_write_opts(root, flg, &alc, &dat_len, err); + if (unlikely(!dat)) return false; + suc = write_dat_to_file(path, dat, dat_len, err); + alc.free(alc.ctx, dat); + return suc; +} + +bool yyjson_val_write_fp(FILE *fp, + const yyjson_val *val, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + yyjson_write_err *err) { + yyjson_write_err tmp_err; + yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC; + u8 *dat; + usize dat_len = 0; + yyjson_val *root = constcast(yyjson_val *)val; + bool suc; + + if (!err) err = &tmp_err; + if (unlikely(!fp)) { + err->msg = "input fp is invalid"; + err->code = YYJSON_READ_ERROR_INVALID_PARAMETER; + return false; + } + + dat = (u8 *)yyjson_val_write_opts(root, flg, &alc, &dat_len, err); + if (unlikely(!dat)) return false; + suc = write_dat_to_fp(fp, dat, dat_len, err); + alc.free(alc.ctx, dat); + return suc; +} + +bool yyjson_write_file(const char *path, + const yyjson_doc *doc, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + yyjson_write_err *err) { + yyjson_val *root = doc ? doc->root : NULL; + return yyjson_val_write_file(path, root, flg, alc_ptr, err); +} + +bool yyjson_write_fp(FILE *fp, + const yyjson_doc *doc, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + yyjson_write_err *err) { + yyjson_val *root = doc ? doc->root : NULL; + return yyjson_val_write_fp(fp, root, flg, alc_ptr, err); +} + + + +/*============================================================================== + * MARK: - Mutable JSON Writer Implementation (Private) + *============================================================================*/ + +typedef struct yyjson_mut_write_ctx { + usize tag; + yyjson_mut_val *ctn; +} yyjson_mut_write_ctx; + +static_inline void yyjson_mut_write_ctx_set(yyjson_mut_write_ctx *ctx, + yyjson_mut_val *ctn, + usize size, bool is_obj) { + ctx->tag = (size << 1) | (usize)is_obj; + ctx->ctn = ctn; +} + +static_inline void yyjson_mut_write_ctx_get(yyjson_mut_write_ctx *ctx, + yyjson_mut_val **ctn, + usize *size, bool *is_obj) { + usize tag = ctx->tag; + *size = tag >> 1; + *is_obj = (bool)(tag & 1); + *ctn = ctx->ctn; +} + +/** Get the estimated number of values for the mutable JSON document. */ +static_inline usize yyjson_mut_doc_estimated_val_num( + const yyjson_mut_doc *doc) { + usize sum = 0; + yyjson_val_chunk *chunk = doc->val_pool.chunks; + while (chunk) { + sum += chunk->chunk_size / sizeof(yyjson_mut_val) - 1; + if (chunk == doc->val_pool.chunks) { + sum -= (usize)(doc->val_pool.end - doc->val_pool.cur); + } + chunk = chunk->next; + } + return sum; +} + +/** Write single JSON value. */ +static_inline u8 *yyjson_mut_write_single(yyjson_mut_val *val, + yyjson_write_flag flg, + yyjson_alc alc, + usize *dat_len, + yyjson_write_err *err) { + return yyjson_write_single((yyjson_val *)val, flg, alc, dat_len, err); +} + +/** Write JSON document minify. + The root of this document should be a non-empty container. */ +static_inline u8 *yyjson_mut_write_minify(const yyjson_mut_val *root, + usize estimated_val_num, + yyjson_write_flag flg, + yyjson_alc alc, + usize *dat_len, + yyjson_write_err *err) { +#define return_err(_code, _msg) do { \ + *dat_len = 0; \ + err->code = YYJSON_WRITE_ERROR_##_code; \ + err->msg = _msg; \ + if (hdr) alc.free(alc.ctx, hdr); \ + return NULL; \ +} while (false) + +#define incr_len(_len) do { \ + ext_len = (usize)(_len); \ + if (unlikely((u8 *)(cur + ext_len) >= (u8 *)ctx)) { \ + usize ctx_pos = (usize)((u8 *)ctx - hdr); \ + usize cur_pos = (usize)(cur - hdr); \ + ctx_len = (usize)(end - (u8 *)ctx); \ + alc_inc = yyjson_max(alc_len / 2, ext_len); \ + alc_inc = size_align_up(alc_inc, sizeof(yyjson_mut_write_ctx)); \ + if ((sizeof(usize) < 8) && size_add_is_overflow(alc_len, alc_inc)) \ + goto fail_alloc; \ + alc_len += alc_inc; \ + tmp = (u8 *)alc.realloc(alc.ctx, hdr, alc_len - alc_inc, alc_len); \ + if (unlikely(!tmp)) goto fail_alloc; \ + ctx_tmp = (yyjson_mut_write_ctx *)(void *)(tmp + (alc_len - ctx_len)); \ + memmove((void *)ctx_tmp, (void *)(tmp + ctx_pos), ctx_len); \ + ctx = ctx_tmp; \ + cur = tmp + cur_pos; \ + end = tmp + alc_len; \ + hdr = tmp; \ + } \ +} while (false) + +#define check_str_len(_len) do { \ + if ((sizeof(usize) < 8) && (_len >= (USIZE_MAX - 16) / 6)) \ + goto fail_alloc; \ +} while (false) + + yyjson_mut_val *val, *ctn; + yyjson_type val_type; + usize ctn_len, ctn_len_tmp; + bool ctn_obj, ctn_obj_tmp, is_key; + u8 *hdr, *cur, *end, *tmp; + yyjson_mut_write_ctx *ctx, *ctx_tmp; + usize alc_len, alc_inc, ctx_len, ext_len, str_len; + const u8 *str_ptr; + const char_enc_type *enc_table = get_enc_table_with_flag(flg); + bool cpy = (enc_table == enc_table_cpy); + bool esc = has_flg(ESCAPE_UNICODE) != 0; + bool inv = has_allow(INVALID_UNICODE) != 0; + bool newline = has_flg(NEWLINE_AT_END) != 0; + + alc_len = estimated_val_num * YYJSON_WRITER_ESTIMATED_MINIFY_RATIO + 64; + alc_len = size_align_up(alc_len, sizeof(yyjson_mut_write_ctx)); + hdr = (u8 *)alc.malloc(alc.ctx, alc_len); + if (!hdr) goto fail_alloc; + cur = hdr; + end = hdr + alc_len; + ctx = (yyjson_mut_write_ctx *)(void *)end; + +doc_begin: + val = constcast(yyjson_mut_val *)root; + val_type = unsafe_yyjson_get_type(val); + ctn_obj = (val_type == YYJSON_TYPE_OBJ); + ctn_len = unsafe_yyjson_get_len(val) << (u8)ctn_obj; + *cur++ = (u8)('[' | ((u8)ctn_obj << 5)); + ctn = val; + val = (yyjson_mut_val *)val->uni.ptr; /* tail */ + val = ctn_obj ? val->next->next : val->next; + +val_begin: + val_type = unsafe_yyjson_get_type(val); + if (val_type == YYJSON_TYPE_STR) { + is_key = ((u8)ctn_obj & (u8)~ctn_len); + str_len = unsafe_yyjson_get_len(val); + str_ptr = (const u8 *)unsafe_yyjson_get_str(val); + check_str_len(str_len); + incr_len(str_len * 6 + 16); + if (likely(cpy) && unsafe_yyjson_get_subtype(val)) { + cur = write_str_noesc(cur, str_ptr, str_len); + } else { + cur = write_str(cur, esc, inv, str_ptr, str_len, enc_table); + if (unlikely(!cur)) goto fail_str; + } + *cur++ = is_key ? ':' : ','; + goto val_end; + } + if (val_type == YYJSON_TYPE_NUM) { + incr_len(FP_BUF_LEN); + cur = write_num(cur, (yyjson_val *)val, flg); + if (unlikely(!cur)) goto fail_num; + *cur++ = ','; + goto val_end; + } + if ((val_type & (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) == + (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) { + ctn_len_tmp = unsafe_yyjson_get_len(val); + ctn_obj_tmp = (val_type == YYJSON_TYPE_OBJ); + incr_len(16); + if (unlikely(ctn_len_tmp == 0)) { + /* write empty container */ + *cur++ = (u8)('[' | ((u8)ctn_obj_tmp << 5)); + *cur++ = (u8)(']' | ((u8)ctn_obj_tmp << 5)); + *cur++ = ','; + goto val_end; + } else { + /* push context, setup new container */ + yyjson_mut_write_ctx_set(--ctx, ctn, ctn_len, ctn_obj); + ctn_len = ctn_len_tmp << (u8)ctn_obj_tmp; + ctn_obj = ctn_obj_tmp; + *cur++ = (u8)('[' | ((u8)ctn_obj << 5)); + ctn = val; + val = (yyjson_mut_val *)ctn->uni.ptr; /* tail */ + val = ctn_obj ? val->next->next : val->next; + goto val_begin; + } + } + if (val_type == YYJSON_TYPE_BOOL) { + incr_len(16); + cur = write_bool(cur, unsafe_yyjson_get_bool(val)); + cur++; + goto val_end; + } + if (val_type == YYJSON_TYPE_NULL) { + incr_len(16); + cur = write_null(cur); + cur++; + goto val_end; + } + if (val_type == YYJSON_TYPE_RAW) { + str_len = unsafe_yyjson_get_len(val); + str_ptr = (const u8 *)unsafe_yyjson_get_str(val); + check_str_len(str_len); + incr_len(str_len + 2); + cur = write_raw(cur, str_ptr, str_len); + *cur++ = ','; + goto val_end; + } + goto fail_type; + +val_end: + ctn_len--; + if (unlikely(ctn_len == 0)) goto ctn_end; + val = val->next; + goto val_begin; + +ctn_end: + cur--; + *cur++ = (u8)(']' | ((u8)ctn_obj << 5)); + *cur++ = ','; + if (unlikely((u8 *)ctx >= end)) goto doc_end; + val = ctn->next; + yyjson_mut_write_ctx_get(ctx++, &ctn, &ctn_len, &ctn_obj); + ctn_len--; + if (likely(ctn_len > 0)) { + goto val_begin; + } else { + goto ctn_end; + } + +doc_end: + if (newline) { + incr_len(2); + *(cur - 1) = '\n'; + cur++; + } + *--cur = '\0'; + *dat_len = (usize)(cur - hdr); + err->code = YYJSON_WRITE_SUCCESS; + err->msg = NULL; + return hdr; + +fail_alloc: return_err(MEMORY_ALLOCATION, MSG_MALLOC); +fail_type: return_err(INVALID_VALUE_TYPE, MSG_ERR_TYPE); +fail_num: return_err(NAN_OR_INF, MSG_NAN_INF); +fail_str: return_err(INVALID_STRING, MSG_ERR_UTF8); + +#undef return_err +#undef incr_len +#undef check_str_len +} + +/** Write JSON document pretty. + The root of this document should be a non-empty container. */ +static_inline u8 *yyjson_mut_write_pretty(const yyjson_mut_val *root, + usize estimated_val_num, + yyjson_write_flag flg, + yyjson_alc alc, + usize *dat_len, + yyjson_write_err *err) { +#define return_err(_code, _msg) do { \ + *dat_len = 0; \ + err->code = YYJSON_WRITE_ERROR_##_code; \ + err->msg = _msg; \ + if (hdr) alc.free(alc.ctx, hdr); \ + return NULL; \ +} while (false) + +#define incr_len(_len) do { \ + ext_len = (usize)(_len); \ + if (unlikely((u8 *)(cur + ext_len) >= (u8 *)ctx)) { \ + usize ctx_pos = (usize)((u8 *)ctx - hdr); \ + usize cur_pos = (usize)(cur - hdr); \ + ctx_len = (usize)(end - (u8 *)ctx); \ + alc_inc = yyjson_max(alc_len / 2, ext_len); \ + alc_inc = size_align_up(alc_inc, sizeof(yyjson_mut_write_ctx)); \ + if ((sizeof(usize) < 8) && size_add_is_overflow(alc_len, alc_inc)) \ + goto fail_alloc; \ + alc_len += alc_inc; \ + tmp = (u8 *)alc.realloc(alc.ctx, hdr, alc_len - alc_inc, alc_len); \ + if (unlikely(!tmp)) goto fail_alloc; \ + ctx_tmp = (yyjson_mut_write_ctx *)(void *)(tmp + (alc_len - ctx_len)); \ + memmove((void *)ctx_tmp, (void *)(tmp + ctx_pos), ctx_len); \ + ctx = ctx_tmp; \ + cur = tmp + cur_pos; \ + end = tmp + alc_len; \ + hdr = tmp; \ + } \ +} while (false) + +#define check_str_len(_len) do { \ + if ((sizeof(usize) < 8) && (_len >= (USIZE_MAX - 16) / 6)) \ + goto fail_alloc; \ +} while (false) + + yyjson_mut_val *val, *ctn; + yyjson_type val_type; + usize ctn_len, ctn_len_tmp; + bool ctn_obj, ctn_obj_tmp, is_key, no_indent; + u8 *hdr, *cur, *end, *tmp; + yyjson_mut_write_ctx *ctx, *ctx_tmp; + usize alc_len, alc_inc, ctx_len, ext_len, str_len, level; + const u8 *str_ptr; + const char_enc_type *enc_table = get_enc_table_with_flag(flg); + bool cpy = (enc_table == enc_table_cpy); + bool esc = has_flg(ESCAPE_UNICODE) != 0; + bool inv = has_allow(INVALID_UNICODE) != 0; + usize spaces = has_flg(PRETTY_TWO_SPACES) ? 2 : 4; + bool newline = has_flg(NEWLINE_AT_END) != 0; + + alc_len = estimated_val_num * YYJSON_WRITER_ESTIMATED_PRETTY_RATIO + 64; + alc_len = size_align_up(alc_len, sizeof(yyjson_mut_write_ctx)); + hdr = (u8 *)alc.malloc(alc.ctx, alc_len); + if (!hdr) goto fail_alloc; + cur = hdr; + end = hdr + alc_len; + ctx = (yyjson_mut_write_ctx *)(void *)end; + +doc_begin: + val = constcast(yyjson_mut_val *)root; + val_type = unsafe_yyjson_get_type(val); + ctn_obj = (val_type == YYJSON_TYPE_OBJ); + ctn_len = unsafe_yyjson_get_len(val) << (u8)ctn_obj; + *cur++ = (u8)('[' | ((u8)ctn_obj << 5)); + *cur++ = '\n'; + ctn = val; + val = (yyjson_mut_val *)val->uni.ptr; /* tail */ + val = ctn_obj ? val->next->next : val->next; + level = 1; + +val_begin: + val_type = unsafe_yyjson_get_type(val); + if (val_type == YYJSON_TYPE_STR) { + is_key = (bool)((u8)ctn_obj & (u8)~ctn_len); + no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); + str_len = unsafe_yyjson_get_len(val); + str_ptr = (const u8 *)unsafe_yyjson_get_str(val); + check_str_len(str_len); + incr_len(str_len * 6 + 16 + (no_indent ? 0 : level * 4)); + cur = write_indent(cur, no_indent ? 0 : level, spaces); + if (likely(cpy) && unsafe_yyjson_get_subtype(val)) { + cur = write_str_noesc(cur, str_ptr, str_len); + } else { + cur = write_str(cur, esc, inv, str_ptr, str_len, enc_table); + if (unlikely(!cur)) goto fail_str; + } + *cur++ = is_key ? ':' : ','; + *cur++ = is_key ? ' ' : '\n'; + goto val_end; + } + if (val_type == YYJSON_TYPE_NUM) { + no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); + incr_len(FP_BUF_LEN + (no_indent ? 0 : level * 4)); + cur = write_indent(cur, no_indent ? 0 : level, spaces); + cur = write_num(cur, (yyjson_val *)val, flg); + if (unlikely(!cur)) goto fail_num; + *cur++ = ','; + *cur++ = '\n'; + goto val_end; + } + if ((val_type & (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) == + (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) { + no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); + ctn_len_tmp = unsafe_yyjson_get_len(val); + ctn_obj_tmp = (val_type == YYJSON_TYPE_OBJ); + if (unlikely(ctn_len_tmp == 0)) { + /* write empty container */ + incr_len(16 + (no_indent ? 0 : level * 4)); + cur = write_indent(cur, no_indent ? 0 : level, spaces); + *cur++ = (u8)('[' | ((u8)ctn_obj_tmp << 5)); + *cur++ = (u8)(']' | ((u8)ctn_obj_tmp << 5)); + *cur++ = ','; + *cur++ = '\n'; + goto val_end; + } else { + /* push context, setup new container */ + incr_len(32 + (no_indent ? 0 : level * 4)); + yyjson_mut_write_ctx_set(--ctx, ctn, ctn_len, ctn_obj); + ctn_len = ctn_len_tmp << (u8)ctn_obj_tmp; + ctn_obj = ctn_obj_tmp; + cur = write_indent(cur, no_indent ? 0 : level, spaces); + level++; + *cur++ = (u8)('[' | ((u8)ctn_obj << 5)); + *cur++ = '\n'; + ctn = val; + val = (yyjson_mut_val *)ctn->uni.ptr; /* tail */ + val = ctn_obj ? val->next->next : val->next; + goto val_begin; + } + } + if (val_type == YYJSON_TYPE_BOOL) { + no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); + incr_len(16 + (no_indent ? 0 : level * 4)); + cur = write_indent(cur, no_indent ? 0 : level, spaces); + cur = write_bool(cur, unsafe_yyjson_get_bool(val)); + cur += 2; + goto val_end; + } + if (val_type == YYJSON_TYPE_NULL) { + no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); + incr_len(16 + (no_indent ? 0 : level * 4)); + cur = write_indent(cur, no_indent ? 0 : level, spaces); + cur = write_null(cur); + cur += 2; + goto val_end; + } + if (val_type == YYJSON_TYPE_RAW) { + no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); + str_len = unsafe_yyjson_get_len(val); + str_ptr = (const u8 *)unsafe_yyjson_get_str(val); + check_str_len(str_len); + incr_len(str_len + 3 + (no_indent ? 0 : level * 4)); + cur = write_indent(cur, no_indent ? 0 : level, spaces); + cur = write_raw(cur, str_ptr, str_len); + *cur++ = ','; + *cur++ = '\n'; + goto val_end; + } + goto fail_type; + +val_end: + ctn_len--; + if (unlikely(ctn_len == 0)) goto ctn_end; + val = val->next; + goto val_begin; + +ctn_end: + cur -= 2; + *cur++ = '\n'; + incr_len(level * 4); + cur = write_indent(cur, --level, spaces); + *cur++ = (u8)(']' | ((u8)ctn_obj << 5)); + if (unlikely((u8 *)ctx >= end)) goto doc_end; + val = ctn->next; + yyjson_mut_write_ctx_get(ctx++, &ctn, &ctn_len, &ctn_obj); + ctn_len--; + *cur++ = ','; + *cur++ = '\n'; + if (likely(ctn_len > 0)) { + goto val_begin; + } else { + goto ctn_end; + } + +doc_end: + if (newline) { + incr_len(2); + *cur++ = '\n'; + } + *cur = '\0'; + *dat_len = (usize)(cur - hdr); + err->code = YYJSON_WRITE_SUCCESS; + err->msg = NULL; + return hdr; + +fail_alloc: return_err(MEMORY_ALLOCATION, MSG_MALLOC); +fail_type: return_err(INVALID_VALUE_TYPE, MSG_ERR_TYPE); +fail_num: return_err(NAN_OR_INF, MSG_NAN_INF); +fail_str: return_err(INVALID_STRING, MSG_ERR_UTF8); + +#undef return_err +#undef incr_len +#undef check_str_len +} + +static char *yyjson_mut_write_opts_impl(const yyjson_mut_val *val, + usize estimated_val_num, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + usize *dat_len, + yyjson_write_err *err) { + yyjson_write_err tmp_err; + usize tmp_dat_len; + yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC; + yyjson_mut_val *root = constcast(yyjson_mut_val *)val; + + if (!err) err = &tmp_err; + if (!dat_len) dat_len = &tmp_dat_len; + + if (unlikely(!root)) { + *dat_len = 0; + err->msg = "input JSON is NULL"; + err->code = YYJSON_WRITE_ERROR_INVALID_PARAMETER; + return NULL; + } + + if (!unsafe_yyjson_is_ctn(root) || unsafe_yyjson_get_len(root) == 0) { + return (char *)yyjson_mut_write_single(root, flg, alc, dat_len, err); + } else if (flg & (YYJSON_WRITE_PRETTY | YYJSON_WRITE_PRETTY_TWO_SPACES)) { + return (char *)yyjson_mut_write_pretty(root, estimated_val_num, + flg, alc, dat_len, err); + } else { + return (char *)yyjson_mut_write_minify(root, estimated_val_num, + flg, alc, dat_len, err); + } +} + + + +/*============================================================================== + * MARK: - Mutable JSON Writer (Public) + *============================================================================*/ + +char *yyjson_mut_val_write_opts(const yyjson_mut_val *val, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + usize *dat_len, + yyjson_write_err *err) { + return yyjson_mut_write_opts_impl(val, 0, flg, alc_ptr, dat_len, err); +} + +char *yyjson_mut_write_opts(const yyjson_mut_doc *doc, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + usize *dat_len, + yyjson_write_err *err) { + yyjson_mut_val *root; + usize estimated_val_num; + if (likely(doc)) { + root = doc->root; + estimated_val_num = yyjson_mut_doc_estimated_val_num(doc); + } else { + root = NULL; + estimated_val_num = 0; + } + return yyjson_mut_write_opts_impl(root, estimated_val_num, + flg, alc_ptr, dat_len, err); +} + +bool yyjson_mut_val_write_file(const char *path, + const yyjson_mut_val *val, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + yyjson_write_err *err) { + yyjson_write_err tmp_err; + yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC; + u8 *dat; + usize dat_len = 0; + yyjson_mut_val *root = constcast(yyjson_mut_val *)val; + bool suc; + + if (!err) err = &tmp_err; + if (unlikely(!path || !*path)) { + err->msg = "input path is invalid"; + err->code = YYJSON_WRITE_ERROR_INVALID_PARAMETER; + return false; + } + + dat = (u8 *)yyjson_mut_val_write_opts(root, flg, &alc, &dat_len, err); + if (unlikely(!dat)) return false; + suc = write_dat_to_file(path, dat, dat_len, err); + alc.free(alc.ctx, dat); + return suc; +} + +bool yyjson_mut_val_write_fp(FILE *fp, + const yyjson_mut_val *val, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + yyjson_write_err *err) { + yyjson_write_err tmp_err; + yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC; + u8 *dat; + usize dat_len = 0; + yyjson_mut_val *root = constcast(yyjson_mut_val *)val; + bool suc; + + if (!err) err = &tmp_err; + if (unlikely(!fp)) { + err->msg = "input fp is invalid"; + err->code = YYJSON_WRITE_ERROR_INVALID_PARAMETER; + return false; + } + + dat = (u8 *)yyjson_mut_val_write_opts(root, flg, &alc, &dat_len, err); + if (unlikely(!dat)) return false; + suc = write_dat_to_fp(fp, dat, dat_len, err); + alc.free(alc.ctx, dat); + return suc; +} + +bool yyjson_mut_write_file(const char *path, + const yyjson_mut_doc *doc, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + yyjson_write_err *err) { + yyjson_mut_val *root = doc ? doc->root : NULL; + return yyjson_mut_val_write_file(path, root, flg, alc_ptr, err); +} + +bool yyjson_mut_write_fp(FILE *fp, + const yyjson_mut_doc *doc, + yyjson_write_flag flg, + const yyjson_alc *alc_ptr, + yyjson_write_err *err) { + yyjson_mut_val *root = doc ? doc->root : NULL; + return yyjson_mut_val_write_fp(fp, root, flg, alc_ptr, err); +} + +#undef has_flg +#undef has_allow +#endif /* YYJSON_DISABLE_WRITER */ + + + +#if !YYJSON_DISABLE_UTILS + +/*============================================================================== + * MARK: - JSON Pointer API (RFC 6901) (Public) + *============================================================================*/ + +/** + Get a token from JSON pointer string. + @param ptr [in] string that points to current token prefix `/` + [out] string that points to next token prefix `/`, or string end + @param end [in] end of the entire JSON Pointer string + @param len [out] unescaped token length + @param esc [out] number of escaped characters in this token + @return head of the token, or NULL if syntax error + */ +static_inline const char *ptr_next_token(const char **ptr, const char *end, + usize *len, usize *esc) { + const char *hdr = *ptr + 1; + const char *cur = hdr; + /* skip unescaped characters */ + while (cur < end && *cur != '/' && *cur != '~') cur++; + if (likely(cur == end || *cur != '~')) { + /* no escaped characters, return */ + *ptr = cur; + *len = (usize)(cur - hdr); + *esc = 0; + return hdr; + } else { + /* handle escaped characters */ + usize esc_num = 0; + while (cur < end && *cur != '/') { + if (*cur++ == '~') { + if (cur == end || (*cur != '0' && *cur != '1')) { + *ptr = cur - 1; + return NULL; + } + esc_num++; + } + } + *ptr = cur; + *len = (usize)(cur - hdr) - esc_num; + *esc = esc_num; + return hdr; + } +} + +/** + Convert token string to index. + @param cur [in] token head + @param len [in] token length + @param idx [out] the index number, or USIZE_MAX if token is '-' + @return true if token is a valid array index + */ +static_inline bool ptr_token_to_idx(const char *cur, usize len, usize *idx) { + const char *end = cur + len; + usize num = 0, add; + if (unlikely(len == 0 || len > USIZE_SAFE_DIG)) return false; + if (*cur == '0') { + if (unlikely(len > 1)) return false; + *idx = 0; + return true; + } + if (*cur == '-') { + if (unlikely(len > 1)) return false; + *idx = USIZE_MAX; + return true; + } + for (; cur < end && (add = (usize)((u8)*cur - (u8)'0')) <= 9; cur++) { + num = num * 10 + add; + } + if (unlikely(num == 0 || cur < end)) return false; + *idx = num; + return true; +} + +/** + Compare JSON key with token. + @param key a string key (yyjson_val or yyjson_mut_val) + @param token a JSON pointer token + @param len unescaped token length + @param esc number of escaped characters in this token + @return true if `str` is equals to `token` + */ +static_inline bool ptr_token_eq(void *key, + const char *token, usize len, usize esc) { + yyjson_val *val = (yyjson_val *)key; + if (unsafe_yyjson_get_len(val) != len) return false; + if (likely(!esc)) { + return memcmp(val->uni.str, token, len) == 0; + } else { + const char *str = val->uni.str; + for (; len-- > 0; token++, str++) { + if (*token == '~') { + if (*str != (*++token == '0' ? '~' : '/')) return false; + } else { + if (*str != *token) return false; + } + } + return true; + } +} + +/** + Get a value from array by token. + @param arr an array, should not be NULL or non-array type + @param token a JSON pointer token + @param len unescaped token length + @param esc number of escaped characters in this token + @return value at index, or NULL if token is not index or index is out of range + */ +static_inline yyjson_val *ptr_arr_get(yyjson_val *arr, const char *token, + usize len, usize esc) { + yyjson_val *val = unsafe_yyjson_get_first(arr); + usize num = unsafe_yyjson_get_len(arr), idx = 0; + if (unlikely(num == 0)) return NULL; + if (unlikely(!ptr_token_to_idx(token, len, &idx))) return NULL; + if (unlikely(idx >= num)) return NULL; + if (unsafe_yyjson_arr_is_flat(arr)) { + return val + idx; + } else { + while (idx-- > 0) val = unsafe_yyjson_get_next(val); + return val; + } +} + +/** + Get a value from object by token. + @param obj [in] an object, should not be NULL or non-object type + @param token [in] a JSON pointer token + @param len [in] unescaped token length + @param esc [in] number of escaped characters in this token + @return value associated with the token, or NULL if no value + */ +static_inline yyjson_val *ptr_obj_get(yyjson_val *obj, const char *token, + usize len, usize esc) { + yyjson_val *key = unsafe_yyjson_get_first(obj); + usize num = unsafe_yyjson_get_len(obj); + if (unlikely(num == 0)) return NULL; + for (; num > 0; num--, key = unsafe_yyjson_get_next(key + 1)) { + if (ptr_token_eq(key, token, len, esc)) return key + 1; + } + return NULL; +} + +/** + Get a value from array by token. + @param arr [in] an array, should not be NULL or non-array type + @param token [in] a JSON pointer token + @param len [in] unescaped token length + @param esc [in] number of escaped characters in this token + @param pre [out] previous (sibling) value of the returned value + @param last [out] whether index is last + @return value at index, or NULL if token is not index or index is out of range + */ +static_inline yyjson_mut_val *ptr_mut_arr_get(yyjson_mut_val *arr, + const char *token, + usize len, usize esc, + yyjson_mut_val **pre, + bool *last) { + yyjson_mut_val *val = (yyjson_mut_val *)arr->uni.ptr; /* last (tail) */ + usize num = unsafe_yyjson_get_len(arr), idx; + if (last) *last = false; + if (pre) *pre = NULL; + if (unlikely(num == 0)) { + if (last && len == 1 && (*token == '0' || *token == '-')) *last = true; + return NULL; + } + if (unlikely(!ptr_token_to_idx(token, len, &idx))) return NULL; + if (last) *last = (idx == num || idx == USIZE_MAX); + if (unlikely(idx >= num)) return NULL; + while (idx-- > 0) val = val->next; + if (pre) *pre = val; + return val->next; +} + +/** + Get a value from object by token. + @param obj [in] an object, should not be NULL or non-object type + @param token [in] a JSON pointer token + @param len [in] unescaped token length + @param esc [in] number of escaped characters in this token + @param pre [out] previous (sibling) key of the returned value's key + @return value associated with the token, or NULL if no value + */ +static_inline yyjson_mut_val *ptr_mut_obj_get(yyjson_mut_val *obj, + const char *token, + usize len, usize esc, + yyjson_mut_val **pre) { + yyjson_mut_val *pre_key = (yyjson_mut_val *)obj->uni.ptr, *key; + usize num = unsafe_yyjson_get_len(obj); + if (pre) *pre = NULL; + if (unlikely(num == 0)) return NULL; + for (; num > 0; num--, pre_key = key) { + key = pre_key->next->next; + if (ptr_token_eq(key, token, len, esc)) { + if (pre) *pre = pre_key; + return key->next; + } + } + return NULL; +} + +/** + Create a string value with JSON pointer token. + @param token [in] a JSON pointer token + @param len [in] unescaped token length + @param esc [in] number of escaped characters in this token + @param doc [in] used for memory allocation when creating value + @return new string value, or NULL if memory allocation failed + */ +static_inline yyjson_mut_val *ptr_new_key(const char *token, + usize len, usize esc, + yyjson_mut_doc *doc) { + const char *src = token; + if (likely(!esc)) { + return yyjson_mut_strncpy(doc, src, len); + } else { + const char *end = src + len + esc; + char *dst = unsafe_yyjson_mut_str_alc(doc, len + esc); + char *str = dst; + if (unlikely(!dst)) return NULL; + for (; src < end; src++, dst++) { + if (*src != '~') *dst = *src; + else *dst = (*++src == '0' ? '~' : '/'); + } + *dst = '\0'; + return yyjson_mut_strn(doc, str, len); + } +} + +/* macros for yyjson_ptr */ +#define return_err(_ret, _code, _pos, _msg) do { \ + if (err) { \ + err->code = YYJSON_PTR_ERR_##_code; \ + err->msg = _msg; \ + err->pos = (usize)(_pos); \ + } \ + return _ret; \ +} while (false) + +#define return_err_resolve(_ret, _pos) \ + return_err(_ret, RESOLVE, _pos, "JSON pointer cannot be resolved") +#define return_err_syntax(_ret, _pos) \ + return_err(_ret, SYNTAX, _pos, "invalid escaped character") +#define return_err_alloc(_ret) \ + return_err(_ret, MEMORY_ALLOCATION, 0, "failed to create value") + +yyjson_val *unsafe_yyjson_ptr_getx(yyjson_val *val, + const char *ptr, size_t ptr_len, + yyjson_ptr_err *err) { + + const char *hdr = ptr, *end = ptr + ptr_len, *token; + usize len, esc; + yyjson_type type; + + while (true) { + token = ptr_next_token(&ptr, end, &len, &esc); + if (unlikely(!token)) return_err_syntax(NULL, ptr - hdr); + type = unsafe_yyjson_get_type(val); + if (type == YYJSON_TYPE_OBJ) { + val = ptr_obj_get(val, token, len, esc); + } else if (type == YYJSON_TYPE_ARR) { + val = ptr_arr_get(val, token, len, esc); + } else { + val = NULL; + } + if (!val) return_err_resolve(NULL, token - hdr); + if (ptr == end) return val; + } +} + +yyjson_mut_val *unsafe_yyjson_mut_ptr_getx( + yyjson_mut_val *val, const char *ptr, size_t ptr_len, + yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { + + const char *hdr = ptr, *end = ptr + ptr_len, *token; + usize len, esc; + yyjson_mut_val *ctn, *pre = NULL; + yyjson_type type; + bool idx_is_last = false; + + while (true) { + token = ptr_next_token(&ptr, end, &len, &esc); + if (unlikely(!token)) return_err_syntax(NULL, ptr - hdr); + ctn = val; + type = unsafe_yyjson_get_type(val); + if (type == YYJSON_TYPE_OBJ) { + val = ptr_mut_obj_get(val, token, len, esc, &pre); + } else if (type == YYJSON_TYPE_ARR) { + val = ptr_mut_arr_get(val, token, len, esc, &pre, &idx_is_last); + } else { + val = NULL; + } + if (ctx && (ptr == end)) { + if (type == YYJSON_TYPE_OBJ || + (type == YYJSON_TYPE_ARR && (val || idx_is_last))) { + ctx->ctn = ctn; + ctx->pre = pre; + } + } + if (!val) return_err_resolve(NULL, token - hdr); + if (ptr == end) return val; + } +} + +bool unsafe_yyjson_mut_ptr_putx( + yyjson_mut_val *val, const char *ptr, size_t ptr_len, + yyjson_mut_val *new_val, yyjson_mut_doc *doc, bool create_parent, + bool insert_new, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { + + const char *hdr = ptr, *end = ptr + ptr_len, *token; + usize token_len, esc, ctn_len; + yyjson_mut_val *ctn, *key, *pre = NULL; + yyjson_mut_val *sep_ctn = NULL, *sep_key = NULL, *sep_val = NULL; + yyjson_type ctn_type; + bool idx_is_last = false; + + /* skip exist parent nodes */ + while (true) { + token = ptr_next_token(&ptr, end, &token_len, &esc); + if (unlikely(!token)) return_err_syntax(false, ptr - hdr); + ctn = val; + ctn_type = unsafe_yyjson_get_type(ctn); + if (ctn_type == YYJSON_TYPE_OBJ) { + val = ptr_mut_obj_get(ctn, token, token_len, esc, &pre); + } else if (ctn_type == YYJSON_TYPE_ARR) { + val = ptr_mut_arr_get(ctn, token, token_len, esc, &pre, + &idx_is_last); + } else return_err_resolve(false, token - hdr); + if (!val) break; + if (ptr == end) break; /* is last token */ + } + + /* create parent nodes if not exist */ + if (unlikely(ptr != end)) { /* not last token */ + if (!create_parent) return_err_resolve(false, token - hdr); + + /* add value at last index if container is array */ + if (ctn_type == YYJSON_TYPE_ARR) { + if (!idx_is_last || !insert_new) { + return_err_resolve(false, token - hdr); + } + val = yyjson_mut_obj(doc); + if (!val) return_err_alloc(false); + + /* delay attaching until all operations are completed */ + sep_ctn = ctn; + sep_key = NULL; + sep_val = val; + + /* move to next token */ + ctn = val; + val = NULL; + ctn_type = YYJSON_TYPE_OBJ; + token = ptr_next_token(&ptr, end, &token_len, &esc); + if (unlikely(!token)) return_err_resolve(false, token - hdr); + } + + /* container is object, create parent nodes */ + while (ptr != end) { /* not last token */ + key = ptr_new_key(token, token_len, esc, doc); + if (!key) return_err_alloc(false); + val = yyjson_mut_obj(doc); + if (!val) return_err_alloc(false); + + /* delay attaching until all operations are completed */ + if (!sep_ctn) { + sep_ctn = ctn; + sep_key = key; + sep_val = val; + } else { + yyjson_mut_obj_add(ctn, key, val); + } + + /* move to next token */ + ctn = val; + val = NULL; + token = ptr_next_token(&ptr, end, &token_len, &esc); + if (unlikely(!token)) return_err_syntax(false, ptr - hdr); + } + } + + /* JSON pointer is resolved, insert or replace target value */ + ctn_len = unsafe_yyjson_get_len(ctn); + if (ctn_type == YYJSON_TYPE_OBJ) { + if (ctx) ctx->ctn = ctn; + if (!val || insert_new) { + /* insert new key-value pair */ + key = ptr_new_key(token, token_len, esc, doc); + if (unlikely(!key)) return_err_alloc(false); + if (ctx) ctx->pre = ctn_len ? (yyjson_mut_val *)ctn->uni.ptr : key; + unsafe_yyjson_mut_obj_add(ctn, key, new_val, ctn_len); + } else { + /* replace exist value */ + key = pre->next->next; + if (ctx) ctx->pre = pre; + if (ctx) ctx->old = val; + yyjson_mut_obj_put(ctn, key, new_val); + } + } else { + /* array */ + if (ctx && (val || idx_is_last)) ctx->ctn = ctn; + if (insert_new) { + /* append new value */ + if (val) { + pre->next = new_val; + new_val->next = val; + if (ctx) ctx->pre = pre; + unsafe_yyjson_set_len(ctn, ctn_len + 1); + } else if (idx_is_last) { + if (ctx) ctx->pre = ctn_len ? + (yyjson_mut_val *)ctn->uni.ptr : new_val; + yyjson_mut_arr_append(ctn, new_val); + } else { + return_err_resolve(false, token - hdr); + } + } else { + /* replace exist value */ + if (!val) return_err_resolve(false, token - hdr); + if (ctn_len > 1) { + new_val->next = val->next; + pre->next = new_val; + if (ctn->uni.ptr == val) ctn->uni.ptr = new_val; + } else { + new_val->next = new_val; + ctn->uni.ptr = new_val; + pre = new_val; + } + if (ctx) ctx->pre = pre; + if (ctx) ctx->old = val; + } + } + + /* all operations are completed, attach the new components to the target */ + if (unlikely(sep_ctn)) { + if (sep_key) yyjson_mut_obj_add(sep_ctn, sep_key, sep_val); + else yyjson_mut_arr_append(sep_ctn, sep_val); + } + return true; +} + +yyjson_mut_val *unsafe_yyjson_mut_ptr_replacex( + yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val, + yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { + + yyjson_mut_val *cur_val; + yyjson_ptr_ctx cur_ctx; + memset(&cur_ctx, 0, sizeof(cur_ctx)); + if (!ctx) ctx = &cur_ctx; + cur_val = unsafe_yyjson_mut_ptr_getx(val, ptr, len, ctx, err); + if (!cur_val) return NULL; + + if (yyjson_mut_is_obj(ctx->ctn)) { + yyjson_mut_val *key = ctx->pre->next->next; + yyjson_mut_obj_put(ctx->ctn, key, new_val); + } else { + yyjson_ptr_ctx_replace(ctx, new_val); + } + ctx->old = cur_val; + return cur_val; +} + +yyjson_mut_val *unsafe_yyjson_mut_ptr_removex( + yyjson_mut_val *val, const char *ptr, size_t len, + yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { + + yyjson_mut_val *cur_val; + yyjson_ptr_ctx cur_ctx; + memset(&cur_ctx, 0, sizeof(cur_ctx)); + if (!ctx) ctx = &cur_ctx; + cur_val = unsafe_yyjson_mut_ptr_getx(val, ptr, len, ctx, err); + if (cur_val) { + if (yyjson_mut_is_obj(ctx->ctn)) { + yyjson_mut_val *key = ctx->pre->next->next; + yyjson_mut_obj_put(ctx->ctn, key, NULL); + } else { + yyjson_ptr_ctx_remove(ctx); + } + ctx->pre = NULL; + ctx->old = cur_val; + } + return cur_val; +} + +/* macros for yyjson_ptr */ +#undef return_err +#undef return_err_resolve +#undef return_err_syntax +#undef return_err_alloc + + + +/*============================================================================== + * MARK: - JSON Patch API (RFC 6902) (Public) + *============================================================================*/ + +/* JSON Patch operation */ +typedef enum patch_op { + PATCH_OP_ADD, /* path, value */ + PATCH_OP_REMOVE, /* path */ + PATCH_OP_REPLACE, /* path, value */ + PATCH_OP_MOVE, /* from, path */ + PATCH_OP_COPY, /* from, path */ + PATCH_OP_TEST, /* path, value */ + PATCH_OP_NONE /* invalid */ +} patch_op; + +static patch_op patch_op_get(yyjson_val *op) { + const char *str = op->uni.str; + switch (unsafe_yyjson_get_len(op)) { + case 3: + if (!memcmp(str, "add", 3)) return PATCH_OP_ADD; + return PATCH_OP_NONE; + case 4: + if (!memcmp(str, "move", 4)) return PATCH_OP_MOVE; + if (!memcmp(str, "copy", 4)) return PATCH_OP_COPY; + if (!memcmp(str, "test", 4)) return PATCH_OP_TEST; + return PATCH_OP_NONE; + case 6: + if (!memcmp(str, "remove", 6)) return PATCH_OP_REMOVE; + return PATCH_OP_NONE; + case 7: + if (!memcmp(str, "replace", 7)) return PATCH_OP_REPLACE; + return PATCH_OP_NONE; + default: + return PATCH_OP_NONE; + } +} + +/* macros for yyjson_patch */ +#define return_err(_code, _msg) do { \ + if (err->ptr.code == YYJSON_PTR_ERR_MEMORY_ALLOCATION) { \ + err->code = YYJSON_PATCH_ERROR_MEMORY_ALLOCATION; \ + err->msg = _msg; \ + memset(&err->ptr, 0, sizeof(yyjson_ptr_err)); \ + } else { \ + err->code = YYJSON_PATCH_ERROR_##_code; \ + err->msg = _msg; \ + err->idx = iter.idx ? iter.idx - 1 : 0; \ + } \ + return NULL; \ +} while (false) + +#define return_err_copy() \ + return_err(MEMORY_ALLOCATION, "failed to copy value") +#define return_err_key(_key) \ + return_err(MISSING_KEY, "missing key " _key) +#define return_err_val(_key) \ + return_err(INVALID_MEMBER, "invalid member " _key) + +#define ptr_get(_ptr) yyjson_mut_ptr_getx( \ + root, _ptr->uni.str, _ptr##_len, NULL, &err->ptr) +#define ptr_add(_ptr, _val) yyjson_mut_ptr_addx( \ + root, _ptr->uni.str, _ptr##_len, _val, doc, false, NULL, &err->ptr) +#define ptr_remove(_ptr) yyjson_mut_ptr_removex( \ + root, _ptr->uni.str, _ptr##_len, NULL, &err->ptr) +#define ptr_replace(_ptr, _val)yyjson_mut_ptr_replacex( \ + root, _ptr->uni.str, _ptr##_len, _val, NULL, &err->ptr) + +yyjson_mut_val *yyjson_patch(yyjson_mut_doc *doc, + yyjson_val *orig, + yyjson_val *patch, + yyjson_patch_err *err) { + + yyjson_mut_val *root; + yyjson_val *obj; + yyjson_arr_iter iter; + yyjson_patch_err err_tmp; + if (!err) err = &err_tmp; + memset(err, 0, sizeof(*err)); + memset(&iter, 0, sizeof(iter)); + + if (unlikely(!doc || !orig || !patch)) { + return_err(INVALID_PARAMETER, "input parameter is NULL"); + } + if (unlikely(!yyjson_is_arr(patch))) { + return_err(INVALID_PARAMETER, "input patch is not array"); + } + root = yyjson_val_mut_copy(doc, orig); + if (unlikely(!root)) return_err_copy(); + + /* iterate through the patch array */ + yyjson_arr_iter_init(patch, &iter); + while ((obj = yyjson_arr_iter_next(&iter))) { + patch_op op_enum; + yyjson_val *op, *path, *from = NULL, *value; + yyjson_mut_val *val = NULL, *test; + usize path_len, from_len = 0; + if (unlikely(!unsafe_yyjson_is_obj(obj))) { + return_err(INVALID_OPERATION, "JSON patch operation is not object"); + } + + /* get required member: op */ + op = yyjson_obj_get(obj, "op"); + if (unlikely(!op)) return_err_key("`op`"); + if (unlikely(!yyjson_is_str(op))) return_err_val("`op`"); + op_enum = patch_op_get(op); + + /* get required member: path */ + path = yyjson_obj_get(obj, "path"); + if (unlikely(!path)) return_err_key("`path`"); + if (unlikely(!yyjson_is_str(path))) return_err_val("`path`"); + path_len = unsafe_yyjson_get_len(path); + + /* get required member: value, from */ + switch ((int)op_enum) { + case PATCH_OP_ADD: case PATCH_OP_REPLACE: case PATCH_OP_TEST: + value = yyjson_obj_get(obj, "value"); + if (unlikely(!value)) return_err_key("`value`"); + val = yyjson_val_mut_copy(doc, value); + if (unlikely(!val)) return_err_copy(); + break; + case PATCH_OP_MOVE: case PATCH_OP_COPY: + from = yyjson_obj_get(obj, "from"); + if (unlikely(!from)) return_err_key("`from`"); + if (unlikely(!yyjson_is_str(from))) return_err_val("`from`"); + from_len = unsafe_yyjson_get_len(from); + break; + default: + break; + } + + /* perform an operation */ + switch ((int)op_enum) { + case PATCH_OP_ADD: /* add(path, val) */ + if (unlikely(path_len == 0)) { root = val; break; } + if (unlikely(!ptr_add(path, val))) { + return_err(POINTER, "failed to add `path`"); + } + break; + case PATCH_OP_REMOVE: /* remove(path) */ + if (unlikely(!ptr_remove(path))) { + return_err(POINTER, "failed to remove `path`"); + } + break; + case PATCH_OP_REPLACE: /* replace(path, val) */ + if (unlikely(path_len == 0)) { root = val; break; } + if (unlikely(!ptr_replace(path, val))) { + return_err(POINTER, "failed to replace `path`"); + } + break; + case PATCH_OP_MOVE: /* val = remove(from), add(path, val) */ + if (unlikely(from_len == 0 && path_len == 0)) break; + val = ptr_remove(from); + if (unlikely(!val)) { + return_err(POINTER, "failed to remove `from`"); + } + if (unlikely(path_len == 0)) { root = val; break; } + if (unlikely(!ptr_add(path, val))) { + return_err(POINTER, "failed to add `path`"); + } + break; + case PATCH_OP_COPY: /* val = get(from).copy, add(path, val) */ + val = ptr_get(from); + if (unlikely(!val)) { + return_err(POINTER, "failed to get `from`"); + } + if (unlikely(path_len == 0)) { root = val; break; } + val = yyjson_mut_val_mut_copy(doc, val); + if (unlikely(!val)) return_err_copy(); + if (unlikely(!ptr_add(path, val))) { + return_err(POINTER, "failed to add `path`"); + } + break; + case PATCH_OP_TEST: /* test = get(path), test.eq(val) */ + test = ptr_get(path); + if (unlikely(!test)) { + return_err(POINTER, "failed to get `path`"); + } + if (unlikely(!yyjson_mut_equals(val, test))) { + return_err(EQUAL, "failed to test equal"); + } + break; + default: + return_err(INVALID_MEMBER, "unsupported `op`"); + } + } + return root; +} + +yyjson_mut_val *yyjson_mut_patch(yyjson_mut_doc *doc, + yyjson_mut_val *orig, + yyjson_mut_val *patch, + yyjson_patch_err *err) { + yyjson_mut_val *root, *obj; + yyjson_mut_arr_iter iter; + yyjson_patch_err err_tmp; + if (!err) err = &err_tmp; + memset(err, 0, sizeof(*err)); + memset(&iter, 0, sizeof(iter)); + + if (unlikely(!doc || !orig || !patch)) { + return_err(INVALID_PARAMETER, "input parameter is NULL"); + } + if (unlikely(!yyjson_mut_is_arr(patch))) { + return_err(INVALID_PARAMETER, "input patch is not array"); + } + root = yyjson_mut_val_mut_copy(doc, orig); + if (unlikely(!root)) return_err_copy(); + + /* iterate through the patch array */ + yyjson_mut_arr_iter_init(patch, &iter); + while ((obj = yyjson_mut_arr_iter_next(&iter))) { + patch_op op_enum; + yyjson_mut_val *op, *path, *from = NULL, *value; + yyjson_mut_val *val = NULL, *test; + usize path_len, from_len = 0; + if (!unsafe_yyjson_is_obj(obj)) { + return_err(INVALID_OPERATION, "JSON patch operation is not object"); + } + + /* get required member: op */ + op = yyjson_mut_obj_get(obj, "op"); + if (unlikely(!op)) return_err_key("`op`"); + if (unlikely(!yyjson_mut_is_str(op))) return_err_val("`op`"); + op_enum = patch_op_get((yyjson_val *)(void *)op); + + /* get required member: path */ + path = yyjson_mut_obj_get(obj, "path"); + if (unlikely(!path)) return_err_key("`path`"); + if (unlikely(!yyjson_mut_is_str(path))) return_err_val("`path`"); + path_len = unsafe_yyjson_get_len(path); + + /* get required member: value, from */ + switch ((int)op_enum) { + case PATCH_OP_ADD: case PATCH_OP_REPLACE: case PATCH_OP_TEST: + value = yyjson_mut_obj_get(obj, "value"); + if (unlikely(!value)) return_err_key("`value`"); + val = yyjson_mut_val_mut_copy(doc, value); + if (unlikely(!val)) return_err_copy(); + break; + case PATCH_OP_MOVE: case PATCH_OP_COPY: + from = yyjson_mut_obj_get(obj, "from"); + if (unlikely(!from)) return_err_key("`from`"); + if (unlikely(!yyjson_mut_is_str(from))) { + return_err_val("`from`"); + } + from_len = unsafe_yyjson_get_len(from); + break; + default: + break; + } + + /* perform an operation */ + switch ((int)op_enum) { + case PATCH_OP_ADD: /* add(path, val) */ + if (unlikely(path_len == 0)) { root = val; break; } + if (unlikely(!ptr_add(path, val))) { + return_err(POINTER, "failed to add `path`"); + } + break; + case PATCH_OP_REMOVE: /* remove(path) */ + if (unlikely(!ptr_remove(path))) { + return_err(POINTER, "failed to remove `path`"); + } + break; + case PATCH_OP_REPLACE: /* replace(path, val) */ + if (unlikely(path_len == 0)) { root = val; break; } + if (unlikely(!ptr_replace(path, val))) { + return_err(POINTER, "failed to replace `path`"); + } + break; + case PATCH_OP_MOVE: /* val = remove(from), add(path, val) */ + if (unlikely(from_len == 0 && path_len == 0)) break; + val = ptr_remove(from); + if (unlikely(!val)) { + return_err(POINTER, "failed to remove `from`"); + } + if (unlikely(path_len == 0)) { root = val; break; } + if (unlikely(!ptr_add(path, val))) { + return_err(POINTER, "failed to add `path`"); + } + break; + case PATCH_OP_COPY: /* val = get(from).copy, add(path, val) */ + val = ptr_get(from); + if (unlikely(!val)) { + return_err(POINTER, "failed to get `from`"); + } + if (unlikely(path_len == 0)) { root = val; break; } + val = yyjson_mut_val_mut_copy(doc, val); + if (unlikely(!val)) return_err_copy(); + if (unlikely(!ptr_add(path, val))) { + return_err(POINTER, "failed to add `path`"); + } + break; + case PATCH_OP_TEST: /* test = get(path), test.eq(val) */ + test = ptr_get(path); + if (unlikely(!test)) { + return_err(POINTER, "failed to get `path`"); + } + if (unlikely(!yyjson_mut_equals(val, test))) { + return_err(EQUAL, "failed to test equal"); + } + break; + default: + return_err(INVALID_MEMBER, "unsupported `op`"); + } + } + return root; +} + +/* macros for yyjson_patch */ +#undef return_err +#undef return_err_copy +#undef return_err_key +#undef return_err_val +#undef ptr_get +#undef ptr_add +#undef ptr_remove +#undef ptr_replace + + + +/*============================================================================== + * MARK: - JSON Merge-Patch API (RFC 7386) (Public) + *============================================================================*/ + +yyjson_mut_val *yyjson_merge_patch(yyjson_mut_doc *doc, + yyjson_val *orig, + yyjson_val *patch) { + usize idx, max; + yyjson_val *key, *orig_val, *patch_val, local_orig; + yyjson_mut_val *builder, *mut_key, *mut_val, *merged_val; + + if (unlikely(!yyjson_is_obj(patch))) { + return yyjson_val_mut_copy(doc, patch); + } + + builder = yyjson_mut_obj(doc); + if (unlikely(!builder)) return NULL; + + memset(&local_orig, 0, sizeof(local_orig)); + if (!yyjson_is_obj(orig)) { + orig = &local_orig; + orig->tag = builder->tag; + orig->uni = builder->uni; + } + + /* If orig is contributing, copy any items not modified by the patch */ + if (orig != &local_orig) { + yyjson_obj_foreach(orig, idx, max, key, orig_val) { + patch_val = yyjson_obj_getn(patch, + unsafe_yyjson_get_str(key), + unsafe_yyjson_get_len(key)); + if (!patch_val) { + mut_key = yyjson_val_mut_copy(doc, key); + mut_val = yyjson_val_mut_copy(doc, orig_val); + if (!yyjson_mut_obj_add(builder, mut_key, mut_val)) return NULL; + } + } + } + + /* Merge items modified by the patch. */ + yyjson_obj_foreach(patch, idx, max, key, patch_val) { + /* null indicates the field is removed. */ + if (unsafe_yyjson_is_null(patch_val)) { + continue; + } + mut_key = yyjson_val_mut_copy(doc, key); + orig_val = yyjson_obj_getn(orig, + unsafe_yyjson_get_str(key), + unsafe_yyjson_get_len(key)); + merged_val = yyjson_merge_patch(doc, orig_val, patch_val); + if (!yyjson_mut_obj_add(builder, mut_key, merged_val)) return NULL; + } + + return builder; +} + +yyjson_mut_val *yyjson_mut_merge_patch(yyjson_mut_doc *doc, + yyjson_mut_val *orig, + yyjson_mut_val *patch) { + usize idx, max; + yyjson_mut_val *key, *orig_val, *patch_val, local_orig; + yyjson_mut_val *builder, *mut_key, *mut_val, *merged_val; + + if (unlikely(!yyjson_mut_is_obj(patch))) { + return yyjson_mut_val_mut_copy(doc, patch); + } + + builder = yyjson_mut_obj(doc); + if (unlikely(!builder)) return NULL; + + memset(&local_orig, 0, sizeof(local_orig)); + if (!yyjson_mut_is_obj(orig)) { + orig = &local_orig; + orig->tag = builder->tag; + orig->uni = builder->uni; + } + + /* If orig is contributing, copy any items not modified by the patch */ + if (orig != &local_orig) { + yyjson_mut_obj_foreach(orig, idx, max, key, orig_val) { + patch_val = yyjson_mut_obj_getn(patch, + unsafe_yyjson_get_str(key), + unsafe_yyjson_get_len(key)); + if (!patch_val) { + mut_key = yyjson_mut_val_mut_copy(doc, key); + mut_val = yyjson_mut_val_mut_copy(doc, orig_val); + if (!yyjson_mut_obj_add(builder, mut_key, mut_val)) return NULL; + } + } + } + + /* Merge items modified by the patch. */ + yyjson_mut_obj_foreach(patch, idx, max, key, patch_val) { + /* null indicates the field is removed. */ + if (unsafe_yyjson_is_null(patch_val)) { + continue; + } + mut_key = yyjson_mut_val_mut_copy(doc, key); + orig_val = yyjson_mut_obj_getn(orig, + unsafe_yyjson_get_str(key), + unsafe_yyjson_get_len(key)); + merged_val = yyjson_mut_merge_patch(doc, orig_val, patch_val); + if (!yyjson_mut_obj_add(builder, mut_key, merged_val)) return NULL; + } + + return builder; +} + +#endif /* YYJSON_DISABLE_UTILS */ diff --git a/research/experiments/003-json-fanout/vendor/yyjson/yyjson.h b/research/experiments/003-json-fanout/vendor/yyjson/yyjson.h new file mode 100644 index 0000000..5eb6d46 --- /dev/null +++ b/research/experiments/003-json-fanout/vendor/yyjson/yyjson.h @@ -0,0 +1,8230 @@ +/*============================================================================== + Copyright (c) 2020 YaoYuan <[email protected]> + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + *============================================================================*/ + +/** + @file yyjson.h + @date 2019-03-09 + @author YaoYuan + */ + +#ifndef YYJSON_H +#define YYJSON_H + + + +/*============================================================================== + * MARK: - Header Files + *============================================================================*/ + +#include <stdio.h> +#include <stdlib.h> +#include <stddef.h> +#include <limits.h> +#include <string.h> +#include <float.h> + + + +/*============================================================================== + * MARK: - Compile-time Options + *============================================================================*/ + +/* + Define as 1 to disable JSON reader at compile-time. + This disables functions with "read" in their name. + Reduces binary size by about 60%. + */ +#ifndef YYJSON_DISABLE_READER +#endif + +/* + Define as 1 to disable JSON writer at compile-time. + This disables functions with "write" in their name. + Reduces binary size by about 30%. + */ +#ifndef YYJSON_DISABLE_WRITER +#endif + +/* + Define as 1 to disable JSON incremental reader at compile-time. + This disables functions with "incr" in their name. + */ +#ifndef YYJSON_DISABLE_INCR_READER +#endif + +/* + Define as 1 to disable JSON Pointer, JSON Patch and JSON Merge Patch supports. + This disables functions with "ptr" or "patch" in their name. + */ +#ifndef YYJSON_DISABLE_UTILS +#endif + +/* + Define as 1 to disable the fast floating-point number conversion in yyjson. + Libc's `strtod/snprintf` will be used instead. + + This reduces binary size by about 30%, but significantly slows down the + floating-point read/write speed. + */ +#ifndef YYJSON_DISABLE_FAST_FP_CONV +#endif + +/* + Define as 1 to disable non-standard JSON features support at compile-time, + such as YYJSON_READ_ALLOW_XXX and YYJSON_WRITE_ALLOW_XXX. + + This reduces binary size by about 10%, and slightly improves performance. + */ +#ifndef YYJSON_DISABLE_NON_STANDARD +#endif + +/* + Define as 1 to disable UTF-8 validation at compile-time. + + Use this if all input strings are guaranteed to be valid UTF-8 + (e.g. language-level String types are already validated). + + Disabling UTF-8 validation improves performance for non-ASCII strings by about + 3% to 7%. + + Note: If this flag is enabled while passing illegal UTF-8 strings, + the following errors may occur: + - Escaped characters may be ignored when parsing JSON strings. + - Ending quotes may be ignored when parsing JSON strings, causing the + string to merge with the next value. + - When serializing with `yyjson_mut_val`, the string's end may be accessed + out of bounds, potentially causing a segmentation fault. + */ +#ifndef YYJSON_DISABLE_UTF8_VALIDATION +#endif + +/* + Define as 1 to improve performance on architectures that do not support + unaligned memory access. + + Normally, this does not need to be set manually. See the C file for details. + */ +#ifndef YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS +#endif + +/* Define as 1 to export symbols when building this library as a Windows DLL. */ +#ifndef YYJSON_EXPORTS +#endif + +/* Define as 1 to import symbols when using this library as a Windows DLL. */ +#ifndef YYJSON_IMPORTS +#endif + +/* Define as 1 to include <stdint.h> for compilers without C99 support. */ +#ifndef YYJSON_HAS_STDINT_H +#endif + +/* Define as 1 to include <stdbool.h> for compilers without C99 support. */ +#ifndef YYJSON_HAS_STDBOOL_H +#endif + + + +/*============================================================================== + * MARK: - Compiler Macros + *============================================================================*/ + +/** compiler version (MSVC) */ +#ifdef _MSC_VER +# define YYJSON_MSC_VER _MSC_VER +#else +# define YYJSON_MSC_VER 0 +#endif + +/** compiler version (GCC) */ +#ifdef __GNUC__ +# define YYJSON_GCC_VER __GNUC__ +# if defined(__GNUC_PATCHLEVEL__) +# define yyjson_gcc_available(major, minor, patch) \ + ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) \ + >= (major * 10000 + minor * 100 + patch)) +# else +# define yyjson_gcc_available(major, minor, patch) \ + ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100) \ + >= (major * 10000 + minor * 100 + patch)) +# endif +#else +# define YYJSON_GCC_VER 0 +# define yyjson_gcc_available(major, minor, patch) 0 +#endif + +/** real gcc check */ +#if defined(__GNUC__) && defined(__GNUC_MINOR__) && \ + !defined(__clang__) && !defined(__llvm__) && \ + !defined(__INTEL_COMPILER) && !defined(__ICC) && \ + !defined(__NVCC__) && !defined(__PGI) && !defined(__TINYC__) +# define YYJSON_IS_REAL_GCC 1 +#else +# define YYJSON_IS_REAL_GCC 0 +#endif + +/** C version (STDC) */ +#if defined(__STDC__) && (__STDC__ >= 1) && defined(__STDC_VERSION__) +# define YYJSON_STDC_VER __STDC_VERSION__ +#else +# define YYJSON_STDC_VER 0 +#endif + +/** C++ version */ +#if defined(__cplusplus) +# define YYJSON_CPP_VER __cplusplus +#else +# define YYJSON_CPP_VER 0 +#endif + +/** compiler builtin check (since gcc 10.0, clang 2.6, icc 2021) */ +#ifndef yyjson_has_builtin +# ifdef __has_builtin +# define yyjson_has_builtin(x) __has_builtin(x) +# else +# define yyjson_has_builtin(x) 0 +# endif +#endif + +/** compiler attribute check (since gcc 5.0, clang 2.9, icc 17) */ +#ifndef yyjson_has_attribute +# ifdef __has_attribute +# define yyjson_has_attribute(x) __has_attribute(x) +# else +# define yyjson_has_attribute(x) 0 +# endif +#endif + +/** compiler feature check (since clang 2.6, icc 17) */ +#ifndef yyjson_has_feature +# ifdef __has_feature +# define yyjson_has_feature(x) __has_feature(x) +# else +# define yyjson_has_feature(x) 0 +# endif +#endif + +/** include check (since gcc 5.0, clang 2.7, icc 16, msvc 2017 15.3) */ +#ifndef yyjson_has_include +# ifdef __has_include +# define yyjson_has_include(x) __has_include(x) +# else +# define yyjson_has_include(x) 0 +# endif +#endif + +/** inline for compiler */ +#ifndef yyjson_inline +# if YYJSON_MSC_VER >= 1200 +# define yyjson_inline __forceinline +# elif defined(_MSC_VER) +# define yyjson_inline __inline +# elif yyjson_has_attribute(always_inline) || YYJSON_GCC_VER >= 4 +# define yyjson_inline __inline__ __attribute__((always_inline)) +# elif defined(__clang__) || defined(__GNUC__) +# define yyjson_inline __inline__ +# elif defined(__cplusplus) || YYJSON_STDC_VER >= 199901L +# define yyjson_inline inline +# else +# define yyjson_inline +# endif +#endif + +/** noinline for compiler */ +#ifndef yyjson_noinline +# if YYJSON_MSC_VER >= 1400 +# define yyjson_noinline __declspec(noinline) +# elif yyjson_has_attribute(noinline) || YYJSON_GCC_VER >= 4 +# define yyjson_noinline __attribute__((noinline)) +# else +# define yyjson_noinline +# endif +#endif + +/** align for compiler */ +#ifndef yyjson_align +# if YYJSON_MSC_VER >= 1300 +# define yyjson_align(x) __declspec(align(x)) +# elif yyjson_has_attribute(aligned) || defined(__GNUC__) +# define yyjson_align(x) __attribute__((aligned(x))) +# elif YYJSON_CPP_VER >= 201103L +# define yyjson_align(x) alignas(x) +# else +# define yyjson_align(x) +# endif +#endif + +/** likely for compiler */ +#ifndef yyjson_likely +# if yyjson_has_builtin(__builtin_expect) || \ + (YYJSON_GCC_VER >= 4 && YYJSON_GCC_VER != 5) +# define yyjson_likely(expr) __builtin_expect(!!(expr), 1) +# else +# define yyjson_likely(expr) (expr) +# endif +#endif + +/** unlikely for compiler */ +#ifndef yyjson_unlikely +# if yyjson_has_builtin(__builtin_expect) || \ + (YYJSON_GCC_VER >= 4 && YYJSON_GCC_VER != 5) +# define yyjson_unlikely(expr) __builtin_expect(!!(expr), 0) +# else +# define yyjson_unlikely(expr) (expr) +# endif +#endif + +/** compile-time constant check for compiler */ +#ifndef yyjson_constant_p +# if yyjson_has_builtin(__builtin_constant_p) || (YYJSON_GCC_VER >= 3) +# define YYJSON_HAS_CONSTANT_P 1 +# define yyjson_constant_p(value) __builtin_constant_p(value) +# else +# define YYJSON_HAS_CONSTANT_P 0 +# define yyjson_constant_p(value) 0 +# endif +#endif + +/** deprecate warning */ +#ifndef yyjson_deprecated +# if YYJSON_MSC_VER >= 1400 +# define yyjson_deprecated(msg) __declspec(deprecated(msg)) +# elif yyjson_has_feature(attribute_deprecated_with_message) || \ + (YYJSON_GCC_VER > 4 || (YYJSON_GCC_VER == 4 && __GNUC_MINOR__ >= 5)) +# define yyjson_deprecated(msg) __attribute__((deprecated(msg))) +# elif YYJSON_GCC_VER >= 3 +# define yyjson_deprecated(msg) __attribute__((deprecated)) +# else +# define yyjson_deprecated(msg) +# endif +#endif + +/** function export */ +#ifndef yyjson_api +# if defined(_WIN32) +# if defined(YYJSON_EXPORTS) && YYJSON_EXPORTS +# define yyjson_api __declspec(dllexport) +# elif defined(YYJSON_IMPORTS) && YYJSON_IMPORTS +# define yyjson_api __declspec(dllimport) +# else +# define yyjson_api +# endif +# elif yyjson_has_attribute(visibility) || YYJSON_GCC_VER >= 4 +# define yyjson_api __attribute__((visibility("default"))) +# else +# define yyjson_api +# endif +#endif + +/** inline function export */ +#ifndef yyjson_api_inline +# define yyjson_api_inline static yyjson_inline +#endif + +/** stdint (C89 compatible) */ +#if (defined(YYJSON_HAS_STDINT_H) && YYJSON_HAS_STDINT_H) || \ + YYJSON_MSC_VER >= 1600 || YYJSON_STDC_VER >= 199901L || \ + defined(_STDINT_H) || defined(_STDINT_H_) || \ + defined(__CLANG_STDINT_H) || defined(_STDINT_H_INCLUDED) || \ + yyjson_has_include(<stdint.h>) +# include <stdint.h> +#elif defined(_MSC_VER) +# if _MSC_VER < 1300 + typedef signed char int8_t; + typedef signed short int16_t; + typedef signed int int32_t; + typedef unsigned char uint8_t; + typedef unsigned short uint16_t; + typedef unsigned int uint32_t; + typedef signed __int64 int64_t; + typedef unsigned __int64 uint64_t; +# else + typedef signed __int8 int8_t; + typedef signed __int16 int16_t; + typedef signed __int32 int32_t; + typedef unsigned __int8 uint8_t; + typedef unsigned __int16 uint16_t; + typedef unsigned __int32 uint32_t; + typedef signed __int64 int64_t; + typedef unsigned __int64 uint64_t; +# endif +#else +# if UCHAR_MAX == 0xFFU + typedef signed char int8_t; + typedef unsigned char uint8_t; +# else +# error cannot find 8-bit integer type +# endif +# if USHRT_MAX == 0xFFFFU + typedef unsigned short uint16_t; + typedef signed short int16_t; +# elif UINT_MAX == 0xFFFFU + typedef unsigned int uint16_t; + typedef signed int int16_t; +# else +# error cannot find 16-bit integer type +# endif +# if UINT_MAX == 0xFFFFFFFFUL + typedef unsigned int uint32_t; + typedef signed int int32_t; +# elif ULONG_MAX == 0xFFFFFFFFUL + typedef unsigned long uint32_t; + typedef signed long int32_t; +# elif USHRT_MAX == 0xFFFFFFFFUL + typedef unsigned short uint32_t; + typedef signed short int32_t; +# else +# error cannot find 32-bit integer type +# endif +# if defined(__INT64_TYPE__) && defined(__UINT64_TYPE__) + typedef __INT64_TYPE__ int64_t; + typedef __UINT64_TYPE__ uint64_t; +# elif defined(__GNUC__) || defined(__clang__) +# if !defined(_SYS_TYPES_H) && !defined(__int8_t_defined) + __extension__ typedef long long int64_t; +# endif + __extension__ typedef unsigned long long uint64_t; +# elif defined(_LONG_LONG) || defined(__MWERKS__) || defined(_CRAYC) || \ + defined(__SUNPRO_C) || defined(__SUNPRO_CC) + typedef long long int64_t; + typedef unsigned long long uint64_t; +# elif (defined(__BORLANDC__) && __BORLANDC__ > 0x460) || \ + defined(__WATCOM_INT64__) || defined (__alpha) || defined (__DECC) + typedef __int64 int64_t; + typedef unsigned __int64 uint64_t; +# else +# error cannot find 64-bit integer type +# endif +#endif + +/** stdbool (C89 compatible) */ +#if (defined(YYJSON_HAS_STDBOOL_H) && YYJSON_HAS_STDBOOL_H) || \ + (yyjson_has_include(<stdbool.h>) && !defined(__STRICT_ANSI__)) || \ + YYJSON_MSC_VER >= 1800 || YYJSON_STDC_VER >= 199901L +# include <stdbool.h> +#elif !defined(__bool_true_false_are_defined) +# define __bool_true_false_are_defined 1 +# if defined(__cplusplus) +# if defined(__GNUC__) && !defined(__STRICT_ANSI__) +# define _Bool bool +# if __cplusplus < 201103L +# define bool bool +# define false false +# define true true +# endif +# endif +# else +# define bool unsigned char +# define true 1 +# define false 0 +# endif +#endif + +/** char bit check */ +#if defined(CHAR_BIT) +# if CHAR_BIT != 8 +# error non 8-bit char is not supported +# endif +#endif + +/** + Microsoft Visual C++ 6.0 doesn't support converting number from u64 to f64: + error C2520: conversion from unsigned __int64 to double not implemented. + */ +#ifndef YYJSON_U64_TO_F64_NO_IMPL +# if (0 < YYJSON_MSC_VER) && (YYJSON_MSC_VER <= 1200) +# define YYJSON_U64_TO_F64_NO_IMPL 1 +# else +# define YYJSON_U64_TO_F64_NO_IMPL 0 +# endif +#endif + + + +/*============================================================================== + * MARK: - Compile Hint Begin + *============================================================================*/ + +/* extern "C" begin */ +#ifdef __cplusplus +extern "C" { +#endif + +/* warning suppress begin */ +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wunused-function" +# pragma clang diagnostic ignored "-Wunused-parameter" +#elif defined(__GNUC__) +# if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) +# pragma GCC diagnostic push +# endif +# pragma GCC diagnostic ignored "-Wunused-function" +# pragma GCC diagnostic ignored "-Wunused-parameter" +#elif defined(_MSC_VER) +# pragma warning(push) +# pragma warning(disable:4800) /* 'int': forcing value to 'true' or 'false' */ +#endif + + + +/*============================================================================== + * MARK: - Version + *============================================================================*/ + +/** The major version of yyjson. */ +#define YYJSON_VERSION_MAJOR 0 + +/** The minor version of yyjson. */ +#define YYJSON_VERSION_MINOR 12 + +/** The patch version of yyjson. */ +#define YYJSON_VERSION_PATCH 0 + +/** The version of yyjson in hex: `(major << 16) | (minor << 8) | (patch)`. */ +#define YYJSON_VERSION_HEX 0x000C00 + +/** The version string of yyjson. */ +#define YYJSON_VERSION_STRING "0.12.0" + +/** The version of yyjson in hex, same as `YYJSON_VERSION_HEX`. */ +yyjson_api uint32_t yyjson_version(void); + + + +/*============================================================================== + * MARK: - JSON Types + *============================================================================*/ + +/** Type of a JSON value (3 bit). */ +typedef uint8_t yyjson_type; +/** No type, invalid. */ +#define YYJSON_TYPE_NONE ((uint8_t)0) /* _____000 */ +/** Raw string type, no subtype. */ +#define YYJSON_TYPE_RAW ((uint8_t)1) /* _____001 */ +/** Null type: `null` literal, no subtype. */ +#define YYJSON_TYPE_NULL ((uint8_t)2) /* _____010 */ +/** Boolean type, subtype: TRUE, FALSE. */ +#define YYJSON_TYPE_BOOL ((uint8_t)3) /* _____011 */ +/** Number type, subtype: UINT, SINT, REAL. */ +#define YYJSON_TYPE_NUM ((uint8_t)4) /* _____100 */ +/** String type, subtype: NONE, NOESC. */ +#define YYJSON_TYPE_STR ((uint8_t)5) /* _____101 */ +/** Array type, no subtype. */ +#define YYJSON_TYPE_ARR ((uint8_t)6) /* _____110 */ +/** Object type, no subtype. */ +#define YYJSON_TYPE_OBJ ((uint8_t)7) /* _____111 */ + +/** Subtype of a JSON value (2 bit). */ +typedef uint8_t yyjson_subtype; +/** No subtype. */ +#define YYJSON_SUBTYPE_NONE ((uint8_t)(0 << 3)) /* ___00___ */ +/** False subtype: `false` literal. */ +#define YYJSON_SUBTYPE_FALSE ((uint8_t)(0 << 3)) /* ___00___ */ +/** True subtype: `true` literal. */ +#define YYJSON_SUBTYPE_TRUE ((uint8_t)(1 << 3)) /* ___01___ */ +/** Unsigned integer subtype: `uint64_t`. */ +#define YYJSON_SUBTYPE_UINT ((uint8_t)(0 << 3)) /* ___00___ */ +/** Signed integer subtype: `int64_t`. */ +#define YYJSON_SUBTYPE_SINT ((uint8_t)(1 << 3)) /* ___01___ */ +/** Real number subtype: `double`. */ +#define YYJSON_SUBTYPE_REAL ((uint8_t)(2 << 3)) /* ___10___ */ +/** String that do not need to be escaped for writing (internal use). */ +#define YYJSON_SUBTYPE_NOESC ((uint8_t)(1 << 3)) /* ___01___ */ + +/** The mask used to extract the type of a JSON value. */ +#define YYJSON_TYPE_MASK ((uint8_t)0x07) /* _____111 */ +/** The number of bits used by the type. */ +#define YYJSON_TYPE_BIT ((uint8_t)3) +/** The mask used to extract the subtype of a JSON value. */ +#define YYJSON_SUBTYPE_MASK ((uint8_t)0x18) /* ___11___ */ +/** The number of bits used by the subtype. */ +#define YYJSON_SUBTYPE_BIT ((uint8_t)2) +/** The mask used to extract the reserved bits of a JSON value. */ +#define YYJSON_RESERVED_MASK ((uint8_t)0xE0) /* 111_____ */ +/** The number of reserved bits. */ +#define YYJSON_RESERVED_BIT ((uint8_t)3) +/** The mask used to extract the tag of a JSON value. */ +#define YYJSON_TAG_MASK ((uint8_t)0xFF) /* 11111111 */ +/** The number of bits used by the tag. */ +#define YYJSON_TAG_BIT ((uint8_t)8) + +/** Padding size for JSON reader. */ +#define YYJSON_PADDING_SIZE 4 + + + +/*============================================================================== + * MARK: - Allocator + *============================================================================*/ + +/** + A memory allocator. + + Typically you don't need to use it, unless you want to customize your own + memory allocator. + */ +typedef struct yyjson_alc { + /** Same as libc's malloc(size), should not be NULL. */ + void *(*malloc)(void *ctx, size_t size); + /** Same as libc's realloc(ptr, size), should not be NULL. */ + void *(*realloc)(void *ctx, void *ptr, size_t old_size, size_t size); + /** Same as libc's free(ptr), should not be NULL. */ + void (*free)(void *ctx, void *ptr); + /** A context for malloc/realloc/free, can be NULL. */ + void *ctx; +} yyjson_alc; + +/** + A pool allocator uses fixed length pre-allocated memory. + + This allocator may be used to avoid malloc/realloc calls. The pre-allocated + memory should be held by the caller. The maximum amount of memory required to + read a JSON can be calculated using the `yyjson_read_max_memory_usage()` + function, but the amount of memory required to write a JSON cannot be directly + calculated. + + This is not a general-purpose allocator. It is designed to handle a single JSON + data at a time. If it is used for overly complex memory tasks, such as parsing + multiple JSON documents using the same allocator but releasing only a few of + them, it may cause memory fragmentation, resulting in performance degradation + and memory waste. + + @param alc The allocator to be initialized. + If this parameter is NULL, the function will fail and return false. + If `buf` or `size` is invalid, this will be set to an empty allocator. + @param buf The buffer memory for this allocator. + If this parameter is NULL, the function will fail and return false. + @param size The size of `buf`, in bytes. + If this parameter is less than 8 words (32/64 bytes on 32/64-bit OS), the + function will fail and return false. + @return true if the `alc` has been successfully initialized. + + @b Example + @code + // parse JSON with stack memory + char buf[1024]; + yyjson_alc alc; + yyjson_alc_pool_init(&alc, buf, 1024); + + const char *json = "{\"name\":\"Helvetica\",\"size\":16}" + yyjson_doc *doc = yyjson_read_opts(json, strlen(json), 0, &alc, NULL); + // the memory of `doc` is on the stack + @endcode + + @warning This Allocator is not thread-safe. + */ +yyjson_api bool yyjson_alc_pool_init(yyjson_alc *alc, void *buf, size_t size); + +/** + A dynamic allocator. + + This allocator has a similar usage to the pool allocator above. However, when + there is not enough memory, this allocator will dynamically request more memory + using libc's `malloc` function, and frees it all at once when it is destroyed. + + @return A new dynamic allocator, or NULL if memory allocation failed. + @note The returned value should be freed with `yyjson_alc_dyn_free()`. + + @warning This Allocator is not thread-safe. + */ +yyjson_api yyjson_alc *yyjson_alc_dyn_new(void); + +/** + Free a dynamic allocator which is created by `yyjson_alc_dyn_new()`. + @param alc The dynamic allocator to be destroyed. + */ +yyjson_api void yyjson_alc_dyn_free(yyjson_alc *alc); + + + +/*============================================================================== + * MARK: - Text Locating + *============================================================================*/ + +/** + Locate the line and column number for a byte position in a string. + This can be used to get better description for error position. + + @param str The input string. + @param len The byte length of the input string. + @param pos The byte position within the input string. + @param line A pointer to receive the line number, starting from 1. + @param col A pointer to receive the column number, starting from 1. + @param chr A pointer to receive the character index, starting from 0. + @return true on success, false if `str` is NULL or `pos` is out of bounds. + @note Line/column/character are calculated based on Unicode characters for + compatibility with text editors. For multi-byte UTF-8 characters, + the returned value may not directly correspond to the byte position. + */ +yyjson_api bool yyjson_locate_pos(const char *str, size_t len, size_t pos, + size_t *line, size_t *col, size_t *chr); + + + +/*============================================================================== + * MARK: - JSON Structure + *============================================================================*/ + +/** + An immutable document for reading JSON. + This document holds memory for all its JSON values and strings. When it is no + longer used, the user should call `yyjson_doc_free()` to free its memory. + */ +typedef struct yyjson_doc yyjson_doc; + +/** + An immutable value for reading JSON. + A JSON Value has the same lifetime as its document. The memory is held by its + document and and cannot be freed alone. + */ +typedef struct yyjson_val yyjson_val; + +/** + A mutable document for building JSON. + This document holds memory for all its JSON values and strings. When it is no + longer used, the user should call `yyjson_mut_doc_free()` to free its memory. + */ +typedef struct yyjson_mut_doc yyjson_mut_doc; + +/** + A mutable value for building JSON. + A JSON Value has the same lifetime as its document. The memory is held by its + document and and cannot be freed alone. + */ +typedef struct yyjson_mut_val yyjson_mut_val; + + + +/*============================================================================== + * MARK: - JSON Reader API + *============================================================================*/ + +/** Run-time options for JSON reader. */ +typedef uint32_t yyjson_read_flag; + +/** Default option (RFC 8259 compliant): + - Read positive integer as uint64_t. + - Read negative integer as int64_t. + - Read floating-point number as double with round-to-nearest mode. + - Read integer which cannot fit in uint64_t or int64_t as double. + - Report error if double number is infinity. + - Report error if string contains invalid UTF-8 character or BOM. + - Report error on trailing commas, comments, inf and nan literals. */ +static const yyjson_read_flag YYJSON_READ_NOFLAG = 0; + +/** Read the input data in-situ. + This option allows the reader to modify and use input data to store string + values, which can increase reading speed slightly. + The caller should hold the input data before free the document. + The input data must be padded by at least `YYJSON_PADDING_SIZE` bytes. + For example: `[1,2]` should be `[1,2]\0\0\0\0`, input length should be 5. */ +static const yyjson_read_flag YYJSON_READ_INSITU = 1 << 0; + +/** Stop when done instead of issuing an error if there's additional content + after a JSON document. This option may be used to parse small pieces of JSON + in larger data, such as `NDJSON`. */ +static const yyjson_read_flag YYJSON_READ_STOP_WHEN_DONE = 1 << 1; + +/** Allow single trailing comma at the end of an object or array, + such as `[1,2,3,]`, `{"a":1,"b":2,}` (non-standard). */ +static const yyjson_read_flag YYJSON_READ_ALLOW_TRAILING_COMMAS = 1 << 2; + +/** Allow C-style single-line and mult-line comments (non-standard). */ +static const yyjson_read_flag YYJSON_READ_ALLOW_COMMENTS = 1 << 3; + +/** Allow inf/nan number and literal, case-insensitive, + such as 1e999, NaN, inf, -Infinity (non-standard). */ +static const yyjson_read_flag YYJSON_READ_ALLOW_INF_AND_NAN = 1 << 4; + +/** Read all numbers as raw strings (value with `YYJSON_TYPE_RAW` type), + inf/nan literal is also read as raw with `ALLOW_INF_AND_NAN` flag. */ +static const yyjson_read_flag YYJSON_READ_NUMBER_AS_RAW = 1 << 5; + +/** Allow reading invalid unicode when parsing string values (non-standard). + Invalid characters will be allowed to appear in the string values, but + invalid escape sequences will still be reported as errors. + This flag does not affect the performance of correctly encoded strings. + + @warning Strings in JSON values may contain incorrect encoding when this + option is used, you need to handle these strings carefully to avoid security + risks. */ +static const yyjson_read_flag YYJSON_READ_ALLOW_INVALID_UNICODE = 1 << 6; + +/** Read big numbers as raw strings. These big numbers include integers that + cannot be represented by `int64_t` and `uint64_t`, and floating-point + numbers that cannot be represented by finite `double`. + The flag will be overridden by `YYJSON_READ_NUMBER_AS_RAW` flag. */ +static const yyjson_read_flag YYJSON_READ_BIGNUM_AS_RAW = 1 << 7; + +/** Allow UTF-8 BOM and skip it before parsing if any (non-standard). */ +static const yyjson_read_flag YYJSON_READ_ALLOW_BOM = 1 << 8; + +/** Allow extended number formats (non-standard): + - Hexadecimal numbers, such as `0x7B`. + - Numbers with leading or trailing decimal point, such as `.123`, `123.`. + - Numbers with a leading plus sign, such as `+123`. */ +static const yyjson_read_flag YYJSON_READ_ALLOW_EXT_NUMBER = 1 << 9; + +/** Allow extended escape sequences in strings (non-standard): + - Additional escapes: `\a`, `\e`, `\v`, ``\'``, `\?`, `\0`. + - Hex escapes: `\xNN`, such as `\x7B`. + - Line continuation: backslash followed by line terminator sequences. + - Unknown escape: if backslash is followed by an unsupported character, + the backslash will be removed and the character will be kept as-is. + However, `\1`-`\9` will still trigger an error. */ +static const yyjson_read_flag YYJSON_READ_ALLOW_EXT_ESCAPE = 1 << 10; + +/** Allow extended whitespace characters (non-standard): + - Vertical tab `\v` and form feed `\f`. + - Line separator `\u2028` and paragraph separator `\u2029`. + - Non-breaking space `\xA0`. + - Byte order mark: `\uFEFF`. + - Other Unicode characters in the Zs (Separator, space) category. */ +static const yyjson_read_flag YYJSON_READ_ALLOW_EXT_WHITESPACE = 1 << 11; + +/** Allow strings enclosed in single quotes (non-standard), such as ``'ab'``. */ +static const yyjson_read_flag YYJSON_READ_ALLOW_SINGLE_QUOTED_STR = 1 << 12; + +/** Allow object keys without quotes (non-standard), such as `{a:1,b:2}`. + This extends the ECMAScript IdentifierName rule by allowing any + non-whitespace character with code point above `U+007F`. */ +static const yyjson_read_flag YYJSON_READ_ALLOW_UNQUOTED_KEY = 1 << 13; + +/** Allow JSON5 format, see: [https://json5.org]. + This flag supports all JSON5 features with some additional extensions: + - Accepts more escape sequences than JSON5 (e.g. `\a`, `\e`). + - Unquoted keys are not limited to ECMAScript IdentifierName. + - Allow case-insensitive `NaN`, `Inf` and `Infinity` literals. */ +static const yyjson_read_flag YYJSON_READ_JSON5 = + (1 << 2) | /* YYJSON_READ_ALLOW_TRAILING_COMMAS */ + (1 << 3) | /* YYJSON_READ_ALLOW_COMMENTS */ + (1 << 4) | /* YYJSON_READ_ALLOW_INF_AND_NAN */ + (1 << 9) | /* YYJSON_READ_ALLOW_EXT_NUMBER */ + (1 << 10) | /* YYJSON_READ_ALLOW_EXT_ESCAPE */ + (1 << 11) | /* YYJSON_READ_ALLOW_EXT_WHITESPACE */ + (1 << 12) | /* YYJSON_READ_ALLOW_SINGLE_QUOTED_STR */ + (1 << 13); /* YYJSON_READ_ALLOW_UNQUOTED_KEY */ + + + +/** Result code for JSON reader. */ +typedef uint32_t yyjson_read_code; + +/** Success, no error. */ +static const yyjson_read_code YYJSON_READ_SUCCESS = 0; + +/** Invalid parameter, such as NULL input string or 0 input length. */ +static const yyjson_read_code YYJSON_READ_ERROR_INVALID_PARAMETER = 1; + +/** Memory allocation failed. */ +static const yyjson_read_code YYJSON_READ_ERROR_MEMORY_ALLOCATION = 2; + +/** Input JSON string is empty. */ +static const yyjson_read_code YYJSON_READ_ERROR_EMPTY_CONTENT = 3; + +/** Unexpected content after document, such as `[123]abc`. */ +static const yyjson_read_code YYJSON_READ_ERROR_UNEXPECTED_CONTENT = 4; + +/** Unexpected end of input, the parsed part is valid, such as `[123`. */ +static const yyjson_read_code YYJSON_READ_ERROR_UNEXPECTED_END = 5; + +/** Unexpected character inside the document, such as `[abc]`. */ +static const yyjson_read_code YYJSON_READ_ERROR_UNEXPECTED_CHARACTER = 6; + +/** Invalid JSON structure, such as `[1,]`. */ +static const yyjson_read_code YYJSON_READ_ERROR_JSON_STRUCTURE = 7; + +/** Invalid comment, deprecated, use `UNEXPECTED_END` for unclosed comment. */ +static const yyjson_read_code YYJSON_READ_ERROR_INVALID_COMMENT = 8; + +/** Invalid number, such as `123.e12`, `000`. */ +static const yyjson_read_code YYJSON_READ_ERROR_INVALID_NUMBER = 9; + +/** Invalid string, such as invalid escaped character inside a string. */ +static const yyjson_read_code YYJSON_READ_ERROR_INVALID_STRING = 10; + +/** Invalid JSON literal, such as `truu`. */ +static const yyjson_read_code YYJSON_READ_ERROR_LITERAL = 11; + +/** Failed to open a file. */ +static const yyjson_read_code YYJSON_READ_ERROR_FILE_OPEN = 12; + +/** Failed to read a file. */ +static const yyjson_read_code YYJSON_READ_ERROR_FILE_READ = 13; + +/** Incomplete input during incremental parsing; parsing state is preserved. */ +static const yyjson_read_code YYJSON_READ_ERROR_MORE = 14; + +/** Error information for JSON reader. */ +typedef struct yyjson_read_err { + /** Error code, see `yyjson_read_code` for all possible values. */ + yyjson_read_code code; + /** Error message, constant, no need to free (NULL if success). */ + const char *msg; + /** Error byte position for input data (0 if success). */ + size_t pos; +} yyjson_read_err; + + + +#if !defined(YYJSON_DISABLE_READER) || !YYJSON_DISABLE_READER + +/** + Read JSON with options. + + This function is thread-safe when: + 1. The `dat` is not modified by other threads. + 2. The `alc` is thread-safe or NULL. + + @param dat The JSON data (UTF-8 without BOM), null-terminator is not required. + If this parameter is NULL, the function will fail and return NULL. + The `dat` will not be modified without the flag `YYJSON_READ_INSITU`, so you + can pass a `const char *` string and case it to `char *` if you don't use + the `YYJSON_READ_INSITU` flag. + @param len The length of JSON data in bytes. + If this parameter is 0, the function will fail and return NULL. + @param flg The JSON read options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON reader. + Pass NULL to use the libc's default allocator. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return A new JSON document, or NULL if an error occurs. + When it's no longer needed, it should be freed with `yyjson_doc_free()`. + */ +yyjson_api yyjson_doc *yyjson_read_opts(char *dat, + size_t len, + yyjson_read_flag flg, + const yyjson_alc *alc, + yyjson_read_err *err); + +/** + Read a JSON file. + + This function is thread-safe when: + 1. The file is not modified by other threads. + 2. The `alc` is thread-safe or NULL. + + @param path The JSON file's path. + This should be a null-terminated string using the system's native encoding. + If this path is NULL or invalid, the function will fail and return NULL. + @param flg The JSON read options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON reader. + Pass NULL to use the libc's default allocator. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return A new JSON document, or NULL if an error occurs. + When it's no longer needed, it should be freed with `yyjson_doc_free()`. + + @warning On 32-bit operating system, files larger than 2GB may fail to read. + */ +yyjson_api yyjson_doc *yyjson_read_file(const char *path, + yyjson_read_flag flg, + const yyjson_alc *alc, + yyjson_read_err *err); + +/** + Read JSON from a file pointer. + + @param fp The file pointer. + The data will be read from the current position of the FILE to the end. + If this fp is NULL or invalid, the function will fail and return NULL. + @param flg The JSON read options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON reader. + Pass NULL to use the libc's default allocator. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return A new JSON document, or NULL if an error occurs. + When it's no longer needed, it should be freed with `yyjson_doc_free()`. + + @warning On 32-bit operating system, files larger than 2GB may fail to read. + */ +yyjson_api yyjson_doc *yyjson_read_fp(FILE *fp, + yyjson_read_flag flg, + const yyjson_alc *alc, + yyjson_read_err *err); + +/** + Read a JSON string. + + This function is thread-safe. + + @param dat The JSON data (UTF-8 without BOM), null-terminator is not required. + If this parameter is NULL, the function will fail and return NULL. + @param len The length of JSON data in bytes. + If this parameter is 0, the function will fail and return NULL. + @param flg The JSON read options. + Multiple options can be combined with `|` operator. 0 means no options. + @return A new JSON document, or NULL if an error occurs. + When it's no longer needed, it should be freed with `yyjson_doc_free()`. + */ +yyjson_api_inline yyjson_doc *yyjson_read(const char *dat, + size_t len, + yyjson_read_flag flg) { + flg &= ~YYJSON_READ_INSITU; /* const string cannot be modified */ + return yyjson_read_opts((char *)(void *)(size_t)(const void *)dat, + len, flg, NULL, NULL); +} + + + +#if !defined(YYJSON_DISABLE_INCR_READER) || !YYJSON_DISABLE_INCR_READER + +/** Opaque state for incremental JSON reader. */ +typedef struct yyjson_incr_state yyjson_incr_state; + +/** + Initialize state for incremental read. + + To read a large JSON document incrementally: + 1. Call `yyjson_incr_new()` to create the state for incremental reading. + 2. Call `yyjson_incr_read()` repeatedly. + 3. Call `yyjson_incr_free()` to free the state. + + Note: The incremental JSON reader only supports standard JSON. + Flags for non-standard features (e.g. comments, trailing commas) are ignored. + + @param buf The JSON data, null-terminator is not required. + If this parameter is NULL, the function will fail and return NULL. + @param buf_len The length of the JSON data in `buf`. + If use `YYJSON_READ_INSITU`, `buf_len` should not include the padding size. + @param flg The JSON read options. + Multiple options can be combined with `|` operator. + @param alc The memory allocator used by JSON reader. + Pass NULL to use the libc's default allocator. + @return A state for incremental reading. + It should be freed with `yyjson_incr_free()`. + NULL is returned if memory allocation fails. +*/ +yyjson_api yyjson_incr_state *yyjson_incr_new(char *buf, size_t buf_len, + yyjson_read_flag flg, + const yyjson_alc *alc); + +/** + Performs incremental read of up to `len` bytes. + + If NULL is returned and `err->code` is set to `YYJSON_READ_ERROR_MORE`, it + indicates that more data is required to continue parsing. Then, call this + function again with incremented `len`. Continue until a document is returned or + an error other than `YYJSON_READ_ERROR_MORE` is returned. + + Note: Parsing in very small increments is not efficient. An increment of + several kilobytes or megabytes is recommended. + + @param state The state for incremental reading, created using + `yyjson_incr_new()`. + @param len The number of bytes of JSON data available to parse. + If this parameter is 0, the function will fail and return NULL. + @param err A pointer to receive error information. + @return A new JSON document, or NULL if an error occurs. + When the document is no longer needed, it should be freed with + `yyjson_doc_free()`. +*/ +yyjson_api yyjson_doc *yyjson_incr_read(yyjson_incr_state *state, size_t len, + yyjson_read_err *err); + +/** Release the incremental read state and free the memory. */ +yyjson_api void yyjson_incr_free(yyjson_incr_state *state); + +#endif /* YYJSON_DISABLE_INCR_READER */ + +/** + Returns the size of maximum memory usage to read a JSON data. + + You may use this value to avoid malloc() or calloc() call inside the reader + to get better performance, or read multiple JSON with one piece of memory. + + @param len The length of JSON data in bytes. + @param flg The JSON read options. + @return The maximum memory size to read this JSON, or 0 if overflow. + + @b Example + @code + // read multiple JSON with same pre-allocated memory + + char *dat1, *dat2, *dat3; // JSON data + size_t len1, len2, len3; // JSON length + size_t max_len = MAX(len1, MAX(len2, len3)); + yyjson_doc *doc; + + // use one allocator for multiple JSON + size_t size = yyjson_read_max_memory_usage(max_len, 0); + void *buf = malloc(size); + yyjson_alc alc; + yyjson_alc_pool_init(&alc, buf, size); + + // no more alloc() or realloc() call during reading + doc = yyjson_read_opts(dat1, len1, 0, &alc, NULL); + yyjson_doc_free(doc); + doc = yyjson_read_opts(dat2, len2, 0, &alc, NULL); + yyjson_doc_free(doc); + doc = yyjson_read_opts(dat3, len3, 0, &alc, NULL); + yyjson_doc_free(doc); + + free(buf); + @endcode + @see yyjson_alc_pool_init() + */ +yyjson_api_inline size_t yyjson_read_max_memory_usage(size_t len, + yyjson_read_flag flg) { + /* + 1. The max value count is (json_size / 2 + 1), + for example: "[1,2,3,4]" size is 9, value count is 5. + 2. Some broken JSON may cost more memory during reading, but fail at end, + for example: "[[[[[[[[". + 3. yyjson use 16 bytes per value, see struct yyjson_val. + 4. yyjson use dynamic memory with a growth factor of 1.5. + + The max memory size is (json_size / 2 * 16 * 1.5 + padding). + */ + size_t mul = (size_t)12 + !(flg & YYJSON_READ_INSITU); + size_t pad = 256; + size_t max = (size_t)(~(size_t)0); + if (flg & YYJSON_READ_STOP_WHEN_DONE) len = len < 256 ? 256 : len; + if (len >= (max - pad - mul) / mul) return 0; + return len * mul + pad; +} + +/** + Read a JSON number. + + This function is thread-safe when data is not modified by other threads. + + @param dat The JSON data (UTF-8 without BOM), null-terminator is required. + If this parameter is NULL, the function will fail and return NULL. + @param val The output value where result is stored. + If this parameter is NULL, the function will fail and return NULL. + The value will hold either UINT or SINT or REAL number; + @param flg The JSON read options. + Multiple options can be combined with `|` operator. 0 means no options. + Supports `YYJSON_READ_NUMBER_AS_RAW` and `YYJSON_READ_ALLOW_INF_AND_NAN`. + @param alc The memory allocator used for long number. + It is only used when the built-in floating point reader is disabled. + Pass NULL to use the libc's default allocator. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return If successful, a pointer to the character after the last character + used in the conversion, NULL if an error occurs. + */ +yyjson_api const char *yyjson_read_number(const char *dat, + yyjson_val *val, + yyjson_read_flag flg, + const yyjson_alc *alc, + yyjson_read_err *err); + +/** Same as `yyjson_read_number()`. */ +yyjson_api_inline const char *yyjson_mut_read_number(const char *dat, + yyjson_mut_val *val, + yyjson_read_flag flg, + const yyjson_alc *alc, + yyjson_read_err *err) { + return yyjson_read_number(dat, (yyjson_val *)val, flg, alc, err); +} + +#endif /* YYJSON_DISABLE_READER) */ + + + +/*============================================================================== + * MARK: - JSON Writer API + *============================================================================*/ + +/** Run-time options for JSON writer. */ +typedef uint32_t yyjson_write_flag; + +/** Default option: + - Write JSON minify. + - Report error on inf or nan number. + - Report error on invalid UTF-8 string. + - Do not escape unicode or slash. */ +static const yyjson_write_flag YYJSON_WRITE_NOFLAG = 0; + +/** Write JSON pretty with 4 space indent. */ +static const yyjson_write_flag YYJSON_WRITE_PRETTY = 1 << 0; + +/** Escape unicode as `uXXXX`, make the output ASCII only. */ +static const yyjson_write_flag YYJSON_WRITE_ESCAPE_UNICODE = 1 << 1; + +/** Escape '/' as '\/'. */ +static const yyjson_write_flag YYJSON_WRITE_ESCAPE_SLASHES = 1 << 2; + +/** Write inf and nan number as 'Infinity' and 'NaN' literal (non-standard). */ +static const yyjson_write_flag YYJSON_WRITE_ALLOW_INF_AND_NAN = 1 << 3; + +/** Write inf and nan number as null literal. + This flag will override `YYJSON_WRITE_ALLOW_INF_AND_NAN` flag. */ +static const yyjson_write_flag YYJSON_WRITE_INF_AND_NAN_AS_NULL = 1 << 4; + +/** Allow invalid unicode when encoding string values (non-standard). + Invalid characters in string value will be copied byte by byte. + If `YYJSON_WRITE_ESCAPE_UNICODE` flag is also set, invalid character will be + escaped as `U+FFFD` (replacement character). + This flag does not affect the performance of correctly encoded strings. */ +static const yyjson_write_flag YYJSON_WRITE_ALLOW_INVALID_UNICODE = 1 << 5; + +/** Write JSON pretty with 2 space indent. + This flag will override `YYJSON_WRITE_PRETTY` flag. */ +static const yyjson_write_flag YYJSON_WRITE_PRETTY_TWO_SPACES = 1 << 6; + +/** Adds a newline character `\n` at the end of the JSON. + This can be helpful for text editors or NDJSON. */ +static const yyjson_write_flag YYJSON_WRITE_NEWLINE_AT_END = 1 << 7; + + + +/** The highest 8 bits of `yyjson_write_flag` and real number value's `tag` + are reserved for controlling the output format of floating-point numbers. */ +#define YYJSON_WRITE_FP_FLAG_BITS 8 + +/** The highest 4 bits of flag are reserved for precision value. */ +#define YYJSON_WRITE_FP_PREC_BITS 4 + +/** Write floating-point number using fixed-point notation. + - This is similar to ECMAScript `Number.prototype.toFixed(prec)`, + but with trailing zeros removed. The `prec` ranges from 1 to 15. + - This will produce shorter output but may lose some precision. */ +#define YYJSON_WRITE_FP_TO_FIXED(prec) ((yyjson_write_flag)( \ + (uint32_t)((uint32_t)(prec)) << (32 - 4) )) + +/** Write floating-point numbers using single-precision (float). + - This casts `double` to `float` before serialization. + - This will produce shorter output, but may lose some precision. + - This flag is ignored if `YYJSON_WRITE_FP_TO_FIXED(prec)` is also used. */ +#define YYJSON_WRITE_FP_TO_FLOAT ((yyjson_write_flag)(1 << (32 - 5))) + + + +/** Result code for JSON writer */ +typedef uint32_t yyjson_write_code; + +/** Success, no error. */ +static const yyjson_write_code YYJSON_WRITE_SUCCESS = 0; + +/** Invalid parameter, such as NULL document. */ +static const yyjson_write_code YYJSON_WRITE_ERROR_INVALID_PARAMETER = 1; + +/** Memory allocation failure occurs. */ +static const yyjson_write_code YYJSON_WRITE_ERROR_MEMORY_ALLOCATION = 2; + +/** Invalid value type in JSON document. */ +static const yyjson_write_code YYJSON_WRITE_ERROR_INVALID_VALUE_TYPE = 3; + +/** NaN or Infinity number occurs. */ +static const yyjson_write_code YYJSON_WRITE_ERROR_NAN_OR_INF = 4; + +/** Failed to open a file. */ +static const yyjson_write_code YYJSON_WRITE_ERROR_FILE_OPEN = 5; + +/** Failed to write a file. */ +static const yyjson_write_code YYJSON_WRITE_ERROR_FILE_WRITE = 6; + +/** Invalid unicode in string. */ +static const yyjson_write_code YYJSON_WRITE_ERROR_INVALID_STRING = 7; + +/** Error information for JSON writer. */ +typedef struct yyjson_write_err { + /** Error code, see `yyjson_write_code` for all possible values. */ + yyjson_write_code code; + /** Error message, constant, no need to free (NULL if success). */ + const char *msg; +} yyjson_write_err; + + + +#if !defined(YYJSON_DISABLE_WRITER) || !YYJSON_DISABLE_WRITER + +/*============================================================================== + * MARK: - JSON Document Writer API + *============================================================================*/ + +/** + Write a document to JSON string with options. + + This function is thread-safe when: + The `alc` is thread-safe or NULL. + + @param doc The JSON document. + If this doc is NULL or has no root, the function will fail and return false. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON writer. + Pass NULL to use the libc's default allocator. + @param len A pointer to receive output length in bytes (not including the + null-terminator). Pass NULL if you don't need length information. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return A new JSON string, or NULL if an error occurs. + This string is encoded as UTF-8 with a null-terminator. + When it's no longer needed, it should be freed with free() or alc->free(). + */ +yyjson_api char *yyjson_write_opts(const yyjson_doc *doc, + yyjson_write_flag flg, + const yyjson_alc *alc, + size_t *len, + yyjson_write_err *err); + +/** + Write a document to JSON file with options. + + This function is thread-safe when: + 1. The file is not accessed by other threads. + 2. The `alc` is thread-safe or NULL. + + @param path The JSON file's path. + This should be a null-terminated string using the system's native encoding. + If this path is NULL or invalid, the function will fail and return false. + If this file is not empty, the content will be discarded. + @param doc The JSON document. + If this doc is NULL or has no root, the function will fail and return false. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON writer. + Pass NULL to use the libc's default allocator. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return true if successful, false if an error occurs. + + @warning On 32-bit operating system, files larger than 2GB may fail to write. + */ +yyjson_api bool yyjson_write_file(const char *path, + const yyjson_doc *doc, + yyjson_write_flag flg, + const yyjson_alc *alc, + yyjson_write_err *err); + +/** + Write a document to file pointer with options. + + @param fp The file pointer. + The data will be written to the current position of the file. + If this fp is NULL or invalid, the function will fail and return false. + @param doc The JSON document. + If this doc is NULL or has no root, the function will fail and return false. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON writer. + Pass NULL to use the libc's default allocator. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return true if successful, false if an error occurs. + + @warning On 32-bit operating system, files larger than 2GB may fail to write. + */ +yyjson_api bool yyjson_write_fp(FILE *fp, + const yyjson_doc *doc, + yyjson_write_flag flg, + const yyjson_alc *alc, + yyjson_write_err *err); + +/** + Write a document to JSON string. + + This function is thread-safe. + + @param doc The JSON document. + If this doc is NULL or has no root, the function will fail and return false. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param len A pointer to receive output length in bytes (not including the + null-terminator). Pass NULL if you don't need length information. + @return A new JSON string, or NULL if an error occurs. + This string is encoded as UTF-8 with a null-terminator. + When it's no longer needed, it should be freed with free(). + */ +yyjson_api_inline char *yyjson_write(const yyjson_doc *doc, + yyjson_write_flag flg, + size_t *len) { + return yyjson_write_opts(doc, flg, NULL, len, NULL); +} + + + +/** + Write a document to JSON string with options. + + This function is thread-safe when: + 1. The `doc` is not modified by other threads. + 2. The `alc` is thread-safe or NULL. + + @param doc The mutable JSON document. + If this doc is NULL or has no root, the function will fail and return false. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON writer. + Pass NULL to use the libc's default allocator. + @param len A pointer to receive output length in bytes (not including the + null-terminator). Pass NULL if you don't need length information. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return A new JSON string, or NULL if an error occurs. + This string is encoded as UTF-8 with a null-terminator. + When it's no longer needed, it should be freed with free() or alc->free(). + */ +yyjson_api char *yyjson_mut_write_opts(const yyjson_mut_doc *doc, + yyjson_write_flag flg, + const yyjson_alc *alc, + size_t *len, + yyjson_write_err *err); + +/** + Write a document to JSON file with options. + + This function is thread-safe when: + 1. The file is not accessed by other threads. + 2. The `doc` is not modified by other threads. + 3. The `alc` is thread-safe or NULL. + + @param path The JSON file's path. + This should be a null-terminated string using the system's native encoding. + If this path is NULL or invalid, the function will fail and return false. + If this file is not empty, the content will be discarded. + @param doc The mutable JSON document. + If this doc is NULL or has no root, the function will fail and return false. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON writer. + Pass NULL to use the libc's default allocator. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return true if successful, false if an error occurs. + + @warning On 32-bit operating system, files larger than 2GB may fail to write. + */ +yyjson_api bool yyjson_mut_write_file(const char *path, + const yyjson_mut_doc *doc, + yyjson_write_flag flg, + const yyjson_alc *alc, + yyjson_write_err *err); + +/** + Write a document to file pointer with options. + + @param fp The file pointer. + The data will be written to the current position of the file. + If this fp is NULL or invalid, the function will fail and return false. + @param doc The mutable JSON document. + If this doc is NULL or has no root, the function will fail and return false. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON writer. + Pass NULL to use the libc's default allocator. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return true if successful, false if an error occurs. + + @warning On 32-bit operating system, files larger than 2GB may fail to write. + */ +yyjson_api bool yyjson_mut_write_fp(FILE *fp, + const yyjson_mut_doc *doc, + yyjson_write_flag flg, + const yyjson_alc *alc, + yyjson_write_err *err); + +/** + Write a document to JSON string. + + This function is thread-safe when: + The `doc` is not modified by other threads. + + @param doc The JSON document. + If this doc is NULL or has no root, the function will fail and return false. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param len A pointer to receive output length in bytes (not including the + null-terminator). Pass NULL if you don't need length information. + @return A new JSON string, or NULL if an error occurs. + This string is encoded as UTF-8 with a null-terminator. + When it's no longer needed, it should be freed with free(). + */ +yyjson_api_inline char *yyjson_mut_write(const yyjson_mut_doc *doc, + yyjson_write_flag flg, + size_t *len) { + return yyjson_mut_write_opts(doc, flg, NULL, len, NULL); +} + + + +/*============================================================================== + * MARK: - JSON Value Writer API + *============================================================================*/ + +/** + Write a value to JSON string with options. + + This function is thread-safe when: + The `alc` is thread-safe or NULL. + + @param val The JSON root value. + If this parameter is NULL, the function will fail and return NULL. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON writer. + Pass NULL to use the libc's default allocator. + @param len A pointer to receive output length in bytes (not including the + null-terminator). Pass NULL if you don't need length information. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return A new JSON string, or NULL if an error occurs. + This string is encoded as UTF-8 with a null-terminator. + When it's no longer needed, it should be freed with free() or alc->free(). + */ +yyjson_api char *yyjson_val_write_opts(const yyjson_val *val, + yyjson_write_flag flg, + const yyjson_alc *alc, + size_t *len, + yyjson_write_err *err); + +/** + Write a value to JSON file with options. + + This function is thread-safe when: + 1. The file is not accessed by other threads. + 2. The `alc` is thread-safe or NULL. + + @param path The JSON file's path. + This should be a null-terminated string using the system's native encoding. + If this path is NULL or invalid, the function will fail and return false. + If this file is not empty, the content will be discarded. + @param val The JSON root value. + If this parameter is NULL, the function will fail and return NULL. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON writer. + Pass NULL to use the libc's default allocator. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return true if successful, false if an error occurs. + + @warning On 32-bit operating system, files larger than 2GB may fail to write. + */ +yyjson_api bool yyjson_val_write_file(const char *path, + const yyjson_val *val, + yyjson_write_flag flg, + const yyjson_alc *alc, + yyjson_write_err *err); + +/** + Write a value to file pointer with options. + + @param fp The file pointer. + The data will be written to the current position of the file. + If this path is NULL or invalid, the function will fail and return false. + @param val The JSON root value. + If this parameter is NULL, the function will fail and return NULL. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON writer. + Pass NULL to use the libc's default allocator. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return true if successful, false if an error occurs. + + @warning On 32-bit operating system, files larger than 2GB may fail to write. + */ +yyjson_api bool yyjson_val_write_fp(FILE *fp, + const yyjson_val *val, + yyjson_write_flag flg, + const yyjson_alc *alc, + yyjson_write_err *err); + +/** + Write a value to JSON string. + + This function is thread-safe. + + @param val The JSON root value. + If this parameter is NULL, the function will fail and return NULL. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param len A pointer to receive output length in bytes (not including the + null-terminator). Pass NULL if you don't need length information. + @return A new JSON string, or NULL if an error occurs. + This string is encoded as UTF-8 with a null-terminator. + When it's no longer needed, it should be freed with free(). + */ +yyjson_api_inline char *yyjson_val_write(const yyjson_val *val, + yyjson_write_flag flg, + size_t *len) { + return yyjson_val_write_opts(val, flg, NULL, len, NULL); +} + +/** + Write a value to JSON string with options. + + This function is thread-safe when: + 1. The `val` is not modified by other threads. + 2. The `alc` is thread-safe or NULL. + + @param val The mutable JSON root value. + If this parameter is NULL, the function will fail and return NULL. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON writer. + Pass NULL to use the libc's default allocator. + @param len A pointer to receive output length in bytes (not including the + null-terminator). Pass NULL if you don't need length information. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return A new JSON string, or NULL if an error occurs. + This string is encoded as UTF-8 with a null-terminator. + When it's no longer needed, it should be freed with free() or alc->free(). + */ +yyjson_api char *yyjson_mut_val_write_opts(const yyjson_mut_val *val, + yyjson_write_flag flg, + const yyjson_alc *alc, + size_t *len, + yyjson_write_err *err); + +/** + Write a value to JSON file with options. + + This function is thread-safe when: + 1. The file is not accessed by other threads. + 2. The `val` is not modified by other threads. + 3. The `alc` is thread-safe or NULL. + + @param path The JSON file's path. + This should be a null-terminated string using the system's native encoding. + If this path is NULL or invalid, the function will fail and return false. + If this file is not empty, the content will be discarded. + @param val The mutable JSON root value. + If this parameter is NULL, the function will fail and return NULL. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON writer. + Pass NULL to use the libc's default allocator. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return true if successful, false if an error occurs. + + @warning On 32-bit operating system, files larger than 2GB may fail to write. + */ +yyjson_api bool yyjson_mut_val_write_file(const char *path, + const yyjson_mut_val *val, + yyjson_write_flag flg, + const yyjson_alc *alc, + yyjson_write_err *err); + +/** + Write a value to JSON file with options. + + @param fp The file pointer. + The data will be written to the current position of the file. + If this path is NULL or invalid, the function will fail and return false. + @param val The mutable JSON root value. + If this parameter is NULL, the function will fail and return NULL. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param alc The memory allocator used by JSON writer. + Pass NULL to use the libc's default allocator. + @param err A pointer to receive error information. + Pass NULL if you don't need error information. + @return true if successful, false if an error occurs. + + @warning On 32-bit operating system, files larger than 2GB may fail to write. + */ +yyjson_api bool yyjson_mut_val_write_fp(FILE *fp, + const yyjson_mut_val *val, + yyjson_write_flag flg, + const yyjson_alc *alc, + yyjson_write_err *err); + +/** + Write a value to JSON string. + + This function is thread-safe when: + The `val` is not modified by other threads. + + @param val The JSON root value. + If this parameter is NULL, the function will fail and return NULL. + @param flg The JSON write options. + Multiple options can be combined with `|` operator. 0 means no options. + @param len A pointer to receive output length in bytes (not including the + null-terminator). Pass NULL if you don't need length information. + @return A new JSON string, or NULL if an error occurs. + This string is encoded as UTF-8 with a null-terminator. + When it's no longer needed, it should be freed with free(). + */ +yyjson_api_inline char *yyjson_mut_val_write(const yyjson_mut_val *val, + yyjson_write_flag flg, + size_t *len) { + return yyjson_mut_val_write_opts(val, flg, NULL, len, NULL); +} + +/** + Write a JSON number. + + @param val A JSON number value to be converted to a string. + If this parameter is invalid, the function will fail and return NULL. + @param buf A buffer to store the resulting null-terminated string. + If this parameter is NULL, the function will fail and return NULL. + For integer values, the buffer must be at least 21 bytes. + For floating-point values, the buffer must be at least 40 bytes. + @return On success, returns a pointer to the character after the last + written character. On failure, returns NULL. + @note + - This function is thread-safe and does not allocate memory + (when `YYJSON_DISABLE_FAST_FP_CONV` is not defined). + - This function will fail and return NULL only in the following cases: + 1) `val` or `buf` is NULL; + 2) `val` is not a number type; + 3) `val` is `inf` or `nan`, and non-standard JSON is explicitly disabled + via the `YYJSON_DISABLE_NON_STANDARD` flag. + */ +yyjson_api char *yyjson_write_number(const yyjson_val *val, char *buf); + +/** Same as `yyjson_write_number()`. */ +yyjson_api_inline char *yyjson_mut_write_number(const yyjson_mut_val *val, + char *buf) { + return yyjson_write_number((const yyjson_val *)val, buf); +} + +#endif /* YYJSON_DISABLE_WRITER */ + + + +/*============================================================================== + * MARK: - JSON Document API + *============================================================================*/ + +/** Returns the root value of this JSON document. + Returns NULL if `doc` is NULL. */ +yyjson_api_inline yyjson_val *yyjson_doc_get_root(yyjson_doc *doc); + +/** Returns read size of input JSON data. + Returns 0 if `doc` is NULL. + For example: the read size of `[1,2,3]` is 7 bytes. */ +yyjson_api_inline size_t yyjson_doc_get_read_size(yyjson_doc *doc); + +/** Returns total value count in this JSON document. + Returns 0 if `doc` is NULL. + For example: the value count of `[1,2,3]` is 4. */ +yyjson_api_inline size_t yyjson_doc_get_val_count(yyjson_doc *doc); + +/** Release the JSON document and free the memory. + After calling this function, the `doc` and all values from the `doc` are no + longer available. This function will do nothing if the `doc` is NULL. */ +yyjson_api_inline void yyjson_doc_free(yyjson_doc *doc); + + + +/*============================================================================== + * MARK: - JSON Value Type API + *============================================================================*/ + +/** Returns whether the JSON value is raw. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_raw(yyjson_val *val); + +/** Returns whether the JSON value is `null`. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_null(yyjson_val *val); + +/** Returns whether the JSON value is `true`. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_true(yyjson_val *val); + +/** Returns whether the JSON value is `false`. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_false(yyjson_val *val); + +/** Returns whether the JSON value is bool (true/false). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_bool(yyjson_val *val); + +/** Returns whether the JSON value is unsigned integer (uint64_t). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_uint(yyjson_val *val); + +/** Returns whether the JSON value is signed integer (int64_t). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_sint(yyjson_val *val); + +/** Returns whether the JSON value is integer (uint64_t/int64_t). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_int(yyjson_val *val); + +/** Returns whether the JSON value is real number (double). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_real(yyjson_val *val); + +/** Returns whether the JSON value is number (uint64_t/int64_t/double). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_num(yyjson_val *val); + +/** Returns whether the JSON value is string. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_str(yyjson_val *val); + +/** Returns whether the JSON value is array. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_arr(yyjson_val *val); + +/** Returns whether the JSON value is object. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_obj(yyjson_val *val); + +/** Returns whether the JSON value is container (array/object). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_is_ctn(yyjson_val *val); + + + +/*============================================================================== + * MARK: - JSON Value Content API + *============================================================================*/ + +/** Returns the JSON value's type. + Returns YYJSON_TYPE_NONE if `val` is NULL. */ +yyjson_api_inline yyjson_type yyjson_get_type(yyjson_val *val); + +/** Returns the JSON value's subtype. + Returns YYJSON_SUBTYPE_NONE if `val` is NULL. */ +yyjson_api_inline yyjson_subtype yyjson_get_subtype(yyjson_val *val); + +/** Returns the JSON value's tag. + Returns 0 if `val` is NULL. */ +yyjson_api_inline uint8_t yyjson_get_tag(yyjson_val *val); + +/** Returns the JSON value's type description. + The return value should be one of these strings: "raw", "null", "string", + "array", "object", "true", "false", "uint", "sint", "real", "unknown". */ +yyjson_api_inline const char *yyjson_get_type_desc(yyjson_val *val); + +/** Returns the content if the value is raw. + Returns NULL if `val` is NULL or type is not raw. */ +yyjson_api_inline const char *yyjson_get_raw(yyjson_val *val); + +/** Returns the content if the value is bool. + Returns false if `val` is NULL or type is not bool. */ +yyjson_api_inline bool yyjson_get_bool(yyjson_val *val); + +/** Returns the content and cast to uint64_t. + Returns 0 if `val` is NULL or type is not integer(sint/uint). */ +yyjson_api_inline uint64_t yyjson_get_uint(yyjson_val *val); + +/** Returns the content and cast to int64_t. + Returns 0 if `val` is NULL or type is not integer(sint/uint). */ +yyjson_api_inline int64_t yyjson_get_sint(yyjson_val *val); + +/** Returns the content and cast to int. + Returns 0 if `val` is NULL or type is not integer(sint/uint). */ +yyjson_api_inline int yyjson_get_int(yyjson_val *val); + +/** Returns the content if the value is real number, or 0.0 on error. + Returns 0.0 if `val` is NULL or type is not real(double). */ +yyjson_api_inline double yyjson_get_real(yyjson_val *val); + +/** Returns the content and typecast to `double` if the value is number. + Returns 0.0 if `val` is NULL or type is not number(uint/sint/real). */ +yyjson_api_inline double yyjson_get_num(yyjson_val *val); + +/** Returns the content if the value is string. + Returns NULL if `val` is NULL or type is not string. */ +yyjson_api_inline const char *yyjson_get_str(yyjson_val *val); + +/** Returns the content length (string length, array size, object size. + Returns 0 if `val` is NULL or type is not string/array/object. */ +yyjson_api_inline size_t yyjson_get_len(yyjson_val *val); + +/** Returns whether the JSON value is equals to a string. + Returns false if input is NULL or type is not string. */ +yyjson_api_inline bool yyjson_equals_str(yyjson_val *val, const char *str); + +/** Returns whether the JSON value is equals to a string. + The `str` should be a UTF-8 string, null-terminator is not required. + Returns false if input is NULL or type is not string. */ +yyjson_api_inline bool yyjson_equals_strn(yyjson_val *val, const char *str, + size_t len); + +/** Returns whether two JSON values are equal (deep compare). + Returns false if input is NULL. + @note the result may be inaccurate if object has duplicate keys. + @warning This function is recursive and may cause a stack overflow + if the object level is too deep. */ +yyjson_api_inline bool yyjson_equals(yyjson_val *lhs, yyjson_val *rhs); + +/** Set the value to raw. + Returns false if input is NULL or `val` is object or array. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_raw(yyjson_val *val, + const char *raw, size_t len); + +/** Set the value to null. + Returns false if input is NULL or `val` is object or array. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_null(yyjson_val *val); + +/** Set the value to bool. + Returns false if input is NULL or `val` is object or array. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_bool(yyjson_val *val, bool num); + +/** Set the value to uint. + Returns false if input is NULL or `val` is object or array. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_uint(yyjson_val *val, uint64_t num); + +/** Set the value to sint. + Returns false if input is NULL or `val` is object or array. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_sint(yyjson_val *val, int64_t num); + +/** Set the value to int. + Returns false if input is NULL or `val` is object or array. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_int(yyjson_val *val, int num); + +/** Set the value to float. + Returns false if input is NULL or `val` is object or array. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_float(yyjson_val *val, float num); + +/** Set the value to double. + Returns false if input is NULL or `val` is object or array. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_double(yyjson_val *val, double num); + +/** Set the value to real. + Returns false if input is NULL or `val` is object or array. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_real(yyjson_val *val, double num); + +/** Set the floating-point number's output format to fixed-point notation. + Returns false if input is NULL or `val` is not real type. + @see YYJSON_WRITE_FP_TO_FIXED flag. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_fp_to_fixed(yyjson_val *val, int prec); + +/** Set the floating-point number's output format to single-precision. + Returns false if input is NULL or `val` is not real type. + @see YYJSON_WRITE_FP_TO_FLOAT flag. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_fp_to_float(yyjson_val *val, bool flt); + +/** Set the value to string (null-terminated). + Returns false if input is NULL or `val` is object or array. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_str(yyjson_val *val, const char *str); + +/** Set the value to string (with length). + Returns false if input is NULL or `val` is object or array. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_strn(yyjson_val *val, + const char *str, size_t len); + +/** Marks this string as not needing to be escaped during JSON writing. + This can be used to avoid the overhead of escaping if the string contains + only characters that do not require escaping. + Returns false if input is NULL or `val` is not string. + @see YYJSON_SUBTYPE_NOESC subtype. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_set_str_noesc(yyjson_val *val, bool noesc); + + + +/*============================================================================== + * MARK: - JSON Array API + *============================================================================*/ + +/** Returns the number of elements in this array. + Returns 0 if `arr` is NULL or type is not array. */ +yyjson_api_inline size_t yyjson_arr_size(yyjson_val *arr); + +/** Returns the element at the specified position in this array. + Returns NULL if array is NULL/empty or the index is out of bounds. + @warning This function takes a linear search time if array is not flat. + For example: `[1,{},3]` is flat, `[1,[2],3]` is not flat. */ +yyjson_api_inline yyjson_val *yyjson_arr_get(yyjson_val *arr, size_t idx); + +/** Returns the first element of this array. + Returns NULL if `arr` is NULL/empty or type is not array. */ +yyjson_api_inline yyjson_val *yyjson_arr_get_first(yyjson_val *arr); + +/** Returns the last element of this array. + Returns NULL if `arr` is NULL/empty or type is not array. + @warning This function takes a linear search time if array is not flat. + For example: `[1,{},3]` is flat, `[1,[2],3]` is not flat.*/ +yyjson_api_inline yyjson_val *yyjson_arr_get_last(yyjson_val *arr); + + + +/*============================================================================== + * MARK: - JSON Array Iterator API + *============================================================================*/ + +/** + A JSON array iterator. + + @b Example + @code + yyjson_val *val; + yyjson_arr_iter iter = yyjson_arr_iter_with(arr); + while ((val = yyjson_arr_iter_next(&iter))) { + your_func(val); + } + @endcode + */ +typedef struct yyjson_arr_iter { + size_t idx; /**< next value's index */ + size_t max; /**< maximum index (arr.size) */ + yyjson_val *cur; /**< next value */ +} yyjson_arr_iter; + +/** + Initialize an iterator for this array. + + @param arr The array to be iterated over. + If this parameter is NULL or not an array, `iter` will be set to empty. + @param iter The iterator to be initialized. + If this parameter is NULL, the function will fail and return false. + @return true if the `iter` has been successfully initialized. + + @note The iterator does not need to be destroyed. + */ +yyjson_api_inline bool yyjson_arr_iter_init(yyjson_val *arr, + yyjson_arr_iter *iter); + +/** + Create an iterator with an array , same as `yyjson_arr_iter_init()`. + + @param arr The array to be iterated over. + If this parameter is NULL or not an array, an empty iterator will returned. + @return A new iterator for the array. + + @note The iterator does not need to be destroyed. + */ +yyjson_api_inline yyjson_arr_iter yyjson_arr_iter_with(yyjson_val *arr); + +/** + Returns whether the iteration has more elements. + If `iter` is NULL, this function will return false. + */ +yyjson_api_inline bool yyjson_arr_iter_has_next(yyjson_arr_iter *iter); + +/** + Returns the next element in the iteration, or NULL on end. + If `iter` is NULL, this function will return NULL. + */ +yyjson_api_inline yyjson_val *yyjson_arr_iter_next(yyjson_arr_iter *iter); + +/** + Macro for iterating over an array. + It works like iterator, but with a more intuitive API. + + @b Example + @code + size_t idx, max; + yyjson_val *val; + yyjson_arr_foreach(arr, idx, max, val) { + your_func(idx, val); + } + @endcode + */ +#define yyjson_arr_foreach(arr, idx, max, val) \ + for ((idx) = 0, \ + (max) = yyjson_arr_size(arr), \ + (val) = yyjson_arr_get_first(arr); \ + (idx) < (max); \ + (idx)++, \ + (val) = unsafe_yyjson_get_next(val)) + + + +/*============================================================================== + * MARK: - JSON Object API + *============================================================================*/ + +/** Returns the number of key-value pairs in this object. + Returns 0 if `obj` is NULL or type is not object. */ +yyjson_api_inline size_t yyjson_obj_size(yyjson_val *obj); + +/** Returns the value to which the specified key is mapped. + Returns NULL if this object contains no mapping for the key. + Returns NULL if `obj/key` is NULL, or type is not object. + + The `key` should be a null-terminated UTF-8 string. + + @warning This function takes a linear search time. */ +yyjson_api_inline yyjson_val *yyjson_obj_get(yyjson_val *obj, const char *key); + +/** Returns the value to which the specified key is mapped. + Returns NULL if this object contains no mapping for the key. + Returns NULL if `obj/key` is NULL, or type is not object. + + The `key` should be a UTF-8 string, null-terminator is not required. + The `key_len` should be the length of the key, in bytes. + + @warning This function takes a linear search time. */ +yyjson_api_inline yyjson_val *yyjson_obj_getn(yyjson_val *obj, const char *key, + size_t key_len); + + + +/*============================================================================== + * MARK: - JSON Object Iterator API + *============================================================================*/ + +/** + A JSON object iterator. + + @b Example + @code + yyjson_val *key, *val; + yyjson_obj_iter iter = yyjson_obj_iter_with(obj); + while ((key = yyjson_obj_iter_next(&iter))) { + val = yyjson_obj_iter_get_val(key); + your_func(key, val); + } + @endcode + + If the ordering of the keys is known at compile-time, you can use this method + to speed up value lookups: + @code + // {"k1":1, "k2": 3, "k3": 3} + yyjson_val *key, *val; + yyjson_obj_iter iter = yyjson_obj_iter_with(obj); + yyjson_val *v1 = yyjson_obj_iter_get(&iter, "k1"); + yyjson_val *v3 = yyjson_obj_iter_get(&iter, "k3"); + @endcode + @see yyjson_obj_iter_get() and yyjson_obj_iter_getn() + */ +typedef struct yyjson_obj_iter { + size_t idx; /**< next key's index */ + size_t max; /**< maximum key index (obj.size) */ + yyjson_val *cur; /**< next key */ + yyjson_val *obj; /**< the object being iterated */ +} yyjson_obj_iter; + +/** + Initialize an iterator for this object. + + @param obj The object to be iterated over. + If this parameter is NULL or not an object, `iter` will be set to empty. + @param iter The iterator to be initialized. + If this parameter is NULL, the function will fail and return false. + @return true if the `iter` has been successfully initialized. + + @note The iterator does not need to be destroyed. + */ +yyjson_api_inline bool yyjson_obj_iter_init(yyjson_val *obj, + yyjson_obj_iter *iter); + +/** + Create an iterator with an object, same as `yyjson_obj_iter_init()`. + + @param obj The object to be iterated over. + If this parameter is NULL or not an object, an empty iterator will returned. + @return A new iterator for the object. + + @note The iterator does not need to be destroyed. + */ +yyjson_api_inline yyjson_obj_iter yyjson_obj_iter_with(yyjson_val *obj); + +/** + Returns whether the iteration has more elements. + If `iter` is NULL, this function will return false. + */ +yyjson_api_inline bool yyjson_obj_iter_has_next(yyjson_obj_iter *iter); + +/** + Returns the next key in the iteration, or NULL on end. + If `iter` is NULL, this function will return NULL. + */ +yyjson_api_inline yyjson_val *yyjson_obj_iter_next(yyjson_obj_iter *iter); + +/** + Returns the value for key inside the iteration. + If `iter` is NULL, this function will return NULL. + */ +yyjson_api_inline yyjson_val *yyjson_obj_iter_get_val(yyjson_val *key); + +/** + Iterates to a specified key and returns the value. + + This function does the same thing as `yyjson_obj_get()`, but is much faster + if the ordering of the keys is known at compile-time and you are using the same + order to look up the values. If the key exists in this object, then the + iterator will stop at the next key, otherwise the iterator will not change and + NULL is returned. + + @param iter The object iterator, should not be NULL. + @param key The key, should be a UTF-8 string with null-terminator. + @return The value to which the specified key is mapped. + NULL if this object contains no mapping for the key or input is invalid. + + @warning This function takes a linear search time if the key is not nearby. + */ +yyjson_api_inline yyjson_val *yyjson_obj_iter_get(yyjson_obj_iter *iter, + const char *key); + +/** + Iterates to a specified key and returns the value. + + This function does the same thing as `yyjson_obj_getn()`, but is much faster + if the ordering of the keys is known at compile-time and you are using the same + order to look up the values. If the key exists in this object, then the + iterator will stop at the next key, otherwise the iterator will not change and + NULL is returned. + + @param iter The object iterator, should not be NULL. + @param key The key, should be a UTF-8 string, null-terminator is not required. + @param key_len The the length of `key`, in bytes. + @return The value to which the specified key is mapped. + NULL if this object contains no mapping for the key or input is invalid. + + @warning This function takes a linear search time if the key is not nearby. + */ +yyjson_api_inline yyjson_val *yyjson_obj_iter_getn(yyjson_obj_iter *iter, + const char *key, + size_t key_len); + +/** + Macro for iterating over an object. + It works like iterator, but with a more intuitive API. + + @b Example + @code + size_t idx, max; + yyjson_val *key, *val; + yyjson_obj_foreach(obj, idx, max, key, val) { + your_func(key, val); + } + @endcode + */ +#define yyjson_obj_foreach(obj, idx, max, key, val) \ + for ((idx) = 0, \ + (max) = yyjson_obj_size(obj), \ + (key) = (obj) ? unsafe_yyjson_get_first(obj) : NULL, \ + (val) = (key) + 1; \ + (idx) < (max); \ + (idx)++, \ + (key) = unsafe_yyjson_get_next(val), \ + (val) = (key) + 1) + + + +/*============================================================================== + * MARK: - Mutable JSON Document API + *============================================================================*/ + +/** Returns the root value of this JSON document. + Returns NULL if `doc` is NULL. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_get_root(yyjson_mut_doc *doc); + +/** Sets the root value of this JSON document. + Pass NULL to clear root value of the document. */ +yyjson_api_inline void yyjson_mut_doc_set_root(yyjson_mut_doc *doc, + yyjson_mut_val *root); + +/** + Set the string pool size for a mutable document. + This function does not allocate memory immediately, but uses the size when + the next memory allocation is needed. + + If the caller knows the approximate bytes of strings that the document needs to + store (e.g. copy string with `yyjson_mut_strcpy` function), setting a larger + size can avoid multiple memory allocations and improve performance. + + @param doc The mutable document. + @param len The desired string pool size in bytes (total string length). + @return true if successful, false if size is 0 or overflow. + */ +yyjson_api bool yyjson_mut_doc_set_str_pool_size(yyjson_mut_doc *doc, + size_t len); + +/** + Set the value pool size for a mutable document. + This function does not allocate memory immediately, but uses the size when + the next memory allocation is needed. + + If the caller knows the approximate number of values that the document needs to + store (e.g. create new value with `yyjson_mut_xxx` functions), setting a larger + size can avoid multiple memory allocations and improve performance. + + @param doc The mutable document. + @param count The desired value pool size (number of `yyjson_mut_val`). + @return true if successful, false if size is 0 or overflow. + */ +yyjson_api bool yyjson_mut_doc_set_val_pool_size(yyjson_mut_doc *doc, + size_t count); + +/** Release the JSON document and free the memory. + After calling this function, the `doc` and all values from the `doc` are no + longer available. This function will do nothing if the `doc` is NULL. */ +yyjson_api void yyjson_mut_doc_free(yyjson_mut_doc *doc); + +/** Creates and returns a new mutable JSON document, returns NULL on error. + If allocator is NULL, the default allocator will be used. */ +yyjson_api yyjson_mut_doc *yyjson_mut_doc_new(const yyjson_alc *alc); + +/** Copies and returns a new mutable document from input, returns NULL on error. + This makes a `deep-copy` on the immutable document. + If allocator is NULL, the default allocator will be used. + @note `imut_doc` -> `mut_doc`. */ +yyjson_api yyjson_mut_doc *yyjson_doc_mut_copy(yyjson_doc *doc, + const yyjson_alc *alc); + +/** Copies and returns a new mutable document from input, returns NULL on error. + This makes a `deep-copy` on the mutable document. + If allocator is NULL, the default allocator will be used. + @note `mut_doc` -> `mut_doc`. */ +yyjson_api yyjson_mut_doc *yyjson_mut_doc_mut_copy(yyjson_mut_doc *doc, + const yyjson_alc *alc); + +/** Copies and returns a new mutable value from input, returns NULL on error. + This makes a `deep-copy` on the immutable value. + The memory was managed by mutable document. + @note `imut_val` -> `mut_val`. */ +yyjson_api yyjson_mut_val *yyjson_val_mut_copy(yyjson_mut_doc *doc, + yyjson_val *val); + +/** Copies and returns a new mutable value from input, returns NULL on error. + This makes a `deep-copy` on the mutable value. + The memory was managed by mutable document. + @note `mut_val` -> `mut_val`. + @warning This function is recursive and may cause a stack overflow + if the object level is too deep. */ +yyjson_api yyjson_mut_val *yyjson_mut_val_mut_copy(yyjson_mut_doc *doc, + yyjson_mut_val *val); + +/** Copies and returns a new immutable document from input, + returns NULL on error. This makes a `deep-copy` on the mutable document. + The returned document should be freed with `yyjson_doc_free()`. + @note `mut_doc` -> `imut_doc`. + @warning This function is recursive and may cause a stack overflow + if the object level is too deep. */ +yyjson_api yyjson_doc *yyjson_mut_doc_imut_copy(yyjson_mut_doc *doc, + const yyjson_alc *alc); + +/** Copies and returns a new immutable document from input, + returns NULL on error. This makes a `deep-copy` on the mutable value. + The returned document should be freed with `yyjson_doc_free()`. + @note `mut_val` -> `imut_doc`. + @warning This function is recursive and may cause a stack overflow + if the object level is too deep. */ +yyjson_api yyjson_doc *yyjson_mut_val_imut_copy(yyjson_mut_val *val, + const yyjson_alc *alc); + + + +/*============================================================================== + * MARK: - Mutable JSON Value Type API + *============================================================================*/ + +/** Returns whether the JSON value is raw. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_raw(yyjson_mut_val *val); + +/** Returns whether the JSON value is `null`. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_null(yyjson_mut_val *val); + +/** Returns whether the JSON value is `true`. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_true(yyjson_mut_val *val); + +/** Returns whether the JSON value is `false`. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_false(yyjson_mut_val *val); + +/** Returns whether the JSON value is bool (true/false). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_bool(yyjson_mut_val *val); + +/** Returns whether the JSON value is unsigned integer (uint64_t). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_uint(yyjson_mut_val *val); + +/** Returns whether the JSON value is signed integer (int64_t). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_sint(yyjson_mut_val *val); + +/** Returns whether the JSON value is integer (uint64_t/int64_t). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_int(yyjson_mut_val *val); + +/** Returns whether the JSON value is real number (double). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_real(yyjson_mut_val *val); + +/** Returns whether the JSON value is number (uint/sint/real). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_num(yyjson_mut_val *val); + +/** Returns whether the JSON value is string. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_str(yyjson_mut_val *val); + +/** Returns whether the JSON value is array. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_arr(yyjson_mut_val *val); + +/** Returns whether the JSON value is object. + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_obj(yyjson_mut_val *val); + +/** Returns whether the JSON value is container (array/object). + Returns false if `val` is NULL. */ +yyjson_api_inline bool yyjson_mut_is_ctn(yyjson_mut_val *val); + + + +/*============================================================================== + * MARK: - Mutable JSON Value Content API + *============================================================================*/ + +/** Returns the JSON value's type. + Returns `YYJSON_TYPE_NONE` if `val` is NULL. */ +yyjson_api_inline yyjson_type yyjson_mut_get_type(yyjson_mut_val *val); + +/** Returns the JSON value's subtype. + Returns `YYJSON_SUBTYPE_NONE` if `val` is NULL. */ +yyjson_api_inline yyjson_subtype yyjson_mut_get_subtype(yyjson_mut_val *val); + +/** Returns the JSON value's tag. + Returns 0 if `val` is NULL. */ +yyjson_api_inline uint8_t yyjson_mut_get_tag(yyjson_mut_val *val); + +/** Returns the JSON value's type description. + The return value should be one of these strings: "raw", "null", "string", + "array", "object", "true", "false", "uint", "sint", "real", "unknown". */ +yyjson_api_inline const char *yyjson_mut_get_type_desc(yyjson_mut_val *val); + +/** Returns the content if the value is raw. + Returns NULL if `val` is NULL or type is not raw. */ +yyjson_api_inline const char *yyjson_mut_get_raw(yyjson_mut_val *val); + +/** Returns the content if the value is bool. + Returns NULL if `val` is NULL or type is not bool. */ +yyjson_api_inline bool yyjson_mut_get_bool(yyjson_mut_val *val); + +/** Returns the content and cast to uint64_t. + Returns 0 if `val` is NULL or type is not integer(sint/uint). */ +yyjson_api_inline uint64_t yyjson_mut_get_uint(yyjson_mut_val *val); + +/** Returns the content and cast to int64_t. + Returns 0 if `val` is NULL or type is not integer(sint/uint). */ +yyjson_api_inline int64_t yyjson_mut_get_sint(yyjson_mut_val *val); + +/** Returns the content and cast to int. + Returns 0 if `val` is NULL or type is not integer(sint/uint). */ +yyjson_api_inline int yyjson_mut_get_int(yyjson_mut_val *val); + +/** Returns the content if the value is real number. + Returns 0.0 if `val` is NULL or type is not real(double). */ +yyjson_api_inline double yyjson_mut_get_real(yyjson_mut_val *val); + +/** Returns the content and typecast to `double` if the value is number. + Returns 0.0 if `val` is NULL or type is not number(uint/sint/real). */ +yyjson_api_inline double yyjson_mut_get_num(yyjson_mut_val *val); + +/** Returns the content if the value is string. + Returns NULL if `val` is NULL or type is not string. */ +yyjson_api_inline const char *yyjson_mut_get_str(yyjson_mut_val *val); + +/** Returns the content length (string length, array size, object size. + Returns 0 if `val` is NULL or type is not string/array/object. */ +yyjson_api_inline size_t yyjson_mut_get_len(yyjson_mut_val *val); + +/** Returns whether the JSON value is equals to a string. + The `str` should be a null-terminated UTF-8 string. + Returns false if input is NULL or type is not string. */ +yyjson_api_inline bool yyjson_mut_equals_str(yyjson_mut_val *val, + const char *str); + +/** Returns whether the JSON value is equals to a string. + The `str` should be a UTF-8 string, null-terminator is not required. + Returns false if input is NULL or type is not string. */ +yyjson_api_inline bool yyjson_mut_equals_strn(yyjson_mut_val *val, + const char *str, size_t len); + +/** Returns whether two JSON values are equal (deep compare). + Returns false if input is NULL. + @note the result may be inaccurate if object has duplicate keys. + @warning This function is recursive and may cause a stack overflow + if the object level is too deep. */ +yyjson_api_inline bool yyjson_mut_equals(yyjson_mut_val *lhs, + yyjson_mut_val *rhs); + +/** Set the value to raw. + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_raw(yyjson_mut_val *val, + const char *raw, size_t len); + +/** Set the value to null. + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_null(yyjson_mut_val *val); + +/** Set the value to bool. + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_bool(yyjson_mut_val *val, bool num); + +/** Set the value to uint. + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_uint(yyjson_mut_val *val, uint64_t num); + +/** Set the value to sint. + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_sint(yyjson_mut_val *val, int64_t num); + +/** Set the value to int. + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_int(yyjson_mut_val *val, int num); + +/** Set the value to float. + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_float(yyjson_mut_val *val, float num); + +/** Set the value to double. + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_double(yyjson_mut_val *val, double num); + +/** Set the value to real. + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_real(yyjson_mut_val *val, double num); + +/** Set the floating-point number's output format to fixed-point notation. + Returns false if input is NULL or `val` is not real type. + @see YYJSON_WRITE_FP_TO_FIXED flag. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_mut_set_fp_to_fixed(yyjson_mut_val *val, + int prec); + +/** Set the floating-point number's output format to single-precision. + Returns false if input is NULL or `val` is not real type. + @see YYJSON_WRITE_FP_TO_FLOAT flag. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_mut_set_fp_to_float(yyjson_mut_val *val, + bool flt); + +/** Set the value to string (null-terminated). + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_str(yyjson_mut_val *val, const char *str); + +/** Set the value to string (with length). + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_strn(yyjson_mut_val *val, + const char *str, size_t len); + +/** Marks this string as not needing to be escaped during JSON writing. + This can be used to avoid the overhead of escaping if the string contains + only characters that do not require escaping. + Returns false if input is NULL or `val` is not string. + @see YYJSON_SUBTYPE_NOESC subtype. + @warning This will modify the `immutable` value, use with caution. */ +yyjson_api_inline bool yyjson_mut_set_str_noesc(yyjson_mut_val *val, + bool noesc); + +/** Set the value to array. + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_arr(yyjson_mut_val *val); + +/** Set the value to array. + Returns false if input is NULL. + @warning This function should not be used on an existing object or array. */ +yyjson_api_inline bool yyjson_mut_set_obj(yyjson_mut_val *val); + + + +/*============================================================================== + * MARK: - Mutable JSON Value Creation API + *============================================================================*/ + +/** Creates and returns a raw value, returns NULL on error. + The `str` should be a null-terminated UTF-8 string. + + @warning The input string is not copied, you should keep this string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_raw(yyjson_mut_doc *doc, + const char *str); + +/** Creates and returns a raw value, returns NULL on error. + The `str` should be a UTF-8 string, null-terminator is not required. + + @warning The input string is not copied, you should keep this string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_rawn(yyjson_mut_doc *doc, + const char *str, + size_t len); + +/** Creates and returns a raw value, returns NULL on error. + The `str` should be a null-terminated UTF-8 string. + The input string is copied and held by the document. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_rawcpy(yyjson_mut_doc *doc, + const char *str); + +/** Creates and returns a raw value, returns NULL on error. + The `str` should be a UTF-8 string, null-terminator is not required. + The input string is copied and held by the document. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_rawncpy(yyjson_mut_doc *doc, + const char *str, + size_t len); + +/** Creates and returns a null value, returns NULL on error. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_null(yyjson_mut_doc *doc); + +/** Creates and returns a true value, returns NULL on error. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_true(yyjson_mut_doc *doc); + +/** Creates and returns a false value, returns NULL on error. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_false(yyjson_mut_doc *doc); + +/** Creates and returns a bool value, returns NULL on error. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_bool(yyjson_mut_doc *doc, + bool val); + +/** Creates and returns an unsigned integer value, returns NULL on error. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_uint(yyjson_mut_doc *doc, + uint64_t num); + +/** Creates and returns a signed integer value, returns NULL on error. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_sint(yyjson_mut_doc *doc, + int64_t num); + +/** Creates and returns a signed integer value, returns NULL on error. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_int(yyjson_mut_doc *doc, + int64_t num); + +/** Creates and returns a float number value, returns NULL on error. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_float(yyjson_mut_doc *doc, + float num); + +/** Creates and returns a double number value, returns NULL on error. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_double(yyjson_mut_doc *doc, + double num); + +/** Creates and returns a real number value, returns NULL on error. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_real(yyjson_mut_doc *doc, + double num); + +/** Creates and returns a string value, returns NULL on error. + The `str` should be a null-terminated UTF-8 string. + @warning The input string is not copied, you should keep this string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_str(yyjson_mut_doc *doc, + const char *str); + +/** Creates and returns a string value, returns NULL on error. + The `str` should be a UTF-8 string, null-terminator is not required. + @warning The input string is not copied, you should keep this string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_strn(yyjson_mut_doc *doc, + const char *str, + size_t len); + +/** Creates and returns a string value, returns NULL on error. + The `str` should be a null-terminated UTF-8 string. + The input string is copied and held by the document. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_strcpy(yyjson_mut_doc *doc, + const char *str); + +/** Creates and returns a string value, returns NULL on error. + The `str` should be a UTF-8 string, null-terminator is not required. + The input string is copied and held by the document. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_strncpy(yyjson_mut_doc *doc, + const char *str, + size_t len); + + + +/*============================================================================== + * MARK: - Mutable JSON Array API + *============================================================================*/ + +/** Returns the number of elements in this array. + Returns 0 if `arr` is NULL or type is not array. */ +yyjson_api_inline size_t yyjson_mut_arr_size(yyjson_mut_val *arr); + +/** Returns the element at the specified position in this array. + Returns NULL if array is NULL/empty or the index is out of bounds. + @warning This function takes a linear search time. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_get(yyjson_mut_val *arr, + size_t idx); + +/** Returns the first element of this array. + Returns NULL if `arr` is NULL/empty or type is not array. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_get_first(yyjson_mut_val *arr); + +/** Returns the last element of this array. + Returns NULL if `arr` is NULL/empty or type is not array. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_get_last(yyjson_mut_val *arr); + + + +/*============================================================================== + * MARK: - Mutable JSON Array Iterator API + *============================================================================*/ + +/** + A mutable JSON array iterator. + + @warning You should not modify the array while iterating over it, but you can + use `yyjson_mut_arr_iter_remove()` to remove current value. + + @b Example + @code + yyjson_mut_val *val; + yyjson_mut_arr_iter iter = yyjson_mut_arr_iter_with(arr); + while ((val = yyjson_mut_arr_iter_next(&iter))) { + your_func(val); + if (your_val_is_unused(val)) { + yyjson_mut_arr_iter_remove(&iter); + } + } + @endcode + */ +typedef struct yyjson_mut_arr_iter { + size_t idx; /**< next value's index */ + size_t max; /**< maximum index (arr.size) */ + yyjson_mut_val *cur; /**< current value */ + yyjson_mut_val *pre; /**< previous value */ + yyjson_mut_val *arr; /**< the array being iterated */ +} yyjson_mut_arr_iter; + +/** + Initialize an iterator for this array. + + @param arr The array to be iterated over. + If this parameter is NULL or not an array, `iter` will be set to empty. + @param iter The iterator to be initialized. + If this parameter is NULL, the function will fail and return false. + @return true if the `iter` has been successfully initialized. + + @note The iterator does not need to be destroyed. + */ +yyjson_api_inline bool yyjson_mut_arr_iter_init(yyjson_mut_val *arr, + yyjson_mut_arr_iter *iter); + +/** + Create an iterator with an array , same as `yyjson_mut_arr_iter_init()`. + + @param arr The array to be iterated over. + If this parameter is NULL or not an array, an empty iterator will returned. + @return A new iterator for the array. + + @note The iterator does not need to be destroyed. + */ +yyjson_api_inline yyjson_mut_arr_iter yyjson_mut_arr_iter_with( + yyjson_mut_val *arr); + +/** + Returns whether the iteration has more elements. + If `iter` is NULL, this function will return false. + */ +yyjson_api_inline bool yyjson_mut_arr_iter_has_next( + yyjson_mut_arr_iter *iter); + +/** + Returns the next element in the iteration, or NULL on end. + If `iter` is NULL, this function will return NULL. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_iter_next( + yyjson_mut_arr_iter *iter); + +/** + Removes and returns current element in the iteration. + If `iter` is NULL, this function will return NULL. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_iter_remove( + yyjson_mut_arr_iter *iter); + +/** + Macro for iterating over an array. + It works like iterator, but with a more intuitive API. + + @warning You should not modify the array while iterating over it. + + @b Example + @code + size_t idx, max; + yyjson_mut_val *val; + yyjson_mut_arr_foreach(arr, idx, max, val) { + your_func(idx, val); + } + @endcode + */ +#define yyjson_mut_arr_foreach(arr, idx, max, val) \ + for ((idx) = 0, \ + (max) = yyjson_mut_arr_size(arr), \ + (val) = yyjson_mut_arr_get_first(arr); \ + (idx) < (max); \ + (idx)++, \ + (val) = (val)->next) + + + +/*============================================================================== + * MARK: - Mutable JSON Array Creation API + *============================================================================*/ + +/** + Creates and returns an empty mutable array. + @param doc A mutable document, used for memory allocation only. + @return The new array. NULL if input is NULL or memory allocation failed. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr(yyjson_mut_doc *doc); + +/** + Creates and returns a new mutable array with the given boolean values. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of boolean values. + @param count The value count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const bool vals[3] = { true, false, true }; + yyjson_mut_val *arr = yyjson_mut_arr_with_bool(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_bool( + yyjson_mut_doc *doc, const bool *vals, size_t count); + +/** + Creates and returns a new mutable array with the given sint numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of sint numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const int64_t vals[3] = { -1, 0, 1 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_sint64(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint( + yyjson_mut_doc *doc, const int64_t *vals, size_t count); + +/** + Creates and returns a new mutable array with the given uint numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of uint numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const uint64_t vals[3] = { 0, 1, 0 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_uint(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint( + yyjson_mut_doc *doc, const uint64_t *vals, size_t count); + +/** + Creates and returns a new mutable array with the given real numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of real numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const double vals[3] = { 0.1, 0.2, 0.3 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_real(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_real( + yyjson_mut_doc *doc, const double *vals, size_t count); + +/** + Creates and returns a new mutable array with the given int8 numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of int8 numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const int8_t vals[3] = { -1, 0, 1 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_sint8(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint8( + yyjson_mut_doc *doc, const int8_t *vals, size_t count); + +/** + Creates and returns a new mutable array with the given int16 numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of int16 numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const int16_t vals[3] = { -1, 0, 1 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_sint16(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint16( + yyjson_mut_doc *doc, const int16_t *vals, size_t count); + +/** + Creates and returns a new mutable array with the given int32 numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of int32 numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const int32_t vals[3] = { -1, 0, 1 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_sint32(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint32( + yyjson_mut_doc *doc, const int32_t *vals, size_t count); + +/** + Creates and returns a new mutable array with the given int64 numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of int64 numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const int64_t vals[3] = { -1, 0, 1 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_sint64(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint64( + yyjson_mut_doc *doc, const int64_t *vals, size_t count); + +/** + Creates and returns a new mutable array with the given uint8 numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of uint8 numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const uint8_t vals[3] = { 0, 1, 0 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_uint8(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint8( + yyjson_mut_doc *doc, const uint8_t *vals, size_t count); + +/** + Creates and returns a new mutable array with the given uint16 numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of uint16 numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const uint16_t vals[3] = { 0, 1, 0 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_uint16(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint16( + yyjson_mut_doc *doc, const uint16_t *vals, size_t count); + +/** + Creates and returns a new mutable array with the given uint32 numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of uint32 numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const uint32_t vals[3] = { 0, 1, 0 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_uint32(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint32( + yyjson_mut_doc *doc, const uint32_t *vals, size_t count); + +/** + Creates and returns a new mutable array with the given uint64 numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of uint64 numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const uint64_t vals[3] = { 0, 1, 0 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_uint64(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint64( + yyjson_mut_doc *doc, const uint64_t *vals, size_t count); + +/** + Creates and returns a new mutable array with the given float numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of float numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const float vals[3] = { -1.0f, 0.0f, 1.0f }; + yyjson_mut_val *arr = yyjson_mut_arr_with_float(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_float( + yyjson_mut_doc *doc, const float *vals, size_t count); + +/** + Creates and returns a new mutable array with the given double numbers. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of double numbers. + @param count The number count. If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const double vals[3] = { -1.0, 0.0, 1.0 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_double(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_double( + yyjson_mut_doc *doc, const double *vals, size_t count); + +/** + Creates and returns a new mutable array with the given strings, these strings + will not be copied. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of UTF-8 null-terminator strings. + If this array contains NULL, the function will fail and return NULL. + @param count The number of values in `vals`. + If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @warning The input strings are not copied, you should keep these strings + unmodified for the lifetime of this JSON document. If these strings will be + modified, you should use `yyjson_mut_arr_with_strcpy()` instead. + + @b Example + @code + const char *vals[3] = { "a", "b", "c" }; + yyjson_mut_val *arr = yyjson_mut_arr_with_str(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_str( + yyjson_mut_doc *doc, const char **vals, size_t count); + +/** + Creates and returns a new mutable array with the given strings and string + lengths, these strings will not be copied. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of UTF-8 strings, null-terminator is not required. + If this array contains NULL, the function will fail and return NULL. + @param lens A C array of string lengths, in bytes. + @param count The number of strings in `vals`. + If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @warning The input strings are not copied, you should keep these strings + unmodified for the lifetime of this JSON document. If these strings will be + modified, you should use `yyjson_mut_arr_with_strncpy()` instead. + + @b Example + @code + const char *vals[3] = { "a", "bb", "c" }; + const size_t lens[3] = { 1, 2, 1 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_strn(doc, vals, lens, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_strn( + yyjson_mut_doc *doc, const char **vals, const size_t *lens, size_t count); + +/** + Creates and returns a new mutable array with the given strings, these strings + will be copied. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of UTF-8 null-terminator strings. + If this array contains NULL, the function will fail and return NULL. + @param count The number of values in `vals`. + If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const char *vals[3] = { "a", "b", "c" }; + yyjson_mut_val *arr = yyjson_mut_arr_with_strcpy(doc, vals, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_strcpy( + yyjson_mut_doc *doc, const char **vals, size_t count); + +/** + Creates and returns a new mutable array with the given strings and string + lengths, these strings will be copied. + + @param doc A mutable document, used for memory allocation only. + If this parameter is NULL, the function will fail and return NULL. + @param vals A C array of UTF-8 strings, null-terminator is not required. + If this array contains NULL, the function will fail and return NULL. + @param lens A C array of string lengths, in bytes. + @param count The number of strings in `vals`. + If this value is 0, an empty array will return. + @return The new array. NULL if input is invalid or memory allocation failed. + + @b Example + @code + const char *vals[3] = { "a", "bb", "c" }; + const size_t lens[3] = { 1, 2, 1 }; + yyjson_mut_val *arr = yyjson_mut_arr_with_strn(doc, vals, lens, 3); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_strncpy( + yyjson_mut_doc *doc, const char **vals, const size_t *lens, size_t count); + + + +/*============================================================================== + * MARK: - Mutable JSON Array Modification API + *============================================================================*/ + +/** + Inserts a value into an array at a given index. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param val The value to be inserted. Returns false if it is NULL. + @param idx The index to which to insert the new value. + Returns false if the index is out of range. + @return Whether successful. + @warning This function takes a linear search time. + */ +yyjson_api_inline bool yyjson_mut_arr_insert(yyjson_mut_val *arr, + yyjson_mut_val *val, size_t idx); + +/** + Inserts a value at the end of the array. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param val The value to be inserted. Returns false if it is NULL. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_append(yyjson_mut_val *arr, + yyjson_mut_val *val); + +/** + Inserts a value at the head of the array. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param val The value to be inserted. Returns false if it is NULL. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_prepend(yyjson_mut_val *arr, + yyjson_mut_val *val); + +/** + Replaces a value at index and returns old value. + @param arr The array to which the value is to be replaced. + Returns false if it is NULL or not an array. + @param idx The index to which to replace the value. + Returns false if the index is out of range. + @param val The new value to replace. Returns false if it is NULL. + @return Old value, or NULL on error. + @warning This function takes a linear search time. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_replace(yyjson_mut_val *arr, + size_t idx, + yyjson_mut_val *val); + +/** + Removes and returns a value at index. + @param arr The array from which the value is to be removed. + Returns false if it is NULL or not an array. + @param idx The index from which to remove the value. + Returns false if the index is out of range. + @return Old value, or NULL on error. + @warning This function takes a linear search time. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_remove(yyjson_mut_val *arr, + size_t idx); + +/** + Removes and returns the first value in this array. + @param arr The array from which the value is to be removed. + Returns false if it is NULL or not an array. + @return The first value, or NULL on error. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_remove_first( + yyjson_mut_val *arr); + +/** + Removes and returns the last value in this array. + @param arr The array from which the value is to be removed. + Returns false if it is NULL or not an array. + @return The last value, or NULL on error. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_remove_last( + yyjson_mut_val *arr); + +/** + Removes all values within a specified range in the array. + @param arr The array from which the value is to be removed. + Returns false if it is NULL or not an array. + @param idx The start index of the range (0 is the first). + @param len The number of items in the range (can be 0). + @return Whether successful. + @warning This function takes a linear search time. + */ +yyjson_api_inline bool yyjson_mut_arr_remove_range(yyjson_mut_val *arr, + size_t idx, size_t len); + +/** + Removes all values in this array. + @param arr The array from which all of the values are to be removed. + Returns false if it is NULL or not an array. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_clear(yyjson_mut_val *arr); + +/** + Rotates values in this array for the given number of times. + For example: `[1,2,3,4,5]` rotate 2 is `[3,4,5,1,2]`. + @param arr The array to be rotated. + @param idx Index (or times) to rotate. + @warning This function takes a linear search time. + */ +yyjson_api_inline bool yyjson_mut_arr_rotate(yyjson_mut_val *arr, + size_t idx); + + + +/*============================================================================== + * MARK: - Mutable JSON Array Modification Convenience API + *============================================================================*/ + +/** + Adds a value at the end of the array. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param val The value to be inserted. Returns false if it is NULL. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_val(yyjson_mut_val *arr, + yyjson_mut_val *val); + +/** + Adds a `null` value at the end of the array. + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_null(yyjson_mut_doc *doc, + yyjson_mut_val *arr); + +/** + Adds a `true` value at the end of the array. + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_true(yyjson_mut_doc *doc, + yyjson_mut_val *arr); + +/** + Adds a `false` value at the end of the array. + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_false(yyjson_mut_doc *doc, + yyjson_mut_val *arr); + +/** + Adds a bool value at the end of the array. + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param val The bool value to be added. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_bool(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + bool val); + +/** + Adds an unsigned integer value at the end of the array. + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param num The number to be added. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_uint(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + uint64_t num); + +/** + Adds a signed integer value at the end of the array. + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param num The number to be added. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_sint(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + int64_t num); + +/** + Adds an integer value at the end of the array. + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param num The number to be added. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_int(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + int64_t num); + +/** + Adds a float value at the end of the array. + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param num The number to be added. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_float(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + float num); + +/** + Adds a double value at the end of the array. + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param num The number to be added. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_double(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + double num); + +/** + Adds a double value at the end of the array. + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param num The number to be added. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_real(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + double num); + +/** + Adds a string value at the end of the array (no copy). + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param str A null-terminated UTF-8 string. + @return Whether successful. + @warning The input string is not copied, you should keep this string unmodified + for the lifetime of this JSON document. + */ +yyjson_api_inline bool yyjson_mut_arr_add_str(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + const char *str); + +/** + Adds a string value at the end of the array (no copy). + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param str A UTF-8 string, null-terminator is not required. + @param len The length of the string, in bytes. + @return Whether successful. + @warning The input string is not copied, you should keep this string unmodified + for the lifetime of this JSON document. + */ +yyjson_api_inline bool yyjson_mut_arr_add_strn(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + const char *str, + size_t len); + +/** + Adds a string value at the end of the array (copied). + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param str A null-terminated UTF-8 string. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_strcpy(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + const char *str); + +/** + Adds a string value at the end of the array (copied). + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @param str A UTF-8 string, null-terminator is not required. + @param len The length of the string, in bytes. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_arr_add_strncpy(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + const char *str, + size_t len); + +/** + Creates and adds a new array at the end of the array. + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @return The new array, or NULL on error. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_add_arr(yyjson_mut_doc *doc, + yyjson_mut_val *arr); + +/** + Creates and adds a new object at the end of the array. + @param doc The `doc` is only used for memory allocation. + @param arr The array to which the value is to be inserted. + Returns false if it is NULL or not an array. + @return The new object, or NULL on error. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_add_obj(yyjson_mut_doc *doc, + yyjson_mut_val *arr); + + + +/*============================================================================== + * MARK: - Mutable JSON Object API + *============================================================================*/ + +/** Returns the number of key-value pairs in this object. + Returns 0 if `obj` is NULL or type is not object. */ +yyjson_api_inline size_t yyjson_mut_obj_size(yyjson_mut_val *obj); + +/** Returns the value to which the specified key is mapped. + Returns NULL if this object contains no mapping for the key. + Returns NULL if `obj/key` is NULL, or type is not object. + + The `key` should be a null-terminated UTF-8 string. + + @warning This function takes a linear search time. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_get(yyjson_mut_val *obj, + const char *key); + +/** Returns the value to which the specified key is mapped. + Returns NULL if this object contains no mapping for the key. + Returns NULL if `obj/key` is NULL, or type is not object. + + The `key` should be a UTF-8 string, null-terminator is not required. + The `key_len` should be the length of the key, in bytes. + + @warning This function takes a linear search time. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_getn(yyjson_mut_val *obj, + const char *key, + size_t key_len); + + + +/*============================================================================== + * MARK: - Mutable JSON Object Iterator API + *============================================================================*/ + +/** + A mutable JSON object iterator. + + @warning You should not modify the object while iterating over it, but you can + use `yyjson_mut_obj_iter_remove()` to remove current value. + + @b Example + @code + yyjson_mut_val *key, *val; + yyjson_mut_obj_iter iter = yyjson_mut_obj_iter_with(obj); + while ((key = yyjson_mut_obj_iter_next(&iter))) { + val = yyjson_mut_obj_iter_get_val(key); + your_func(key, val); + if (your_val_is_unused(key, val)) { + yyjson_mut_obj_iter_remove(&iter); + } + } + @endcode + + If the ordering of the keys is known at compile-time, you can use this method + to speed up value lookups: + @code + // {"k1":1, "k2": 3, "k3": 3} + yyjson_mut_val *key, *val; + yyjson_mut_obj_iter iter = yyjson_mut_obj_iter_with(obj); + yyjson_mut_val *v1 = yyjson_mut_obj_iter_get(&iter, "k1"); + yyjson_mut_val *v3 = yyjson_mut_obj_iter_get(&iter, "k3"); + @endcode + @see `yyjson_mut_obj_iter_get()` and `yyjson_mut_obj_iter_getn()` + */ +typedef struct yyjson_mut_obj_iter { + size_t idx; /**< next key's index */ + size_t max; /**< maximum key index (obj.size) */ + yyjson_mut_val *cur; /**< current key */ + yyjson_mut_val *pre; /**< previous key */ + yyjson_mut_val *obj; /**< the object being iterated */ +} yyjson_mut_obj_iter; + +/** + Initialize an iterator for this object. + + @param obj The object to be iterated over. + If this parameter is NULL or not an array, `iter` will be set to empty. + @param iter The iterator to be initialized. + If this parameter is NULL, the function will fail and return false. + @return true if the `iter` has been successfully initialized. + + @note The iterator does not need to be destroyed. + */ +yyjson_api_inline bool yyjson_mut_obj_iter_init(yyjson_mut_val *obj, + yyjson_mut_obj_iter *iter); + +/** + Create an iterator with an object, same as `yyjson_obj_iter_init()`. + + @param obj The object to be iterated over. + If this parameter is NULL or not an object, an empty iterator will returned. + @return A new iterator for the object. + + @note The iterator does not need to be destroyed. + */ +yyjson_api_inline yyjson_mut_obj_iter yyjson_mut_obj_iter_with( + yyjson_mut_val *obj); + +/** + Returns whether the iteration has more elements. + If `iter` is NULL, this function will return false. + */ +yyjson_api_inline bool yyjson_mut_obj_iter_has_next( + yyjson_mut_obj_iter *iter); + +/** + Returns the next key in the iteration, or NULL on end. + If `iter` is NULL, this function will return NULL. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_next( + yyjson_mut_obj_iter *iter); + +/** + Returns the value for key inside the iteration. + If `iter` is NULL, this function will return NULL. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_get_val( + yyjson_mut_val *key); + +/** + Removes current key-value pair in the iteration, returns the removed value. + If `iter` is NULL, this function will return NULL. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_remove( + yyjson_mut_obj_iter *iter); + +/** + Iterates to a specified key and returns the value. + + This function does the same thing as `yyjson_mut_obj_get()`, but is much faster + if the ordering of the keys is known at compile-time and you are using the same + order to look up the values. If the key exists in this object, then the + iterator will stop at the next key, otherwise the iterator will not change and + NULL is returned. + + @param iter The object iterator, should not be NULL. + @param key The key, should be a UTF-8 string with null-terminator. + @return The value to which the specified key is mapped. + NULL if this object contains no mapping for the key or input is invalid. + + @warning This function takes a linear search time if the key is not nearby. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_get( + yyjson_mut_obj_iter *iter, const char *key); + +/** + Iterates to a specified key and returns the value. + + This function does the same thing as `yyjson_mut_obj_getn()` but is much faster + if the ordering of the keys is known at compile-time and you are using the same + order to look up the values. If the key exists in this object, then the + iterator will stop at the next key, otherwise the iterator will not change and + NULL is returned. + + @param iter The object iterator, should not be NULL. + @param key The key, should be a UTF-8 string, null-terminator is not required. + @param key_len The the length of `key`, in bytes. + @return The value to which the specified key is mapped. + NULL if this object contains no mapping for the key or input is invalid. + + @warning This function takes a linear search time if the key is not nearby. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_getn( + yyjson_mut_obj_iter *iter, const char *key, size_t key_len); + +/** + Macro for iterating over an object. + It works like iterator, but with a more intuitive API. + + @warning You should not modify the object while iterating over it. + + @b Example + @code + size_t idx, max; + yyjson_mut_val *key, *val; + yyjson_mut_obj_foreach(obj, idx, max, key, val) { + your_func(key, val); + } + @endcode + */ +#define yyjson_mut_obj_foreach(obj, idx, max, key, val) \ + for ((idx) = 0, \ + (max) = yyjson_mut_obj_size(obj), \ + (key) = (max) ? ((yyjson_mut_val *)(obj)->uni.ptr)->next->next : NULL, \ + (val) = (key) ? (key)->next : NULL; \ + (idx) < (max); \ + (idx)++, \ + (key) = (val)->next, \ + (val) = (key)->next) + + + +/*============================================================================== + * MARK: - Mutable JSON Object Creation API + *============================================================================*/ + +/** Creates and returns a mutable object, returns NULL on error. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj(yyjson_mut_doc *doc); + +/** + Creates and returns a mutable object with keys and values, returns NULL on + error. The keys and values are not copied. The strings should be a + null-terminated UTF-8 string. + + @warning The input string is not copied, you should keep this string + unmodified for the lifetime of this JSON document. + + @b Example + @code + const char *keys[2] = { "id", "name" }; + const char *vals[2] = { "01", "Harry" }; + yyjson_mut_val *obj = yyjson_mut_obj_with_str(doc, keys, vals, 2); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_with_str(yyjson_mut_doc *doc, + const char **keys, + const char **vals, + size_t count); + +/** + Creates and returns a mutable object with key-value pairs and pair count, + returns NULL on error. The keys and values are not copied. The strings should + be a null-terminated UTF-8 string. + + @warning The input string is not copied, you should keep this string + unmodified for the lifetime of this JSON document. + + @b Example + @code + const char *kv_pairs[4] = { "id", "01", "name", "Harry" }; + yyjson_mut_val *obj = yyjson_mut_obj_with_kv(doc, kv_pairs, 2); + @endcode + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_with_kv(yyjson_mut_doc *doc, + const char **kv_pairs, + size_t pair_count); + + + +/*============================================================================== + * MARK: - Mutable JSON Object Modification API + *============================================================================*/ + +/** + Adds a key-value pair at the end of the object. + This function allows duplicated key in one object. + @param obj The object to which the new key-value pair is to be added. + @param key The key, should be a string which is created by `yyjson_mut_str()`, + `yyjson_mut_strn()`, `yyjson_mut_strcpy()` or `yyjson_mut_strncpy()`. + @param val The value to add to the object. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_obj_add(yyjson_mut_val *obj, + yyjson_mut_val *key, + yyjson_mut_val *val); +/** + Sets a key-value pair at the end of the object. + This function may remove all key-value pairs for the given key before add. + @param obj The object to which the new key-value pair is to be added. + @param key The key, should be a string which is created by `yyjson_mut_str()`, + `yyjson_mut_strn()`, `yyjson_mut_strcpy()` or `yyjson_mut_strncpy()`. + @param val The value to add to the object. If this value is null, the behavior + is same as `yyjson_mut_obj_remove()`. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_obj_put(yyjson_mut_val *obj, + yyjson_mut_val *key, + yyjson_mut_val *val); + +/** + Inserts a key-value pair to the object at the given position. + This function allows duplicated key in one object. + @param obj The object to which the new key-value pair is to be added. + @param key The key, should be a string which is created by `yyjson_mut_str()`, + `yyjson_mut_strn()`, `yyjson_mut_strcpy()` or `yyjson_mut_strncpy()`. + @param val The value to add to the object. + @param idx The index to which to insert the new pair. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_obj_insert(yyjson_mut_val *obj, + yyjson_mut_val *key, + yyjson_mut_val *val, + size_t idx); + +/** + Removes all key-value pair from the object with given key. + @param obj The object from which the key-value pair is to be removed. + @param key The key, should be a string value. + @return The first matched value, or NULL if no matched value. + @warning This function takes a linear search time. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove(yyjson_mut_val *obj, + yyjson_mut_val *key); + +/** + Removes all key-value pair from the object with given key. + @param obj The object from which the key-value pair is to be removed. + @param key The key, should be a UTF-8 string with null-terminator. + @return The first matched value, or NULL if no matched value. + @warning This function takes a linear search time. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_key( + yyjson_mut_val *obj, const char *key); + +/** + Removes all key-value pair from the object with given key. + @param obj The object from which the key-value pair is to be removed. + @param key The key, should be a UTF-8 string, null-terminator is not required. + @param key_len The length of the key. + @return The first matched value, or NULL if no matched value. + @warning This function takes a linear search time. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_keyn( + yyjson_mut_val *obj, const char *key, size_t key_len); + +/** + Removes all key-value pairs in this object. + @param obj The object from which all of the values are to be removed. + @return Whether successful. + */ +yyjson_api_inline bool yyjson_mut_obj_clear(yyjson_mut_val *obj); + +/** + Replaces value from the object with given key. + If the key is not exist, or the value is NULL, it will fail. + @param obj The object to which the value is to be replaced. + @param key The key, should be a string value. + @param val The value to replace into the object. + @return Whether successful. + @warning This function takes a linear search time. + */ +yyjson_api_inline bool yyjson_mut_obj_replace(yyjson_mut_val *obj, + yyjson_mut_val *key, + yyjson_mut_val *val); + +/** + Rotates key-value pairs in the object for the given number of times. + For example: `{"a":1,"b":2,"c":3,"d":4}` rotate 1 is + `{"b":2,"c":3,"d":4,"a":1}`. + @param obj The object to be rotated. + @param idx Index (or times) to rotate. + @return Whether successful. + @warning This function takes a linear search time. + */ +yyjson_api_inline bool yyjson_mut_obj_rotate(yyjson_mut_val *obj, + size_t idx); + + + +/*============================================================================== + * MARK: - Mutable JSON Object Modification Convenience API + *============================================================================*/ + +/** Adds a `null` value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep the string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_null(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key); + +/** Adds a `true` value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep the string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_true(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key); + +/** Adds a `false` value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep the string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_false(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key); + +/** Adds a bool value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep the string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_bool(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, bool val); + +/** Adds an unsigned integer value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep the string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_uint(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, uint64_t val); + +/** Adds a signed integer value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep the string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_sint(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, int64_t val); + +/** Adds an int value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep the string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_int(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, int64_t val); + +/** Adds a float value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep the string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_float(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, float val); + +/** Adds a double value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep the string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_double(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, double val); + +/** Adds a real value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep the string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_real(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, double val); + +/** Adds a string value at the end of the object. + The `key` and `val` should be null-terminated UTF-8 strings. + This function allows duplicated key in one object. + + @warning The key/value strings are not copied, you should keep these strings + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_str(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, const char *val); + +/** Adds a string value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + The `val` should be a UTF-8 string, null-terminator is not required. + The `len` should be the length of the `val`, in bytes. + This function allows duplicated key in one object. + + @warning The key/value strings are not copied, you should keep these strings + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_strn(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, + const char *val, size_t len); + +/** Adds a string value at the end of the object. + The `key` and `val` should be null-terminated UTF-8 strings. + The value string is copied. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep the string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_strcpy(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, + const char *val); + +/** Adds a string value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + The `val` should be a UTF-8 string, null-terminator is not required. + The `len` should be the length of the `val`, in bytes. + This function allows duplicated key in one object. + + @warning The key strings are not copied, you should keep these strings + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_strncpy(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, + const char *val, size_t len); + +/** + Creates and adds a new array to the target object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep these strings + unmodified for the lifetime of this JSON document. + @return The new array, or NULL on error. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_add_arr(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key); + +/** + Creates and adds a new object to the target object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep these strings + unmodified for the lifetime of this JSON document. + @return The new object, or NULL on error. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_add_obj(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key); + +/** Adds a JSON value at the end of the object. + The `key` should be a null-terminated UTF-8 string. + This function allows duplicated key in one object. + + @warning The key string is not copied, you should keep the string + unmodified for the lifetime of this JSON document. */ +yyjson_api_inline bool yyjson_mut_obj_add_val(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, + yyjson_mut_val *val); + +/** Removes all key-value pairs for the given key. + Returns the first value to which the specified key is mapped or NULL if this + object contains no mapping for the key. + The `key` should be a null-terminated UTF-8 string. + + @warning This function takes a linear search time. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_str( + yyjson_mut_val *obj, const char *key); + +/** Removes all key-value pairs for the given key. + Returns the first value to which the specified key is mapped or NULL if this + object contains no mapping for the key. + The `key` should be a UTF-8 string, null-terminator is not required. + The `len` should be the length of the key, in bytes. + + @warning This function takes a linear search time. */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_strn( + yyjson_mut_val *obj, const char *key, size_t len); + +/** Replaces all matching keys with the new key. + Returns true if at least one key was renamed. + The `key` and `new_key` should be a null-terminated UTF-8 string. + The `new_key` is copied and held by doc. + + @warning This function takes a linear search time. + If `new_key` already exists, it will cause duplicate keys. + */ +yyjson_api_inline bool yyjson_mut_obj_rename_key(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, + const char *new_key); + +/** Replaces all matching keys with the new key. + Returns true if at least one key was renamed. + The `key` and `new_key` should be a UTF-8 string, + null-terminator is not required. The `new_key` is copied and held by doc. + + @warning This function takes a linear search time. + If `new_key` already exists, it will cause duplicate keys. + */ +yyjson_api_inline bool yyjson_mut_obj_rename_keyn(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, + size_t len, + const char *new_key, + size_t new_len); + + + +#if !defined(YYJSON_DISABLE_UTILS) || !YYJSON_DISABLE_UTILS + +/*============================================================================== + * MARK: - JSON Pointer API (RFC 6901) + * https://tools.ietf.org/html/rfc6901 + *============================================================================*/ + +/** JSON Pointer error code. */ +typedef uint32_t yyjson_ptr_code; + +/** No JSON pointer error. */ +static const yyjson_ptr_code YYJSON_PTR_ERR_NONE = 0; + +/** Invalid input parameter, such as NULL input. */ +static const yyjson_ptr_code YYJSON_PTR_ERR_PARAMETER = 1; + +/** JSON pointer syntax error, such as invalid escape, token no prefix. */ +static const yyjson_ptr_code YYJSON_PTR_ERR_SYNTAX = 2; + +/** JSON pointer resolve failed, such as index out of range, key not found. */ +static const yyjson_ptr_code YYJSON_PTR_ERR_RESOLVE = 3; + +/** Document's root is NULL, but it is required for the function call. */ +static const yyjson_ptr_code YYJSON_PTR_ERR_NULL_ROOT = 4; + +/** Cannot set root as the target is not a document. */ +static const yyjson_ptr_code YYJSON_PTR_ERR_SET_ROOT = 5; + +/** The memory allocation failed and a new value could not be created. */ +static const yyjson_ptr_code YYJSON_PTR_ERR_MEMORY_ALLOCATION = 6; + +/** Error information for JSON pointer. */ +typedef struct yyjson_ptr_err { + /** Error code, see `yyjson_ptr_code` for all possible values. */ + yyjson_ptr_code code; + /** Error message, constant, no need to free (NULL if no error). */ + const char *msg; + /** Error byte position for input JSON pointer (0 if no error). */ + size_t pos; +} yyjson_ptr_err; + +/** + A context for JSON pointer operation. + + This struct stores the context of JSON Pointer operation result. The struct + can be used with three helper functions: `ctx_append()`, `ctx_replace()`, and + `ctx_remove()`, which perform the corresponding operations on the container + without re-parsing the JSON Pointer. + + For example: + @code + // doc before: {"a":[0,1,null]} + // ptr: "/a/2" + val = yyjson_mut_doc_ptr_getx(doc, ptr, strlen(ptr), &ctx, &err); + if (yyjson_is_null(val)) { + yyjson_ptr_ctx_remove(&ctx); + } + // doc after: {"a":[0,1]} + @endcode + */ +typedef struct yyjson_ptr_ctx { + /** + The container (parent) of the target value. It can be either an array or + an object. If the target location has no value, but all its parent + containers exist, and the target location can be used to insert a new + value, then `ctn` is the parent container of the target location. + Otherwise, `ctn` is NULL. + */ + yyjson_mut_val *ctn; + /** + The previous sibling of the target value. It can be either a value in an + array or a key in an object. As the container is a `circular linked list` + of elements, `pre` is the previous node of the target value. If the + operation is `add` or `set`, then `pre` is the previous node of the new + value, not the original target value. If the target value does not exist, + `pre` is NULL. + */ + yyjson_mut_val *pre; + /** + The removed value if the operation is `set`, `replace` or `remove`. It can + be used to restore the original state of the document if needed. + */ + yyjson_mut_val *old; +} yyjson_ptr_ctx; + +/** + Get value by a JSON Pointer. + @param doc The JSON document to be queried. + @param ptr The JSON pointer string (UTF-8 with null-terminator). + @return The value referenced by the JSON pointer. + NULL if `doc` or `ptr` is NULL, or the JSON pointer cannot be resolved. + */ +yyjson_api_inline yyjson_val *yyjson_doc_ptr_get(yyjson_doc *doc, + const char *ptr); + +/** + Get value by a JSON Pointer. + @param doc The JSON document to be queried. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @return The value referenced by the JSON pointer. + NULL if `doc` or `ptr` is NULL, or the JSON pointer cannot be resolved. + */ +yyjson_api_inline yyjson_val *yyjson_doc_ptr_getn(yyjson_doc *doc, + const char *ptr, size_t len); + +/** + Get value by a JSON Pointer. + @param doc The JSON document to be queried. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param err A pointer to store the error information, or NULL if not needed. + @return The value referenced by the JSON pointer. + NULL if `doc` or `ptr` is NULL, or the JSON pointer cannot be resolved. + */ +yyjson_api_inline yyjson_val *yyjson_doc_ptr_getx(yyjson_doc *doc, + const char *ptr, size_t len, + yyjson_ptr_err *err); + +/** + Get value by a JSON Pointer. + @param val The JSON value to be queried. + @param ptr The JSON pointer string (UTF-8 with null-terminator). + @return The value referenced by the JSON pointer. + NULL if `val` or `ptr` is NULL, or the JSON pointer cannot be resolved. + */ +yyjson_api_inline yyjson_val *yyjson_ptr_get(yyjson_val *val, + const char *ptr); + +/** + Get value by a JSON Pointer. + @param val The JSON value to be queried. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @return The value referenced by the JSON pointer. + NULL if `val` or `ptr` is NULL, or the JSON pointer cannot be resolved. + */ +yyjson_api_inline yyjson_val *yyjson_ptr_getn(yyjson_val *val, + const char *ptr, size_t len); + +/** + Get value by a JSON Pointer. + @param val The JSON value to be queried. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param err A pointer to store the error information, or NULL if not needed. + @return The value referenced by the JSON pointer. + NULL if `val` or `ptr` is NULL, or the JSON pointer cannot be resolved. + */ +yyjson_api_inline yyjson_val *yyjson_ptr_getx(yyjson_val *val, + const char *ptr, size_t len, + yyjson_ptr_err *err); + +/** + Get value by a JSON Pointer. + @param doc The JSON document to be queried. + @param ptr The JSON pointer string (UTF-8 with null-terminator). + @return The value referenced by the JSON pointer. + NULL if `doc` or `ptr` is NULL, or the JSON pointer cannot be resolved. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_get(yyjson_mut_doc *doc, + const char *ptr); + +/** + Get value by a JSON Pointer. + @param doc The JSON document to be queried. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @return The value referenced by the JSON pointer. + NULL if `doc` or `ptr` is NULL, or the JSON pointer cannot be resolved. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_getn(yyjson_mut_doc *doc, + const char *ptr, + size_t len); + +/** + Get value by a JSON Pointer. + @param doc The JSON document to be queried. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param ctx A pointer to store the result context, or NULL if not needed. + @param err A pointer to store the error information, or NULL if not needed. + @return The value referenced by the JSON pointer. + NULL if `doc` or `ptr` is NULL, or the JSON pointer cannot be resolved. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_getx(yyjson_mut_doc *doc, + const char *ptr, + size_t len, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err); + +/** + Get value by a JSON Pointer. + @param val The JSON value to be queried. + @param ptr The JSON pointer string (UTF-8 with null-terminator). + @return The value referenced by the JSON pointer. + NULL if `val` or `ptr` is NULL, or the JSON pointer cannot be resolved. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_get(yyjson_mut_val *val, + const char *ptr); + +/** + Get value by a JSON Pointer. + @param val The JSON value to be queried. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @return The value referenced by the JSON pointer. + NULL if `val` or `ptr` is NULL, or the JSON pointer cannot be resolved. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_getn(yyjson_mut_val *val, + const char *ptr, + size_t len); + +/** + Get value by a JSON Pointer. + @param val The JSON value to be queried. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param ctx A pointer to store the result context, or NULL if not needed. + @param err A pointer to store the error information, or NULL if not needed. + @return The value referenced by the JSON pointer. + NULL if `val` or `ptr` is NULL, or the JSON pointer cannot be resolved. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_getx(yyjson_mut_val *val, + const char *ptr, + size_t len, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err); + +/** + Add (insert) value by a JSON pointer. + @param doc The target JSON document. + @param ptr The JSON pointer string (UTF-8 with null-terminator). + @param new_val The value to be added. + @return true if JSON pointer is valid and new value is added, false otherwise. + @note The parent nodes will be created if they do not exist. + */ +yyjson_api_inline bool yyjson_mut_doc_ptr_add(yyjson_mut_doc *doc, + const char *ptr, + yyjson_mut_val *new_val); + +/** + Add (insert) value by a JSON pointer. + @param doc The target JSON document. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param new_val The value to be added. + @return true if JSON pointer is valid and new value is added, false otherwise. + @note The parent nodes will be created if they do not exist. + */ +yyjson_api_inline bool yyjson_mut_doc_ptr_addn(yyjson_mut_doc *doc, + const char *ptr, size_t len, + yyjson_mut_val *new_val); + +/** + Add (insert) value by a JSON pointer. + @param doc The target JSON document. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param new_val The value to be added. + @param create_parent Whether to create parent nodes if not exist. + @param ctx A pointer to store the result context, or NULL if not needed. + @param err A pointer to store the error information, or NULL if not needed. + @return true if JSON pointer is valid and new value is added, false otherwise. + */ +yyjson_api_inline bool yyjson_mut_doc_ptr_addx(yyjson_mut_doc *doc, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + bool create_parent, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err); + +/** + Add (insert) value by a JSON pointer. + @param val The target JSON value. + @param ptr The JSON pointer string (UTF-8 with null-terminator). + @param doc Only used to create new values when needed. + @param new_val The value to be added. + @return true if JSON pointer is valid and new value is added, false otherwise. + @note The parent nodes will be created if they do not exist. + */ +yyjson_api_inline bool yyjson_mut_ptr_add(yyjson_mut_val *val, + const char *ptr, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc); + +/** + Add (insert) value by a JSON pointer. + @param val The target JSON value. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param doc Only used to create new values when needed. + @param new_val The value to be added. + @return true if JSON pointer is valid and new value is added, false otherwise. + @note The parent nodes will be created if they do not exist. + */ +yyjson_api_inline bool yyjson_mut_ptr_addn(yyjson_mut_val *val, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc); + +/** + Add (insert) value by a JSON pointer. + @param val The target JSON value. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param doc Only used to create new values when needed. + @param new_val The value to be added. + @param create_parent Whether to create parent nodes if not exist. + @param ctx A pointer to store the result context, or NULL if not needed. + @param err A pointer to store the error information, or NULL if not needed. + @return true if JSON pointer is valid and new value is added, false otherwise. + */ +yyjson_api_inline bool yyjson_mut_ptr_addx(yyjson_mut_val *val, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc, + bool create_parent, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err); + +/** + Set value by a JSON pointer. + @param doc The target JSON document. + @param ptr The JSON pointer string (UTF-8 with null-terminator). + @param new_val The value to be set, pass NULL to remove. + @return true if JSON pointer is valid and new value is set, false otherwise. + @note The parent nodes will be created if they do not exist. + If the target value already exists, it will be replaced by the new value. + */ +yyjson_api_inline bool yyjson_mut_doc_ptr_set(yyjson_mut_doc *doc, + const char *ptr, + yyjson_mut_val *new_val); + +/** + Set value by a JSON pointer. + @param doc The target JSON document. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param new_val The value to be set, pass NULL to remove. + @return true if JSON pointer is valid and new value is set, false otherwise. + @note The parent nodes will be created if they do not exist. + If the target value already exists, it will be replaced by the new value. + */ +yyjson_api_inline bool yyjson_mut_doc_ptr_setn(yyjson_mut_doc *doc, + const char *ptr, size_t len, + yyjson_mut_val *new_val); + +/** + Set value by a JSON pointer. + @param doc The target JSON document. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param new_val The value to be set, pass NULL to remove. + @param create_parent Whether to create parent nodes if not exist. + @param ctx A pointer to store the result context, or NULL if not needed. + @param err A pointer to store the error information, or NULL if not needed. + @return true if JSON pointer is valid and new value is set, false otherwise. + @note If the target value already exists, it will be replaced by the new value. + */ +yyjson_api_inline bool yyjson_mut_doc_ptr_setx(yyjson_mut_doc *doc, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + bool create_parent, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err); + +/** + Set value by a JSON pointer. + @param val The target JSON value. + @param ptr The JSON pointer string (UTF-8 with null-terminator). + @param new_val The value to be set, pass NULL to remove. + @param doc Only used to create new values when needed. + @return true if JSON pointer is valid and new value is set, false otherwise. + @note The parent nodes will be created if they do not exist. + If the target value already exists, it will be replaced by the new value. + */ +yyjson_api_inline bool yyjson_mut_ptr_set(yyjson_mut_val *val, + const char *ptr, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc); + +/** + Set value by a JSON pointer. + @param val The target JSON value. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param new_val The value to be set, pass NULL to remove. + @param doc Only used to create new values when needed. + @return true if JSON pointer is valid and new value is set, false otherwise. + @note The parent nodes will be created if they do not exist. + If the target value already exists, it will be replaced by the new value. + */ +yyjson_api_inline bool yyjson_mut_ptr_setn(yyjson_mut_val *val, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc); + +/** + Set value by a JSON pointer. + @param val The target JSON value. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param new_val The value to be set, pass NULL to remove. + @param doc Only used to create new values when needed. + @param create_parent Whether to create parent nodes if not exist. + @param ctx A pointer to store the result context, or NULL if not needed. + @param err A pointer to store the error information, or NULL if not needed. + @return true if JSON pointer is valid and new value is set, false otherwise. + @note If the target value already exists, it will be replaced by the new value. + */ +yyjson_api_inline bool yyjson_mut_ptr_setx(yyjson_mut_val *val, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc, + bool create_parent, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err); + +/** + Replace value by a JSON pointer. + @param doc The target JSON document. + @param ptr The JSON pointer string (UTF-8 with null-terminator). + @param new_val The new value to replace the old one. + @return The old value that was replaced, or NULL if not found. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_replace( + yyjson_mut_doc *doc, const char *ptr, yyjson_mut_val *new_val); + +/** + Replace value by a JSON pointer. + @param doc The target JSON document. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param new_val The new value to replace the old one. + @return The old value that was replaced, or NULL if not found. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_replacen( + yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_mut_val *new_val); + +/** + Replace value by a JSON pointer. + @param doc The target JSON document. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param new_val The new value to replace the old one. + @param ctx A pointer to store the result context, or NULL if not needed. + @param err A pointer to store the error information, or NULL if not needed. + @return The old value that was replaced, or NULL if not found. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_replacex( + yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_mut_val *new_val, + yyjson_ptr_ctx *ctx, yyjson_ptr_err *err); + +/** + Replace value by a JSON pointer. + @param val The target JSON value. + @param ptr The JSON pointer string (UTF-8 with null-terminator). + @param new_val The new value to replace the old one. + @return The old value that was replaced, or NULL if not found. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_replace( + yyjson_mut_val *val, const char *ptr, yyjson_mut_val *new_val); + +/** + Replace value by a JSON pointer. + @param val The target JSON value. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param new_val The new value to replace the old one. + @return The old value that was replaced, or NULL if not found. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_replacen( + yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val); + +/** + Replace value by a JSON pointer. + @param val The target JSON value. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param new_val The new value to replace the old one. + @param ctx A pointer to store the result context, or NULL if not needed. + @param err A pointer to store the error information, or NULL if not needed. + @return The old value that was replaced, or NULL if not found. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_replacex( + yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val, + yyjson_ptr_ctx *ctx, yyjson_ptr_err *err); + +/** + Remove value by a JSON pointer. + @param doc The target JSON document. + @param ptr The JSON pointer string (UTF-8 with null-terminator). + @return The removed value, or NULL on error. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_remove( + yyjson_mut_doc *doc, const char *ptr); + +/** + Remove value by a JSON pointer. + @param doc The target JSON document. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @return The removed value, or NULL on error. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_removen( + yyjson_mut_doc *doc, const char *ptr, size_t len); + +/** + Remove value by a JSON pointer. + @param doc The target JSON document. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param ctx A pointer to store the result context, or NULL if not needed. + @param err A pointer to store the error information, or NULL if not needed. + @return The removed value, or NULL on error. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_removex( + yyjson_mut_doc *doc, const char *ptr, size_t len, + yyjson_ptr_ctx *ctx, yyjson_ptr_err *err); + +/** + Remove value by a JSON pointer. + @param val The target JSON value. + @param ptr The JSON pointer string (UTF-8 with null-terminator). + @return The removed value, or NULL on error. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_remove(yyjson_mut_val *val, + const char *ptr); + +/** + Remove value by a JSON pointer. + @param val The target JSON value. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @return The removed value, or NULL on error. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_removen(yyjson_mut_val *val, + const char *ptr, + size_t len); + +/** + Remove value by a JSON pointer. + @param val The target JSON value. + @param ptr The JSON pointer string (UTF-8, null-terminator is not required). + @param len The length of `ptr` in bytes. + @param ctx A pointer to store the result context, or NULL if not needed. + @param err A pointer to store the error information, or NULL if not needed. + @return The removed value, or NULL on error. + */ +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_removex(yyjson_mut_val *val, + const char *ptr, + size_t len, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err); + +/** + Append value by JSON pointer context. + @param ctx The context from the `yyjson_mut_ptr_xxx()` calls. + @param key New key if `ctx->ctn` is object, or NULL if `ctx->ctn` is array. + @param val New value to be added. + @return true on success or false on fail. + */ +yyjson_api_inline bool yyjson_ptr_ctx_append(yyjson_ptr_ctx *ctx, + yyjson_mut_val *key, + yyjson_mut_val *val); + +/** + Replace value by JSON pointer context. + @param ctx The context from the `yyjson_mut_ptr_xxx()` calls. + @param val New value to be replaced. + @return true on success or false on fail. + @note If success, the old value will be returned via `ctx->old`. + */ +yyjson_api_inline bool yyjson_ptr_ctx_replace(yyjson_ptr_ctx *ctx, + yyjson_mut_val *val); + +/** + Remove value by JSON pointer context. + @param ctx The context from the `yyjson_mut_ptr_xxx()` calls. + @return true on success or false on fail. + @note If success, the old value will be returned via `ctx->old`. + */ +yyjson_api_inline bool yyjson_ptr_ctx_remove(yyjson_ptr_ctx *ctx); + + + +/*============================================================================== + * MARK: - JSON Patch API (RFC 6902) + * https://tools.ietf.org/html/rfc6902 + *============================================================================*/ + +/** Result code for JSON patch. */ +typedef uint32_t yyjson_patch_code; + +/** Success, no error. */ +static const yyjson_patch_code YYJSON_PATCH_SUCCESS = 0; + +/** Invalid parameter, such as NULL input or non-array patch. */ +static const yyjson_patch_code YYJSON_PATCH_ERROR_INVALID_PARAMETER = 1; + +/** Memory allocation failure occurs. */ +static const yyjson_patch_code YYJSON_PATCH_ERROR_MEMORY_ALLOCATION = 2; + +/** JSON patch operation is not object type. */ +static const yyjson_patch_code YYJSON_PATCH_ERROR_INVALID_OPERATION = 3; + +/** JSON patch operation is missing a required key. */ +static const yyjson_patch_code YYJSON_PATCH_ERROR_MISSING_KEY = 4; + +/** JSON patch operation member is invalid. */ +static const yyjson_patch_code YYJSON_PATCH_ERROR_INVALID_MEMBER = 5; + +/** JSON patch operation `test` not equal. */ +static const yyjson_patch_code YYJSON_PATCH_ERROR_EQUAL = 6; + +/** JSON patch operation failed on JSON pointer. */ +static const yyjson_patch_code YYJSON_PATCH_ERROR_POINTER = 7; + +/** Error information for JSON patch. */ +typedef struct yyjson_patch_err { + /** Error code, see `yyjson_patch_code` for all possible values. */ + yyjson_patch_code code; + /** Index of the error operation (0 if no error). */ + size_t idx; + /** Error message, constant, no need to free (NULL if no error). */ + const char *msg; + /** JSON pointer error if `code == YYJSON_PATCH_ERROR_POINTER`. */ + yyjson_ptr_err ptr; +} yyjson_patch_err; + +/** + Creates and returns a patched JSON value (RFC 6902). + The memory of the returned value is allocated by the `doc`. + The `err` is used to receive error information, pass NULL if not needed. + Returns NULL if the patch could not be applied. + */ +yyjson_api yyjson_mut_val *yyjson_patch(yyjson_mut_doc *doc, + yyjson_val *orig, + yyjson_val *patch, + yyjson_patch_err *err); + +/** + Creates and returns a patched JSON value (RFC 6902). + The memory of the returned value is allocated by the `doc`. + The `err` is used to receive error information, pass NULL if not needed. + Returns NULL if the patch could not be applied. + */ +yyjson_api yyjson_mut_val *yyjson_mut_patch(yyjson_mut_doc *doc, + yyjson_mut_val *orig, + yyjson_mut_val *patch, + yyjson_patch_err *err); + + + +/*============================================================================== + * MARK: - JSON Merge-Patch API (RFC 7386) + * https://tools.ietf.org/html/rfc7386 + *============================================================================*/ + +/** + Creates and returns a merge-patched JSON value (RFC 7386). + The memory of the returned value is allocated by the `doc`. + Returns NULL if the patch could not be applied. + + @warning This function is recursive and may cause a stack overflow if the + object level is too deep. + */ +yyjson_api yyjson_mut_val *yyjson_merge_patch(yyjson_mut_doc *doc, + yyjson_val *orig, + yyjson_val *patch); + +/** + Creates and returns a merge-patched JSON value (RFC 7386). + The memory of the returned value is allocated by the `doc`. + Returns NULL if the patch could not be applied. + + @warning This function is recursive and may cause a stack overflow if the + object level is too deep. + */ +yyjson_api yyjson_mut_val *yyjson_mut_merge_patch(yyjson_mut_doc *doc, + yyjson_mut_val *orig, + yyjson_mut_val *patch); + +#endif /* YYJSON_DISABLE_UTILS */ + + + +/*============================================================================== + * MARK: - JSON Structure (Implementation) + *============================================================================*/ + +/** Payload of a JSON value (8 bytes). */ +typedef union yyjson_val_uni { + uint64_t u64; + int64_t i64; + double f64; + const char *str; + void *ptr; + size_t ofs; +} yyjson_val_uni; + +/** + Immutable JSON value, 16 bytes. + */ +struct yyjson_val { + uint64_t tag; /**< type, subtype and length */ + yyjson_val_uni uni; /**< payload */ +}; + +struct yyjson_doc { + /** Root value of the document (nonnull). */ + yyjson_val *root; + /** Allocator used by document (nonnull). */ + yyjson_alc alc; + /** The total number of bytes read when parsing JSON (nonzero). */ + size_t dat_read; + /** The total number of value read when parsing JSON (nonzero). */ + size_t val_read; + /** The string pool used by JSON values (nullable). */ + char *str_pool; +}; + + + +/*============================================================================== + * MARK: - Unsafe JSON Value API (Implementation) + *============================================================================*/ + +/* + Whether the string does not need to be escaped for serialization. + This function is used to optimize the writing speed of small constant strings. + This function works only if the compiler can evaluate it at compile time. + + Clang supports it since v8.0, + earlier versions do not support constant_p(strlen) and return false. + GCC supports it since at least v4.4, + earlier versions may compile it as run-time instructions. + ICC supports it since at least v16, + earlier versions are uncertain. + + @param str The C string. + @param len The returnd value from strlen(str). + */ +yyjson_api_inline bool unsafe_yyjson_is_str_noesc(const char *str, size_t len) { +#if YYJSON_HAS_CONSTANT_P && \ + (!YYJSON_IS_REAL_GCC || yyjson_gcc_available(4, 4, 0)) + if (yyjson_constant_p(len) && len <= 32) { + /* + Same as the following loop: + + for (size_t i = 0; i < len; i++) { + char c = str[i]; + if (c < ' ' || c > '~' || c == '"' || c == '\\') return false; + } + + GCC evaluates it at compile time only if the string length is within 17 + and -O3 (which turns on the -fpeel-loops flag) is used. + So the loop is unrolled for GCC. + */ +# define yyjson_repeat32_incr(x) \ + x(0) x(1) x(2) x(3) x(4) x(5) x(6) x(7) \ + x(8) x(9) x(10) x(11) x(12) x(13) x(14) x(15) \ + x(16) x(17) x(18) x(19) x(20) x(21) x(22) x(23) \ + x(24) x(25) x(26) x(27) x(28) x(29) x(30) x(31) +# define yyjson_check_char_noesc(i) \ + if (i < len) { \ + char c = str[i]; \ + if (c < ' ' || c > '~' || c == '"' || c == '\\') return false; } + yyjson_repeat32_incr(yyjson_check_char_noesc) +# undef yyjson_repeat32_incr +# undef yyjson_check_char_noesc + return true; + } +#else + (void)str; + (void)len; +#endif + return false; +} + +yyjson_api_inline double unsafe_yyjson_u64_to_f64(uint64_t num) { +#if YYJSON_U64_TO_F64_NO_IMPL + uint64_t msb = ((uint64_t)1) << 63; + if ((num & msb) == 0) { + return (double)(int64_t)num; + } else { + return ((double)(int64_t)((num >> 1) | (num & 1))) * (double)2.0; + } +#else + return (double)num; +#endif +} + +yyjson_api_inline yyjson_type unsafe_yyjson_get_type(void *val) { + uint8_t tag = (uint8_t)((yyjson_val *)val)->tag; + return (yyjson_type)(tag & YYJSON_TYPE_MASK); +} + +yyjson_api_inline yyjson_subtype unsafe_yyjson_get_subtype(void *val) { + uint8_t tag = (uint8_t)((yyjson_val *)val)->tag; + return (yyjson_subtype)(tag & YYJSON_SUBTYPE_MASK); +} + +yyjson_api_inline uint8_t unsafe_yyjson_get_tag(void *val) { + uint8_t tag = (uint8_t)((yyjson_val *)val)->tag; + return (uint8_t)(tag & YYJSON_TAG_MASK); +} + +yyjson_api_inline bool unsafe_yyjson_is_raw(void *val) { + return unsafe_yyjson_get_type(val) == YYJSON_TYPE_RAW; +} + +yyjson_api_inline bool unsafe_yyjson_is_null(void *val) { + return unsafe_yyjson_get_type(val) == YYJSON_TYPE_NULL; +} + +yyjson_api_inline bool unsafe_yyjson_is_bool(void *val) { + return unsafe_yyjson_get_type(val) == YYJSON_TYPE_BOOL; +} + +yyjson_api_inline bool unsafe_yyjson_is_num(void *val) { + return unsafe_yyjson_get_type(val) == YYJSON_TYPE_NUM; +} + +yyjson_api_inline bool unsafe_yyjson_is_str(void *val) { + return unsafe_yyjson_get_type(val) == YYJSON_TYPE_STR; +} + +yyjson_api_inline bool unsafe_yyjson_is_arr(void *val) { + return unsafe_yyjson_get_type(val) == YYJSON_TYPE_ARR; +} + +yyjson_api_inline bool unsafe_yyjson_is_obj(void *val) { + return unsafe_yyjson_get_type(val) == YYJSON_TYPE_OBJ; +} + +yyjson_api_inline bool unsafe_yyjson_is_ctn(void *val) { + uint8_t mask = YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ; + return (unsafe_yyjson_get_tag(val) & mask) == mask; +} + +yyjson_api_inline bool unsafe_yyjson_is_uint(void *val) { + const uint8_t patt = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT; + return unsafe_yyjson_get_tag(val) == patt; +} + +yyjson_api_inline bool unsafe_yyjson_is_sint(void *val) { + const uint8_t patt = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_SINT; + return unsafe_yyjson_get_tag(val) == patt; +} + +yyjson_api_inline bool unsafe_yyjson_is_int(void *val) { + const uint8_t mask = YYJSON_TAG_MASK & (~YYJSON_SUBTYPE_SINT); + const uint8_t patt = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT; + return (unsafe_yyjson_get_tag(val) & mask) == patt; +} + +yyjson_api_inline bool unsafe_yyjson_is_real(void *val) { + const uint8_t patt = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; + return unsafe_yyjson_get_tag(val) == patt; +} + +yyjson_api_inline bool unsafe_yyjson_is_true(void *val) { + const uint8_t patt = YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_TRUE; + return unsafe_yyjson_get_tag(val) == patt; +} + +yyjson_api_inline bool unsafe_yyjson_is_false(void *val) { + const uint8_t patt = YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_FALSE; + return unsafe_yyjson_get_tag(val) == patt; +} + +yyjson_api_inline bool unsafe_yyjson_arr_is_flat(yyjson_val *val) { + size_t ofs = val->uni.ofs; + size_t len = (size_t)(val->tag >> YYJSON_TAG_BIT); + return len * sizeof(yyjson_val) + sizeof(yyjson_val) == ofs; +} + +yyjson_api_inline const char *unsafe_yyjson_get_raw(void *val) { + return ((yyjson_val *)val)->uni.str; +} + +yyjson_api_inline bool unsafe_yyjson_get_bool(void *val) { + uint8_t tag = unsafe_yyjson_get_tag(val); + return (bool)((tag & YYJSON_SUBTYPE_MASK) >> YYJSON_TYPE_BIT); +} + +yyjson_api_inline uint64_t unsafe_yyjson_get_uint(void *val) { + return ((yyjson_val *)val)->uni.u64; +} + +yyjson_api_inline int64_t unsafe_yyjson_get_sint(void *val) { + return ((yyjson_val *)val)->uni.i64; +} + +yyjson_api_inline int unsafe_yyjson_get_int(void *val) { + return (int)((yyjson_val *)val)->uni.i64; +} + +yyjson_api_inline double unsafe_yyjson_get_real(void *val) { + return ((yyjson_val *)val)->uni.f64; +} + +yyjson_api_inline double unsafe_yyjson_get_num(void *val) { + uint8_t tag = unsafe_yyjson_get_tag(val); + if (tag == (YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL)) { + return ((yyjson_val *)val)->uni.f64; + } else if (tag == (YYJSON_TYPE_NUM | YYJSON_SUBTYPE_SINT)) { + return (double)((yyjson_val *)val)->uni.i64; + } else if (tag == (YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT)) { + return unsafe_yyjson_u64_to_f64(((yyjson_val *)val)->uni.u64); + } + return 0.0; +} + +yyjson_api_inline const char *unsafe_yyjson_get_str(void *val) { + return ((yyjson_val *)val)->uni.str; +} + +yyjson_api_inline size_t unsafe_yyjson_get_len(void *val) { + return (size_t)(((yyjson_val *)val)->tag >> YYJSON_TAG_BIT); +} + +yyjson_api_inline yyjson_val *unsafe_yyjson_get_first(yyjson_val *ctn) { + return ctn + 1; +} + +yyjson_api_inline yyjson_val *unsafe_yyjson_get_next(yyjson_val *val) { + bool is_ctn = unsafe_yyjson_is_ctn(val); + size_t ctn_ofs = val->uni.ofs; + size_t ofs = (is_ctn ? ctn_ofs : sizeof(yyjson_val)); + return (yyjson_val *)(void *)((uint8_t *)val + ofs); +} + +yyjson_api_inline bool unsafe_yyjson_equals_strn(void *val, const char *str, + size_t len) { + return unsafe_yyjson_get_len(val) == len && + memcmp(((yyjson_val *)val)->uni.str, str, len) == 0; +} + +yyjson_api_inline bool unsafe_yyjson_equals_str(void *val, const char *str) { + return unsafe_yyjson_equals_strn(val, str, strlen(str)); +} + +yyjson_api_inline void unsafe_yyjson_set_type(void *val, yyjson_type type, + yyjson_subtype subtype) { + uint8_t tag = (type | subtype); + uint64_t new_tag = ((yyjson_val *)val)->tag; + new_tag = (new_tag & (~(uint64_t)YYJSON_TAG_MASK)) | (uint64_t)tag; + ((yyjson_val *)val)->tag = new_tag; +} + +yyjson_api_inline void unsafe_yyjson_set_len(void *val, size_t len) { + uint64_t tag = ((yyjson_val *)val)->tag & YYJSON_TAG_MASK; + tag |= (uint64_t)len << YYJSON_TAG_BIT; + ((yyjson_val *)val)->tag = tag; +} + +yyjson_api_inline void unsafe_yyjson_set_tag(void *val, yyjson_type type, + yyjson_subtype subtype, + size_t len) { + uint64_t tag = (uint64_t)len << YYJSON_TAG_BIT; + tag |= (type | subtype); + ((yyjson_val *)val)->tag = tag; +} + +yyjson_api_inline void unsafe_yyjson_inc_len(void *val) { + uint64_t tag = ((yyjson_val *)val)->tag; + tag += (uint64_t)(1 << YYJSON_TAG_BIT); + ((yyjson_val *)val)->tag = tag; +} + +yyjson_api_inline void unsafe_yyjson_set_raw(void *val, const char *raw, + size_t len) { + unsafe_yyjson_set_tag(val, YYJSON_TYPE_RAW, YYJSON_SUBTYPE_NONE, len); + ((yyjson_val *)val)->uni.str = raw; +} + +yyjson_api_inline void unsafe_yyjson_set_null(void *val) { + unsafe_yyjson_set_tag(val, YYJSON_TYPE_NULL, YYJSON_SUBTYPE_NONE, 0); +} + +yyjson_api_inline void unsafe_yyjson_set_bool(void *val, bool num) { + yyjson_subtype subtype = num ? YYJSON_SUBTYPE_TRUE : YYJSON_SUBTYPE_FALSE; + unsafe_yyjson_set_tag(val, YYJSON_TYPE_BOOL, subtype, 0); +} + +yyjson_api_inline void unsafe_yyjson_set_uint(void *val, uint64_t num) { + unsafe_yyjson_set_tag(val, YYJSON_TYPE_NUM, YYJSON_SUBTYPE_UINT, 0); + ((yyjson_val *)val)->uni.u64 = num; +} + +yyjson_api_inline void unsafe_yyjson_set_sint(void *val, int64_t num) { + unsafe_yyjson_set_tag(val, YYJSON_TYPE_NUM, YYJSON_SUBTYPE_SINT, 0); + ((yyjson_val *)val)->uni.i64 = num; +} + +yyjson_api_inline void unsafe_yyjson_set_fp_to_fixed(void *val, int prec) { + ((yyjson_val *)val)->tag &= ~((uint64_t)YYJSON_WRITE_FP_TO_FIXED(15) << 32); + ((yyjson_val *)val)->tag |= (uint64_t)YYJSON_WRITE_FP_TO_FIXED(prec) << 32; +} + +yyjson_api_inline void unsafe_yyjson_set_fp_to_float(void *val, bool flt) { + uint64_t flag = (uint64_t)YYJSON_WRITE_FP_TO_FLOAT << 32; + if (flt) ((yyjson_val *)val)->tag |= flag; + else ((yyjson_val *)val)->tag &= ~flag; +} + +yyjson_api_inline void unsafe_yyjson_set_float(void *val, float num) { + unsafe_yyjson_set_tag(val, YYJSON_TYPE_NUM, YYJSON_SUBTYPE_REAL, 0); + ((yyjson_val *)val)->tag |= (uint64_t)YYJSON_WRITE_FP_TO_FLOAT << 32; + ((yyjson_val *)val)->uni.f64 = (double)num; +} + +yyjson_api_inline void unsafe_yyjson_set_double(void *val, double num) { + unsafe_yyjson_set_tag(val, YYJSON_TYPE_NUM, YYJSON_SUBTYPE_REAL, 0); + ((yyjson_val *)val)->uni.f64 = num; +} + +yyjson_api_inline void unsafe_yyjson_set_real(void *val, double num) { + unsafe_yyjson_set_tag(val, YYJSON_TYPE_NUM, YYJSON_SUBTYPE_REAL, 0); + ((yyjson_val *)val)->uni.f64 = num; +} + +yyjson_api_inline void unsafe_yyjson_set_str_noesc(void *val, bool noesc) { + ((yyjson_val *)val)->tag &= ~(uint64_t)YYJSON_SUBTYPE_MASK; + if (noesc) ((yyjson_val *)val)->tag |= (uint64_t)YYJSON_SUBTYPE_NOESC; +} + +yyjson_api_inline void unsafe_yyjson_set_strn(void *val, const char *str, + size_t len) { + unsafe_yyjson_set_tag(val, YYJSON_TYPE_STR, YYJSON_SUBTYPE_NONE, len); + ((yyjson_val *)val)->uni.str = str; +} + +yyjson_api_inline void unsafe_yyjson_set_str(void *val, const char *str) { + size_t len = strlen(str); + bool noesc = unsafe_yyjson_is_str_noesc(str, len); + yyjson_subtype subtype = noesc ? YYJSON_SUBTYPE_NOESC : YYJSON_SUBTYPE_NONE; + unsafe_yyjson_set_tag(val, YYJSON_TYPE_STR, subtype, len); + ((yyjson_val *)val)->uni.str = str; +} + +yyjson_api_inline void unsafe_yyjson_set_arr(void *val, size_t size) { + unsafe_yyjson_set_tag(val, YYJSON_TYPE_ARR, YYJSON_SUBTYPE_NONE, size); +} + +yyjson_api_inline void unsafe_yyjson_set_obj(void *val, size_t size) { + unsafe_yyjson_set_tag(val, YYJSON_TYPE_OBJ, YYJSON_SUBTYPE_NONE, size); +} + + + +/*============================================================================== + * MARK: - JSON Document API (Implementation) + *============================================================================*/ + +yyjson_api_inline yyjson_val *yyjson_doc_get_root(yyjson_doc *doc) { + return doc ? doc->root : NULL; +} + +yyjson_api_inline size_t yyjson_doc_get_read_size(yyjson_doc *doc) { + return doc ? doc->dat_read : 0; +} + +yyjson_api_inline size_t yyjson_doc_get_val_count(yyjson_doc *doc) { + return doc ? doc->val_read : 0; +} + +yyjson_api_inline void yyjson_doc_free(yyjson_doc *doc) { + if (doc) { + yyjson_alc alc = doc->alc; + memset(&doc->alc, 0, sizeof(alc)); + if (doc->str_pool) alc.free(alc.ctx, doc->str_pool); + alc.free(alc.ctx, doc); + } +} + + + +/*============================================================================== + * MARK: - JSON Value Type API (Implementation) + *============================================================================*/ + +yyjson_api_inline bool yyjson_is_raw(yyjson_val *val) { + return val ? unsafe_yyjson_is_raw(val) : false; +} + +yyjson_api_inline bool yyjson_is_null(yyjson_val *val) { + return val ? unsafe_yyjson_is_null(val) : false; +} + +yyjson_api_inline bool yyjson_is_true(yyjson_val *val) { + return val ? unsafe_yyjson_is_true(val) : false; +} + +yyjson_api_inline bool yyjson_is_false(yyjson_val *val) { + return val ? unsafe_yyjson_is_false(val) : false; +} + +yyjson_api_inline bool yyjson_is_bool(yyjson_val *val) { + return val ? unsafe_yyjson_is_bool(val) : false; +} + +yyjson_api_inline bool yyjson_is_uint(yyjson_val *val) { + return val ? unsafe_yyjson_is_uint(val) : false; +} + +yyjson_api_inline bool yyjson_is_sint(yyjson_val *val) { + return val ? unsafe_yyjson_is_sint(val) : false; +} + +yyjson_api_inline bool yyjson_is_int(yyjson_val *val) { + return val ? unsafe_yyjson_is_int(val) : false; +} + +yyjson_api_inline bool yyjson_is_real(yyjson_val *val) { + return val ? unsafe_yyjson_is_real(val) : false; +} + +yyjson_api_inline bool yyjson_is_num(yyjson_val *val) { + return val ? unsafe_yyjson_is_num(val) : false; +} + +yyjson_api_inline bool yyjson_is_str(yyjson_val *val) { + return val ? unsafe_yyjson_is_str(val) : false; +} + +yyjson_api_inline bool yyjson_is_arr(yyjson_val *val) { + return val ? unsafe_yyjson_is_arr(val) : false; +} + +yyjson_api_inline bool yyjson_is_obj(yyjson_val *val) { + return val ? unsafe_yyjson_is_obj(val) : false; +} + +yyjson_api_inline bool yyjson_is_ctn(yyjson_val *val) { + return val ? unsafe_yyjson_is_ctn(val) : false; +} + + + +/*============================================================================== + * MARK: - JSON Value Content API (Implementation) + *============================================================================*/ + +yyjson_api_inline yyjson_type yyjson_get_type(yyjson_val *val) { + return val ? unsafe_yyjson_get_type(val) : YYJSON_TYPE_NONE; +} + +yyjson_api_inline yyjson_subtype yyjson_get_subtype(yyjson_val *val) { + return val ? unsafe_yyjson_get_subtype(val) : YYJSON_SUBTYPE_NONE; +} + +yyjson_api_inline uint8_t yyjson_get_tag(yyjson_val *val) { + return val ? unsafe_yyjson_get_tag(val) : 0; +} + +yyjson_api_inline const char *yyjson_get_type_desc(yyjson_val *val) { + switch (yyjson_get_tag(val)) { + case YYJSON_TYPE_RAW | YYJSON_SUBTYPE_NONE: return "raw"; + case YYJSON_TYPE_NULL | YYJSON_SUBTYPE_NONE: return "null"; + case YYJSON_TYPE_STR | YYJSON_SUBTYPE_NONE: return "string"; + case YYJSON_TYPE_STR | YYJSON_SUBTYPE_NOESC: return "string"; + case YYJSON_TYPE_ARR | YYJSON_SUBTYPE_NONE: return "array"; + case YYJSON_TYPE_OBJ | YYJSON_SUBTYPE_NONE: return "object"; + case YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_TRUE: return "true"; + case YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_FALSE: return "false"; + case YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT: return "uint"; + case YYJSON_TYPE_NUM | YYJSON_SUBTYPE_SINT: return "sint"; + case YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL: return "real"; + default: return "unknown"; + } +} + +yyjson_api_inline const char *yyjson_get_raw(yyjson_val *val) { + return yyjson_is_raw(val) ? unsafe_yyjson_get_raw(val) : NULL; +} + +yyjson_api_inline bool yyjson_get_bool(yyjson_val *val) { + return yyjson_is_bool(val) ? unsafe_yyjson_get_bool(val) : false; +} + +yyjson_api_inline uint64_t yyjson_get_uint(yyjson_val *val) { + return yyjson_is_int(val) ? unsafe_yyjson_get_uint(val) : 0; +} + +yyjson_api_inline int64_t yyjson_get_sint(yyjson_val *val) { + return yyjson_is_int(val) ? unsafe_yyjson_get_sint(val) : 0; +} + +yyjson_api_inline int yyjson_get_int(yyjson_val *val) { + return yyjson_is_int(val) ? unsafe_yyjson_get_int(val) : 0; +} + +yyjson_api_inline double yyjson_get_real(yyjson_val *val) { + return yyjson_is_real(val) ? unsafe_yyjson_get_real(val) : 0.0; +} + +yyjson_api_inline double yyjson_get_num(yyjson_val *val) { + return val ? unsafe_yyjson_get_num(val) : 0.0; +} + +yyjson_api_inline const char *yyjson_get_str(yyjson_val *val) { + return yyjson_is_str(val) ? unsafe_yyjson_get_str(val) : NULL; +} + +yyjson_api_inline size_t yyjson_get_len(yyjson_val *val) { + return val ? unsafe_yyjson_get_len(val) : 0; +} + +yyjson_api_inline bool yyjson_equals_str(yyjson_val *val, const char *str) { + if (yyjson_likely(val && str)) { + return unsafe_yyjson_is_str(val) && + unsafe_yyjson_equals_str(val, str); + } + return false; +} + +yyjson_api_inline bool yyjson_equals_strn(yyjson_val *val, const char *str, + size_t len) { + if (yyjson_likely(val && str)) { + return unsafe_yyjson_is_str(val) && + unsafe_yyjson_equals_strn(val, str, len); + } + return false; +} + +yyjson_api bool unsafe_yyjson_equals(yyjson_val *lhs, yyjson_val *rhs); + +yyjson_api_inline bool yyjson_equals(yyjson_val *lhs, yyjson_val *rhs) { + if (yyjson_unlikely(!lhs || !rhs)) return false; + return unsafe_yyjson_equals(lhs, rhs); +} + +yyjson_api_inline bool yyjson_set_raw(yyjson_val *val, + const char *raw, size_t len) { + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + unsafe_yyjson_set_raw(val, raw, len); + return true; +} + +yyjson_api_inline bool yyjson_set_null(yyjson_val *val) { + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + unsafe_yyjson_set_null(val); + return true; +} + +yyjson_api_inline bool yyjson_set_bool(yyjson_val *val, bool num) { + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + unsafe_yyjson_set_bool(val, num); + return true; +} + +yyjson_api_inline bool yyjson_set_uint(yyjson_val *val, uint64_t num) { + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + unsafe_yyjson_set_uint(val, num); + return true; +} + +yyjson_api_inline bool yyjson_set_sint(yyjson_val *val, int64_t num) { + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + unsafe_yyjson_set_sint(val, num); + return true; +} + +yyjson_api_inline bool yyjson_set_int(yyjson_val *val, int num) { + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + unsafe_yyjson_set_sint(val, (int64_t)num); + return true; +} + +yyjson_api_inline bool yyjson_set_float(yyjson_val *val, float num) { + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + unsafe_yyjson_set_float(val, num); + return true; +} + +yyjson_api_inline bool yyjson_set_double(yyjson_val *val, double num) { + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + unsafe_yyjson_set_double(val, num); + return true; +} + +yyjson_api_inline bool yyjson_set_real(yyjson_val *val, double num) { + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + unsafe_yyjson_set_real(val, num); + return true; +} + +yyjson_api_inline bool yyjson_set_fp_to_fixed(yyjson_val *val, int prec) { + if (yyjson_unlikely(!yyjson_is_real(val))) return false; + unsafe_yyjson_set_fp_to_fixed(val, prec); + return true; +} + +yyjson_api_inline bool yyjson_set_fp_to_float(yyjson_val *val, bool flt) { + if (yyjson_unlikely(!yyjson_is_real(val))) return false; + unsafe_yyjson_set_fp_to_float(val, flt); + return true; +} + +yyjson_api_inline bool yyjson_set_str(yyjson_val *val, const char *str) { + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + if (yyjson_unlikely(!str)) return false; + unsafe_yyjson_set_str(val, str); + return true; +} + +yyjson_api_inline bool yyjson_set_strn(yyjson_val *val, + const char *str, size_t len) { + if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; + if (yyjson_unlikely(!str)) return false; + unsafe_yyjson_set_strn(val, str, len); + return true; +} + +yyjson_api_inline bool yyjson_set_str_noesc(yyjson_val *val, bool noesc) { + if (yyjson_unlikely(!yyjson_is_str(val))) return false; + unsafe_yyjson_set_str_noesc(val, noesc); + return true; +} + + + +/*============================================================================== + * MARK: - JSON Array API (Implementation) + *============================================================================*/ + +yyjson_api_inline size_t yyjson_arr_size(yyjson_val *arr) { + return yyjson_is_arr(arr) ? unsafe_yyjson_get_len(arr) : 0; +} + +yyjson_api_inline yyjson_val *yyjson_arr_get(yyjson_val *arr, size_t idx) { + if (yyjson_likely(yyjson_is_arr(arr))) { + if (yyjson_likely(unsafe_yyjson_get_len(arr) > idx)) { + yyjson_val *val = unsafe_yyjson_get_first(arr); + if (unsafe_yyjson_arr_is_flat(arr)) { + return val + idx; + } else { + while (idx-- > 0) val = unsafe_yyjson_get_next(val); + return val; + } + } + } + return NULL; +} + +yyjson_api_inline yyjson_val *yyjson_arr_get_first(yyjson_val *arr) { + if (yyjson_likely(yyjson_is_arr(arr))) { + if (yyjson_likely(unsafe_yyjson_get_len(arr) > 0)) { + return unsafe_yyjson_get_first(arr); + } + } + return NULL; +} + +yyjson_api_inline yyjson_val *yyjson_arr_get_last(yyjson_val *arr) { + if (yyjson_likely(yyjson_is_arr(arr))) { + size_t len = unsafe_yyjson_get_len(arr); + if (yyjson_likely(len > 0)) { + yyjson_val *val = unsafe_yyjson_get_first(arr); + if (unsafe_yyjson_arr_is_flat(arr)) { + return val + (len - 1); + } else { + while (len-- > 1) val = unsafe_yyjson_get_next(val); + return val; + } + } + } + return NULL; +} + + + +/*============================================================================== + * MARK: - JSON Array Iterator API (Implementation) + *============================================================================*/ + +yyjson_api_inline bool yyjson_arr_iter_init(yyjson_val *arr, + yyjson_arr_iter *iter) { + if (yyjson_likely(yyjson_is_arr(arr) && iter)) { + iter->idx = 0; + iter->max = unsafe_yyjson_get_len(arr); + iter->cur = unsafe_yyjson_get_first(arr); + return true; + } + if (iter) memset(iter, 0, sizeof(yyjson_arr_iter)); + return false; +} + +yyjson_api_inline yyjson_arr_iter yyjson_arr_iter_with(yyjson_val *arr) { + yyjson_arr_iter iter; + yyjson_arr_iter_init(arr, &iter); + return iter; +} + +yyjson_api_inline bool yyjson_arr_iter_has_next(yyjson_arr_iter *iter) { + return iter ? iter->idx < iter->max : false; +} + +yyjson_api_inline yyjson_val *yyjson_arr_iter_next(yyjson_arr_iter *iter) { + yyjson_val *val; + if (iter && iter->idx < iter->max) { + val = iter->cur; + iter->cur = unsafe_yyjson_get_next(val); + iter->idx++; + return val; + } + return NULL; +} + + + +/*============================================================================== + * MARK: - JSON Object API (Implementation) + *============================================================================*/ + +yyjson_api_inline size_t yyjson_obj_size(yyjson_val *obj) { + return yyjson_is_obj(obj) ? unsafe_yyjson_get_len(obj) : 0; +} + +yyjson_api_inline yyjson_val *yyjson_obj_get(yyjson_val *obj, + const char *key) { + return yyjson_obj_getn(obj, key, key ? strlen(key) : 0); +} + +yyjson_api_inline yyjson_val *yyjson_obj_getn(yyjson_val *obj, + const char *_key, + size_t key_len) { + if (yyjson_likely(yyjson_is_obj(obj) && _key)) { + size_t len = unsafe_yyjson_get_len(obj); + yyjson_val *key = unsafe_yyjson_get_first(obj); + while (len-- > 0) { + if (unsafe_yyjson_equals_strn(key, _key, key_len)) return key + 1; + key = unsafe_yyjson_get_next(key + 1); + } + } + return NULL; +} + + + +/*============================================================================== + * MARK: - JSON Object Iterator API (Implementation) + *============================================================================*/ + +yyjson_api_inline bool yyjson_obj_iter_init(yyjson_val *obj, + yyjson_obj_iter *iter) { + if (yyjson_likely(yyjson_is_obj(obj) && iter)) { + iter->idx = 0; + iter->max = unsafe_yyjson_get_len(obj); + iter->cur = unsafe_yyjson_get_first(obj); + iter->obj = obj; + return true; + } + if (iter) memset(iter, 0, sizeof(yyjson_obj_iter)); + return false; +} + +yyjson_api_inline yyjson_obj_iter yyjson_obj_iter_with(yyjson_val *obj) { + yyjson_obj_iter iter; + yyjson_obj_iter_init(obj, &iter); + return iter; +} + +yyjson_api_inline bool yyjson_obj_iter_has_next(yyjson_obj_iter *iter) { + return iter ? iter->idx < iter->max : false; +} + +yyjson_api_inline yyjson_val *yyjson_obj_iter_next(yyjson_obj_iter *iter) { + if (iter && iter->idx < iter->max) { + yyjson_val *key = iter->cur; + iter->idx++; + iter->cur = unsafe_yyjson_get_next(key + 1); + return key; + } + return NULL; +} + +yyjson_api_inline yyjson_val *yyjson_obj_iter_get_val(yyjson_val *key) { + return key ? key + 1 : NULL; +} + +yyjson_api_inline yyjson_val *yyjson_obj_iter_get(yyjson_obj_iter *iter, + const char *key) { + return yyjson_obj_iter_getn(iter, key, key ? strlen(key) : 0); +} + +yyjson_api_inline yyjson_val *yyjson_obj_iter_getn(yyjson_obj_iter *iter, + const char *key, + size_t key_len) { + if (iter && key) { + size_t idx = iter->idx; + size_t max = iter->max; + yyjson_val *cur = iter->cur; + if (yyjson_unlikely(idx == max)) { + idx = 0; + cur = unsafe_yyjson_get_first(iter->obj); + } + while (idx++ < max) { + yyjson_val *next = unsafe_yyjson_get_next(cur + 1); + if (unsafe_yyjson_equals_strn(cur, key, key_len)) { + iter->idx = idx; + iter->cur = next; + return cur + 1; + } + cur = next; + if (idx == iter->max && iter->idx < iter->max) { + idx = 0; + max = iter->idx; + cur = unsafe_yyjson_get_first(iter->obj); + } + } + } + return NULL; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Structure (Implementation) + *============================================================================*/ + +/** + Mutable JSON value, 24 bytes. + The 'tag' and 'uni' field is same as immutable value. + The 'next' field links all elements inside the container to be a cycle. + */ +struct yyjson_mut_val { + uint64_t tag; /**< type, subtype and length */ + yyjson_val_uni uni; /**< payload */ + yyjson_mut_val *next; /**< the next value in circular linked list */ +}; + +/** + A memory chunk in string memory pool. + */ +typedef struct yyjson_str_chunk { + struct yyjson_str_chunk *next; /* next chunk linked list */ + size_t chunk_size; /* chunk size in bytes */ + /* char str[]; flexible array member */ +} yyjson_str_chunk; + +/** + A memory pool to hold all strings in a mutable document. + */ +typedef struct yyjson_str_pool { + char *cur; /* cursor inside current chunk */ + char *end; /* the end of current chunk */ + size_t chunk_size; /* chunk size in bytes while creating new chunk */ + size_t chunk_size_max; /* maximum chunk size in bytes */ + yyjson_str_chunk *chunks; /* a linked list of chunks, nullable */ +} yyjson_str_pool; + +/** + A memory chunk in value memory pool. + `sizeof(yyjson_val_chunk)` should not larger than `sizeof(yyjson_mut_val)`. + */ +typedef struct yyjson_val_chunk { + struct yyjson_val_chunk *next; /* next chunk linked list */ + size_t chunk_size; /* chunk size in bytes */ + /* char pad[sizeof(yyjson_mut_val) - sizeof(yyjson_val_chunk)]; padding */ + /* yyjson_mut_val vals[]; flexible array member */ +} yyjson_val_chunk; + +/** + A memory pool to hold all values in a mutable document. + */ +typedef struct yyjson_val_pool { + yyjson_mut_val *cur; /* cursor inside current chunk */ + yyjson_mut_val *end; /* the end of current chunk */ + size_t chunk_size; /* chunk size in bytes while creating new chunk */ + size_t chunk_size_max; /* maximum chunk size in bytes */ + yyjson_val_chunk *chunks; /* a linked list of chunks, nullable */ +} yyjson_val_pool; + +struct yyjson_mut_doc { + yyjson_mut_val *root; /**< root value of the JSON document, nullable */ + yyjson_alc alc; /**< a valid allocator, nonnull */ + yyjson_str_pool str_pool; /**< string memory pool */ + yyjson_val_pool val_pool; /**< value memory pool */ +}; + +/* Ensures the capacity to at least equal to the specified byte length. */ +yyjson_api bool unsafe_yyjson_str_pool_grow(yyjson_str_pool *pool, + const yyjson_alc *alc, + size_t len); + +/* Ensures the capacity to at least equal to the specified value count. */ +yyjson_api bool unsafe_yyjson_val_pool_grow(yyjson_val_pool *pool, + const yyjson_alc *alc, + size_t count); + +/* Allocate memory for string. */ +yyjson_api_inline char *unsafe_yyjson_mut_str_alc(yyjson_mut_doc *doc, + size_t len) { + char *mem; + const yyjson_alc *alc = &doc->alc; + yyjson_str_pool *pool = &doc->str_pool; + if (yyjson_unlikely((size_t)(pool->end - pool->cur) <= len)) { + if (yyjson_unlikely(!unsafe_yyjson_str_pool_grow(pool, alc, len + 1))) { + return NULL; + } + } + mem = pool->cur; + pool->cur = mem + len + 1; + return mem; +} + +yyjson_api_inline char *unsafe_yyjson_mut_strncpy(yyjson_mut_doc *doc, + const char *str, size_t len) { + char *mem = unsafe_yyjson_mut_str_alc(doc, len); + if (yyjson_unlikely(!mem)) return NULL; + memcpy((void *)mem, (const void *)str, len); + mem[len] = '\0'; + return mem; +} + +yyjson_api_inline yyjson_mut_val *unsafe_yyjson_mut_val(yyjson_mut_doc *doc, + size_t count) { + yyjson_mut_val *val; + yyjson_alc *alc = &doc->alc; + yyjson_val_pool *pool = &doc->val_pool; + if (yyjson_unlikely((size_t)(pool->end - pool->cur) < count)) { + if (yyjson_unlikely(!unsafe_yyjson_val_pool_grow(pool, alc, count))) { + return NULL; + } + } + val = pool->cur; + pool->cur += count; + return val; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Document API (Implementation) + *============================================================================*/ + +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_get_root(yyjson_mut_doc *doc) { + return doc ? doc->root : NULL; +} + +yyjson_api_inline void yyjson_mut_doc_set_root(yyjson_mut_doc *doc, + yyjson_mut_val *root) { + if (doc) doc->root = root; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Value Type API (Implementation) + *============================================================================*/ + +yyjson_api_inline bool yyjson_mut_is_raw(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_raw(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_null(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_null(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_true(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_true(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_false(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_false(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_bool(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_bool(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_uint(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_uint(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_sint(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_sint(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_int(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_int(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_real(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_real(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_num(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_num(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_str(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_str(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_arr(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_arr(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_obj(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_obj(val) : false; +} + +yyjson_api_inline bool yyjson_mut_is_ctn(yyjson_mut_val *val) { + return val ? unsafe_yyjson_is_ctn(val) : false; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Value Content API (Implementation) + *============================================================================*/ + +yyjson_api_inline yyjson_type yyjson_mut_get_type(yyjson_mut_val *val) { + return yyjson_get_type((yyjson_val *)val); +} + +yyjson_api_inline yyjson_subtype yyjson_mut_get_subtype(yyjson_mut_val *val) { + return yyjson_get_subtype((yyjson_val *)val); +} + +yyjson_api_inline uint8_t yyjson_mut_get_tag(yyjson_mut_val *val) { + return yyjson_get_tag((yyjson_val *)val); +} + +yyjson_api_inline const char *yyjson_mut_get_type_desc(yyjson_mut_val *val) { + return yyjson_get_type_desc((yyjson_val *)val); +} + +yyjson_api_inline const char *yyjson_mut_get_raw(yyjson_mut_val *val) { + return yyjson_get_raw((yyjson_val *)val); +} + +yyjson_api_inline bool yyjson_mut_get_bool(yyjson_mut_val *val) { + return yyjson_get_bool((yyjson_val *)val); +} + +yyjson_api_inline uint64_t yyjson_mut_get_uint(yyjson_mut_val *val) { + return yyjson_get_uint((yyjson_val *)val); +} + +yyjson_api_inline int64_t yyjson_mut_get_sint(yyjson_mut_val *val) { + return yyjson_get_sint((yyjson_val *)val); +} + +yyjson_api_inline int yyjson_mut_get_int(yyjson_mut_val *val) { + return yyjson_get_int((yyjson_val *)val); +} + +yyjson_api_inline double yyjson_mut_get_real(yyjson_mut_val *val) { + return yyjson_get_real((yyjson_val *)val); +} + +yyjson_api_inline double yyjson_mut_get_num(yyjson_mut_val *val) { + return yyjson_get_num((yyjson_val *)val); +} + +yyjson_api_inline const char *yyjson_mut_get_str(yyjson_mut_val *val) { + return yyjson_get_str((yyjson_val *)val); +} + +yyjson_api_inline size_t yyjson_mut_get_len(yyjson_mut_val *val) { + return yyjson_get_len((yyjson_val *)val); +} + +yyjson_api_inline bool yyjson_mut_equals_str(yyjson_mut_val *val, + const char *str) { + return yyjson_equals_str((yyjson_val *)val, str); +} + +yyjson_api_inline bool yyjson_mut_equals_strn(yyjson_mut_val *val, + const char *str, size_t len) { + return yyjson_equals_strn((yyjson_val *)val, str, len); +} + +yyjson_api bool unsafe_yyjson_mut_equals(yyjson_mut_val *lhs, + yyjson_mut_val *rhs); + +yyjson_api_inline bool yyjson_mut_equals(yyjson_mut_val *lhs, + yyjson_mut_val *rhs) { + if (yyjson_unlikely(!lhs || !rhs)) return false; + return unsafe_yyjson_mut_equals(lhs, rhs); +} + +yyjson_api_inline bool yyjson_mut_set_raw(yyjson_mut_val *val, + const char *raw, size_t len) { + if (yyjson_unlikely(!val || !raw)) return false; + unsafe_yyjson_set_raw(val, raw, len); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_null(yyjson_mut_val *val) { + if (yyjson_unlikely(!val)) return false; + unsafe_yyjson_set_null(val); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_bool(yyjson_mut_val *val, bool num) { + if (yyjson_unlikely(!val)) return false; + unsafe_yyjson_set_bool(val, num); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_uint(yyjson_mut_val *val, uint64_t num) { + if (yyjson_unlikely(!val)) return false; + unsafe_yyjson_set_uint(val, num); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_sint(yyjson_mut_val *val, int64_t num) { + if (yyjson_unlikely(!val)) return false; + unsafe_yyjson_set_sint(val, num); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_int(yyjson_mut_val *val, int num) { + if (yyjson_unlikely(!val)) return false; + unsafe_yyjson_set_sint(val, (int64_t)num); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_float(yyjson_mut_val *val, float num) { + if (yyjson_unlikely(!val)) return false; + unsafe_yyjson_set_float(val, num); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_double(yyjson_mut_val *val, double num) { + if (yyjson_unlikely(!val)) return false; + unsafe_yyjson_set_double(val, num); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_real(yyjson_mut_val *val, double num) { + if (yyjson_unlikely(!val)) return false; + unsafe_yyjson_set_real(val, num); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_fp_to_fixed(yyjson_mut_val *val, + int prec) { + if (yyjson_unlikely(!yyjson_mut_is_real(val))) return false; + unsafe_yyjson_set_fp_to_fixed(val, prec); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_fp_to_float(yyjson_mut_val *val, + bool flt) { + if (yyjson_unlikely(!yyjson_mut_is_real(val))) return false; + unsafe_yyjson_set_fp_to_float(val, flt); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_str(yyjson_mut_val *val, + const char *str) { + if (yyjson_unlikely(!val || !str)) return false; + unsafe_yyjson_set_str(val, str); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_strn(yyjson_mut_val *val, + const char *str, size_t len) { + if (yyjson_unlikely(!val || !str)) return false; + unsafe_yyjson_set_strn(val, str, len); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_str_noesc(yyjson_mut_val *val, + bool noesc) { + if (yyjson_unlikely(!yyjson_mut_is_str(val))) return false; + unsafe_yyjson_set_str_noesc(val, noesc); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_arr(yyjson_mut_val *val) { + if (yyjson_unlikely(!val)) return false; + unsafe_yyjson_set_arr(val, 0); + return true; +} + +yyjson_api_inline bool yyjson_mut_set_obj(yyjson_mut_val *val) { + if (yyjson_unlikely(!val)) return false; + unsafe_yyjson_set_obj(val, 0); + return true; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Value Creation API (Implementation) + *============================================================================*/ + +#define yyjson_mut_val_one(func) \ + if (yyjson_likely(doc)) { \ + yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); \ + if (yyjson_likely(val)) { \ + func \ + return val; \ + } \ + } \ + return NULL + +#define yyjson_mut_val_one_str(func) \ + if (yyjson_likely(doc && str)) { \ + yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); \ + if (yyjson_likely(val)) { \ + func \ + return val; \ + } \ + } \ + return NULL + +yyjson_api_inline yyjson_mut_val *yyjson_mut_raw(yyjson_mut_doc *doc, + const char *str) { + yyjson_mut_val_one_str({ unsafe_yyjson_set_raw(val, str, strlen(str)); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_rawn(yyjson_mut_doc *doc, + const char *str, + size_t len) { + yyjson_mut_val_one_str({ unsafe_yyjson_set_raw(val, str, len); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_rawcpy(yyjson_mut_doc *doc, + const char *str) { + yyjson_mut_val_one_str({ + size_t len = strlen(str); + char *new_str = unsafe_yyjson_mut_strncpy(doc, str, len); + if (yyjson_unlikely(!new_str)) return NULL; + unsafe_yyjson_set_raw(val, new_str, len); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_rawncpy(yyjson_mut_doc *doc, + const char *str, + size_t len) { + yyjson_mut_val_one_str({ + char *new_str = unsafe_yyjson_mut_strncpy(doc, str, len); + if (yyjson_unlikely(!new_str)) return NULL; + unsafe_yyjson_set_raw(val, new_str, len); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_null(yyjson_mut_doc *doc) { + yyjson_mut_val_one({ unsafe_yyjson_set_null(val); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_true(yyjson_mut_doc *doc) { + yyjson_mut_val_one({ unsafe_yyjson_set_bool(val, true); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_false(yyjson_mut_doc *doc) { + yyjson_mut_val_one({ unsafe_yyjson_set_bool(val, false); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_bool(yyjson_mut_doc *doc, + bool _val) { + yyjson_mut_val_one({ unsafe_yyjson_set_bool(val, _val); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_uint(yyjson_mut_doc *doc, + uint64_t num) { + yyjson_mut_val_one({ unsafe_yyjson_set_uint(val, num); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_sint(yyjson_mut_doc *doc, + int64_t num) { + yyjson_mut_val_one({ unsafe_yyjson_set_sint(val, num); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_int(yyjson_mut_doc *doc, + int64_t num) { + yyjson_mut_val_one({ unsafe_yyjson_set_sint(val, num); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_float(yyjson_mut_doc *doc, + float num) { + yyjson_mut_val_one({ unsafe_yyjson_set_float(val, num); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_double(yyjson_mut_doc *doc, + double num) { + yyjson_mut_val_one({ unsafe_yyjson_set_double(val, num); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_real(yyjson_mut_doc *doc, + double num) { + yyjson_mut_val_one({ unsafe_yyjson_set_real(val, num); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_str(yyjson_mut_doc *doc, + const char *str) { + yyjson_mut_val_one_str({ unsafe_yyjson_set_str(val, str); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_strn(yyjson_mut_doc *doc, + const char *str, + size_t len) { + yyjson_mut_val_one_str({ unsafe_yyjson_set_strn(val, str, len); }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_strcpy(yyjson_mut_doc *doc, + const char *str) { + yyjson_mut_val_one_str({ + size_t len = strlen(str); + bool noesc = unsafe_yyjson_is_str_noesc(str, len); + yyjson_subtype sub = noesc ? YYJSON_SUBTYPE_NOESC : YYJSON_SUBTYPE_NONE; + char *new_str = unsafe_yyjson_mut_strncpy(doc, str, len); + if (yyjson_unlikely(!new_str)) return NULL; + unsafe_yyjson_set_tag(val, YYJSON_TYPE_STR, sub, len); + val->uni.str = new_str; + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_strncpy(yyjson_mut_doc *doc, + const char *str, + size_t len) { + yyjson_mut_val_one_str({ + char *new_str = unsafe_yyjson_mut_strncpy(doc, str, len); + if (yyjson_unlikely(!new_str)) return NULL; + unsafe_yyjson_set_strn(val, new_str, len); + }); +} + +#undef yyjson_mut_val_one +#undef yyjson_mut_val_one_str + + + +/*============================================================================== + * MARK: - Mutable JSON Array API (Implementation) + *============================================================================*/ + +yyjson_api_inline size_t yyjson_mut_arr_size(yyjson_mut_val *arr) { + return yyjson_mut_is_arr(arr) ? unsafe_yyjson_get_len(arr) : 0; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_get(yyjson_mut_val *arr, + size_t idx) { + if (yyjson_likely(idx < yyjson_mut_arr_size(arr))) { + yyjson_mut_val *val = (yyjson_mut_val *)arr->uni.ptr; + while (idx-- > 0) val = val->next; + return val->next; + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_get_first( + yyjson_mut_val *arr) { + if (yyjson_likely(yyjson_mut_arr_size(arr) > 0)) { + return ((yyjson_mut_val *)arr->uni.ptr)->next; + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_get_last( + yyjson_mut_val *arr) { + if (yyjson_likely(yyjson_mut_arr_size(arr) > 0)) { + return ((yyjson_mut_val *)arr->uni.ptr); + } + return NULL; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Array Iterator API (Implementation) + *============================================================================*/ + +yyjson_api_inline bool yyjson_mut_arr_iter_init(yyjson_mut_val *arr, + yyjson_mut_arr_iter *iter) { + if (yyjson_likely(yyjson_mut_is_arr(arr) && iter)) { + iter->idx = 0; + iter->max = unsafe_yyjson_get_len(arr); + iter->cur = iter->max ? (yyjson_mut_val *)arr->uni.ptr : NULL; + iter->pre = NULL; + iter->arr = arr; + return true; + } + if (iter) memset(iter, 0, sizeof(yyjson_mut_arr_iter)); + return false; +} + +yyjson_api_inline yyjson_mut_arr_iter yyjson_mut_arr_iter_with( + yyjson_mut_val *arr) { + yyjson_mut_arr_iter iter; + yyjson_mut_arr_iter_init(arr, &iter); + return iter; +} + +yyjson_api_inline bool yyjson_mut_arr_iter_has_next(yyjson_mut_arr_iter *iter) { + return iter ? iter->idx < iter->max : false; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_iter_next( + yyjson_mut_arr_iter *iter) { + if (iter && iter->idx < iter->max) { + yyjson_mut_val *val = iter->cur; + iter->pre = val; + iter->cur = val->next; + iter->idx++; + return iter->cur; + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_iter_remove( + yyjson_mut_arr_iter *iter) { + if (yyjson_likely(iter && 0 < iter->idx && iter->idx <= iter->max)) { + yyjson_mut_val *prev = iter->pre; + yyjson_mut_val *cur = iter->cur; + yyjson_mut_val *next = cur->next; + if (yyjson_unlikely(iter->idx == iter->max)) iter->arr->uni.ptr = prev; + iter->idx--; + iter->max--; + unsafe_yyjson_set_len(iter->arr, iter->max); + prev->next = next; + iter->cur = prev; + return cur; + } + return NULL; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Array Creation API (Implementation) + *============================================================================*/ + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr(yyjson_mut_doc *doc) { + if (yyjson_likely(doc)) { + yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); + if (yyjson_likely(val)) { + val->tag = YYJSON_TYPE_ARR | YYJSON_SUBTYPE_NONE; + return val; + } + } + return NULL; +} + +#define yyjson_mut_arr_with_func(func) \ + if (yyjson_likely(doc && ((0 < count && count < \ + (~(size_t)0) / sizeof(yyjson_mut_val) && vals) || count == 0))) { \ + yyjson_mut_val *arr = unsafe_yyjson_mut_val(doc, 1 + count); \ + if (yyjson_likely(arr)) { \ + arr->tag = ((uint64_t)count << YYJSON_TAG_BIT) | YYJSON_TYPE_ARR; \ + if (count > 0) { \ + size_t i; \ + for (i = 0; i < count; i++) { \ + yyjson_mut_val *val = arr + i + 1; \ + func \ + val->next = val + 1; \ + } \ + arr[count].next = arr + 1; \ + arr->uni.ptr = arr + count; \ + } \ + return arr; \ + } \ + } \ + return NULL + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_bool( + yyjson_mut_doc *doc, const bool *vals, size_t count) { + yyjson_mut_arr_with_func({ + unsafe_yyjson_set_bool(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint( + yyjson_mut_doc *doc, const int64_t *vals, size_t count) { + return yyjson_mut_arr_with_sint64(doc, vals, count); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint( + yyjson_mut_doc *doc, const uint64_t *vals, size_t count) { + return yyjson_mut_arr_with_uint64(doc, vals, count); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_real( + yyjson_mut_doc *doc, const double *vals, size_t count) { + yyjson_mut_arr_with_func({ + unsafe_yyjson_set_real(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint8( + yyjson_mut_doc *doc, const int8_t *vals, size_t count) { + yyjson_mut_arr_with_func({ + unsafe_yyjson_set_sint(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint16( + yyjson_mut_doc *doc, const int16_t *vals, size_t count) { + yyjson_mut_arr_with_func({ + unsafe_yyjson_set_sint(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint32( + yyjson_mut_doc *doc, const int32_t *vals, size_t count) { + yyjson_mut_arr_with_func({ + unsafe_yyjson_set_sint(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint64( + yyjson_mut_doc *doc, const int64_t *vals, size_t count) { + yyjson_mut_arr_with_func({ + unsafe_yyjson_set_sint(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint8( + yyjson_mut_doc *doc, const uint8_t *vals, size_t count) { + yyjson_mut_arr_with_func({ + unsafe_yyjson_set_uint(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint16( + yyjson_mut_doc *doc, const uint16_t *vals, size_t count) { + yyjson_mut_arr_with_func({ + unsafe_yyjson_set_uint(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint32( + yyjson_mut_doc *doc, const uint32_t *vals, size_t count) { + yyjson_mut_arr_with_func({ + unsafe_yyjson_set_uint(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint64( + yyjson_mut_doc *doc, const uint64_t *vals, size_t count) { + yyjson_mut_arr_with_func({ + unsafe_yyjson_set_uint(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_float( + yyjson_mut_doc *doc, const float *vals, size_t count) { + yyjson_mut_arr_with_func({ + unsafe_yyjson_set_float(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_double( + yyjson_mut_doc *doc, const double *vals, size_t count) { + yyjson_mut_arr_with_func({ + unsafe_yyjson_set_double(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_str( + yyjson_mut_doc *doc, const char **vals, size_t count) { + yyjson_mut_arr_with_func({ + if (yyjson_unlikely(!vals[i])) return NULL; + unsafe_yyjson_set_str(val, vals[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_strn( + yyjson_mut_doc *doc, const char **vals, const size_t *lens, size_t count) { + if (yyjson_unlikely(count > 0 && !lens)) return NULL; + yyjson_mut_arr_with_func({ + if (yyjson_unlikely(!vals[i])) return NULL; + unsafe_yyjson_set_strn(val, vals[i], lens[i]); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_strcpy( + yyjson_mut_doc *doc, const char **vals, size_t count) { + size_t len; + const char *str, *new_str; + yyjson_mut_arr_with_func({ + str = vals[i]; + if (yyjson_unlikely(!str)) return NULL; + len = strlen(str); + new_str = unsafe_yyjson_mut_strncpy(doc, str, len); + if (yyjson_unlikely(!new_str)) return NULL; + unsafe_yyjson_set_strn(val, new_str, len); + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_strncpy( + yyjson_mut_doc *doc, const char **vals, const size_t *lens, size_t count) { + size_t len; + const char *str, *new_str; + if (yyjson_unlikely(count > 0 && !lens)) return NULL; + yyjson_mut_arr_with_func({ + str = vals[i]; + if (yyjson_unlikely(!str)) return NULL; + len = lens[i]; + new_str = unsafe_yyjson_mut_strncpy(doc, str, len); + if (yyjson_unlikely(!new_str)) return NULL; + unsafe_yyjson_set_strn(val, new_str, len); + }); +} + +#undef yyjson_mut_arr_with_func + + + +/*============================================================================== + * MARK: - Mutable JSON Array Modification API (Implementation) + *============================================================================*/ + +yyjson_api_inline bool yyjson_mut_arr_insert(yyjson_mut_val *arr, + yyjson_mut_val *val, size_t idx) { + if (yyjson_likely(yyjson_mut_is_arr(arr) && val)) { + size_t len = unsafe_yyjson_get_len(arr); + if (yyjson_likely(idx <= len)) { + unsafe_yyjson_set_len(arr, len + 1); + if (len == 0) { + val->next = val; + arr->uni.ptr = val; + } else { + yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); + yyjson_mut_val *next = prev->next; + if (idx == len) { + prev->next = val; + val->next = next; + arr->uni.ptr = val; + } else { + while (idx-- > 0) { + prev = next; + next = next->next; + } + prev->next = val; + val->next = next; + } + } + return true; + } + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_append(yyjson_mut_val *arr, + yyjson_mut_val *val) { + if (yyjson_likely(yyjson_mut_is_arr(arr) && val)) { + size_t len = unsafe_yyjson_get_len(arr); + unsafe_yyjson_set_len(arr, len + 1); + if (len == 0) { + val->next = val; + } else { + yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); + yyjson_mut_val *next = prev->next; + prev->next = val; + val->next = next; + } + arr->uni.ptr = val; + return true; + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_prepend(yyjson_mut_val *arr, + yyjson_mut_val *val) { + if (yyjson_likely(yyjson_mut_is_arr(arr) && val)) { + size_t len = unsafe_yyjson_get_len(arr); + unsafe_yyjson_set_len(arr, len + 1); + if (len == 0) { + val->next = val; + arr->uni.ptr = val; + } else { + yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); + yyjson_mut_val *next = prev->next; + prev->next = val; + val->next = next; + } + return true; + } + return false; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_replace(yyjson_mut_val *arr, + size_t idx, + yyjson_mut_val *val) { + if (yyjson_likely(yyjson_mut_is_arr(arr) && val)) { + size_t len = unsafe_yyjson_get_len(arr); + if (yyjson_likely(idx < len)) { + if (yyjson_likely(len > 1)) { + yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); + yyjson_mut_val *next = prev->next; + while (idx-- > 0) { + prev = next; + next = next->next; + } + prev->next = val; + val->next = next->next; + if ((void *)next == arr->uni.ptr) arr->uni.ptr = val; + return next; + } else { + yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); + val->next = val; + arr->uni.ptr = val; + return prev; + } + } + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_remove(yyjson_mut_val *arr, + size_t idx) { + if (yyjson_likely(yyjson_mut_is_arr(arr))) { + size_t len = unsafe_yyjson_get_len(arr); + if (yyjson_likely(idx < len)) { + unsafe_yyjson_set_len(arr, len - 1); + if (yyjson_likely(len > 1)) { + yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); + yyjson_mut_val *next = prev->next; + while (idx-- > 0) { + prev = next; + next = next->next; + } + prev->next = next->next; + if ((void *)next == arr->uni.ptr) arr->uni.ptr = prev; + return next; + } else { + return ((yyjson_mut_val *)arr->uni.ptr); + } + } + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_remove_first( + yyjson_mut_val *arr) { + if (yyjson_likely(yyjson_mut_is_arr(arr))) { + size_t len = unsafe_yyjson_get_len(arr); + if (len > 1) { + yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); + yyjson_mut_val *next = prev->next; + prev->next = next->next; + unsafe_yyjson_set_len(arr, len - 1); + return next; + } else if (len == 1) { + yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); + unsafe_yyjson_set_len(arr, 0); + return prev; + } + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_remove_last( + yyjson_mut_val *arr) { + if (yyjson_likely(yyjson_mut_is_arr(arr))) { + size_t len = unsafe_yyjson_get_len(arr); + if (yyjson_likely(len > 1)) { + yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); + yyjson_mut_val *next = prev->next; + unsafe_yyjson_set_len(arr, len - 1); + while (--len > 0) prev = prev->next; + prev->next = next; + next = (yyjson_mut_val *)arr->uni.ptr; + arr->uni.ptr = prev; + return next; + } else if (len == 1) { + yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); + unsafe_yyjson_set_len(arr, 0); + return prev; + } + } + return NULL; +} + +yyjson_api_inline bool yyjson_mut_arr_remove_range(yyjson_mut_val *arr, + size_t _idx, size_t _len) { + if (yyjson_likely(yyjson_mut_is_arr(arr))) { + yyjson_mut_val *prev, *next; + bool tail_removed; + size_t len = unsafe_yyjson_get_len(arr); + if (yyjson_unlikely(_idx + _len > len)) return false; + if (yyjson_unlikely(_len == 0)) return true; + unsafe_yyjson_set_len(arr, len - _len); + if (yyjson_unlikely(len == _len)) return true; + tail_removed = (_idx + _len == len); + prev = ((yyjson_mut_val *)arr->uni.ptr); + while (_idx-- > 0) prev = prev->next; + next = prev->next; + while (_len-- > 0) next = next->next; + prev->next = next; + if (yyjson_unlikely(tail_removed)) arr->uni.ptr = prev; + return true; + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_clear(yyjson_mut_val *arr) { + if (yyjson_likely(yyjson_mut_is_arr(arr))) { + unsafe_yyjson_set_len(arr, 0); + return true; + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_rotate(yyjson_mut_val *arr, + size_t idx) { + if (yyjson_likely(yyjson_mut_is_arr(arr) && + unsafe_yyjson_get_len(arr) > idx)) { + yyjson_mut_val *val = (yyjson_mut_val *)arr->uni.ptr; + while (idx-- > 0) val = val->next; + arr->uni.ptr = (void *)val; + return true; + } + return false; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Array Modification Convenience API (Implementation) + *============================================================================*/ + +yyjson_api_inline bool yyjson_mut_arr_add_val(yyjson_mut_val *arr, + yyjson_mut_val *val) { + return yyjson_mut_arr_append(arr, val); +} + +yyjson_api_inline bool yyjson_mut_arr_add_null(yyjson_mut_doc *doc, + yyjson_mut_val *arr) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_null(doc); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_true(yyjson_mut_doc *doc, + yyjson_mut_val *arr) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_true(doc); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_false(yyjson_mut_doc *doc, + yyjson_mut_val *arr) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_false(doc); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_bool(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + bool _val) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_bool(doc, _val); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_uint(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + uint64_t num) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_uint(doc, num); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_sint(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + int64_t num) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_sint(doc, num); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_int(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + int64_t num) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_sint(doc, num); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_float(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + float num) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_float(doc, num); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_double(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + double num) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_double(doc, num); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_real(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + double num) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_real(doc, num); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_str(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + const char *str) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_str(doc, str); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_strn(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + const char *str, size_t len) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_strn(doc, str, len); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_strcpy(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + const char *str) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_strcpy(doc, str); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_arr_add_strncpy(yyjson_mut_doc *doc, + yyjson_mut_val *arr, + const char *str, size_t len) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_strncpy(doc, str, len); + return yyjson_mut_arr_append(arr, val); + } + return false; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_add_arr(yyjson_mut_doc *doc, + yyjson_mut_val *arr) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_arr(doc); + return yyjson_mut_arr_append(arr, val) ? val : NULL; + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_add_obj(yyjson_mut_doc *doc, + yyjson_mut_val *arr) { + if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { + yyjson_mut_val *val = yyjson_mut_obj(doc); + return yyjson_mut_arr_append(arr, val) ? val : NULL; + } + return NULL; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Object API (Implementation) + *============================================================================*/ + +yyjson_api_inline size_t yyjson_mut_obj_size(yyjson_mut_val *obj) { + return yyjson_mut_is_obj(obj) ? unsafe_yyjson_get_len(obj) : 0; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_get(yyjson_mut_val *obj, + const char *key) { + return yyjson_mut_obj_getn(obj, key, key ? strlen(key) : 0); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_getn(yyjson_mut_val *obj, + const char *_key, + size_t key_len) { + size_t len = yyjson_mut_obj_size(obj); + if (yyjson_likely(len && _key)) { + yyjson_mut_val *key = ((yyjson_mut_val *)obj->uni.ptr)->next->next; + while (len-- > 0) { + if (unsafe_yyjson_equals_strn(key, _key, key_len)) return key->next; + key = key->next->next; + } + } + return NULL; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Object Iterator API (Implementation) + *============================================================================*/ + +yyjson_api_inline bool yyjson_mut_obj_iter_init(yyjson_mut_val *obj, + yyjson_mut_obj_iter *iter) { + if (yyjson_likely(yyjson_mut_is_obj(obj) && iter)) { + iter->idx = 0; + iter->max = unsafe_yyjson_get_len(obj); + iter->cur = iter->max ? (yyjson_mut_val *)obj->uni.ptr : NULL; + iter->pre = NULL; + iter->obj = obj; + return true; + } + if (iter) memset(iter, 0, sizeof(yyjson_mut_obj_iter)); + return false; +} + +yyjson_api_inline yyjson_mut_obj_iter yyjson_mut_obj_iter_with( + yyjson_mut_val *obj) { + yyjson_mut_obj_iter iter; + yyjson_mut_obj_iter_init(obj, &iter); + return iter; +} + +yyjson_api_inline bool yyjson_mut_obj_iter_has_next(yyjson_mut_obj_iter *iter) { + return iter ? iter->idx < iter->max : false; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_next( + yyjson_mut_obj_iter *iter) { + if (iter && iter->idx < iter->max) { + yyjson_mut_val *key = iter->cur; + iter->pre = key; + iter->cur = key->next->next; + iter->idx++; + return iter->cur; + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_get_val( + yyjson_mut_val *key) { + return key ? key->next : NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_remove( + yyjson_mut_obj_iter *iter) { + if (yyjson_likely(iter && 0 < iter->idx && iter->idx <= iter->max)) { + yyjson_mut_val *prev = iter->pre; + yyjson_mut_val *cur = iter->cur; + yyjson_mut_val *next = cur->next->next; + if (yyjson_unlikely(iter->idx == iter->max)) iter->obj->uni.ptr = prev; + iter->idx--; + iter->max--; + unsafe_yyjson_set_len(iter->obj, iter->max); + prev->next->next = next; + iter->cur = prev; + return cur->next; + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_get( + yyjson_mut_obj_iter *iter, const char *key) { + return yyjson_mut_obj_iter_getn(iter, key, key ? strlen(key) : 0); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_getn( + yyjson_mut_obj_iter *iter, const char *key, size_t key_len) { + if (iter && key) { + size_t idx = 0; + size_t max = iter->max; + yyjson_mut_val *pre, *cur = iter->cur; + while (idx++ < max) { + pre = cur; + cur = cur->next->next; + if (unsafe_yyjson_equals_strn(cur, key, key_len)) { + iter->idx += idx; + if (iter->idx > max) iter->idx -= max + 1; + iter->pre = pre; + iter->cur = cur; + return cur->next; + } + } + } + return NULL; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Object Creation API (Implementation) + *============================================================================*/ + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj(yyjson_mut_doc *doc) { + if (yyjson_likely(doc)) { + yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); + if (yyjson_likely(val)) { + val->tag = YYJSON_TYPE_OBJ | YYJSON_SUBTYPE_NONE; + return val; + } + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_with_str(yyjson_mut_doc *doc, + const char **keys, + const char **vals, + size_t count) { + if (yyjson_likely(doc && ((count > 0 && keys && vals) || (count == 0)))) { + yyjson_mut_val *obj = unsafe_yyjson_mut_val(doc, 1 + count * 2); + if (yyjson_likely(obj)) { + obj->tag = ((uint64_t)count << YYJSON_TAG_BIT) | YYJSON_TYPE_OBJ; + if (count > 0) { + size_t i; + for (i = 0; i < count; i++) { + yyjson_mut_val *key = obj + (i * 2 + 1); + yyjson_mut_val *val = obj + (i * 2 + 2); + uint64_t key_len = (uint64_t)strlen(keys[i]); + uint64_t val_len = (uint64_t)strlen(vals[i]); + key->tag = (key_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; + val->tag = (val_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; + key->uni.str = keys[i]; + val->uni.str = vals[i]; + key->next = val; + val->next = val + 1; + } + obj[count * 2].next = obj + 1; + obj->uni.ptr = obj + (count * 2 - 1); + } + return obj; + } + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_with_kv(yyjson_mut_doc *doc, + const char **pairs, + size_t count) { + if (yyjson_likely(doc && ((count > 0 && pairs) || (count == 0)))) { + yyjson_mut_val *obj = unsafe_yyjson_mut_val(doc, 1 + count * 2); + if (yyjson_likely(obj)) { + obj->tag = ((uint64_t)count << YYJSON_TAG_BIT) | YYJSON_TYPE_OBJ; + if (count > 0) { + size_t i; + for (i = 0; i < count; i++) { + yyjson_mut_val *key = obj + (i * 2 + 1); + yyjson_mut_val *val = obj + (i * 2 + 2); + const char *key_str = pairs[i * 2 + 0]; + const char *val_str = pairs[i * 2 + 1]; + uint64_t key_len = (uint64_t)strlen(key_str); + uint64_t val_len = (uint64_t)strlen(val_str); + key->tag = (key_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; + val->tag = (val_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; + key->uni.str = key_str; + val->uni.str = val_str; + key->next = val; + val->next = val + 1; + } + obj[count * 2].next = obj + 1; + obj->uni.ptr = obj + (count * 2 - 1); + } + return obj; + } + } + return NULL; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Object Modification API (Implementation) + *============================================================================*/ + +yyjson_api_inline void unsafe_yyjson_mut_obj_add(yyjson_mut_val *obj, + yyjson_mut_val *key, + yyjson_mut_val *val, + size_t len) { + if (yyjson_likely(len)) { + yyjson_mut_val *prev_val = ((yyjson_mut_val *)obj->uni.ptr)->next; + yyjson_mut_val *next_key = prev_val->next; + prev_val->next = key; + val->next = next_key; + } else { + val->next = key; + } + key->next = val; + obj->uni.ptr = (void *)key; + unsafe_yyjson_set_len(obj, len + 1); +} + +yyjson_api_inline yyjson_mut_val *unsafe_yyjson_mut_obj_remove( + yyjson_mut_val *obj, const char *key, size_t key_len) { + size_t obj_len = unsafe_yyjson_get_len(obj); + if (obj_len) { + yyjson_mut_val *pre_key = (yyjson_mut_val *)obj->uni.ptr; + yyjson_mut_val *cur_key = pre_key->next->next; + yyjson_mut_val *removed_item = NULL; + size_t i; + for (i = 0; i < obj_len; i++) { + if (unsafe_yyjson_equals_strn(cur_key, key, key_len)) { + if (!removed_item) removed_item = cur_key->next; + cur_key = cur_key->next->next; + pre_key->next->next = cur_key; + if (i + 1 == obj_len) obj->uni.ptr = pre_key; + i--; + obj_len--; + } else { + pre_key = cur_key; + cur_key = cur_key->next->next; + } + } + unsafe_yyjson_set_len(obj, obj_len); + return removed_item; + } else { + return NULL; + } +} + +yyjson_api_inline bool unsafe_yyjson_mut_obj_replace(yyjson_mut_val *obj, + yyjson_mut_val *key, + yyjson_mut_val *val) { + size_t key_len = unsafe_yyjson_get_len(key); + size_t obj_len = unsafe_yyjson_get_len(obj); + if (obj_len) { + yyjson_mut_val *pre_key = (yyjson_mut_val *)obj->uni.ptr; + yyjson_mut_val *cur_key = pre_key->next->next; + size_t i; + for (i = 0; i < obj_len; i++) { + if (unsafe_yyjson_equals_strn(cur_key, key->uni.str, key_len)) { + cur_key->next->tag = val->tag; + cur_key->next->uni.u64 = val->uni.u64; + return true; + } else { + cur_key = cur_key->next->next; + } + } + } + return false; +} + +yyjson_api_inline void unsafe_yyjson_mut_obj_rotate(yyjson_mut_val *obj, + size_t idx) { + yyjson_mut_val *key = (yyjson_mut_val *)obj->uni.ptr; + while (idx-- > 0) key = key->next->next; + obj->uni.ptr = (void *)key; +} + +yyjson_api_inline bool yyjson_mut_obj_add(yyjson_mut_val *obj, + yyjson_mut_val *key, + yyjson_mut_val *val) { + if (yyjson_likely(yyjson_mut_is_obj(obj) && + yyjson_mut_is_str(key) && val)) { + unsafe_yyjson_mut_obj_add(obj, key, val, unsafe_yyjson_get_len(obj)); + return true; + } + return false; +} + +yyjson_api_inline bool yyjson_mut_obj_put(yyjson_mut_val *obj, + yyjson_mut_val *key, + yyjson_mut_val *val) { + bool replaced = false; + size_t key_len; + yyjson_mut_obj_iter iter; + yyjson_mut_val *cur_key; + if (yyjson_unlikely(!yyjson_mut_is_obj(obj) || + !yyjson_mut_is_str(key))) return false; + key_len = unsafe_yyjson_get_len(key); + yyjson_mut_obj_iter_init(obj, &iter); + while ((cur_key = yyjson_mut_obj_iter_next(&iter)) != 0) { + if (unsafe_yyjson_equals_strn(cur_key, key->uni.str, key_len)) { + if (!replaced && val) { + replaced = true; + val->next = cur_key->next->next; + cur_key->next = val; + } else { + yyjson_mut_obj_iter_remove(&iter); + } + } + } + if (!replaced && val) unsafe_yyjson_mut_obj_add(obj, key, val, iter.max); + return true; +} + +yyjson_api_inline bool yyjson_mut_obj_insert(yyjson_mut_val *obj, + yyjson_mut_val *key, + yyjson_mut_val *val, + size_t idx) { + if (yyjson_likely(yyjson_mut_is_obj(obj) && + yyjson_mut_is_str(key) && val)) { + size_t len = unsafe_yyjson_get_len(obj); + if (yyjson_likely(len >= idx)) { + if (len > idx) { + void *ptr = obj->uni.ptr; + unsafe_yyjson_mut_obj_rotate(obj, idx); + unsafe_yyjson_mut_obj_add(obj, key, val, len); + obj->uni.ptr = ptr; + } else { + unsafe_yyjson_mut_obj_add(obj, key, val, len); + } + return true; + } + } + return false; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove(yyjson_mut_val *obj, + yyjson_mut_val *key) { + if (yyjson_likely(yyjson_mut_is_obj(obj) && yyjson_mut_is_str(key))) { + return unsafe_yyjson_mut_obj_remove(obj, key->uni.str, + unsafe_yyjson_get_len(key)); + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_key( + yyjson_mut_val *obj, const char *key) { + if (yyjson_likely(yyjson_mut_is_obj(obj) && key)) { + size_t key_len = strlen(key); + return unsafe_yyjson_mut_obj_remove(obj, key, key_len); + } + return NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_keyn( + yyjson_mut_val *obj, const char *key, size_t key_len) { + if (yyjson_likely(yyjson_mut_is_obj(obj) && key)) { + return unsafe_yyjson_mut_obj_remove(obj, key, key_len); + } + return NULL; +} + +yyjson_api_inline bool yyjson_mut_obj_clear(yyjson_mut_val *obj) { + if (yyjson_likely(yyjson_mut_is_obj(obj))) { + unsafe_yyjson_set_len(obj, 0); + return true; + } + return false; +} + +yyjson_api_inline bool yyjson_mut_obj_replace(yyjson_mut_val *obj, + yyjson_mut_val *key, + yyjson_mut_val *val) { + if (yyjson_likely(yyjson_mut_is_obj(obj) && + yyjson_mut_is_str(key) && val)) { + return unsafe_yyjson_mut_obj_replace(obj, key, val); + } + return false; +} + +yyjson_api_inline bool yyjson_mut_obj_rotate(yyjson_mut_val *obj, + size_t idx) { + if (yyjson_likely(yyjson_mut_is_obj(obj) && + unsafe_yyjson_get_len(obj) > idx)) { + unsafe_yyjson_mut_obj_rotate(obj, idx); + return true; + } + return false; +} + + + +/*============================================================================== + * MARK: - Mutable JSON Object Modification Convenience API (Implementation) + *============================================================================*/ + +#define yyjson_mut_obj_add_func(func) \ + if (yyjson_likely(doc && yyjson_mut_is_obj(obj) && _key)) { \ + yyjson_mut_val *key = unsafe_yyjson_mut_val(doc, 2); \ + if (yyjson_likely(key)) { \ + size_t len = unsafe_yyjson_get_len(obj); \ + yyjson_mut_val *val = key + 1; \ + size_t key_len = strlen(_key); \ + bool noesc = unsafe_yyjson_is_str_noesc(_key, key_len); \ + key->tag = YYJSON_TYPE_STR; \ + key->tag |= noesc ? YYJSON_SUBTYPE_NOESC : YYJSON_SUBTYPE_NONE; \ + key->tag |= (uint64_t)strlen(_key) << YYJSON_TAG_BIT; \ + key->uni.str = _key; \ + func \ + unsafe_yyjson_mut_obj_add(obj, key, val, len); \ + return true; \ + } \ + } \ + return false + +yyjson_api_inline bool yyjson_mut_obj_add_null(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key) { + yyjson_mut_obj_add_func({ unsafe_yyjson_set_null(val); }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_true(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key) { + yyjson_mut_obj_add_func({ unsafe_yyjson_set_bool(val, true); }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_false(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key) { + yyjson_mut_obj_add_func({ unsafe_yyjson_set_bool(val, false); }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_bool(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key, + bool _val) { + yyjson_mut_obj_add_func({ unsafe_yyjson_set_bool(val, _val); }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_uint(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key, + uint64_t _val) { + yyjson_mut_obj_add_func({ unsafe_yyjson_set_uint(val, _val); }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_sint(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key, + int64_t _val) { + yyjson_mut_obj_add_func({ unsafe_yyjson_set_sint(val, _val); }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_int(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key, + int64_t _val) { + yyjson_mut_obj_add_func({ unsafe_yyjson_set_sint(val, _val); }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_float(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key, + float _val) { + yyjson_mut_obj_add_func({ unsafe_yyjson_set_float(val, _val); }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_double(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key, + double _val) { + yyjson_mut_obj_add_func({ unsafe_yyjson_set_double(val, _val); }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_real(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key, + double _val) { + yyjson_mut_obj_add_func({ unsafe_yyjson_set_real(val, _val); }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_str(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key, + const char *_val) { + if (yyjson_unlikely(!_val)) return false; + yyjson_mut_obj_add_func({ + size_t val_len = strlen(_val); + bool val_noesc = unsafe_yyjson_is_str_noesc(_val, val_len); + val->tag = ((uint64_t)strlen(_val) << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; + val->tag |= val_noesc ? YYJSON_SUBTYPE_NOESC : YYJSON_SUBTYPE_NONE; + val->uni.str = _val; + }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_strn(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key, + const char *_val, + size_t _len) { + if (yyjson_unlikely(!_val)) return false; + yyjson_mut_obj_add_func({ + val->tag = ((uint64_t)_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; + val->uni.str = _val; + }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_strcpy(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key, + const char *_val) { + if (yyjson_unlikely(!_val)) return false; + yyjson_mut_obj_add_func({ + size_t _len = strlen(_val); + val->uni.str = unsafe_yyjson_mut_strncpy(doc, _val, _len); + if (yyjson_unlikely(!val->uni.str)) return false; + val->tag = ((uint64_t)_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; + }); +} + +yyjson_api_inline bool yyjson_mut_obj_add_strncpy(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key, + const char *_val, + size_t _len) { + if (yyjson_unlikely(!_val)) return false; + yyjson_mut_obj_add_func({ + val->uni.str = unsafe_yyjson_mut_strncpy(doc, _val, _len); + if (yyjson_unlikely(!val->uni.str)) return false; + val->tag = ((uint64_t)_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_add_arr(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key) { + yyjson_mut_val *key = yyjson_mut_str(doc, _key); + yyjson_mut_val *val = yyjson_mut_arr(doc); + return yyjson_mut_obj_add(obj, key, val) ? val : NULL; +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_add_obj(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key) { + yyjson_mut_val *key = yyjson_mut_str(doc, _key); + yyjson_mut_val *val = yyjson_mut_obj(doc); + return yyjson_mut_obj_add(obj, key, val) ? val : NULL; +} + +yyjson_api_inline bool yyjson_mut_obj_add_val(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *_key, + yyjson_mut_val *_val) { + if (yyjson_unlikely(!_val)) return false; + yyjson_mut_obj_add_func({ + val = _val; + }); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_str(yyjson_mut_val *obj, + const char *key) { + return yyjson_mut_obj_remove_strn(obj, key, key ? strlen(key) : 0); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_strn( + yyjson_mut_val *obj, const char *_key, size_t _len) { + if (yyjson_likely(yyjson_mut_is_obj(obj) && _key)) { + yyjson_mut_val *key; + yyjson_mut_obj_iter iter; + yyjson_mut_val *val_removed = NULL; + yyjson_mut_obj_iter_init(obj, &iter); + while ((key = yyjson_mut_obj_iter_next(&iter)) != NULL) { + if (unsafe_yyjson_equals_strn(key, _key, _len)) { + if (!val_removed) val_removed = key->next; + yyjson_mut_obj_iter_remove(&iter); + } + } + return val_removed; + } + return NULL; +} + +yyjson_api_inline bool yyjson_mut_obj_rename_key(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, + const char *new_key) { + if (!key || !new_key) return false; + return yyjson_mut_obj_rename_keyn(doc, obj, key, strlen(key), + new_key, strlen(new_key)); +} + +yyjson_api_inline bool yyjson_mut_obj_rename_keyn(yyjson_mut_doc *doc, + yyjson_mut_val *obj, + const char *key, + size_t len, + const char *new_key, + size_t new_len) { + char *cpy_key = NULL; + yyjson_mut_val *old_key; + yyjson_mut_obj_iter iter; + if (!doc || !obj || !key || !new_key) return false; + yyjson_mut_obj_iter_init(obj, &iter); + while ((old_key = yyjson_mut_obj_iter_next(&iter))) { + if (unsafe_yyjson_equals_strn((void *)old_key, key, len)) { + if (!cpy_key) { + cpy_key = unsafe_yyjson_mut_strncpy(doc, new_key, new_len); + if (!cpy_key) return false; + } + yyjson_mut_set_strn(old_key, cpy_key, new_len); + } + } + return cpy_key != NULL; +} + + + +#if !defined(YYJSON_DISABLE_UTILS) || !YYJSON_DISABLE_UTILS + +/*============================================================================== + * MARK: - JSON Pointer API (Implementation) + *============================================================================*/ + +#define yyjson_ptr_set_err(_code, _msg) do { \ + if (err) { \ + err->code = YYJSON_PTR_ERR_##_code; \ + err->msg = _msg; \ + err->pos = 0; \ + } \ +} while(false) + +/* require: val != NULL, *ptr == '/', len > 0 */ +yyjson_api yyjson_val *unsafe_yyjson_ptr_getx(yyjson_val *val, + const char *ptr, size_t len, + yyjson_ptr_err *err); + +/* require: val != NULL, *ptr == '/', len > 0 */ +yyjson_api yyjson_mut_val *unsafe_yyjson_mut_ptr_getx(yyjson_mut_val *val, + const char *ptr, + size_t len, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err); + +/* require: val/new_val/doc != NULL, *ptr == '/', len > 0 */ +yyjson_api bool unsafe_yyjson_mut_ptr_putx(yyjson_mut_val *val, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc, + bool create_parent, bool insert_new, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err); + +/* require: val/err != NULL, *ptr == '/', len > 0 */ +yyjson_api yyjson_mut_val *unsafe_yyjson_mut_ptr_replacex( + yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val, + yyjson_ptr_ctx *ctx, yyjson_ptr_err *err); + +/* require: val/err != NULL, *ptr == '/', len > 0 */ +yyjson_api yyjson_mut_val *unsafe_yyjson_mut_ptr_removex(yyjson_mut_val *val, + const char *ptr, + size_t len, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err); + +yyjson_api_inline yyjson_val *yyjson_doc_ptr_get(yyjson_doc *doc, + const char *ptr) { + if (yyjson_unlikely(!ptr)) return NULL; + return yyjson_doc_ptr_getn(doc, ptr, strlen(ptr)); +} + +yyjson_api_inline yyjson_val *yyjson_doc_ptr_getn(yyjson_doc *doc, + const char *ptr, size_t len) { + return yyjson_doc_ptr_getx(doc, ptr, len, NULL); +} + +yyjson_api_inline yyjson_val *yyjson_doc_ptr_getx(yyjson_doc *doc, + const char *ptr, size_t len, + yyjson_ptr_err *err) { + yyjson_ptr_set_err(NONE, NULL); + if (yyjson_unlikely(!doc || !ptr)) { + yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); + return NULL; + } + if (yyjson_unlikely(!doc->root)) { + yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL"); + return NULL; + } + if (yyjson_unlikely(len == 0)) { + return doc->root; + } + if (yyjson_unlikely(*ptr != '/')) { + yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); + return NULL; + } + return unsafe_yyjson_ptr_getx(doc->root, ptr, len, err); +} + +yyjson_api_inline yyjson_val *yyjson_ptr_get(yyjson_val *val, + const char *ptr) { + if (yyjson_unlikely(!ptr)) return NULL; + return yyjson_ptr_getn(val, ptr, strlen(ptr)); +} + +yyjson_api_inline yyjson_val *yyjson_ptr_getn(yyjson_val *val, + const char *ptr, size_t len) { + return yyjson_ptr_getx(val, ptr, len, NULL); +} + +yyjson_api_inline yyjson_val *yyjson_ptr_getx(yyjson_val *val, + const char *ptr, size_t len, + yyjson_ptr_err *err) { + yyjson_ptr_set_err(NONE, NULL); + if (yyjson_unlikely(!val || !ptr)) { + yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); + return NULL; + } + if (yyjson_unlikely(len == 0)) { + return val; + } + if (yyjson_unlikely(*ptr != '/')) { + yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); + return NULL; + } + return unsafe_yyjson_ptr_getx(val, ptr, len, err); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_get(yyjson_mut_doc *doc, + const char *ptr) { + if (!ptr) return NULL; + return yyjson_mut_doc_ptr_getn(doc, ptr, strlen(ptr)); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_getn(yyjson_mut_doc *doc, + const char *ptr, + size_t len) { + return yyjson_mut_doc_ptr_getx(doc, ptr, len, NULL, NULL); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_getx(yyjson_mut_doc *doc, + const char *ptr, + size_t len, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err) { + yyjson_ptr_set_err(NONE, NULL); + if (ctx) memset(ctx, 0, sizeof(*ctx)); + + if (yyjson_unlikely(!doc || !ptr)) { + yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); + return NULL; + } + if (yyjson_unlikely(!doc->root)) { + yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL"); + return NULL; + } + if (yyjson_unlikely(len == 0)) { + return doc->root; + } + if (yyjson_unlikely(*ptr != '/')) { + yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); + return NULL; + } + return unsafe_yyjson_mut_ptr_getx(doc->root, ptr, len, ctx, err); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_get(yyjson_mut_val *val, + const char *ptr) { + if (!ptr) return NULL; + return yyjson_mut_ptr_getn(val, ptr, strlen(ptr)); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_getn(yyjson_mut_val *val, + const char *ptr, + size_t len) { + return yyjson_mut_ptr_getx(val, ptr, len, NULL, NULL); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_getx(yyjson_mut_val *val, + const char *ptr, + size_t len, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err) { + yyjson_ptr_set_err(NONE, NULL); + if (ctx) memset(ctx, 0, sizeof(*ctx)); + + if (yyjson_unlikely(!val || !ptr)) { + yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); + return NULL; + } + if (yyjson_unlikely(len == 0)) { + return val; + } + if (yyjson_unlikely(*ptr != '/')) { + yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); + return NULL; + } + return unsafe_yyjson_mut_ptr_getx(val, ptr, len, ctx, err); +} + +yyjson_api_inline bool yyjson_mut_doc_ptr_add(yyjson_mut_doc *doc, + const char *ptr, + yyjson_mut_val *new_val) { + if (yyjson_unlikely(!ptr)) return false; + return yyjson_mut_doc_ptr_addn(doc, ptr, strlen(ptr), new_val); +} + +yyjson_api_inline bool yyjson_mut_doc_ptr_addn(yyjson_mut_doc *doc, + const char *ptr, + size_t len, + yyjson_mut_val *new_val) { + return yyjson_mut_doc_ptr_addx(doc, ptr, len, new_val, true, NULL, NULL); +} + +yyjson_api_inline bool yyjson_mut_doc_ptr_addx(yyjson_mut_doc *doc, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + bool create_parent, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err) { + yyjson_ptr_set_err(NONE, NULL); + if (ctx) memset(ctx, 0, sizeof(*ctx)); + + if (yyjson_unlikely(!doc || !ptr || !new_val)) { + yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); + return false; + } + if (yyjson_unlikely(len == 0)) { + if (doc->root) { + yyjson_ptr_set_err(SET_ROOT, "cannot set document's root"); + return false; + } else { + doc->root = new_val; + return true; + } + } + if (yyjson_unlikely(*ptr != '/')) { + yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); + return false; + } + if (yyjson_unlikely(!doc->root && !create_parent)) { + yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL"); + return false; + } + if (yyjson_unlikely(!doc->root)) { + yyjson_mut_val *root = yyjson_mut_obj(doc); + if (yyjson_unlikely(!root)) { + yyjson_ptr_set_err(MEMORY_ALLOCATION, "failed to create value"); + return false; + } + if (unsafe_yyjson_mut_ptr_putx(root, ptr, len, new_val, doc, + create_parent, true, ctx, err)) { + doc->root = root; + return true; + } + return false; + } + return unsafe_yyjson_mut_ptr_putx(doc->root, ptr, len, new_val, doc, + create_parent, true, ctx, err); +} + +yyjson_api_inline bool yyjson_mut_ptr_add(yyjson_mut_val *val, + const char *ptr, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc) { + if (yyjson_unlikely(!ptr)) return false; + return yyjson_mut_ptr_addn(val, ptr, strlen(ptr), new_val, doc); +} + +yyjson_api_inline bool yyjson_mut_ptr_addn(yyjson_mut_val *val, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc) { + return yyjson_mut_ptr_addx(val, ptr, len, new_val, doc, true, NULL, NULL); +} + +yyjson_api_inline bool yyjson_mut_ptr_addx(yyjson_mut_val *val, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc, + bool create_parent, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err) { + yyjson_ptr_set_err(NONE, NULL); + if (ctx) memset(ctx, 0, sizeof(*ctx)); + + if (yyjson_unlikely(!val || !ptr || !new_val || !doc)) { + yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); + return false; + } + if (yyjson_unlikely(len == 0)) { + yyjson_ptr_set_err(SET_ROOT, "cannot set root"); + return false; + } + if (yyjson_unlikely(*ptr != '/')) { + yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); + return false; + } + return unsafe_yyjson_mut_ptr_putx(val, ptr, len, new_val, + doc, create_parent, true, ctx, err); +} + +yyjson_api_inline bool yyjson_mut_doc_ptr_set(yyjson_mut_doc *doc, + const char *ptr, + yyjson_mut_val *new_val) { + if (yyjson_unlikely(!ptr)) return false; + return yyjson_mut_doc_ptr_setn(doc, ptr, strlen(ptr), new_val); +} + +yyjson_api_inline bool yyjson_mut_doc_ptr_setn(yyjson_mut_doc *doc, + const char *ptr, size_t len, + yyjson_mut_val *new_val) { + return yyjson_mut_doc_ptr_setx(doc, ptr, len, new_val, true, NULL, NULL); +} + +yyjson_api_inline bool yyjson_mut_doc_ptr_setx(yyjson_mut_doc *doc, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + bool create_parent, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err) { + yyjson_ptr_set_err(NONE, NULL); + if (ctx) memset(ctx, 0, sizeof(*ctx)); + + if (yyjson_unlikely(!doc || !ptr)) { + yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); + return false; + } + if (yyjson_unlikely(len == 0)) { + if (ctx) ctx->old = doc->root; + doc->root = new_val; + return true; + } + if (yyjson_unlikely(*ptr != '/')) { + yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); + return false; + } + if (!new_val) { + if (!doc->root) { + yyjson_ptr_set_err(RESOLVE, "JSON pointer cannot be resolved"); + return false; + } + return !!unsafe_yyjson_mut_ptr_removex(doc->root, ptr, len, ctx, err); + } + if (yyjson_unlikely(!doc->root && !create_parent)) { + yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL"); + return false; + } + if (yyjson_unlikely(!doc->root)) { + yyjson_mut_val *root = yyjson_mut_obj(doc); + if (yyjson_unlikely(!root)) { + yyjson_ptr_set_err(MEMORY_ALLOCATION, "failed to create value"); + return false; + } + if (unsafe_yyjson_mut_ptr_putx(root, ptr, len, new_val, doc, + create_parent, false, ctx, err)) { + doc->root = root; + return true; + } + return false; + } + return unsafe_yyjson_mut_ptr_putx(doc->root, ptr, len, new_val, doc, + create_parent, false, ctx, err); +} + +yyjson_api_inline bool yyjson_mut_ptr_set(yyjson_mut_val *val, + const char *ptr, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc) { + if (yyjson_unlikely(!ptr)) return false; + return yyjson_mut_ptr_setn(val, ptr, strlen(ptr), new_val, doc); +} + +yyjson_api_inline bool yyjson_mut_ptr_setn(yyjson_mut_val *val, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc) { + return yyjson_mut_ptr_setx(val, ptr, len, new_val, doc, true, NULL, NULL); +} + +yyjson_api_inline bool yyjson_mut_ptr_setx(yyjson_mut_val *val, + const char *ptr, size_t len, + yyjson_mut_val *new_val, + yyjson_mut_doc *doc, + bool create_parent, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err) { + yyjson_ptr_set_err(NONE, NULL); + if (ctx) memset(ctx, 0, sizeof(*ctx)); + + if (yyjson_unlikely(!val || !ptr || !doc)) { + yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); + return false; + } + if (yyjson_unlikely(len == 0)) { + yyjson_ptr_set_err(SET_ROOT, "cannot set root"); + return false; + } + if (yyjson_unlikely(*ptr != '/')) { + yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); + return false; + } + if (!new_val) { + return !!unsafe_yyjson_mut_ptr_removex(val, ptr, len, ctx, err); + } + return unsafe_yyjson_mut_ptr_putx(val, ptr, len, new_val, doc, + create_parent, false, ctx, err); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_replace( + yyjson_mut_doc *doc, const char *ptr, yyjson_mut_val *new_val) { + if (!ptr) return NULL; + return yyjson_mut_doc_ptr_replacen(doc, ptr, strlen(ptr), new_val); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_replacen( + yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_mut_val *new_val) { + return yyjson_mut_doc_ptr_replacex(doc, ptr, len, new_val, NULL, NULL); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_replacex( + yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_mut_val *new_val, + yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { + + yyjson_ptr_set_err(NONE, NULL); + if (ctx) memset(ctx, 0, sizeof(*ctx)); + + if (yyjson_unlikely(!doc || !ptr || !new_val)) { + yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); + return NULL; + } + if (yyjson_unlikely(len == 0)) { + yyjson_mut_val *root = doc->root; + if (yyjson_unlikely(!root)) { + yyjson_ptr_set_err(RESOLVE, "JSON pointer cannot be resolved"); + return NULL; + } + if (ctx) ctx->old = root; + doc->root = new_val; + return root; + } + if (yyjson_unlikely(!doc->root)) { + yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL"); + return NULL; + } + if (yyjson_unlikely(*ptr != '/')) { + yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); + return NULL; + } + return unsafe_yyjson_mut_ptr_replacex(doc->root, ptr, len, new_val, + ctx, err); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_replace( + yyjson_mut_val *val, const char *ptr, yyjson_mut_val *new_val) { + if (!ptr) return NULL; + return yyjson_mut_ptr_replacen(val, ptr, strlen(ptr), new_val); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_replacen( + yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val) { + return yyjson_mut_ptr_replacex(val, ptr, len, new_val, NULL, NULL); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_replacex( + yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val, + yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { + + yyjson_ptr_set_err(NONE, NULL); + if (ctx) memset(ctx, 0, sizeof(*ctx)); + + if (yyjson_unlikely(!val || !ptr || !new_val)) { + yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); + return NULL; + } + if (yyjson_unlikely(len == 0)) { + yyjson_ptr_set_err(SET_ROOT, "cannot set root"); + return NULL; + } + if (yyjson_unlikely(*ptr != '/')) { + yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); + return NULL; + } + return unsafe_yyjson_mut_ptr_replacex(val, ptr, len, new_val, ctx, err); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_remove( + yyjson_mut_doc *doc, const char *ptr) { + if (!ptr) return NULL; + return yyjson_mut_doc_ptr_removen(doc, ptr, strlen(ptr)); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_removen( + yyjson_mut_doc *doc, const char *ptr, size_t len) { + return yyjson_mut_doc_ptr_removex(doc, ptr, len, NULL, NULL); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_removex( + yyjson_mut_doc *doc, const char *ptr, size_t len, + yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { + + yyjson_ptr_set_err(NONE, NULL); + if (ctx) memset(ctx, 0, sizeof(*ctx)); + + if (yyjson_unlikely(!doc || !ptr)) { + yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); + return NULL; + } + if (yyjson_unlikely(!doc->root)) { + yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL"); + return NULL; + } + if (yyjson_unlikely(len == 0)) { + yyjson_mut_val *root = doc->root; + if (ctx) ctx->old = root; + doc->root = NULL; + return root; + } + if (yyjson_unlikely(*ptr != '/')) { + yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); + return NULL; + } + return unsafe_yyjson_mut_ptr_removex(doc->root, ptr, len, ctx, err); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_remove(yyjson_mut_val *val, + const char *ptr) { + if (!ptr) return NULL; + return yyjson_mut_ptr_removen(val, ptr, strlen(ptr)); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_removen(yyjson_mut_val *val, + const char *ptr, + size_t len) { + return yyjson_mut_ptr_removex(val, ptr, len, NULL, NULL); +} + +yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_removex(yyjson_mut_val *val, + const char *ptr, + size_t len, + yyjson_ptr_ctx *ctx, + yyjson_ptr_err *err) { + yyjson_ptr_set_err(NONE, NULL); + if (ctx) memset(ctx, 0, sizeof(*ctx)); + + if (yyjson_unlikely(!val || !ptr)) { + yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); + return NULL; + } + if (yyjson_unlikely(len == 0)) { + yyjson_ptr_set_err(SET_ROOT, "cannot set root"); + return NULL; + } + if (yyjson_unlikely(*ptr != '/')) { + yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); + return NULL; + } + return unsafe_yyjson_mut_ptr_removex(val, ptr, len, ctx, err); +} + +yyjson_api_inline bool yyjson_ptr_ctx_append(yyjson_ptr_ctx *ctx, + yyjson_mut_val *key, + yyjson_mut_val *val) { + yyjson_mut_val *ctn, *pre_key, *pre_val, *cur_key, *cur_val; + if (!ctx || !ctx->ctn || !val) return false; + ctn = ctx->ctn; + + if (yyjson_mut_is_obj(ctn)) { + if (!key) return false; + key->next = val; + pre_key = ctx->pre; + if (unsafe_yyjson_get_len(ctn) == 0) { + val->next = key; + ctn->uni.ptr = key; + ctx->pre = key; + } else if (!pre_key) { + pre_key = (yyjson_mut_val *)ctn->uni.ptr; + pre_val = pre_key->next; + val->next = pre_val->next; + pre_val->next = key; + ctn->uni.ptr = key; + ctx->pre = pre_key; + } else { + cur_key = pre_key->next->next; + cur_val = cur_key->next; + val->next = cur_val->next; + cur_val->next = key; + if (ctn->uni.ptr == cur_key) ctn->uni.ptr = key; + ctx->pre = cur_key; + } + } else { + pre_val = ctx->pre; + if (unsafe_yyjson_get_len(ctn) == 0) { + val->next = val; + ctn->uni.ptr = val; + ctx->pre = val; + } else if (!pre_val) { + pre_val = (yyjson_mut_val *)ctn->uni.ptr; + val->next = pre_val->next; + pre_val->next = val; + ctn->uni.ptr = val; + ctx->pre = pre_val; + } else { + cur_val = pre_val->next; + val->next = cur_val->next; + cur_val->next = val; + if (ctn->uni.ptr == cur_val) ctn->uni.ptr = val; + ctx->pre = cur_val; + } + } + unsafe_yyjson_inc_len(ctn); + return true; +} + +yyjson_api_inline bool yyjson_ptr_ctx_replace(yyjson_ptr_ctx *ctx, + yyjson_mut_val *val) { + yyjson_mut_val *ctn, *pre_key, *cur_key, *pre_val, *cur_val; + if (!ctx || !ctx->ctn || !ctx->pre || !val) return false; + ctn = ctx->ctn; + if (yyjson_mut_is_obj(ctn)) { + pre_key = ctx->pre; + pre_val = pre_key->next; + cur_key = pre_val->next; + cur_val = cur_key->next; + /* replace current value */ + cur_key->next = val; + val->next = cur_val->next; + ctx->old = cur_val; + } else { + pre_val = ctx->pre; + cur_val = pre_val->next; + /* replace current value */ + if (pre_val != cur_val) { + val->next = cur_val->next; + pre_val->next = val; + if (ctn->uni.ptr == cur_val) ctn->uni.ptr = val; + } else { + val->next = val; + ctn->uni.ptr = val; + ctx->pre = val; + } + ctx->old = cur_val; + } + return true; +} + +yyjson_api_inline bool yyjson_ptr_ctx_remove(yyjson_ptr_ctx *ctx) { + yyjson_mut_val *ctn, *pre_key, *pre_val, *cur_key, *cur_val; + size_t len; + if (!ctx || !ctx->ctn || !ctx->pre) return false; + ctn = ctx->ctn; + if (yyjson_mut_is_obj(ctn)) { + pre_key = ctx->pre; + pre_val = pre_key->next; + cur_key = pre_val->next; + cur_val = cur_key->next; + /* remove current key-value */ + pre_val->next = cur_val->next; + if (ctn->uni.ptr == cur_key) ctn->uni.ptr = pre_key; + ctx->pre = NULL; + ctx->old = cur_val; + } else { + pre_val = ctx->pre; + cur_val = pre_val->next; + /* remove current key-value */ + pre_val->next = cur_val->next; + if (ctn->uni.ptr == cur_val) ctn->uni.ptr = pre_val; + ctx->pre = NULL; + ctx->old = cur_val; + } + len = unsafe_yyjson_get_len(ctn) - 1; + if (len == 0) ctn->uni.ptr = NULL; + unsafe_yyjson_set_len(ctn, len); + return true; +} + +#undef yyjson_ptr_set_err + + + +/*============================================================================== + * MARK: - JSON Value at Pointer API (Implementation) + *============================================================================*/ + +/** + Set provided `value` if the JSON Pointer (RFC 6901) exists and is type bool. + Returns true if value at `ptr` exists and is the correct type, otherwise false. + */ +yyjson_api_inline bool yyjson_ptr_get_bool( + yyjson_val *root, const char *ptr, bool *value) { + yyjson_val *val = yyjson_ptr_get(root, ptr); + if (value && yyjson_is_bool(val)) { + *value = unsafe_yyjson_get_bool(val); + return true; + } else { + return false; + } +} + +/** + Set provided `value` if the JSON Pointer (RFC 6901) exists and is an integer + that fits in `uint64_t`. Returns true if successful, otherwise false. + */ +yyjson_api_inline bool yyjson_ptr_get_uint( + yyjson_val *root, const char *ptr, uint64_t *value) { + yyjson_val *val = yyjson_ptr_get(root, ptr); + if (value && val) { + uint64_t ret = val->uni.u64; + if (unsafe_yyjson_is_uint(val) || + (unsafe_yyjson_is_sint(val) && !(ret >> 63))) { + *value = ret; + return true; + } + } + return false; +} + +/** + Set provided `value` if the JSON Pointer (RFC 6901) exists and is an integer + that fits in `int64_t`. Returns true if successful, otherwise false. + */ +yyjson_api_inline bool yyjson_ptr_get_sint( + yyjson_val *root, const char *ptr, int64_t *value) { + yyjson_val *val = yyjson_ptr_get(root, ptr); + if (value && val) { + int64_t ret = val->uni.i64; + if (unsafe_yyjson_is_sint(val) || + (unsafe_yyjson_is_uint(val) && ret >= 0)) { + *value = ret; + return true; + } + } + return false; +} + +/** + Set provided `value` if the JSON Pointer (RFC 6901) exists and is type real. + Returns true if value at `ptr` exists and is the correct type, otherwise false. + */ +yyjson_api_inline bool yyjson_ptr_get_real( + yyjson_val *root, const char *ptr, double *value) { + yyjson_val *val = yyjson_ptr_get(root, ptr); + if (value && yyjson_is_real(val)) { + *value = unsafe_yyjson_get_real(val); + return true; + } else { + return false; + } +} + +/** + Set provided `value` if the JSON Pointer (RFC 6901) exists and is type sint, + uint or real. + Returns true if value at `ptr` exists and is the correct type, otherwise false. + */ +yyjson_api_inline bool yyjson_ptr_get_num( + yyjson_val *root, const char *ptr, double *value) { + yyjson_val *val = yyjson_ptr_get(root, ptr); + if (value && yyjson_is_num(val)) { + *value = unsafe_yyjson_get_num(val); + return true; + } else { + return false; + } +} + +/** + Set provided `value` if the JSON Pointer (RFC 6901) exists and is type string. + Returns true if value at `ptr` exists and is the correct type, otherwise false. + */ +yyjson_api_inline bool yyjson_ptr_get_str( + yyjson_val *root, const char *ptr, const char **value) { + yyjson_val *val = yyjson_ptr_get(root, ptr); + if (value && yyjson_is_str(val)) { + *value = unsafe_yyjson_get_str(val); + return true; + } else { + return false; + } +} + + + +/*============================================================================== + * MARK: - Deprecated + *============================================================================*/ + +/** @deprecated renamed to `yyjson_doc_ptr_get` */ +yyjson_deprecated("renamed to yyjson_doc_ptr_get") +yyjson_api_inline yyjson_val *yyjson_doc_get_pointer(yyjson_doc *doc, + const char *ptr) { + return yyjson_doc_ptr_get(doc, ptr); +} + +/** @deprecated renamed to `yyjson_doc_ptr_getn` */ +yyjson_deprecated("renamed to yyjson_doc_ptr_getn") +yyjson_api_inline yyjson_val *yyjson_doc_get_pointern(yyjson_doc *doc, + const char *ptr, + size_t len) { + return yyjson_doc_ptr_getn(doc, ptr, len); +} + +/** @deprecated renamed to `yyjson_mut_doc_ptr_get` */ +yyjson_deprecated("renamed to yyjson_mut_doc_ptr_get") +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_get_pointer( + yyjson_mut_doc *doc, const char *ptr) { + return yyjson_mut_doc_ptr_get(doc, ptr); +} + +/** @deprecated renamed to `yyjson_mut_doc_ptr_getn` */ +yyjson_deprecated("renamed to yyjson_mut_doc_ptr_getn") +yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_get_pointern( + yyjson_mut_doc *doc, const char *ptr, size_t len) { + return yyjson_mut_doc_ptr_getn(doc, ptr, len); +} + +/** @deprecated renamed to `yyjson_ptr_get` */ +yyjson_deprecated("renamed to yyjson_ptr_get") +yyjson_api_inline yyjson_val *yyjson_get_pointer(yyjson_val *val, + const char *ptr) { + return yyjson_ptr_get(val, ptr); +} + +/** @deprecated renamed to `yyjson_ptr_getn` */ +yyjson_deprecated("renamed to yyjson_ptr_getn") +yyjson_api_inline yyjson_val *yyjson_get_pointern(yyjson_val *val, + const char *ptr, + size_t len) { + return yyjson_ptr_getn(val, ptr, len); +} + +/** @deprecated renamed to `yyjson_mut_ptr_get` */ +yyjson_deprecated("renamed to yyjson_mut_ptr_get") +yyjson_api_inline yyjson_mut_val *yyjson_mut_get_pointer(yyjson_mut_val *val, + const char *ptr) { + return yyjson_mut_ptr_get(val, ptr); +} + +/** @deprecated renamed to `yyjson_mut_ptr_getn` */ +yyjson_deprecated("renamed to yyjson_mut_ptr_getn") +yyjson_api_inline yyjson_mut_val *yyjson_mut_get_pointern(yyjson_mut_val *val, + const char *ptr, + size_t len) { + return yyjson_mut_ptr_getn(val, ptr, len); +} + +/** @deprecated renamed to `yyjson_mut_ptr_getn` */ +yyjson_deprecated("renamed to unsafe_yyjson_ptr_getn") +yyjson_api_inline yyjson_val *unsafe_yyjson_get_pointer(yyjson_val *val, + const char *ptr, + size_t len) { + yyjson_ptr_err err; + return unsafe_yyjson_ptr_getx(val, ptr, len, &err); +} + +/** @deprecated renamed to `unsafe_yyjson_mut_ptr_getx` */ +yyjson_deprecated("renamed to unsafe_yyjson_mut_ptr_getx") +yyjson_api_inline yyjson_mut_val *unsafe_yyjson_mut_get_pointer( + yyjson_mut_val *val, const char *ptr, size_t len) { + yyjson_ptr_err err; + return unsafe_yyjson_mut_ptr_getx(val, ptr, len, NULL, &err); +} + +#endif /* YYJSON_DISABLE_UTILS */ + + + +/*============================================================================== + * MARK: - Compiler Hint End + *============================================================================*/ + +#if defined(__clang__) +# pragma clang diagnostic pop +#elif defined(__GNUC__) +# if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) +# pragma GCC diagnostic pop +# endif +#elif defined(_MSC_VER) +# pragma warning(pop) +#endif /* warning suppress end */ + +#ifdef __cplusplus +} +#endif /* extern "C" end */ + +#endif /* YYJSON_H */ diff --git a/research/experiments/004-direct-document-path/README.md b/research/experiments/004-direct-document-path/README.md new file mode 100644 index 0000000..ae4e3b8 --- /dev/null +++ b/research/experiments/004-direct-document-path/README.md @@ -0,0 +1,50 @@ +# Direct store calls versus the Pure document path + +This is an end-to-end comparison for the existing `editor.pure` document app. +Both variants perform, for each document, a conditional create, a full read, +a conditional one-byte replacement at the end, and another full read. They +check revisions and complete bodies and compute the same digest. Both use the +same `store.c`: a write creates and synchronizes a replacement file, renames +it, then synchronizes the directory. The harness verifies equal digests and +equal final file bytes for each pair of runs. + +The direct executable calls `pure_store_splice` and `pure_store_select`; the +Pure executable runs the prepared `editor.pure` plan through `PureRuntime` and +`pure_store_host`. The direct executable mirrors only this valid-operation +workflow. It does **not** provide the runtime's admission, ownership, budget, +completion, or cancellation contract and is not a feature-equivalent runtime. +The comparison isolates the cost of choosing that contract for this app path; +it does not compare two complete products. + +Run on a Linux host with a C17 compiler, Python 3, GNU `size`, and `df`: + +```sh +python3 research/experiments/004-direct-document-path/run.py \ + --documents 256 --body-bytes 8192 --pairs 4 \ + --output research/experiments/004-direct-document-path/results/local-8k.json +python3 research/experiments/004-direct-document-path/run.py \ + --documents 32 --body-bytes 1048576 --pairs 4 \ + --output research/experiments/004-direct-document-path/results/local-1m.json +``` + +The runner uses a fresh temporary directory for each variant and alternates +direct/Pure order between pairs. Its default `--work-root` is this directory's +`results/`, so the store is on the repository filesystem. It records the +filesystem type, compiler, source hashes, executable hashes, linked sections, +operation counts, four stage times, wall time, user/system CPU time, and peak +child RSS. A small native parent collects RSS because a Python process can +otherwise contaminate the reported child high-water mark across `exec`. +Warmups are untimed, and the runner refuses to compare against a changed +`editor.pure` definition until the direct mirror is reviewed. + +The dated `ext4` JSON files are the report's evidence. The dated `tmpfs` +files are exploratory runs made before filesystem recording was added; their +store was under `/tmp` on this host. They exercised the same store calls but +cannot represent persistent-media latency. One run, even with alternating +order, cannot control host I/O scheduling, cache state, storage firmware, or +clock changes. The byte digest proves this workload's result equality, not +full behavioral equivalence in failures or concurrency. + +The [result and interpretation](../../../docs/research/054-direct-document-path.md) +distinguish linked executable size from the 5,908-byte standalone core and +avoid a speed claim unsupported by the samples. diff --git a/research/experiments/004-direct-document-path/document-path.c b/research/experiments/004-direct-document-path/document-path.c new file mode 100644 index 0000000..b4d6464 --- /dev/null +++ b/research/experiments/004-direct-document-path/document-path.c @@ -0,0 +1,207 @@ +#define _POSIX_C_SOURCE 200809L +/* Two separately linked versions of one durable document workload. The direct + * build invokes the same store primitives that the Pure host uses; the Pure + * build runs the prepared editor.pure program through its execution core. */ +#include "store.h" +#ifndef DIRECT_PATH +#include "runtime.h" +#include "store-port.h" +#include "embedded-plan.h" +#endif +#include <inttypes.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> + +#ifndef PURE_BENCH_BODY_BYTES +#define PURE_BENCH_BODY_BYTES 8192 +#endif +enum { BODY_BYTES = PURE_BENCH_BODY_BYTES }; +static uint64_t digest = UINT64_C(14695981039346656037); + +static void fail(const char *message) { + fprintf(stderr, "%s\n", message); + exit(1); +} + +static void check(int condition, const char *message) { + if (!condition) fail(message); +} + +static void hash_body(const unsigned char *body, size_t size, int64_t revision) { + for (size_t i = 0; i < size; ++i) { + digest ^= body[i]; + digest *= UINT64_C(1099511628211); + } + digest ^= (uint64_t)revision; + digest *= UINT64_C(1099511628211); +} + +static uint64_t nanoseconds(void) { + struct timespec now; + if (clock_gettime(CLOCK_MONOTONIC, &now)) fail("clock_gettime failed"); + return (uint64_t)now.tv_sec * UINT64_C(1000000000) + (uint64_t)now.tv_nsec; +} + +static void pattern(unsigned char *body, unsigned document) { + for (size_t i = 0; i < BODY_BYTES; ++i) + body[i] = (unsigned char)('a' + (document + i) % 26); +} + +#ifdef DIRECT_PATH +static void create(const char *store, const char *key, unsigned document, + const unsigned char *expected) { + unsigned char *input = malloc(BODY_BYTES); + check(input != NULL, "direct input allocation failed"); + pattern(input, document); + check(!memcmp(input, expected, BODY_BYTES), "direct input mismatch"); + int64_t revision = 0; + PureResult status = pure_store_splice(store, key, 0, 0, 0, + (PureSpan){input, BODY_BYTES}, &revision); + check(status == PURE_OK && revision == 1, "direct create failed"); + free(input); +} + +static void edit_last(const char *store, const char *key, unsigned char replacement) { + unsigned char *input = malloc(1); + check(input != NULL, "direct edit allocation failed"); + *input = replacement; + int64_t revision = 0; + PureResult status = pure_store_splice(store, key, 1, BODY_BYTES - 1, 1, + (PureSpan){input, 1}, &revision); + check(status == PURE_OK && revision == 2, "direct edit failed"); + free(input); +} + +static void read_checked(const char *store, const char *key, + const unsigned char *expected, int64_t revision) { + PureStoredView view = {0}; + PureResult status = pure_store_select(store, key, 0, 0, true, 0, + 4u * 1024u * 1024u, &view); + check(status == PURE_OK && view.revision == revision && + view.body.size == BODY_BYTES && !memcmp(view.body.data, expected, BODY_BYTES), + "direct read mismatch"); + hash_body(view.body.data, view.body.size, revision); + pure_store_release(&view); +} +#else +static PureRuntime runtime; +static PureWork work[1]; + +static PureOutcome completed(PureTicket ticket) { + PureOutcome result; + while (!pure_runtime_result(ticket, &result)) + check(pure_runtime_step(&runtime), "runtime made no progress"); + return result; +} + +static void write_checked(const char *key, int64_t expected_revision, + size_t offset, size_t remove, size_t insert_size, + unsigned document, unsigned char replacement, + const unsigned char *expected_reply, int64_t revision) { + PureTicket ticket; + check(pure_runtime_accept(&runtime, PURE_INPUT_WRITE, key, expected_revision, + 8 + insert_size, &ticket) == PURE_OK, "runtime write admission failed"); + size_t size = 0; + unsigned char *input = pure_runtime_ingress(ticket, &size); + check(input != NULL && size == 8 + insert_size, "runtime input loan failed"); + for (unsigned i = 0; i < 4; ++i) { + input[i] = (unsigned char)(offset >> (8 * i)); + input[4 + i] = (unsigned char)(remove >> (8 * i)); + } + if (insert_size == BODY_BYTES) pattern(input + 8, document); + else input[8] = replacement; + check(pure_runtime_ready(ticket), "runtime publication failed"); + PureOutcome result = completed(ticket); + check(result.status == PURE_OK && result.revision == revision && + result.body.size == insert_size && + !memcmp(result.body.data, expected_reply, insert_size), + "runtime write result mismatch"); + check(pure_runtime_release(ticket) && !runtime.active && !runtime.retained, + "runtime write resource not released"); +} + +static void read_checked(const char *store, const char *key, + const unsigned char *expected, int64_t revision) { + (void)store; + PureTicket ticket; + check(pure_runtime_accept(&runtime, PURE_INPUT_READ, key, 0, 0, &ticket) == PURE_OK, + "runtime read admission failed"); + PureOutcome result = completed(ticket); + check(result.status == PURE_OK && result.revision == revision && + result.body.size == BODY_BYTES && !memcmp(result.body.data, expected, BODY_BYTES), + "runtime read mismatch"); + hash_body(result.body.data, result.body.size, revision); + check(pure_runtime_release(ticket) && !runtime.active && !runtime.retained, + "runtime read resource not released"); +} + +static void create(const char *store, const char *key, unsigned document, + const unsigned char *expected) { + (void)store; + write_checked(key, 0, 0, 0, BODY_BYTES, document, 0, expected, 1); +} + +static void edit_last(const char *store, const char *key, unsigned char replacement) { + (void)store; + write_checked(key, 1, BODY_BYTES - 1, 1, 1, 0, replacement, &replacement, 2); +} +#endif + +int main(int argc, char **argv) { + if (argc != 3) fail("usage: document-path STORE DOCUMENT_COUNT"); + char *end = NULL; + unsigned long parsed = strtoul(argv[2], &end, 10); + check(end && !*end && parsed > 0 && parsed <= 4096, + "DOCUMENT_COUNT must be 1..4096"); + unsigned documents = (unsigned)parsed; + check(pure_store_init(argv[1]) == PURE_OK, "store initialization failed"); + unsigned char *expected = malloc(BODY_BYTES); + check(expected != NULL, "expected document allocation failed"); +#ifndef DIRECT_PATH + check(pure_embedded_program.splice && pure_embedded_program.write.offset == 8 && + pure_embedded_program.splice_offset.value == 0 && + pure_embedded_program.splice_remove.value == 4 && + pure_embedded_program.reply_input && pure_embedded_program.read.to_end, + "prepared editor.pure no longer matches direct baseline"); + check(pure_runtime_init(&runtime, work, 1, &pure_embedded_program, + pure_store_host(argv[1]), 4u * 1024u * 1024u), + "runtime initialization failed"); +#endif + uint64_t start = nanoseconds(); + uint64_t stages[4] = {0}; + for (unsigned document = 0; document < documents; ++document) { + char key[16]; + snprintf(key, sizeof(key), "doc%04u", document); + pattern(expected, document); + uint64_t before = nanoseconds(); + create(argv[1], key, document, expected); + stages[0] += nanoseconds() - before; + before = nanoseconds(); + read_checked(argv[1], key, expected, 1); + stages[1] += nanoseconds() - before; + unsigned char replacement = (unsigned char)('A' + document % 26); + before = nanoseconds(); + edit_last(argv[1], key, replacement); + stages[2] += nanoseconds() - before; + expected[BODY_BYTES - 1] = replacement; + before = nanoseconds(); + read_checked(argv[1], key, expected, 2); + stages[3] += nanoseconds() - before; + } + uint64_t elapsed = nanoseconds() - start; + free(expected); + printf("{\"variant\":\"%s\",\"documents\":%u,\"operations\":%u," + "\"body_bytes\":%u,\"elapsed_ns\":%" PRIu64 "," + "\"stage_ns\":[%" PRIu64 ",%" PRIu64 ",%" PRIu64 ",%" PRIu64 "]," + "\"digest\":\"%016" PRIx64 "\"}\n", +#ifdef DIRECT_PATH + "direct", +#else + "pure", +#endif + documents, documents * 4, (unsigned)BODY_BYTES, elapsed, + stages[0], stages[1], stages[2], stages[3], digest); + return 0; +} diff --git a/research/experiments/004-direct-document-path/peak-launcher.c b/research/experiments/004-direct-document-path/peak-launcher.c new file mode 100644 index 0000000..e9f6c00 --- /dev/null +++ b/research/experiments/004-direct-document-path/peak-launcher.c @@ -0,0 +1,26 @@ +#define _GNU_SOURCE +/* Fork from a small native launcher so a Python orchestrator's pre-exec RSS + * cannot become the measured worker's high-water mark. */ +#include <stdio.h> +#include <sys/resource.h> +#include <sys/wait.h> +#include <unistd.h> + +int main(int argc, char **argv) { + if (argc < 2) return 2; + pid_t child = fork(); + if (child < 0) return 2; + if (!child) { + execvp(argv[1], argv + 1); + _exit(127); + } + struct rusage usage; + int status; + if (wait4(child, &status, 0, &usage) < 0 || !WIFEXITED(status) || + WEXITSTATUS(status)) return 1; + long user_ns = usage.ru_utime.tv_sec * 1000000000L + usage.ru_utime.tv_usec * 1000L; + long system_ns = usage.ru_stime.tv_sec * 1000000000L + usage.ru_stime.tv_usec * 1000L; + fprintf(stderr, "PURE_PEAK_RSS_KIB=%ld\nPURE_USER_NS=%ld\nPURE_SYSTEM_NS=%ld\n", + usage.ru_maxrss, user_ns, system_ns); + return 0; +} diff --git a/research/experiments/004-direct-document-path/results/2026-09-24-ext4-1m-linux-aarch64.json b/research/experiments/004-direct-document-path/results/2026-09-24-ext4-1m-linux-aarch64.json new file mode 100644 index 0000000..80ae293 --- /dev/null +++ b/research/experiments/004-direct-document-path/results/2026-09-24-ext4-1m-linux-aarch64.json @@ -0,0 +1,251 @@ +{ + "profile": "same-durable-document-app-direct-versus-pure", + "definition_sha256": "8ca6c191b98bf53a592ce24f2b5cd040e41f05c4ccdda7a072d5d7f79870c06a", + "prepared_sha256": "8e93861539a87c2a091f55afea1bf310fc3d1f1474521d8f8318bfacac3b0649", + "documents_per_variant": 32, + "operations_per_variant": 128, + "body_bytes": 1048576, + "pairs": 4, + "filesystem": { + "device": "/dev/mmcblk0p2", + "type": "ext4", + "mount": "/home/eunhhu/work/pure" + }, + "sections": { + "direct": { + "text": 10364, + "data": 856, + "bss": 16 + }, + "pure": { + "text": 18640, + "data": 864, + "bss": 376 + } + }, + "binary_sha256": { + "direct": "1389e7d95e74e93ab5d9e8c8146d0b8fc5288e7a356df231c3c018d3db9d0e05", + "pure": "9a45a3d92eed499b849560a2c949f24da7d09deb5ec9bd956ab78ae4e8273e54" + }, + "samples": [ + { + "order": [ + "direct", + "pure" + ], + "direct": { + "variant": "direct", + "documents": 32, + "operations": 128, + "body_bytes": 1048576, + "elapsed_ns": 4764012642, + "stage_ns": [ + 2307602623, + 136599863, + 2096570951, + 135696119 + ], + "digest": "b74d25a65553ee41", + "peak_rss_kib": 4128, + "user_ns": 428385000, + "system_ns": 98253000, + "stored_file_bytes": 33555200, + "stored_files_sha256": "cd78e6871643d5ce1ae9f3b0c96985b36996ac23053f49c140c4224516d6e77a" + }, + "pure": { + "variant": "pure", + "documents": 32, + "operations": 128, + "body_bytes": 1048576, + "elapsed_ns": 7285595814, + "stage_ns": [ + 5142956601, + 117263079, + 1831606853, + 117247619 + ], + "digest": "b74d25a65553ee41", + "peak_rss_kib": 4128, + "user_ns": 382221000, + "system_ns": 78088000, + "stored_file_bytes": 33555200, + "stored_files_sha256": "cd78e6871643d5ce1ae9f3b0c96985b36996ac23053f49c140c4224516d6e77a" + } + }, + { + "order": [ + "pure", + "direct" + ], + "pure": { + "variant": "pure", + "documents": 32, + "operations": 128, + "body_bytes": 1048576, + "elapsed_ns": 3766595455, + "stage_ns": [ + 1765437679, + 95183882, + 1750125337, + 95840266 + ], + "digest": "b74d25a65553ee41", + "peak_rss_kib": 4176, + "user_ns": 290416000, + "system_ns": 85416000, + "stored_file_bytes": 33555200, + "stored_files_sha256": "cd78e6871643d5ce1ae9f3b0c96985b36996ac23053f49c140c4224516d6e77a" + }, + "direct": { + "variant": "direct", + "documents": 32, + "operations": 128, + "body_bytes": 1048576, + "elapsed_ns": 8005833380, + "stage_ns": [ + 2106116647, + 136885177, + 5531253084, + 139444468 + ], + "digest": "b74d25a65553ee41", + "peak_rss_kib": 4160, + "user_ns": 454253000, + "system_ns": 79693000, + "stored_file_bytes": 33555200, + "stored_files_sha256": "cd78e6871643d5ce1ae9f3b0c96985b36996ac23053f49c140c4224516d6e77a" + } + }, + { + "order": [ + "direct", + "pure" + ], + "direct": { + "variant": "direct", + "documents": 32, + "operations": 128, + "body_bytes": 1048576, + "elapsed_ns": 10918834225, + "stage_ns": [ + 2175551809, + 106558403, + 8462573310, + 106534958 + ], + "digest": "b74d25a65553ee41", + "peak_rss_kib": 4576, + "user_ns": 344275000, + "system_ns": 70420000, + "stored_file_bytes": 33555200, + "stored_files_sha256": "cd78e6871643d5ce1ae9f3b0c96985b36996ac23053f49c140c4224516d6e77a" + }, + "pure": { + "variant": "pure", + "documents": 32, + "operations": 128, + "body_bytes": 1048576, + "elapsed_ns": 12394010470, + "stage_ns": [ + 7847769422, + 133123427, + 4192297149, + 133678298 + ], + "digest": "b74d25a65553ee41", + "peak_rss_kib": 4128, + "user_ns": 443388000, + "system_ns": 78475000, + "stored_file_bytes": 33555200, + "stored_files_sha256": "cd78e6871643d5ce1ae9f3b0c96985b36996ac23053f49c140c4224516d6e77a" + } + }, + { + "order": [ + "pure", + "direct" + ], + "pure": { + "variant": "pure", + "documents": 32, + "operations": 128, + "body_bytes": 1048576, + "elapsed_ns": 19998681944, + "stage_ns": [ + 6699663505, + 105108979, + 13020834566, + 105960162 + ], + "digest": "b74d25a65553ee41", + "peak_rss_kib": 4144, + "user_ns": 361242000, + "system_ns": 54606000, + "stored_file_bytes": 33555200, + "stored_files_sha256": "cd78e6871643d5ce1ae9f3b0c96985b36996ac23053f49c140c4224516d6e77a" + }, + "direct": { + "variant": "direct", + "documents": 32, + "operations": 128, + "body_bytes": 1048576, + "elapsed_ns": 9851837474, + "stage_ns": [ + 6446916975, + 136390388, + 3043885903, + 137363089 + ], + "digest": "b74d25a65553ee41", + "peak_rss_kib": 4592, + "user_ns": 460200000, + "system_ns": 68626000, + "stored_file_bytes": 33555200, + "stored_files_sha256": "cd78e6871643d5ce1ae9f3b0c96985b36996ac23053f49c140c4224516d6e77a" + } + } + ], + "medians": { + "direct": { + "elapsed_ms": 8928.835427, + "peak_rss_kib": 4368.0, + "user_ms": 441.319, + "system_ms": 75.0565, + "stages_ms": [ + 2241.577216, + 136.4951255, + 4287.5694935, + 136.529604 + ] + }, + "pure": { + "elapsed_ms": 9839.803142, + "peak_rss_kib": 4136.0, + "user_ms": 371.7315, + "system_ms": 78.2815, + "stages_ms": [ + 5921.310053, + 111.186029, + 3011.952001, + 111.6038905 + ] + } + }, + "median_elapsed_ratio_pure_over_direct": 1.102025367411893, + "sources_sha256": { + "research/experiments/004-direct-document-path/document-path.c": "032d8688db330c355082d150865aa7ade3e5402cc1bbe090b361fd55cb6325fc", + "research/experiments/004-direct-document-path/peak-launcher.c": "fc730205d564b60a4f9e44aa1b880df0debeb1338b86b27eabe3bde1508f3f74", + "research/experiments/004-direct-document-path/run.py": "ab9eaed05ed47afc29cb94e72759dad6534531b52b34a8ba2c5b3be6ded1cac1", + "prototypes/connections/store.c": "733ddcacaffd9e9ffbadfc385eadd4c9e62736a2b97b7bc048ad14845d83070f", + "prototypes/connections/runtime.c": "1ced6734ee07f3688e5c9cc0a8af639da88a1741dc3e6f65ec109baa2d826e6f", + "prototypes/connections/evaluate.c": "ee8b91efc733b9d305711b7cbb7b502ae5d3917e06f750b7f62b632ed0ea6d04", + "prototypes/connections/store-port.c": "d6bf17878b325e039360816edcbf8d68e41b373cf3e6128d7795e11ae21fdd6f", + "prototypes/connections/examples/editor.pure": "8ca6c191b98bf53a592ce24f2b5cd040e41f05c4ccdda7a072d5d7f79870c06a" + }, + "environment": { + "platform": "Linux-6.18.39+rpt-rpi-2712-aarch64-with-glibc2.41", + "machine": "aarch64", + "compiler": "cc (Debian 14.2.0-19) 14.2.0", + "size": "GNU size (GNU Binutils for Debian) 2.44" + } +} diff --git a/research/experiments/004-direct-document-path/results/2026-09-24-ext4-8k-linux-aarch64.json b/research/experiments/004-direct-document-path/results/2026-09-24-ext4-8k-linux-aarch64.json new file mode 100644 index 0000000..2f80581 --- /dev/null +++ b/research/experiments/004-direct-document-path/results/2026-09-24-ext4-8k-linux-aarch64.json @@ -0,0 +1,251 @@ +{ + "profile": "same-durable-document-app-direct-versus-pure", + "definition_sha256": "8ca6c191b98bf53a592ce24f2b5cd040e41f05c4ccdda7a072d5d7f79870c06a", + "prepared_sha256": "8e93861539a87c2a091f55afea1bf310fc3d1f1474521d8f8318bfacac3b0649", + "documents_per_variant": 256, + "operations_per_variant": 1024, + "body_bytes": 8192, + "pairs": 4, + "filesystem": { + "device": "/dev/mmcblk0p2", + "type": "ext4", + "mount": "/home/eunhhu/work/pure" + }, + "sections": { + "direct": { + "text": 10364, + "data": 856, + "bss": 16 + }, + "pure": { + "text": 18640, + "data": 864, + "bss": 376 + } + }, + "binary_sha256": { + "direct": "d265f60f9126da701369c26a6263474164171349867e11079a63b6d9bd1dbbc8", + "pure": "8e71e09bb7923de0e945f4d51c5514dd9ab07a4ff9c0982db712ab895fc54fa0" + }, + "samples": [ + { + "order": [ + "direct", + "pure" + ], + "direct": { + "variant": "direct", + "documents": 256, + "operations": 1024, + "body_bytes": 8192, + "elapsed_ns": 7241112354, + "stage_ns": [ + 3772530510, + 14877249, + 3434303263, + 14649999 + ], + "digest": "b8a08a9615b2eb3b", + "peak_rss_kib": 1072, + "user_ns": 21367000, + "system_ns": 89743000, + "stored_file_bytes": 2103296, + "stored_files_sha256": "93b837ad585f9633f60c4e3fc6c52e403238e5a4cc4ec3f6d248b3981a8f425b" + }, + "pure": { + "variant": "pure", + "documents": 256, + "operations": 1024, + "body_bytes": 8192, + "elapsed_ns": 7649396059, + "stage_ns": [ + 3825503100, + 15159869, + 3788264822, + 15324464 + ], + "digest": "b8a08a9615b2eb3b", + "peak_rss_kib": 1088, + "user_ns": 40394000, + "system_ns": 72710000, + "stored_file_bytes": 2103296, + "stored_files_sha256": "93b837ad585f9633f60c4e3fc6c52e403238e5a4cc4ec3f6d248b3981a8f425b" + } + }, + { + "order": [ + "pure", + "direct" + ], + "pure": { + "variant": "pure", + "documents": 256, + "operations": 1024, + "body_bytes": 8192, + "elapsed_ns": 7398701348, + "stage_ns": [ + 3647571585, + 15698014, + 3714469244, + 15678618 + ], + "digest": "b8a08a9615b2eb3b", + "peak_rss_kib": 1088, + "user_ns": 32058000, + "system_ns": 85489000, + "stored_file_bytes": 2103296, + "stored_files_sha256": "93b837ad585f9633f60c4e3fc6c52e403238e5a4cc4ec3f6d248b3981a8f425b" + }, + "direct": { + "variant": "direct", + "documents": 256, + "operations": 1024, + "body_bytes": 8192, + "elapsed_ns": 7807026262, + "stage_ns": [ + 4021085986, + 16197799, + 3747754749, + 16384614 + ], + "digest": "b8a08a9615b2eb3b", + "peak_rss_kib": 1072, + "user_ns": 23055000, + "system_ns": 96831000, + "stored_file_bytes": 2103296, + "stored_files_sha256": "93b837ad585f9633f60c4e3fc6c52e403238e5a4cc4ec3f6d248b3981a8f425b" + } + }, + { + "order": [ + "direct", + "pure" + ], + "direct": { + "variant": "direct", + "documents": 256, + "operations": 1024, + "body_bytes": 8192, + "elapsed_ns": 8124328908, + "stage_ns": [ + 3722508954, + 16393229, + 4364924440, + 15319853 + ], + "digest": "b8a08a9615b2eb3b", + "peak_rss_kib": 1072, + "user_ns": 45910000, + "system_ns": 67099000, + "stored_file_bytes": 2103296, + "stored_files_sha256": "93b837ad585f9633f60c4e3fc6c52e403238e5a4cc4ec3f6d248b3981a8f425b" + }, + "pure": { + "variant": "pure", + "documents": 256, + "operations": 1024, + "body_bytes": 8192, + "elapsed_ns": 8689792618, + "stage_ns": [ + 3995126011, + 17471391, + 4653440218, + 17835468 + ], + "digest": "b8a08a9615b2eb3b", + "peak_rss_kib": 1088, + "user_ns": 47096000, + "system_ns": 83726000, + "stored_file_bytes": 2103296, + "stored_files_sha256": "93b837ad585f9633f60c4e3fc6c52e403238e5a4cc4ec3f6d248b3981a8f425b" + } + }, + { + "order": [ + "pure", + "direct" + ], + "pure": { + "variant": "pure", + "documents": 256, + "operations": 1024, + "body_bytes": 8192, + "elapsed_ns": 7553568836, + "stage_ns": [ + 3612364797, + 15354345, + 3905074609, + 15629392 + ], + "digest": "b8a08a9615b2eb3b", + "peak_rss_kib": 1088, + "user_ns": 23794000, + "system_ns": 90418000, + "stored_file_bytes": 2103296, + "stored_files_sha256": "93b837ad585f9633f60c4e3fc6c52e403238e5a4cc4ec3f6d248b3981a8f425b" + }, + "direct": { + "variant": "direct", + "documents": 256, + "operations": 1024, + "body_bytes": 8192, + "elapsed_ns": 7932443534, + "stage_ns": [ + 4056315266, + 15670869, + 3839621816, + 15698993 + ], + "digest": "b8a08a9615b2eb3b", + "peak_rss_kib": 1072, + "user_ns": 23088000, + "system_ns": 92353000, + "stored_file_bytes": 2103296, + "stored_files_sha256": "93b837ad585f9633f60c4e3fc6c52e403238e5a4cc4ec3f6d248b3981a8f425b" + } + } + ], + "medians": { + "direct": { + "elapsed_ms": 7869.734898, + "peak_rss_kib": 1072.0, + "user_ms": 23.0715, + "system_ms": 91.048, + "stages_ms": [ + 3896.808248, + 15.934334, + 3793.6882825, + 15.509423 + ] + }, + "pure": { + "elapsed_ms": 7601.4824475, + "peak_rss_kib": 1088.0, + "user_ms": 36.226, + "system_ms": 84.6075, + "stages_ms": [ + 3736.5373425, + 15.5261795, + 3846.6697155, + 15.654005 + ] + } + }, + "median_elapsed_ratio_pure_over_direct": 0.9659134069982239, + "sources_sha256": { + "research/experiments/004-direct-document-path/document-path.c": "032d8688db330c355082d150865aa7ade3e5402cc1bbe090b361fd55cb6325fc", + "research/experiments/004-direct-document-path/peak-launcher.c": "fc730205d564b60a4f9e44aa1b880df0debeb1338b86b27eabe3bde1508f3f74", + "research/experiments/004-direct-document-path/run.py": "ab9eaed05ed47afc29cb94e72759dad6534531b52b34a8ba2c5b3be6ded1cac1", + "prototypes/connections/store.c": "733ddcacaffd9e9ffbadfc385eadd4c9e62736a2b97b7bc048ad14845d83070f", + "prototypes/connections/runtime.c": "1ced6734ee07f3688e5c9cc0a8af639da88a1741dc3e6f65ec109baa2d826e6f", + "prototypes/connections/evaluate.c": "ee8b91efc733b9d305711b7cbb7b502ae5d3917e06f750b7f62b632ed0ea6d04", + "prototypes/connections/store-port.c": "d6bf17878b325e039360816edcbf8d68e41b373cf3e6128d7795e11ae21fdd6f", + "prototypes/connections/examples/editor.pure": "8ca6c191b98bf53a592ce24f2b5cd040e41f05c4ccdda7a072d5d7f79870c06a" + }, + "environment": { + "platform": "Linux-6.18.39+rpt-rpi-2712-aarch64-with-glibc2.41", + "machine": "aarch64", + "compiler": "cc (Debian 14.2.0-19) 14.2.0", + "size": "GNU size (GNU Binutils for Debian) 2.44" + } +} diff --git a/research/experiments/004-direct-document-path/results/2026-09-24-tmpfs-1m-preliminary-linux-aarch64.json b/research/experiments/004-direct-document-path/results/2026-09-24-tmpfs-1m-preliminary-linux-aarch64.json new file mode 100644 index 0000000..ab088e1 --- /dev/null +++ b/research/experiments/004-direct-document-path/results/2026-09-24-tmpfs-1m-preliminary-linux-aarch64.json @@ -0,0 +1,238 @@ +{ + "profile": "same-durable-document-app-direct-versus-pure", + "definition_sha256": "8ca6c191b98bf53a592ce24f2b5cd040e41f05c4ccdda7a072d5d7f79870c06a", + "prepared_sha256": "8e93861539a87c2a091f55afea1bf310fc3d1f1474521d8f8318bfacac3b0649", + "documents_per_variant": 32, + "operations_per_variant": 128, + "body_bytes": 1048576, + "pairs": 4, + "sections": { + "direct": { + "text": 10364, + "data": 856, + "bss": 16 + }, + "pure": { + "text": 18640, + "data": 864, + "bss": 376 + } + }, + "binary_sha256": { + "direct": "1389e7d95e74e93ab5d9e8c8146d0b8fc5288e7a356df231c3c018d3db9d0e05", + "pure": "9a45a3d92eed499b849560a2c949f24da7d09deb5ec9bd956ab78ae4e8273e54" + }, + "samples": [ + { + "order": [ + "direct", + "pure" + ], + "direct": { + "variant": "direct", + "documents": 32, + "operations": 128, + "body_bytes": 1048576, + "elapsed_ns": 340081183, + "stage_ns": [ + 75261818, + 94500701, + 17506146, + 93772922 + ], + "digest": "b74d25a65553ee41", + "peak_rss_kib": 3872, + "user_ns": 308146000, + "system_ns": 32015000, + "stored_file_bytes": 33555200 + }, + "pure": { + "variant": "pure", + "documents": 32, + "operations": 128, + "body_bytes": 1048576, + "elapsed_ns": 341099421, + "stage_ns": [ + 79567567, + 92146853, + 17844589, + 92596187 + ], + "digest": "b74d25a65553ee41", + "peak_rss_kib": 4336, + "user_ns": 305409000, + "system_ns": 36166000, + "stored_file_bytes": 33555200 + } + }, + { + "order": [ + "pure", + "direct" + ], + "pure": { + "variant": "pure", + "documents": 32, + "operations": 128, + "body_bytes": 1048576, + "elapsed_ns": 338271706, + "stage_ns": [ + 77352220, + 91696577, + 18131571, + 92186762 + ], + "digest": "b74d25a65553ee41", + "peak_rss_kib": 3872, + "user_ns": 310861000, + "system_ns": 27897000, + "stored_file_bytes": 33555200 + }, + "direct": { + "variant": "direct", + "documents": 32, + "operations": 128, + "body_bytes": 1048576, + "elapsed_ns": 348018886, + "stage_ns": [ + 79216590, + 98943059, + 17171958, + 93268609 + ], + "digest": "b74d25a65553ee41", + "peak_rss_kib": 3856, + "user_ns": 302866000, + "system_ns": 40382000, + "stored_file_bytes": 33555200 + } + }, + { + "order": [ + "direct", + "pure" + ], + "direct": { + "variant": "direct", + "documents": 32, + "operations": 128, + "body_bytes": 1048576, + "elapsed_ns": 337466024, + "stage_ns": [ + 74499100, + 93470034, + 17836179, + 92757726 + ], + "digest": "b74d25a65553ee41", + "peak_rss_kib": 3872, + "user_ns": 309997000, + "system_ns": 28181000, + "stored_file_bytes": 33555200 + }, + "pure": { + "variant": "pure", + "documents": 32, + "operations": 128, + "body_bytes": 1048576, + "elapsed_ns": 342399605, + "stage_ns": [ + 79958272, + 92458203, + 18037399, + 92971374 + ], + "digest": "b74d25a65553ee41", + "peak_rss_kib": 4336, + "user_ns": 311005000, + "system_ns": 31898000, + "stored_file_bytes": 33555200 + } + }, + { + "order": [ + "pure", + "direct" + ], + "pure": { + "variant": "pure", + "documents": 32, + "operations": 128, + "body_bytes": 1048576, + "elapsed_ns": 340585627, + "stage_ns": [ + 79565343, + 91822001, + 17952418, + 92354743 + ], + "digest": "b74d25a65553ee41", + "peak_rss_kib": 3872, + "user_ns": 301411000, + "system_ns": 39659000, + "stored_file_bytes": 33555200 + }, + "direct": { + "variant": "direct", + "documents": 32, + "operations": 128, + "body_bytes": 1048576, + "elapsed_ns": 336890525, + "stage_ns": [ + 74695433, + 93087459, + 17564345, + 92612242 + ], + "digest": "b74d25a65553ee41", + "peak_rss_kib": 3856, + "user_ns": 309291000, + "system_ns": 28117000, + "stored_file_bytes": 33555200 + } + } + ], + "medians": { + "direct": { + "elapsed_ms": 338.7736035, + "peak_rss_kib": 3864.0, + "user_ms": 308.7185, + "system_ms": 30.098, + "stages_ms": [ + 74.9786255, + 93.9853675, + 17.5352455, + 93.0131675 + ] + }, + "pure": { + "elapsed_ms": 340.842524, + "peak_rss_kib": 4104.0, + "user_ms": 308.135, + "system_ms": 34.032, + "stages_ms": [ + 79.566455, + 91.984427, + 17.9949085, + 92.475465 + ] + } + }, + "median_elapsed_ratio_pure_over_direct": 1.0061070888600092, + "sources_sha256": { + "research/experiments/004-direct-document-path/document-path.c": "032d8688db330c355082d150865aa7ade3e5402cc1bbe090b361fd55cb6325fc", + "research/experiments/004-direct-document-path/peak-launcher.c": "fc730205d564b60a4f9e44aa1b880df0debeb1338b86b27eabe3bde1508f3f74", + "research/experiments/004-direct-document-path/run.py": "1919287fb5dc0f884cecf038c21e0d4326f2e826ee7a48eb65f5d480e27bacb7", + "prototypes/connections/store.c": "733ddcacaffd9e9ffbadfc385eadd4c9e62736a2b97b7bc048ad14845d83070f", + "prototypes/connections/runtime.c": "1ced6734ee07f3688e5c9cc0a8af639da88a1741dc3e6f65ec109baa2d826e6f", + "prototypes/connections/evaluate.c": "ee8b91efc733b9d305711b7cbb7b502ae5d3917e06f750b7f62b632ed0ea6d04", + "prototypes/connections/store-port.c": "d6bf17878b325e039360816edcbf8d68e41b373cf3e6128d7795e11ae21fdd6f", + "prototypes/connections/examples/editor.pure": "8ca6c191b98bf53a592ce24f2b5cd040e41f05c4ccdda7a072d5d7f79870c06a" + }, + "environment": { + "platform": "Linux-6.18.39+rpt-rpi-2712-aarch64-with-glibc2.41", + "machine": "aarch64", + "compiler": "cc (Debian 14.2.0-19) 14.2.0", + "size": "GNU size (GNU Binutils for Debian) 2.44" + } +} diff --git a/research/experiments/004-direct-document-path/results/2026-09-24-tmpfs-8k-preliminary-linux-aarch64.json b/research/experiments/004-direct-document-path/results/2026-09-24-tmpfs-8k-preliminary-linux-aarch64.json new file mode 100644 index 0000000..e8a9f5b --- /dev/null +++ b/research/experiments/004-direct-document-path/results/2026-09-24-tmpfs-8k-preliminary-linux-aarch64.json @@ -0,0 +1,322 @@ +{ + "profile": "same-durable-document-app-direct-versus-pure", + "definition_sha256": "8ca6c191b98bf53a592ce24f2b5cd040e41f05c4ccdda7a072d5d7f79870c06a", + "prepared_sha256": "8e93861539a87c2a091f55afea1bf310fc3d1f1474521d8f8318bfacac3b0649", + "documents_per_variant": 256, + "operations_per_variant": 1024, + "body_bytes": 8192, + "pairs": 6, + "sections": { + "direct": { + "text": 10364, + "data": 856, + "bss": 16 + }, + "pure": { + "text": 18640, + "data": 864, + "bss": 376 + } + }, + "binary_sha256": { + "direct": "d265f60f9126da701369c26a6263474164171349867e11079a63b6d9bd1dbbc8", + "pure": "8e71e09bb7923de0e945f4d51c5514dd9ab07a4ff9c0982db712ab895fc54fa0" + }, + "samples": [ + { + "order": [ + "direct", + "pure" + ], + "direct": { + "variant": "direct", + "documents": 256, + "operations": 1024, + "body_bytes": 8192, + "elapsed_ns": 32443218, + "stage_ns": [ + 8080321, + 7513546, + 5301851, + 7787666 + ], + "digest": "b8a08a9615b2eb3b", + "peak_rss_kib": 1056, + "user_ns": 24559000, + "system_ns": 8186000, + "stored_file_bytes": 2103296 + }, + "pure": { + "variant": "pure", + "documents": 256, + "operations": 1024, + "body_bytes": 8192, + "elapsed_ns": 32009201, + "stage_ns": [ + 8131949, + 7162898, + 5457529, + 7487020 + ], + "digest": "b8a08a9615b2eb3b", + "peak_rss_kib": 1056, + "user_ns": 16183000, + "system_ns": 16183000, + "stored_file_bytes": 2103296 + } + }, + { + "order": [ + "pure", + "direct" + ], + "pure": { + "variant": "pure", + "documents": 256, + "operations": 1024, + "body_bytes": 8192, + "elapsed_ns": 31919941, + "stage_ns": [ + 8166312, + 7144299, + 5410416, + 7352779 + ], + "digest": "b8a08a9615b2eb3b", + "peak_rss_kib": 1040, + "user_ns": 20228000, + "system_ns": 12137000, + "stored_file_bytes": 2103296 + }, + "direct": { + "variant": "direct", + "documents": 256, + "operations": 1024, + "body_bytes": 8192, + "elapsed_ns": 32205996, + "stage_ns": [ + 7984983, + 7590856, + 5294584, + 7570908 + ], + "digest": "b8a08a9615b2eb3b", + "peak_rss_kib": 1040, + "user_ns": 16322000, + "system_ns": 16322000, + "stored_file_bytes": 2103296 + } + }, + { + "order": [ + "direct", + "pure" + ], + "direct": { + "variant": "direct", + "documents": 256, + "operations": 1024, + "body_bytes": 8192, + "elapsed_ns": 32589218, + "stage_ns": [ + 8207096, + 7581051, + 5347608, + 7656447 + ], + "digest": "b8a08a9615b2eb3b", + "peak_rss_kib": 1056, + "user_ns": 16529000, + "system_ns": 16529000, + "stored_file_bytes": 2103296 + }, + "pure": { + "variant": "pure", + "documents": 256, + "operations": 1024, + "body_bytes": 8192, + "elapsed_ns": 31973552, + "stage_ns": [ + 8280075, + 7151887, + 5368944, + 7359984 + ], + "digest": "b8a08a9615b2eb3b", + "peak_rss_kib": 1056, + "user_ns": 24311000, + "system_ns": 8103000, + "stored_file_bytes": 2103296 + } + }, + { + "order": [ + "pure", + "direct" + ], + "pure": { + "variant": "pure", + "documents": 256, + "operations": 1024, + "body_bytes": 8192, + "elapsed_ns": 32080256, + "stage_ns": [ + 8156569, + 7173028, + 5460655, + 7396332 + ], + "digest": "b8a08a9615b2eb3b", + "peak_rss_kib": 1056, + "user_ns": 28408000, + "system_ns": 4058000, + "stored_file_bytes": 2103296 + }, + "direct": { + "variant": "direct", + "documents": 256, + "operations": 1024, + "body_bytes": 8192, + "elapsed_ns": 32571829, + "stage_ns": [ + 8142638, + 7715426, + 5329257, + 7625344 + ], + "digest": "b8a08a9615b2eb3b", + "peak_rss_kib": 1040, + "user_ns": 12350000, + "system_ns": 20584000, + "stored_file_bytes": 2103296 + } + }, + { + "order": [ + "direct", + "pure" + ], + "direct": { + "variant": "direct", + "documents": 256, + "operations": 1024, + "body_bytes": 8192, + "elapsed_ns": 32290107, + "stage_ns": [ + 8045372, + 7543971, + 5349434, + 7600138 + ], + "digest": "b8a08a9615b2eb3b", + "peak_rss_kib": 1056, + "user_ns": 20455000, + "system_ns": 12273000, + "stored_file_bytes": 2103296 + }, + "pure": { + "variant": "pure", + "documents": 256, + "operations": 1024, + "body_bytes": 8192, + "elapsed_ns": 32067756, + "stage_ns": [ + 8225774, + 7252055, + 5472276, + 7359265 + ], + "digest": "b8a08a9615b2eb3b", + "peak_rss_kib": 1056, + "user_ns": 4064000, + "system_ns": 28454000, + "stored_file_bytes": 2103296 + } + }, + { + "order": [ + "pure", + "direct" + ], + "pure": { + "variant": "pure", + "documents": 256, + "operations": 1024, + "body_bytes": 8192, + "elapsed_ns": 32372144, + "stage_ns": [ + 8141941, + 7171001, + 5629064, + 7673781 + ], + "digest": "b8a08a9615b2eb3b", + "peak_rss_kib": 1056, + "user_ns": 21685000, + "system_ns": 10842000, + "stored_file_bytes": 2103296 + }, + "direct": { + "variant": "direct", + "documents": 256, + "operations": 1024, + "body_bytes": 8192, + "elapsed_ns": 32314570, + "stage_ns": [ + 8063229, + 7512835, + 5380849, + 7585506 + ], + "digest": "b8a08a9615b2eb3b", + "peak_rss_kib": 1056, + "user_ns": 16375000, + "system_ns": 16375000, + "stored_file_bytes": 2103296 + } + } + ], + "medians": { + "direct": { + "elapsed_ms": 32.378894, + "peak_rss_kib": 1056.0, + "user_ms": 16.452, + "system_ms": 16.3485, + "stages_ms": [ + 8.071775, + 7.562511, + 5.3384325, + 7.612741 + ] + }, + "pure": { + "elapsed_ms": 32.0384785, + "peak_rss_kib": 1056.0, + "user_ms": 20.9565, + "system_ms": 11.4895, + "stages_ms": [ + 8.1614405, + 7.1669495, + 5.459092, + 7.378158 + ] + } + }, + "median_elapsed_ratio_pure_over_direct": 0.9894865000638995, + "sources_sha256": { + "research/experiments/004-direct-document-path/document-path.c": "032d8688db330c355082d150865aa7ade3e5402cc1bbe090b361fd55cb6325fc", + "research/experiments/004-direct-document-path/peak-launcher.c": "fc730205d564b60a4f9e44aa1b880df0debeb1338b86b27eabe3bde1508f3f74", + "research/experiments/004-direct-document-path/run.py": "1919287fb5dc0f884cecf038c21e0d4326f2e826ee7a48eb65f5d480e27bacb7", + "prototypes/connections/store.c": "733ddcacaffd9e9ffbadfc385eadd4c9e62736a2b97b7bc048ad14845d83070f", + "prototypes/connections/runtime.c": "1ced6734ee07f3688e5c9cc0a8af639da88a1741dc3e6f65ec109baa2d826e6f", + "prototypes/connections/evaluate.c": "ee8b91efc733b9d305711b7cbb7b502ae5d3917e06f750b7f62b632ed0ea6d04", + "prototypes/connections/store-port.c": "d6bf17878b325e039360816edcbf8d68e41b373cf3e6128d7795e11ae21fdd6f", + "prototypes/connections/examples/editor.pure": "8ca6c191b98bf53a592ce24f2b5cd040e41f05c4ccdda7a072d5d7f79870c06a" + }, + "environment": { + "platform": "Linux-6.18.39+rpt-rpi-2712-aarch64-with-glibc2.41", + "machine": "aarch64", + "compiler": "cc (Debian 14.2.0-19) 14.2.0", + "size": "GNU size (GNU Binutils for Debian) 2.44" + } +} diff --git a/research/experiments/004-direct-document-path/run.py b/research/experiments/004-direct-document-path/run.py new file mode 100644 index 0000000..4987fd7 --- /dev/null +++ b/research/experiments/004-direct-document-path/run.py @@ -0,0 +1,160 @@ +#!/usr/bin/env python3 +"""Compare the same durable document job through Pure and direct store calls.""" +import argparse +import hashlib +import json +import os +from pathlib import Path +import platform +import statistics +import subprocess +import tempfile + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[2] +CONNECTIONS = ROOT / 'prototypes/connections' +EDITOR_SHA256 = '8ca6c191b98bf53a592ce24f2b5cd040e41f05c4ccdda7a072d5d7f79870c06a' + + +def sha(path): + return hashlib.sha256(path.read_bytes()).hexdigest() + + +def run(command, timeout=180): + result = subprocess.run([str(item) for item in command], capture_output=True, + text=True, timeout=timeout) + if result.returncode: + raise AssertionError((result.args, result.returncode, + result.stdout[-2000:], result.stderr[-2000:])) + return result + + +def compile_all(directory, cc, body_bytes): + flags = [cc, '-O2', '-std=c17', '-Wall', '-Wextra', '-Wpedantic', '-Werror', + f'-DPURE_BENCH_BODY_BYTES={body_bytes}'] + compiler = directory / 'pure-compile' + run([*flags, CONNECTIONS / 'compile-program.c', CONNECTIONS / 'program.c', + '-o', compiler]) + header = directory / 'embedded-plan.h' + run([compiler, CONNECTIONS / 'examples/editor.pure', header]) + common = [HERE / 'document-path.c', CONNECTIONS / 'store.c'] + direct = directory / 'direct' + pure = directory / 'pure' + run([*flags, '-DDIRECT_PATH', '-I' + str(CONNECTIONS), *common, '-o', direct]) + run([*flags, '-I' + str(CONNECTIONS), '-I' + str(directory), *common, + CONNECTIONS / 'store-port.c', CONNECTIONS / 'runtime.c', + CONNECTIONS / 'evaluate.c', '-o', pure]) + launcher = directory / 'peak-launcher' + run([*flags, HERE / 'peak-launcher.c', '-o', launcher]) + return {'direct': direct, 'pure': pure}, launcher, header + + +def sections(binary): + fields = run(['size', binary]).stdout.splitlines()[1].split() + return {'text': int(fields[0]), 'data': int(fields[1]), 'bss': int(fields[2])} + + +def trial(binary, launcher, store, documents): + result = run([launcher, binary, store, documents]) + measured = json.loads(result.stdout) + resources = dict(line.split('=', 1) for line in result.stderr.splitlines()) + measured['peak_rss_kib'] = int(resources['PURE_PEAK_RSS_KIB']) + measured['user_ns'] = int(resources['PURE_USER_NS']) + measured['system_ns'] = int(resources['PURE_SYSTEM_NS']) + objects = sorted(store.glob('obj-*')) + assert len(objects) == documents, len(objects) + measured['stored_file_bytes'] = sum(path.stat().st_size for path in objects) + final_files = hashlib.sha256() + for path in objects: + content = path.read_bytes() + final_files.update(path.name.encode('ascii')) + final_files.update(len(content).to_bytes(8, 'little')) + final_files.update(content) + measured['stored_files_sha256'] = final_files.hexdigest() + assert measured['documents'] == documents and measured['operations'] == 4 * documents + return measured + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--cc', default=os.environ.get('CC', 'cc')) + parser.add_argument('--documents', type=int, default=256) + parser.add_argument('--body-bytes', type=int, default=8192) + parser.add_argument('--pairs', type=int, default=4) + parser.add_argument('--work-root', type=Path, default=HERE / 'results', + help='filesystem for fresh stores; default is the repository filesystem') + parser.add_argument('--output', type=Path) + args = parser.parse_args() + if (not 1 <= args.documents <= 4096 or not 1 <= args.pairs <= 16 or + not 1 <= args.body_bytes <= 1024 * 1024): + parser.error('documents must be 1..4096, pairs 1..16 and body-bytes 1..1048576') + if args.output and args.output.exists(): + parser.error('evidence file already exists') + if platform.system() != 'Linux': + parser.error('this release RSS apparatus uses Linux wait4 units') + definition = CONNECTIONS / 'examples/editor.pure' + assert sha(definition) == EDITOR_SHA256, 'direct baseline needs review after editor.pure changes' + args.work_root.mkdir(parents=True, exist_ok=True) + filesystem = run(['df', '-T', args.work_root]).stdout.splitlines()[1].split() + with tempfile.TemporaryDirectory(prefix='pure-direct-document-', dir=args.work_root) as name: + root = Path(name) + binaries, launcher, prepared = compile_all(root, args.cc, args.body_bytes) + sizes = {name: sections(binary) for name, binary in binaries.items()} + binaries_sha = {name: sha(binary) for name, binary in binaries.items()} + # One small untimed run per path loads shared code and catches a broken + # comparison before the measured alternating, fresh-store trials. + warmups = {name: trial(binary, launcher, root / ('warm-' + name), 4) + for name, binary in binaries.items()} + assert warmups['direct']['digest'] == warmups['pure']['digest'] + samples = [] + for pair in range(args.pairs): + order = ('direct', 'pure') if pair % 2 == 0 else ('pure', 'direct') + entry = {'order': list(order)} + for variant in order: + entry[variant] = trial(binaries[variant], launcher, + root / f'{pair}-{variant}', args.documents) + assert entry['direct']['digest'] == entry['pure']['digest'] + assert entry['direct']['stored_file_bytes'] == entry['pure']['stored_file_bytes'] + assert entry['direct']['stored_files_sha256'] == entry['pure']['stored_files_sha256'] + samples.append(entry) + prepared_sha = sha(prepared) + medians = {variant: {'elapsed_ms': statistics.median( + sample[variant]['elapsed_ns'] for sample in samples) / 1e6, + 'peak_rss_kib': statistics.median( + sample[variant]['peak_rss_kib'] for sample in samples), + 'user_ms': statistics.median( + sample[variant]['user_ns'] for sample in samples) / 1e6, + 'system_ms': statistics.median( + sample[variant]['system_ns'] for sample in samples) / 1e6, + 'stages_ms': [statistics.median( + sample[variant]['stage_ns'][i] for sample in samples) / 1e6 + for i in range(4)]} + for variant in ('direct', 'pure')} + result = {'profile': 'same-durable-document-app-direct-versus-pure', + 'definition_sha256': sha(definition), 'prepared_sha256': prepared_sha, + 'documents_per_variant': args.documents, + 'operations_per_variant': args.documents * 4, + 'body_bytes': args.body_bytes, 'pairs': args.pairs, + 'filesystem': {'device': filesystem[0], 'type': filesystem[1], + 'mount': filesystem[-1]}, + 'sections': sizes, 'binary_sha256': binaries_sha, + 'samples': samples, 'medians': medians, + 'median_elapsed_ratio_pure_over_direct': + medians['pure']['elapsed_ms'] / medians['direct']['elapsed_ms'], + 'sources_sha256': {str(path.relative_to(ROOT)): sha(path) + for path in [HERE / 'document-path.c', HERE / 'peak-launcher.c', + HERE / 'run.py', CONNECTIONS / 'store.c', + CONNECTIONS / 'runtime.c', CONNECTIONS / 'evaluate.c', + CONNECTIONS / 'store-port.c', definition]}, + 'environment': {'platform': platform.platform(), 'machine': platform.machine(), + 'compiler': run([args.cc, '--version']).stdout.splitlines()[0], + 'size': run(['size', '--version']).stdout.splitlines()[0]}} + body = json.dumps(result, indent=2) + '\n' + if args.output: + args.output.parent.mkdir(parents=True, exist_ok=True) + args.output.write_text(body) + print(body, end='') + + +if __name__ == '__main__': + main() diff --git a/research/experiments/005-direct-document-peer/README.md b/research/experiments/005-direct-document-peer/README.md new file mode 100644 index 0000000..d35ba20 --- /dev/null +++ b/research/experiments/005-direct-document-peer/README.md @@ -0,0 +1,60 @@ +# Authenticated document peer: direct versus Pure + +This experiment uses the real `editor.pure` document app over the same TLS +1.3/TCP transport and `pure-doc/1` wire format. `direct-peer.c` is a +research-only server that parses the same authored program and calls the same +store and evaluator directly. `pure-document-server` is the selected product +server build without its native client commands. The baseline is limited to +the tested synchronous document workflow: it has no Pure work tickets, +admission/lifetime contract, cross-domain forwarding, or cancellation. + +Both servers passed the existing `check_document_peer.py` suite: mutual TLS +identity, ALPN, source identity, external Python and native C clients, version +conflicts, one-byte replacement of a 1 MiB value, fragmented/invalid/truncated +frames, deadlines, and restart. The direct and Pure server builds passed the +same suite under ASan/UBSan. These checks do not establish full feature or +security equivalence under concurrent clients or failure networks. + +To run the selected product checks on Linux AArch64: + +```sh +make -C prototypes/connections check-document-peer +make -C prototypes/connections check-document-server +``` + +The first command checks the existing combined client/server executable; the +second checks the server-only code ceiling and runs the same peer scenarios +with the native C client from the combined executable. Both need permission +to bind a local TCP port. The server-only executable and budget are optional; +the default core and CLI do not link TLS. + +To reproduce the read comparison: + +```sh +python3 research/experiments/005-direct-document-peer/run.py \ + --body-bytes 8192 --reads 1024 --pairs 6 \ + --output research/experiments/005-direct-document-peer/results/local-8k.json +python3 research/experiments/005-direct-document-peer/run.py \ + --body-bytes 1048576 --reads 64 --pairs 4 \ + --output research/experiments/005-direct-document-peer/results/local-1m.json +``` + +The runner compiles both servers from source. Each trial creates and reads a +real stored document, then times repeated full reads on one authenticated, +persistent Python TLS connection. It verifies every response and the final +stored file hash. TLS handshake, certificate creation, file creation, and the +first cache-warming read are outside the timed batch. The server process RSS +is recorded before and after. Fresh stores and alternating order reduce some +order effects but do not control CPU frequency, OpenSSL or Python overhead, +network behavior beyond local loopback, or host scheduling. The JSON files +contain all individual samples, source hashes, compiler and OpenSSL versions. + +The short `before-nodelay` and `after-nodelay` artifacts repeat exactly 32 +authenticated 8 KiB reads through each server, differing only in the common +TLS transport's TCP_NODELAY option. This intervention supports a Nagle/delayed +ACK explanation for the prior ~44 ms per-request stall; no packet trace was +captured, so that exact kernel interaction remains an inference. The longer +post-change runs are for direct-versus-Pure cost, not a claim of Internet or +Kitex/QUIC performance. + +See [the result report](../../../docs/research/055-authenticated-peer-transport-cost.md). diff --git a/research/experiments/005-direct-document-peer/direct-peer-parity-linux-aarch64.json b/research/experiments/005-direct-document-peer/direct-peer-parity-linux-aarch64.json new file mode 100644 index 0000000..05c62cc --- /dev/null +++ b/research/experiments/005-direct-document-peer/direct-peer-parity-linux-aarch64.json @@ -0,0 +1,16 @@ +{ + "profile": "selected-authenticated-document-peer", + "checks": [ + "mutual certificate identity, server hostname and ALPN separation", + "program source identity checked before C client sends work", + "persistent external TLS client: create, read, conflict and recovery", + "native peer edit and local CLI use the same authored document and storage", + "fragmented 1 MiB direct ingress, demand-selected reply and one-byte splice", + "native C peer uploads 1 MiB and receives only the requested metadata", + "incomplete, invalid and oversized frames do not publish a change", + "idle authenticated session closes after deadline", + "server restart and native C peer preserve the committed large document" + ], + "server_idle_rss_kib": 7968, + "server_after_large_work_rss_kib": 9712 +} diff --git a/research/experiments/005-direct-document-peer/direct-peer-sanitized-parity-linux-aarch64.json b/research/experiments/005-direct-document-peer/direct-peer-sanitized-parity-linux-aarch64.json new file mode 100644 index 0000000..356128d --- /dev/null +++ b/research/experiments/005-direct-document-peer/direct-peer-sanitized-parity-linux-aarch64.json @@ -0,0 +1,16 @@ +{ + "profile": "selected-authenticated-document-peer", + "checks": [ + "mutual certificate identity, server hostname and ALPN separation", + "program source identity checked before C client sends work", + "persistent external TLS client: create, read, conflict and recovery", + "native peer edit and local CLI use the same authored document and storage", + "fragmented 1 MiB direct ingress, demand-selected reply and one-byte splice", + "native C peer uploads 1 MiB and receives only the requested metadata", + "incomplete, invalid and oversized frames do not publish a change", + "idle authenticated session closes after deadline", + "server restart and native C peer preserve the committed large document" + ], + "server_idle_rss_kib": 22528, + "server_after_large_work_rss_kib": 31632 +} diff --git a/research/experiments/005-direct-document-peer/direct-peer.c b/research/experiments/005-direct-document-peer/direct-peer.c new file mode 100644 index 0000000..437672d --- /dev/null +++ b/research/experiments/005-direct-document-peer/direct-peer.c @@ -0,0 +1,207 @@ +#define _POSIX_C_SOURCE 200809L +/* Research-only server. It shares the product peer's TLS transport, wire + * format, program parser/evaluator, and store, but calls the store directly. */ +#include "program.h" +#include "store.h" +#include "../../../prototypes/common/tls-link.h" +#include <openssl/err.h> +#include <openssl/sha.h> +#include <arpa/inet.h> +#include <errno.h> +#include <inttypes.h> +#include <poll.h> +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/socket.h> +#include <unistd.h> + +enum { REQUEST_BYTES = 14, REPLY_BYTES = 13, HELLO_BYTES = 40, + OP_READ = 1, OP_WRITE = 2, WANT_BODY = 0x80 }; +static const unsigned char alpn[] = {10, 'p','u','r','e','-','d','o','c','/','1'}; +static volatile sig_atomic_t stopping; +static void signal_stop(int signum) { (void)signum; stopping = 1; } + +typedef struct { PureResult status; int64_t revision; PureSpan body; } DirectOutcome; + +static uint32_t get32(const unsigned char *p) { + return ((uint32_t)p[0] << 24) | ((uint32_t)p[1] << 16) | ((uint32_t)p[2] << 8) | p[3]; +} +static uint64_t get64(const unsigned char *p) { + uint64_t value = 0; + for (unsigned i = 0; i < 8; ++i) value = (value << 8) | p[i]; + return value; +} +static void put32(unsigned char *p, uint32_t value) { + for (unsigned i = 0; i < 4; ++i) p[i] = (unsigned char)(value >> (24 - 8 * i)); +} +static void put64(unsigned char *p, uint64_t value) { + for (unsigned i = 0; i < 8; ++i) p[i] = (unsigned char)(value >> (56 - 8 * i)); +} +static bool number(const char *text, uint64_t limit, uint64_t *out) { + if (!text || !*text) return false; + uint64_t value = 0; + for (; *text; ++text) { + if (*text < '0' || *text > '9') return false; + unsigned digit = (unsigned)(*text - '0'); + if (digit > limit || value > (limit - digit) / 10) return false; + value = value * 10 + digit; + } + *out = value; + return true; +} +static bool valid_key(const char *key) { + if (!key || !*key) return false; + size_t size = 0; + for (; size <= 64 && key[size]; ++size) { + unsigned char c = (unsigned char)key[size]; + if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || + (c >= '0' && c <= '9') || c == '-' || c == '_')) return false; + } + return size <= 64; +} +static bool load_program(const char *path, PureProgram *program, unsigned char digest[32]) { + FILE *file = fopen(path, "rb"); + if (!file) return false; + char source[PURE_PROGRAM_LIMIT + 1]; + size_t length = fread(source, 1, sizeof(source), file); + bool bad = ferror(file) != 0; + if (fclose(file)) bad = true; + char error[160]; + if (bad || !pure_program_parse(source, length, program, error, sizeof(error))) { + if (!bad) fprintf(stderr, "Program: %s\n", error); + return false; + } + return SHA256((const unsigned char *)source, length, digest) != NULL; +} +static bool write_hello(PureLink *link, const unsigned char digest[32], uint64_t deadline) { + unsigned char hello[HELLO_BYTES] = {'P','D','O','C',1,0,0,0}; + memcpy(hello + 8, digest, 32); + return pure_link_write(link, hello, sizeof(hello), deadline); +} +static bool send_result(PureLink *link, DirectOutcome outcome, bool want_body, uint64_t deadline) { + if (outcome.status > PURE_ALLOCATION || outcome.revision < 0 || + outcome.body.size > PURE_OBJECT_LIMIT || (outcome.body.size && !outcome.body.data)) return false; + unsigned char header[REPLY_BYTES]; + header[0] = (unsigned char)outcome.status; + put64(header + 1, (uint64_t)outcome.revision); + put32(header + 9, (uint32_t)outcome.body.size); + return pure_link_write(link, header, sizeof(header), deadline) && + (!want_body || pure_link_write(link, outcome.body.data, outcome.body.size, deadline)); +} +static bool serve_request(PureLink *link, const PureProgram *program, const char *store, int *end) { + uint64_t deadline = pure_link_now_ms() + PURE_LINK_DEADLINE_MS; + unsigned char header[REQUEST_BYTES]; + int got = pure_link_read(link, header, sizeof(header), deadline); + if (!got) { *end = 1; return true; } + if (got != 1) return false; + unsigned op = header[0] & ~WANT_BODY, key_size = header[1]; + bool want_body = (header[0] & WANT_BODY) != 0; + uint64_t expected = get64(header + 2); + uint32_t body_size = get32(header + 10); + if ((op != OP_READ && op != OP_WRITE) || !key_size || key_size > 64 || + expected > INT64_MAX || body_size > PURE_OBJECT_LIMIT || + (op == OP_READ && (expected || body_size))) return false; + char key[65]; + if (pure_link_read(link, key, key_size, deadline) != 1) return false; + if (memchr(key, 0, key_size)) return false; + key[key_size] = 0; + if (!valid_key(key)) { + (void)send_result(link, (DirectOutcome){.status = PURE_INVALID}, want_body, deadline); + return false; + } + DirectOutcome outcome = {0}; + if (op == OP_READ) { + PureStoredView view = {0}; + outcome.status = pure_store_select(store, key, program->read.offset, + program->read.length, program->read.to_end, program->read_required, + 4u * 1024u * 1024u, &view); + if (outcome.status == PURE_OK) { + outcome.body = view.body; + outcome.revision = view.revision; + } + bool sent = send_result(link, outcome, want_body, deadline); + pure_store_release(&view); + return sent; + } + unsigned char *input = body_size ? malloc(body_size) : NULL; + if (body_size && !input) { + (void)send_result(link, (DirectOutcome){.status = PURE_ALLOCATION}, want_body, deadline); + return false; /* Body deliberately not consumed after rejected admission. */ + } + if (body_size && pure_link_read(link, input, body_size, deadline) != 1) { + free(input); + return false; + } + PureSpan value = {0}, reply = {0}, source = {input, body_size}; + size_t offset = 0, remove = 0; + if (!pure_program_input(program, source, &value, &reply) || + (program->splice && !pure_program_splice(program, source, &offset, &remove))) + outcome.status = PURE_LIMIT; + else if (program->splice) + outcome.status = pure_store_splice(store, key, (int64_t)expected, + offset, remove, value, &outcome.revision); + else outcome.status = pure_store_put(store, key, (int64_t)expected, value, + &outcome.revision); + if (outcome.status == PURE_OK) outcome.body = reply; + bool sent = send_result(link, outcome, want_body, deadline); + free(input); + return sent; +} +static bool serve_connection(PureLink *link, const PureProgram *program, const char *store, + const unsigned char digest[32]) { + if (!write_hello(link, digest, pure_link_now_ms() + PURE_LINK_DEADLINE_MS)) return false; + int end = 0; + while (!end) if (!serve_request(link, program, store, &end)) return false; + return true; +} +static int serve(const char *bind_address, const char *port, const char *program_path, + const char *store, const char *ca, const char *cert, + const char *key, const char *client_name, unsigned max_connections) { + if (!pure_link_port_number(port, true) || !client_name || !*client_name) return 2; + PureProgram program; + unsigned char digest[32]; + if (!load_program(program_path, &program, digest) || pure_store_init(store) != PURE_OK) return 2; + SSL_CTX *ctx = pure_link_context(true, ca, cert, key, alpn); + if (!ctx) { ERR_print_errors_fp(stderr); return 2; } + int listener = pure_link_listen_at(bind_address, port); + if (listener < 0) { perror("listen"); SSL_CTX_free(ctx); return 2; } + struct sockaddr_storage address; + socklen_t address_size = sizeof(address); + if (getsockname(listener, (struct sockaddr *)&address, &address_size)) abort(); + unsigned actual_port = address.ss_family == AF_INET + ? ntohs(((struct sockaddr_in *)&address)->sin_port) + : ntohs(((struct sockaddr_in6 *)&address)->sin6_port); + printf("READY %u\n", actual_port); fflush(stdout); + signal(SIGTERM, signal_stop); signal(SIGINT, signal_stop); + unsigned accepted = 0; + while (!stopping && (!max_connections || accepted < max_connections)) { + struct pollfd p = {.fd = listener, .events = POLLIN}; + int result = poll(&p, 1, 1000); + if (result < 0) { if (errno == EINTR) continue; break; } + if (!result) continue; + int fd = accept(listener, NULL, NULL); + if (fd < 0) { if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) continue; break; } + ++accepted; + PureLink link = {.fd = fd}; + bool healthy = pure_link_nonblocking(fd) && + pure_link_handshake(&link, ctx, true, client_name, alpn); + if (healthy) healthy = serve_connection(&link, &program, store, digest); + pure_link_close(&link, healthy); + } + close(listener); + SSL_CTX_free(ctx); + return 0; +} +int main(int argc, char **argv) { + signal(SIGPIPE, SIG_IGN); + if ((argc == 10 || argc == 11) && !strcmp(argv[1], "serve")) { + uint64_t limit = 0; + if (argc == 11 && (!number(argv[10], UINT32_MAX, &limit) || !limit)) return 2; + return serve(argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], + (unsigned)limit); + } + fputs("direct-peer serve BIND_IP PORT PROGRAM STORE_DIR CA CERT KEY CLIENT_DNS [MAX_CONNECTIONS]\n", stderr); + return 2; +} diff --git a/research/experiments/005-direct-document-peer/pure-peer-after-nodelay-parity-linux-aarch64.json b/research/experiments/005-direct-document-peer/pure-peer-after-nodelay-parity-linux-aarch64.json new file mode 100644 index 0000000..45598a9 --- /dev/null +++ b/research/experiments/005-direct-document-peer/pure-peer-after-nodelay-parity-linux-aarch64.json @@ -0,0 +1,16 @@ +{ + "profile": "selected-authenticated-document-peer", + "checks": [ + "mutual certificate identity, server hostname and ALPN separation", + "program source identity checked before C client sends work", + "persistent external TLS client: create, read, conflict and recovery", + "native peer edit and local CLI use the same authored document and storage", + "fragmented 1 MiB direct ingress, demand-selected reply and one-byte splice", + "native C peer uploads 1 MiB and receives only the requested metadata", + "incomplete, invalid and oversized frames do not publish a change", + "idle authenticated session closes after deadline", + "server restart and native C peer preserve the committed large document" + ], + "server_idle_rss_kib": 7952, + "server_after_large_work_rss_kib": 9696 +} diff --git a/research/experiments/005-direct-document-peer/pure-peer-parity-linux-aarch64.json b/research/experiments/005-direct-document-peer/pure-peer-parity-linux-aarch64.json new file mode 100644 index 0000000..05c62cc --- /dev/null +++ b/research/experiments/005-direct-document-peer/pure-peer-parity-linux-aarch64.json @@ -0,0 +1,16 @@ +{ + "profile": "selected-authenticated-document-peer", + "checks": [ + "mutual certificate identity, server hostname and ALPN separation", + "program source identity checked before C client sends work", + "persistent external TLS client: create, read, conflict and recovery", + "native peer edit and local CLI use the same authored document and storage", + "fragmented 1 MiB direct ingress, demand-selected reply and one-byte splice", + "native C peer uploads 1 MiB and receives only the requested metadata", + "incomplete, invalid and oversized frames do not publish a change", + "idle authenticated session closes after deadline", + "server restart and native C peer preserve the committed large document" + ], + "server_idle_rss_kib": 7968, + "server_after_large_work_rss_kib": 9712 +} diff --git a/research/experiments/005-direct-document-peer/pure-server-after-nodelay-parity-linux-aarch64.json b/research/experiments/005-direct-document-peer/pure-server-after-nodelay-parity-linux-aarch64.json new file mode 100644 index 0000000..05c62cc --- /dev/null +++ b/research/experiments/005-direct-document-peer/pure-server-after-nodelay-parity-linux-aarch64.json @@ -0,0 +1,16 @@ +{ + "profile": "selected-authenticated-document-peer", + "checks": [ + "mutual certificate identity, server hostname and ALPN separation", + "program source identity checked before C client sends work", + "persistent external TLS client: create, read, conflict and recovery", + "native peer edit and local CLI use the same authored document and storage", + "fragmented 1 MiB direct ingress, demand-selected reply and one-byte splice", + "native C peer uploads 1 MiB and receives only the requested metadata", + "incomplete, invalid and oversized frames do not publish a change", + "idle authenticated session closes after deadline", + "server restart and native C peer preserve the committed large document" + ], + "server_idle_rss_kib": 7968, + "server_after_large_work_rss_kib": 9712 +} diff --git a/research/experiments/005-direct-document-peer/pure-server-after-nodelay-profile-linux-aarch64.json b/research/experiments/005-direct-document-peer/pure-server-after-nodelay-profile-linux-aarch64.json new file mode 100644 index 0000000..0f6a3ce --- /dev/null +++ b/research/experiments/005-direct-document-peer/pure-server-after-nodelay-profile-linux-aarch64.json @@ -0,0 +1,23 @@ +{ + "passed": true, + "failures": [], + "profile": "linux-aarch64-gcc14-selected-document-server", + "scope": "Reviewed server-only TLS peer ceiling on Linux AArch64/GCC 14. Excludes linked native client code and shared OpenSSL/libc implementations; process RSS is measured separately.", + "budget_sha256": "deae8827323061543193779ada90d1bca4db3a6dda80293e4ad28a9526be9819", + "platform": "Linux-6.18.39+rpt-rpi-2712-aarch64-with-glibc2.41", + "binaries": { + "pure-document-server": { + "sections": { + "text": 43462, + "data": 1352, + "bss": 16 + }, + "needed": [ + "libc.so.6", + "libcrypto.so.3", + "libssl.so.3" + ], + "sha256": "728025cfbdbcdb6d212a2ec8297a0740967653c77ae8908d923c59ddd4ea0315" + } + } +} diff --git a/research/experiments/005-direct-document-peer/pure-server-parity-linux-aarch64.json b/research/experiments/005-direct-document-peer/pure-server-parity-linux-aarch64.json new file mode 100644 index 0000000..05c62cc --- /dev/null +++ b/research/experiments/005-direct-document-peer/pure-server-parity-linux-aarch64.json @@ -0,0 +1,16 @@ +{ + "profile": "selected-authenticated-document-peer", + "checks": [ + "mutual certificate identity, server hostname and ALPN separation", + "program source identity checked before C client sends work", + "persistent external TLS client: create, read, conflict and recovery", + "native peer edit and local CLI use the same authored document and storage", + "fragmented 1 MiB direct ingress, demand-selected reply and one-byte splice", + "native C peer uploads 1 MiB and receives only the requested metadata", + "incomplete, invalid and oversized frames do not publish a change", + "idle authenticated session closes after deadline", + "server restart and native C peer preserve the committed large document" + ], + "server_idle_rss_kib": 7968, + "server_after_large_work_rss_kib": 9712 +} diff --git a/research/experiments/005-direct-document-peer/pure-server-profile-linux-aarch64.json b/research/experiments/005-direct-document-peer/pure-server-profile-linux-aarch64.json new file mode 100644 index 0000000..c74cdf9 --- /dev/null +++ b/research/experiments/005-direct-document-peer/pure-server-profile-linux-aarch64.json @@ -0,0 +1,23 @@ +{ + "passed": true, + "failures": [], + "profile": "linux-aarch64-gcc14-selected-document-server", + "scope": "Reviewed server-only TLS peer ceiling on Linux AArch64/GCC 14. Excludes linked native client code and shared OpenSSL/libc implementations; process RSS is measured separately.", + "budget_sha256": "deae8827323061543193779ada90d1bca4db3a6dda80293e4ad28a9526be9819", + "platform": "Linux-6.18.39+rpt-rpi-2712-aarch64-with-glibc2.41", + "binaries": { + "pure-document-server": { + "sections": { + "text": 43462, + "data": 1352, + "bss": 16 + }, + "needed": [ + "libc.so.6", + "libcrypto.so.3", + "libssl.so.3" + ], + "sha256": "ea88a146270cea96faf976b548ceba7179c535042ec3a8656e92c3596372f9aa" + } + } +} diff --git a/research/experiments/005-direct-document-peer/pure-server-sanitized-parity-linux-aarch64.json b/research/experiments/005-direct-document-peer/pure-server-sanitized-parity-linux-aarch64.json new file mode 100644 index 0000000..161dd4f --- /dev/null +++ b/research/experiments/005-direct-document-peer/pure-server-sanitized-parity-linux-aarch64.json @@ -0,0 +1,16 @@ +{ + "profile": "selected-authenticated-document-peer", + "checks": [ + "mutual certificate identity, server hostname and ALPN separation", + "program source identity checked before C client sends work", + "persistent external TLS client: create, read, conflict and recovery", + "native peer edit and local CLI use the same authored document and storage", + "fragmented 1 MiB direct ingress, demand-selected reply and one-byte splice", + "native C peer uploads 1 MiB and receives only the requested metadata", + "incomplete, invalid and oversized frames do not publish a change", + "idle authenticated session closes after deadline", + "server restart and native C peer preserve the committed large document" + ], + "server_idle_rss_kib": 22640, + "server_after_large_work_rss_kib": 31776 +} diff --git a/research/experiments/005-direct-document-peer/results/2026-09-24-after-nodelay-8k-linux-aarch64.json b/research/experiments/005-direct-document-peer/results/2026-09-24-after-nodelay-8k-linux-aarch64.json new file mode 100644 index 0000000..f739b2b --- /dev/null +++ b/research/experiments/005-direct-document-peer/results/2026-09-24-after-nodelay-8k-linux-aarch64.json @@ -0,0 +1,109 @@ +{ + "profile": "authenticated-document-read-direct-versus-pure", + "definition_sha256": "8ca6c191b98bf53a592ce24f2b5cd040e41f05c4ccdda7a072d5d7f79870c06a", + "body_bytes": 8192, + "reads_per_trial": 32, + "pairs": 2, + "filesystem": { + "device": "/dev/mmcblk0p2", + "type": "ext4", + "mount": "/" + }, + "sections": { + "direct": { + "text": 37862, + "data": 1352, + "bss": 16 + }, + "pure": { + "text": 43454, + "data": 1352, + "bss": 16 + } + }, + "binary_sha256": { + "direct": "9177aebfae07d84af5b6f23fbfe28a3a89a494943b8d0c8d0d35b68593b1f704", + "pure": "be9f569ab444085c761a7f7c9aa91c2acd6581534059785964b3a94da89fff25" + }, + "samples": [ + { + "order": [ + "direct", + "pure" + ], + "direct": { + "reads": 32, + "body_bytes": 8192, + "elapsed_ns": 3028977, + "server_rss_before_kib": 8640, + "server_rss_after_kib": 8640, + "stored_file_bytes": 8216, + "stored_file_sha256": "286cfc86e3ebe6d82dd923ef777eba30f748e8b1dd58d5c4352babbf85d0d64f" + }, + "pure": { + "reads": 32, + "body_bytes": 8192, + "elapsed_ns": 2564107, + "server_rss_before_kib": 8640, + "server_rss_after_kib": 8640, + "stored_file_bytes": 8216, + "stored_file_sha256": "286cfc86e3ebe6d82dd923ef777eba30f748e8b1dd58d5c4352babbf85d0d64f" + } + }, + { + "order": [ + "pure", + "direct" + ], + "pure": { + "reads": 32, + "body_bytes": 8192, + "elapsed_ns": 3016236, + "server_rss_before_kib": 8640, + "server_rss_after_kib": 8640, + "stored_file_bytes": 8216, + "stored_file_sha256": "286cfc86e3ebe6d82dd923ef777eba30f748e8b1dd58d5c4352babbf85d0d64f" + }, + "direct": { + "reads": 32, + "body_bytes": 8192, + "elapsed_ns": 3019977, + "server_rss_before_kib": 8624, + "server_rss_after_kib": 8624, + "stored_file_bytes": 8216, + "stored_file_sha256": "286cfc86e3ebe6d82dd923ef777eba30f748e8b1dd58d5c4352babbf85d0d64f" + } + } + ], + "medians": { + "direct": { + "elapsed_ms": 3.024477, + "server_rss_before_kib": 8632.0, + "server_rss_after_kib": 8632.0 + }, + "pure": { + "elapsed_ms": 2.7901715, + "server_rss_before_kib": 8640.0, + "server_rss_after_kib": 8640.0 + } + }, + "sources_sha256": { + "research/experiments/005-direct-document-peer/direct-peer.c": "b1ee6ba5ec3d09b842ac42d4ca158b339ec2d23b157d2c568180af2731737501", + "research/experiments/005-direct-document-peer/run.py": "b53539f0a915376397011713ebbc9438a9b289d3b4dd745ffab5d6039fccd958", + "prototypes/connections/document-peer.c": "0c72121a6929239f618f8a642247af13fb5b68cca2999c125e52de685e5b2e50", + "prototypes/connections/check_document_peer.py": "d9dc789148951baa6f5d47f8cdea4009fe4d2dcf67b9dfaf2e6501f8e66a0f5c", + "prototypes/common/tls-link.c": "5d47ce411d6a81ce1a29d288c93ff507539fda1f202f2f41c0ff5560564b4f5a", + "prototypes/connections/store.c": "733ddcacaffd9e9ffbadfc385eadd4c9e62736a2b97b7bc048ad14845d83070f", + "prototypes/connections/store-port.c": "d6bf17878b325e039360816edcbf8d68e41b373cf3e6128d7795e11ae21fdd6f", + "prototypes/connections/program.c": "d7186634d2bfd83bbaf87ea3bafdec8d14be8f556cbf3d9877d07e0074b4b389", + "prototypes/connections/evaluate.c": "ee8b91efc733b9d305711b7cbb7b502ae5d3917e06f750b7f62b632ed0ea6d04", + "prototypes/connections/runtime.c": "1ced6734ee07f3688e5c9cc0a8af639da88a1741dc3e6f65ec109baa2d826e6f", + "prototypes/connections/examples/editor.pure": "8ca6c191b98bf53a592ce24f2b5cd040e41f05c4ccdda7a072d5d7f79870c06a" + }, + "environment": { + "platform": "Linux-6.18.39+rpt-rpi-2712-aarch64-with-glibc2.41", + "machine": "aarch64", + "compiler": "cc (Debian 14.2.0-19) 14.2.0", + "openssl": "OpenSSL 3.6.4 25 Aug 2026 (Library: OpenSSL 3.6.4 25 Aug 2026)" + } +} diff --git a/research/experiments/005-direct-document-peer/results/2026-09-24-before-nodelay-8k-linux-aarch64.json b/research/experiments/005-direct-document-peer/results/2026-09-24-before-nodelay-8k-linux-aarch64.json new file mode 100644 index 0000000..019fd1e --- /dev/null +++ b/research/experiments/005-direct-document-peer/results/2026-09-24-before-nodelay-8k-linux-aarch64.json @@ -0,0 +1,109 @@ +{ + "profile": "authenticated-document-read-direct-versus-pure", + "definition_sha256": "8ca6c191b98bf53a592ce24f2b5cd040e41f05c4ccdda7a072d5d7f79870c06a", + "body_bytes": 8192, + "reads_per_trial": 32, + "pairs": 2, + "filesystem": { + "device": "/dev/mmcblk0p2", + "type": "ext4", + "mount": "/" + }, + "sections": { + "direct": { + "text": 37862, + "data": 1352, + "bss": 16 + }, + "pure": { + "text": 43454, + "data": 1352, + "bss": 16 + } + }, + "binary_sha256": { + "direct": "edce33757c398fb23f6bc9e70bb31072714320324912f21599d23469e8381816", + "pure": "22560da4dd66f91f8b899569cfc771835034d7e07a68dd4da44e1605edb46c45" + }, + "samples": [ + { + "order": [ + "direct", + "pure" + ], + "direct": { + "reads": 32, + "body_bytes": 8192, + "elapsed_ns": 1415860581, + "server_rss_before_kib": 8640, + "server_rss_after_kib": 8640, + "stored_file_bytes": 8216, + "stored_file_sha256": "286cfc86e3ebe6d82dd923ef777eba30f748e8b1dd58d5c4352babbf85d0d64f" + }, + "pure": { + "reads": 32, + "body_bytes": 8192, + "elapsed_ns": 1411832180, + "server_rss_before_kib": 8624, + "server_rss_after_kib": 8624, + "stored_file_bytes": 8216, + "stored_file_sha256": "286cfc86e3ebe6d82dd923ef777eba30f748e8b1dd58d5c4352babbf85d0d64f" + } + }, + { + "order": [ + "pure", + "direct" + ], + "pure": { + "reads": 32, + "body_bytes": 8192, + "elapsed_ns": 1411873125, + "server_rss_before_kib": 8640, + "server_rss_after_kib": 8640, + "stored_file_bytes": 8216, + "stored_file_sha256": "286cfc86e3ebe6d82dd923ef777eba30f748e8b1dd58d5c4352babbf85d0d64f" + }, + "direct": { + "reads": 32, + "body_bytes": 8192, + "elapsed_ns": 1407871983, + "server_rss_before_kib": 8624, + "server_rss_after_kib": 8624, + "stored_file_bytes": 8216, + "stored_file_sha256": "286cfc86e3ebe6d82dd923ef777eba30f748e8b1dd58d5c4352babbf85d0d64f" + } + } + ], + "medians": { + "direct": { + "elapsed_ms": 1411.866282, + "server_rss_before_kib": 8632.0, + "server_rss_after_kib": 8632.0 + }, + "pure": { + "elapsed_ms": 1411.8526525, + "server_rss_before_kib": 8632.0, + "server_rss_after_kib": 8632.0 + } + }, + "sources_sha256": { + "research/experiments/005-direct-document-peer/direct-peer.c": "b1ee6ba5ec3d09b842ac42d4ca158b339ec2d23b157d2c568180af2731737501", + "research/experiments/005-direct-document-peer/run.py": "b53539f0a915376397011713ebbc9438a9b289d3b4dd745ffab5d6039fccd958", + "prototypes/connections/document-peer.c": "0c72121a6929239f618f8a642247af13fb5b68cca2999c125e52de685e5b2e50", + "prototypes/connections/check_document_peer.py": "d9dc789148951baa6f5d47f8cdea4009fe4d2dcf67b9dfaf2e6501f8e66a0f5c", + "prototypes/common/tls-link.c": "df259073c5e1cd911495b48d4ccd43c8346d955a19a8773964abe58089fbebf9", + "prototypes/connections/store.c": "733ddcacaffd9e9ffbadfc385eadd4c9e62736a2b97b7bc048ad14845d83070f", + "prototypes/connections/store-port.c": "d6bf17878b325e039360816edcbf8d68e41b373cf3e6128d7795e11ae21fdd6f", + "prototypes/connections/program.c": "d7186634d2bfd83bbaf87ea3bafdec8d14be8f556cbf3d9877d07e0074b4b389", + "prototypes/connections/evaluate.c": "ee8b91efc733b9d305711b7cbb7b502ae5d3917e06f750b7f62b632ed0ea6d04", + "prototypes/connections/runtime.c": "1ced6734ee07f3688e5c9cc0a8af639da88a1741dc3e6f65ec109baa2d826e6f", + "prototypes/connections/examples/editor.pure": "8ca6c191b98bf53a592ce24f2b5cd040e41f05c4ccdda7a072d5d7f79870c06a" + }, + "environment": { + "platform": "Linux-6.18.39+rpt-rpi-2712-aarch64-with-glibc2.41", + "machine": "aarch64", + "compiler": "cc (Debian 14.2.0-19) 14.2.0", + "openssl": "OpenSSL 3.6.4 25 Aug 2026 (Library: OpenSSL 3.6.4 25 Aug 2026)" + } +} diff --git a/research/experiments/005-direct-document-peer/results/2026-09-24-nodelay-1m-linux-aarch64.json b/research/experiments/005-direct-document-peer/results/2026-09-24-nodelay-1m-linux-aarch64.json new file mode 100644 index 0000000..9e65005 --- /dev/null +++ b/research/experiments/005-direct-document-peer/results/2026-09-24-nodelay-1m-linux-aarch64.json @@ -0,0 +1,157 @@ +{ + "profile": "authenticated-document-read-direct-versus-pure", + "definition_sha256": "8ca6c191b98bf53a592ce24f2b5cd040e41f05c4ccdda7a072d5d7f79870c06a", + "body_bytes": 1048576, + "reads_per_trial": 64, + "pairs": 4, + "filesystem": { + "device": "/dev/mmcblk0p2", + "type": "ext4", + "mount": "/" + }, + "sections": { + "direct": { + "text": 37862, + "data": 1352, + "bss": 16 + }, + "pure": { + "text": 43454, + "data": 1352, + "bss": 16 + } + }, + "binary_sha256": { + "direct": "9177aebfae07d84af5b6f23fbfe28a3a89a494943b8d0c8d0d35b68593b1f704", + "pure": "be9f569ab444085c761a7f7c9aa91c2acd6581534059785964b3a94da89fff25" + }, + "samples": [ + { + "order": [ + "direct", + "pure" + ], + "direct": { + "reads": 64, + "body_bytes": 1048576, + "elapsed_ns": 148966030, + "server_rss_before_kib": 8624, + "server_rss_after_kib": 8624, + "stored_file_bytes": 1048600, + "stored_file_sha256": "a89fd11658d8139f5cb9723120126df35590f80d02f72fdfa46c1d7c6cf44383" + }, + "pure": { + "reads": 64, + "body_bytes": 1048576, + "elapsed_ns": 149719696, + "server_rss_before_kib": 8640, + "server_rss_after_kib": 8640, + "stored_file_bytes": 1048600, + "stored_file_sha256": "a89fd11658d8139f5cb9723120126df35590f80d02f72fdfa46c1d7c6cf44383" + } + }, + { + "order": [ + "pure", + "direct" + ], + "pure": { + "reads": 64, + "body_bytes": 1048576, + "elapsed_ns": 149739381, + "server_rss_before_kib": 8640, + "server_rss_after_kib": 8640, + "stored_file_bytes": 1048600, + "stored_file_sha256": "a89fd11658d8139f5cb9723120126df35590f80d02f72fdfa46c1d7c6cf44383" + }, + "direct": { + "reads": 64, + "body_bytes": 1048576, + "elapsed_ns": 150962435, + "server_rss_before_kib": 8640, + "server_rss_after_kib": 8640, + "stored_file_bytes": 1048600, + "stored_file_sha256": "a89fd11658d8139f5cb9723120126df35590f80d02f72fdfa46c1d7c6cf44383" + } + }, + { + "order": [ + "direct", + "pure" + ], + "direct": { + "reads": 64, + "body_bytes": 1048576, + "elapsed_ns": 137503567, + "server_rss_before_kib": 8624, + "server_rss_after_kib": 8624, + "stored_file_bytes": 1048600, + "stored_file_sha256": "a89fd11658d8139f5cb9723120126df35590f80d02f72fdfa46c1d7c6cf44383" + }, + "pure": { + "reads": 64, + "body_bytes": 1048576, + "elapsed_ns": 155644335, + "server_rss_before_kib": 8624, + "server_rss_after_kib": 8624, + "stored_file_bytes": 1048600, + "stored_file_sha256": "a89fd11658d8139f5cb9723120126df35590f80d02f72fdfa46c1d7c6cf44383" + } + }, + { + "order": [ + "pure", + "direct" + ], + "pure": { + "reads": 64, + "body_bytes": 1048576, + "elapsed_ns": 155630742, + "server_rss_before_kib": 8640, + "server_rss_after_kib": 8640, + "stored_file_bytes": 1048600, + "stored_file_sha256": "a89fd11658d8139f5cb9723120126df35590f80d02f72fdfa46c1d7c6cf44383" + }, + "direct": { + "reads": 64, + "body_bytes": 1048576, + "elapsed_ns": 155552075, + "server_rss_before_kib": 8640, + "server_rss_after_kib": 8640, + "stored_file_bytes": 1048600, + "stored_file_sha256": "a89fd11658d8139f5cb9723120126df35590f80d02f72fdfa46c1d7c6cf44383" + } + } + ], + "medians": { + "direct": { + "elapsed_ms": 149.9642325, + "server_rss_before_kib": 8632.0, + "server_rss_after_kib": 8632.0 + }, + "pure": { + "elapsed_ms": 152.6850615, + "server_rss_before_kib": 8640.0, + "server_rss_after_kib": 8640.0 + } + }, + "sources_sha256": { + "research/experiments/005-direct-document-peer/direct-peer.c": "b1ee6ba5ec3d09b842ac42d4ca158b339ec2d23b157d2c568180af2731737501", + "research/experiments/005-direct-document-peer/run.py": "b53539f0a915376397011713ebbc9438a9b289d3b4dd745ffab5d6039fccd958", + "prototypes/connections/document-peer.c": "0c72121a6929239f618f8a642247af13fb5b68cca2999c125e52de685e5b2e50", + "prototypes/connections/check_document_peer.py": "d9dc789148951baa6f5d47f8cdea4009fe4d2dcf67b9dfaf2e6501f8e66a0f5c", + "prototypes/common/tls-link.c": "5d47ce411d6a81ce1a29d288c93ff507539fda1f202f2f41c0ff5560564b4f5a", + "prototypes/connections/store.c": "733ddcacaffd9e9ffbadfc385eadd4c9e62736a2b97b7bc048ad14845d83070f", + "prototypes/connections/store-port.c": "d6bf17878b325e039360816edcbf8d68e41b373cf3e6128d7795e11ae21fdd6f", + "prototypes/connections/program.c": "d7186634d2bfd83bbaf87ea3bafdec8d14be8f556cbf3d9877d07e0074b4b389", + "prototypes/connections/evaluate.c": "ee8b91efc733b9d305711b7cbb7b502ae5d3917e06f750b7f62b632ed0ea6d04", + "prototypes/connections/runtime.c": "1ced6734ee07f3688e5c9cc0a8af639da88a1741dc3e6f65ec109baa2d826e6f", + "prototypes/connections/examples/editor.pure": "8ca6c191b98bf53a592ce24f2b5cd040e41f05c4ccdda7a072d5d7f79870c06a" + }, + "environment": { + "platform": "Linux-6.18.39+rpt-rpi-2712-aarch64-with-glibc2.41", + "machine": "aarch64", + "compiler": "cc (Debian 14.2.0-19) 14.2.0", + "openssl": "OpenSSL 3.6.4 25 Aug 2026 (Library: OpenSSL 3.6.4 25 Aug 2026)" + } +} diff --git a/research/experiments/005-direct-document-peer/results/2026-09-24-nodelay-8k-linux-aarch64.json b/research/experiments/005-direct-document-peer/results/2026-09-24-nodelay-8k-linux-aarch64.json new file mode 100644 index 0000000..153842b --- /dev/null +++ b/research/experiments/005-direct-document-peer/results/2026-09-24-nodelay-8k-linux-aarch64.json @@ -0,0 +1,205 @@ +{ + "profile": "authenticated-document-read-direct-versus-pure", + "definition_sha256": "8ca6c191b98bf53a592ce24f2b5cd040e41f05c4ccdda7a072d5d7f79870c06a", + "body_bytes": 8192, + "reads_per_trial": 1024, + "pairs": 6, + "filesystem": { + "device": "/dev/mmcblk0p2", + "type": "ext4", + "mount": "/" + }, + "sections": { + "direct": { + "text": 37862, + "data": 1352, + "bss": 16 + }, + "pure": { + "text": 43454, + "data": 1352, + "bss": 16 + } + }, + "binary_sha256": { + "direct": "9177aebfae07d84af5b6f23fbfe28a3a89a494943b8d0c8d0d35b68593b1f704", + "pure": "be9f569ab444085c761a7f7c9aa91c2acd6581534059785964b3a94da89fff25" + }, + "samples": [ + { + "order": [ + "direct", + "pure" + ], + "direct": { + "reads": 1024, + "body_bytes": 8192, + "elapsed_ns": 76563753, + "server_rss_before_kib": 8640, + "server_rss_after_kib": 8640, + "stored_file_bytes": 8216, + "stored_file_sha256": "286cfc86e3ebe6d82dd923ef777eba30f748e8b1dd58d5c4352babbf85d0d64f" + }, + "pure": { + "reads": 1024, + "body_bytes": 8192, + "elapsed_ns": 93622467, + "server_rss_before_kib": 8624, + "server_rss_after_kib": 8624, + "stored_file_bytes": 8216, + "stored_file_sha256": "286cfc86e3ebe6d82dd923ef777eba30f748e8b1dd58d5c4352babbf85d0d64f" + } + }, + { + "order": [ + "pure", + "direct" + ], + "pure": { + "reads": 1024, + "body_bytes": 8192, + "elapsed_ns": 90777415, + "server_rss_before_kib": 8624, + "server_rss_after_kib": 8624, + "stored_file_bytes": 8216, + "stored_file_sha256": "286cfc86e3ebe6d82dd923ef777eba30f748e8b1dd58d5c4352babbf85d0d64f" + }, + "direct": { + "reads": 1024, + "body_bytes": 8192, + "elapsed_ns": 92965246, + "server_rss_before_kib": 8640, + "server_rss_after_kib": 8640, + "stored_file_bytes": 8216, + "stored_file_sha256": "286cfc86e3ebe6d82dd923ef777eba30f748e8b1dd58d5c4352babbf85d0d64f" + } + }, + { + "order": [ + "direct", + "pure" + ], + "direct": { + "reads": 1024, + "body_bytes": 8192, + "elapsed_ns": 76165419, + "server_rss_before_kib": 8640, + "server_rss_after_kib": 8640, + "stored_file_bytes": 8216, + "stored_file_sha256": "286cfc86e3ebe6d82dd923ef777eba30f748e8b1dd58d5c4352babbf85d0d64f" + }, + "pure": { + "reads": 1024, + "body_bytes": 8192, + "elapsed_ns": 92132358, + "server_rss_before_kib": 8640, + "server_rss_after_kib": 8640, + "stored_file_bytes": 8216, + "stored_file_sha256": "286cfc86e3ebe6d82dd923ef777eba30f748e8b1dd58d5c4352babbf85d0d64f" + } + }, + { + "order": [ + "pure", + "direct" + ], + "pure": { + "reads": 1024, + "body_bytes": 8192, + "elapsed_ns": 80493468, + "server_rss_before_kib": 8640, + "server_rss_after_kib": 8640, + "stored_file_bytes": 8216, + "stored_file_sha256": "286cfc86e3ebe6d82dd923ef777eba30f748e8b1dd58d5c4352babbf85d0d64f" + }, + "direct": { + "reads": 1024, + "body_bytes": 8192, + "elapsed_ns": 77076696, + "server_rss_before_kib": 8640, + "server_rss_after_kib": 8640, + "stored_file_bytes": 8216, + "stored_file_sha256": "286cfc86e3ebe6d82dd923ef777eba30f748e8b1dd58d5c4352babbf85d0d64f" + } + }, + { + "order": [ + "direct", + "pure" + ], + "direct": { + "reads": 1024, + "body_bytes": 8192, + "elapsed_ns": 91795043, + "server_rss_before_kib": 8640, + "server_rss_after_kib": 8640, + "stored_file_bytes": 8216, + "stored_file_sha256": "286cfc86e3ebe6d82dd923ef777eba30f748e8b1dd58d5c4352babbf85d0d64f" + }, + "pure": { + "reads": 1024, + "body_bytes": 8192, + "elapsed_ns": 90660842, + "server_rss_before_kib": 8640, + "server_rss_after_kib": 8640, + "stored_file_bytes": 8216, + "stored_file_sha256": "286cfc86e3ebe6d82dd923ef777eba30f748e8b1dd58d5c4352babbf85d0d64f" + } + }, + { + "order": [ + "pure", + "direct" + ], + "pure": { + "reads": 1024, + "body_bytes": 8192, + "elapsed_ns": 93672077, + "server_rss_before_kib": 8640, + "server_rss_after_kib": 8640, + "stored_file_bytes": 8216, + "stored_file_sha256": "286cfc86e3ebe6d82dd923ef777eba30f748e8b1dd58d5c4352babbf85d0d64f" + }, + "direct": { + "reads": 1024, + "body_bytes": 8192, + "elapsed_ns": 116319172, + "server_rss_before_kib": 8624, + "server_rss_after_kib": 8624, + "stored_file_bytes": 8216, + "stored_file_sha256": "286cfc86e3ebe6d82dd923ef777eba30f748e8b1dd58d5c4352babbf85d0d64f" + } + } + ], + "medians": { + "direct": { + "elapsed_ms": 84.4358695, + "server_rss_before_kib": 8640.0, + "server_rss_after_kib": 8640.0 + }, + "pure": { + "elapsed_ms": 91.4548865, + "server_rss_before_kib": 8640.0, + "server_rss_after_kib": 8640.0 + } + }, + "sources_sha256": { + "research/experiments/005-direct-document-peer/direct-peer.c": "b1ee6ba5ec3d09b842ac42d4ca158b339ec2d23b157d2c568180af2731737501", + "research/experiments/005-direct-document-peer/run.py": "b53539f0a915376397011713ebbc9438a9b289d3b4dd745ffab5d6039fccd958", + "prototypes/connections/document-peer.c": "0c72121a6929239f618f8a642247af13fb5b68cca2999c125e52de685e5b2e50", + "prototypes/connections/check_document_peer.py": "d9dc789148951baa6f5d47f8cdea4009fe4d2dcf67b9dfaf2e6501f8e66a0f5c", + "prototypes/common/tls-link.c": "5d47ce411d6a81ce1a29d288c93ff507539fda1f202f2f41c0ff5560564b4f5a", + "prototypes/connections/store.c": "733ddcacaffd9e9ffbadfc385eadd4c9e62736a2b97b7bc048ad14845d83070f", + "prototypes/connections/store-port.c": "d6bf17878b325e039360816edcbf8d68e41b373cf3e6128d7795e11ae21fdd6f", + "prototypes/connections/program.c": "d7186634d2bfd83bbaf87ea3bafdec8d14be8f556cbf3d9877d07e0074b4b389", + "prototypes/connections/evaluate.c": "ee8b91efc733b9d305711b7cbb7b502ae5d3917e06f750b7f62b632ed0ea6d04", + "prototypes/connections/runtime.c": "1ced6734ee07f3688e5c9cc0a8af639da88a1741dc3e6f65ec109baa2d826e6f", + "prototypes/connections/examples/editor.pure": "8ca6c191b98bf53a592ce24f2b5cd040e41f05c4ccdda7a072d5d7f79870c06a" + }, + "environment": { + "platform": "Linux-6.18.39+rpt-rpi-2712-aarch64-with-glibc2.41", + "machine": "aarch64", + "compiler": "cc (Debian 14.2.0-19) 14.2.0", + "openssl": "OpenSSL 3.6.4 25 Aug 2026 (Library: OpenSSL 3.6.4 25 Aug 2026)" + } +} diff --git a/research/experiments/005-direct-document-peer/run.py b/research/experiments/005-direct-document-peer/run.py new file mode 100644 index 0000000..ff4654f --- /dev/null +++ b/research/experiments/005-direct-document-peer/run.py @@ -0,0 +1,145 @@ +#!/usr/bin/env python3 +"""Compare authenticated document reads through direct and Pure server paths.""" +import argparse +import hashlib +import json +import os +from pathlib import Path +import platform +import statistics +import subprocess +import sys +import tempfile +import time + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[2] +CONNECTIONS = ROOT / 'prototypes/connections' +COMMON = ROOT / 'prototypes/common' +sys.path.insert(0, str(CONNECTIONS)) +import check_document_peer as peer # noqa: E402 + + +def sha(path): + return hashlib.sha256(path.read_bytes()).hexdigest() + + +def command(*args): + result = subprocess.run([str(arg) for arg in args], capture_output=True, text=True, + timeout=60) + if result.returncode: + raise AssertionError((result.args, result.returncode, result.stdout, result.stderr)) + return result.stdout + + +def compile_servers(directory, cc): + flags = [cc, '-O2', '-g', '-std=c17', '-Wall', '-Wextra', '-Wpedantic', '-Werror', + '-I' + str(CONNECTIONS)] + common = [COMMON / 'tls-link.c', CONNECTIONS / 'store.c', + CONNECTIONS / 'program.c', CONNECTIONS / 'evaluate.c'] + direct = directory / 'direct-peer' + pure = directory / 'pure-server' + command(*flags, HERE / 'direct-peer.c', *common, '-lssl', '-lcrypto', '-o', direct) + command(*flags, '-DPURE_PEER_SERVER_ONLY', CONNECTIONS / 'document-peer.c', + *common, CONNECTIONS / 'store-port.c', CONNECTIONS / 'runtime.c', + '-lssl', '-lcrypto', '-o', pure) + return {'direct': direct, 'pure': pure} + + +def sections(binary): + row = command('size', binary).splitlines()[1].split() + return dict(zip(('text', 'data', 'bss'), map(int, row[:3]))) + + +def trial(binary, program, root, cert_root, ca, body, reads): + store = root / 'store' + server, port = peer.start(binary, program, store, cert_root, ca) + try: + with peer.connect(cert_root, ca, port) as sock: + peer.hello(sock, program) + assert peer.request(sock, 2, 'bench', 0, peer.edit(0, 0, body), + want_body=False) == (0, 1, b'', len(body)) + assert peer.request(sock, 1, 'bench') == (0, 1, body, len(body)) + rss_before = peer.rss_kib(server.pid) + start = time.perf_counter_ns() + for _ in range(reads): + assert peer.request(sock, 1, 'bench') == (0, 1, body, len(body)) + elapsed_ns = time.perf_counter_ns() - start + rss_after = peer.rss_kib(server.pid) + finally: + peer.stop(server) + stored = store / 'obj-bench' + return {'reads': reads, 'body_bytes': len(body), 'elapsed_ns': elapsed_ns, + 'server_rss_before_kib': rss_before, 'server_rss_after_kib': rss_after, + 'stored_file_bytes': stored.stat().st_size, + 'stored_file_sha256': sha(stored)} + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--cc', default=os.environ.get('CC', 'cc')) + parser.add_argument('--body-bytes', type=int, default=8192) + parser.add_argument('--reads', type=int, default=512) + parser.add_argument('--pairs', type=int, default=4) + parser.add_argument('--work-root', type=Path, default=HERE / 'results') + parser.add_argument('--output', type=Path) + args = parser.parse_args() + if not 1 <= args.body_bytes <= 1024 * 1024 or not 1 <= args.reads <= 4096 or not 1 <= args.pairs <= 16: + parser.error('body-bytes 1..1048576, reads 1..4096, pairs 1..16') + if args.output and args.output.exists(): + parser.error('evidence file already exists') + args.work_root.mkdir(parents=True, exist_ok=True) + filesystem = command('df', '-T', args.work_root).splitlines()[1].split() + program = CONNECTIONS / 'examples/editor.pure' + body = bytes((ord('a') + i % 26 for i in range(args.body_bytes))) + with tempfile.TemporaryDirectory(prefix='pure-direct-peer-', dir=args.work_root) as name: + root = Path(name) + binaries = compile_servers(root, args.cc) + sizes = {variant: sections(binary) for variant, binary in binaries.items()} + binary_hashes = {variant: sha(binary) for variant, binary in binaries.items()} + ca = peer.certificates(root) + samples = [] + for pair in range(args.pairs): + order = ('direct', 'pure') if pair % 2 == 0 else ('pure', 'direct') + entry = {'order': list(order)} + for variant in order: + path = root / f'{pair}-{variant}' + path.mkdir() + # The certificates live at the common root. The store is unique + # to each server so conditional revision 0 always means create. + entry[variant] = trial(binaries[variant], program, path, root, ca, + body, args.reads) + assert entry['direct']['stored_file_sha256'] == entry['pure']['stored_file_sha256'] + samples.append(entry) + medians = {variant: {'elapsed_ms': statistics.median( + sample[variant]['elapsed_ns'] for sample in samples) / 1e6, + 'server_rss_before_kib': statistics.median( + sample[variant]['server_rss_before_kib'] for sample in samples), + 'server_rss_after_kib': statistics.median( + sample[variant]['server_rss_after_kib'] for sample in samples)} + for variant in ('direct', 'pure')} + sources = [HERE / 'direct-peer.c', HERE / 'run.py', + CONNECTIONS / 'document-peer.c', CONNECTIONS / 'check_document_peer.py', + COMMON / 'tls-link.c', CONNECTIONS / 'store.c', + CONNECTIONS / 'store-port.c', CONNECTIONS / 'program.c', + CONNECTIONS / 'evaluate.c', CONNECTIONS / 'runtime.c', program] + result = {'profile': 'authenticated-document-read-direct-versus-pure', + 'definition_sha256': sha(program), 'body_bytes': args.body_bytes, + 'reads_per_trial': args.reads, 'pairs': args.pairs, + 'filesystem': {'device': filesystem[0], 'type': filesystem[1], + 'mount': filesystem[-1]}, + 'sections': sizes, 'binary_sha256': binary_hashes, + 'samples': samples, 'medians': medians, + 'sources_sha256': {str(path.relative_to(ROOT)): sha(path) for path in sources}, + 'environment': {'platform': platform.platform(), 'machine': platform.machine(), + 'compiler': command(args.cc, '--version').splitlines()[0], + 'openssl': command('openssl', 'version').strip()}} + output = json.dumps(result, indent=2) + '\n' + if args.output: + args.output.parent.mkdir(parents=True, exist_ok=True) + args.output.write_text(output) + print(output, end='') + + +if __name__ == '__main__': + main() diff --git a/research/experiments/005-direct-document-peer/scalar-peer-after-nodelay-parity-linux-aarch64.json b/research/experiments/005-direct-document-peer/scalar-peer-after-nodelay-parity-linux-aarch64.json new file mode 100644 index 0000000..1316e2e --- /dev/null +++ b/research/experiments/005-direct-document-peer/scalar-peer-after-nodelay-parity-linux-aarch64.json @@ -0,0 +1 @@ +{"alpn": "pass", "disconnect_release": "pass", "idle_deadline": "pass", "malformed_frames": "pass", "mutual_authentication": "pass", "persist_restart": "pass", "python_client": "pass", "revision_conflict": "pass", "server_connected_rss_kib": 8640, "server_hostname": "pass", "server_idle_rss_kib": 7968} diff --git a/research/experiments/005-storage-edit-latency/2026-09-24-check-hybrid.log.gz b/research/experiments/005-storage-edit-latency/2026-09-24-check-hybrid.log.gz Binary files differnew file mode 100644 index 0000000..e4c0174 --- /dev/null +++ b/research/experiments/005-storage-edit-latency/2026-09-24-check-hybrid.log.gz diff --git a/research/experiments/005-storage-edit-latency/2026-09-24-ext4-linux-aarch64.json b/research/experiments/005-storage-edit-latency/2026-09-24-ext4-linux-aarch64.json new file mode 100644 index 0000000..f9decda --- /dev/null +++ b/research/experiments/005-storage-edit-latency/2026-09-24-ext4-linux-aarch64.json @@ -0,0 +1,463 @@ +{ + "profile": "native-cli-durable-one-mib-document-last-byte-edit", + "platform": "Linux-6.18.39+rpt-rpi-2712-aarch64-with-glibc2.41", + "filesystem": "ext4 /dev/mmcblk0p2[/home/eunhhu/work/pure]", + "trials_per_variant": 18, + "final_body_sha256": "06cb5e32505f66804f6e8c79e3230105ca4769444e1389ee36f6f11fd61f2d3a", + "scope": "Each sample starts a new CLI process; create and edit each include program parsing, store initialization, file and directory synchronization. Show verifies the final revision but is outside the timed operations. The host page cache, filesystem and device remain uncontrolled.", + "variants": { + "flat": { + "binary_sha256": "23ebc0ce1df9c49216511bee658fd5b9e373509e296bd2c2f8e76e6d3081cded", + "median_create_ms": 83.556, + "median_edit_ms": 78.805, + "samples": [ + { + "trial": 0, + "create_ms": 93.308, + "edit_ms": 86.265, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 1, + "create_ms": 66.85, + "edit_ms": 81.315, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 2, + "create_ms": 83.243, + "edit_ms": 26.218, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 3, + "create_ms": 25.734, + "edit_ms": 81.636, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 4, + "create_ms": 80.359, + "edit_ms": 22.923, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 5, + "create_ms": 84.855, + "edit_ms": 77.624, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 6, + "create_ms": 83.516, + "edit_ms": 24.882, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 7, + "create_ms": 100.653, + "edit_ms": 65.551, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 8, + "create_ms": 87.547, + "edit_ms": 88.306, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 9, + "create_ms": 100.781, + "edit_ms": 89.489, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 10, + "create_ms": 29.332, + "edit_ms": 79.987, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 11, + "create_ms": 80.05, + "edit_ms": 26.629, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 12, + "create_ms": 79.751, + "edit_ms": 24.165, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 13, + "create_ms": 85.309, + "edit_ms": 23.163, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 14, + "create_ms": 83.597, + "edit_ms": 82.171, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 15, + "create_ms": 97.909, + "edit_ms": 85.934, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 16, + "create_ms": 25.638, + "edit_ms": 82.514, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 17, + "create_ms": 86.699, + "edit_ms": 23.813, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + } + ] + }, + "copy": { + "binary_sha256": "52c2b828b0cba3564a37e3874f60bec793d1dd7031aff77ba850cee7683977f9", + "median_create_ms": 81.672, + "median_edit_ms": 77.908, + "samples": [ + { + "trial": 0, + "create_ms": 29.767, + "edit_ms": 78.001, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 1, + "create_ms": 89.789, + "edit_ms": 91.286, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 2, + "create_ms": 83.106, + "edit_ms": 77.868, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 3, + "create_ms": 84.346, + "edit_ms": 47.881, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 4, + "create_ms": 29.06, + "edit_ms": 78.142, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 5, + "create_ms": 29.801, + "edit_ms": 52.17, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 6, + "create_ms": 81.026, + "edit_ms": 77.948, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 7, + "create_ms": 30.027, + "edit_ms": 87.974, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 8, + "create_ms": 45.522, + "edit_ms": 87.955, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 9, + "create_ms": 80.228, + "edit_ms": 22.863, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 10, + "create_ms": 82.319, + "edit_ms": 77.564, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 11, + "create_ms": 94.951, + "edit_ms": 46.186, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 12, + "create_ms": 84.607, + "edit_ms": 80.2, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 13, + "create_ms": 29.82, + "edit_ms": 86.258, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 14, + "create_ms": 94.36, + "edit_ms": 31.893, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 15, + "create_ms": 97.289, + "edit_ms": 44.737, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 16, + "create_ms": 60.805, + "edit_ms": 80.635, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + }, + { + "trial": 17, + "create_ms": 85.887, + "edit_ms": 77.182, + "store_files": 2, + "store_file_bytes": 1048600, + "store_allocated_bytes": 1052672 + } + ] + }, + "paged": { + "binary_sha256": "e1c12a2f5e736bb86737ceff7849fe95b1a9d13136e8c5eb3f3398cb3971c6f5", + "median_create_ms": 88.948, + "median_edit_ms": 14.473, + "samples": [ + { + "trial": 0, + "create_ms": 117.897, + "edit_ms": 565.484, + "store_files": 3, + "store_file_bytes": 1065520, + "store_allocated_bytes": 1069056 + }, + { + "trial": 1, + "create_ms": 47.619, + "edit_ms": 13.102, + "store_files": 3, + "store_file_bytes": 1065520, + "store_allocated_bytes": 1069056 + }, + { + "trial": 2, + "create_ms": 89.46, + "edit_ms": 14.779, + "store_files": 3, + "store_file_bytes": 1065520, + "store_allocated_bytes": 1069056 + }, + { + "trial": 3, + "create_ms": 30.501, + "edit_ms": 15.016, + "store_files": 3, + "store_file_bytes": 1065520, + "store_allocated_bytes": 1069056 + }, + { + "trial": 4, + "create_ms": 89.223, + "edit_ms": 13.383, + "store_files": 3, + "store_file_bytes": 1065520, + "store_allocated_bytes": 1069056 + }, + { + "trial": 5, + "create_ms": 88.518, + "edit_ms": 12.718, + "store_files": 3, + "store_file_bytes": 1065520, + "store_allocated_bytes": 1069056 + }, + { + "trial": 6, + "create_ms": 88.992, + "edit_ms": 13.681, + "store_files": 3, + "store_file_bytes": 1065520, + "store_allocated_bytes": 1069056 + }, + { + "trial": 7, + "create_ms": 116.568, + "edit_ms": 23.607, + "store_files": 3, + "store_file_bytes": 1065520, + "store_allocated_bytes": 1069056 + }, + { + "trial": 8, + "create_ms": 100.547, + "edit_ms": 24.497, + "store_files": 3, + "store_file_bytes": 1065520, + "store_allocated_bytes": 1069056 + }, + { + "trial": 9, + "create_ms": 54.374, + "edit_ms": 13.896, + "store_files": 3, + "store_file_bytes": 1065520, + "store_allocated_bytes": 1069056 + }, + { + "trial": 10, + "create_ms": 84.894, + "edit_ms": 13.607, + "store_files": 3, + "store_file_bytes": 1065520, + "store_allocated_bytes": 1069056 + }, + { + "trial": 11, + "create_ms": 92.673, + "edit_ms": 14.166, + "store_files": 3, + "store_file_bytes": 1065520, + "store_allocated_bytes": 1069056 + }, + { + "trial": 12, + "create_ms": 34.961, + "edit_ms": 78.767, + "store_files": 3, + "store_file_bytes": 1065520, + "store_allocated_bytes": 1069056 + }, + { + "trial": 13, + "create_ms": 88.903, + "edit_ms": 13.656, + "store_files": 3, + "store_file_bytes": 1065520, + "store_allocated_bytes": 1069056 + }, + { + "trial": 14, + "create_ms": 57.426, + "edit_ms": 13.968, + "store_files": 3, + "store_file_bytes": 1065520, + "store_allocated_bytes": 1069056 + }, + { + "trial": 15, + "create_ms": 38.675, + "edit_ms": 14.937, + "store_files": 3, + "store_file_bytes": 1065520, + "store_allocated_bytes": 1069056 + }, + { + "trial": 16, + "create_ms": 90.664, + "edit_ms": 15.344, + "store_files": 3, + "store_file_bytes": 1065520, + "store_allocated_bytes": 1069056 + }, + { + "trial": 17, + "create_ms": 90.055, + "edit_ms": 14.926, + "store_files": 3, + "store_file_bytes": 1065520, + "store_allocated_bytes": 1069056 + } + ] + } + } +} diff --git a/research/experiments/005-storage-edit-latency/2026-09-24-sequence-ext4-linux-aarch64.json b/research/experiments/005-storage-edit-latency/2026-09-24-sequence-ext4-linux-aarch64.json new file mode 100644 index 0000000..5efbf8b --- /dev/null +++ b/research/experiments/005-storage-edit-latency/2026-09-24-sequence-ext4-linux-aarch64.json @@ -0,0 +1,862 @@ +{ + "profile": "repeated-durable-one-mib-document-last-byte-edit", + "platform": "Linux-6.18.39+rpt-rpi-2712-aarch64-with-glibc2.41", + "filesystem": "ext4 /dev/mmcblk0p2[/home/eunhhu/work/pure]", + "edits_per_variant": 70, + "final_body_sha256": "3cfc240f48e8e1b8553f3e2670adf7b81cafe34f089d4372fa4c28787dc02151", + "scope": "Same actual source-loaded CLI and editor.pure, two persistent stores, alternating operation order. Timings include each edit process, parser, store init and fsync; creation and final show are not timed. Device state is uncontrolled.", + "variants": { + "flat": { + "binary_sha256": "23ebc0ce1df9c49216511bee658fd5b9e373509e296bd2c2f8e76e6d3081cded", + "median_edit_ms": 83.176, + "samples": [ + { + "edit": 1, + "elapsed_ms": 24.328, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 2, + "elapsed_ms": 79.862, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 3, + "elapsed_ms": 177.059, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 4, + "elapsed_ms": 89.804, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 5, + "elapsed_ms": 92.579, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 6, + "elapsed_ms": 83.733, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 7, + "elapsed_ms": 29.379, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 8, + "elapsed_ms": 78.191, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 9, + "elapsed_ms": 57.551, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 10, + "elapsed_ms": 83.875, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 11, + "elapsed_ms": 78.209, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 12, + "elapsed_ms": 85.296, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 13, + "elapsed_ms": 25.204, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 14, + "elapsed_ms": 28.663, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 15, + "elapsed_ms": 82.153, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 16, + "elapsed_ms": 84.924, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 17, + "elapsed_ms": 82.359, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 18, + "elapsed_ms": 39.211, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 19, + "elapsed_ms": 28.648, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 20, + "elapsed_ms": 82.115, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 21, + "elapsed_ms": 83.895, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 22, + "elapsed_ms": 83.007, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 23, + "elapsed_ms": 84.496, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 24, + "elapsed_ms": 28.525, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 25, + "elapsed_ms": 86.499, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 26, + "elapsed_ms": 25.536, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 27, + "elapsed_ms": 93.217, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 28, + "elapsed_ms": 36.673, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 29, + "elapsed_ms": 84.748, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 30, + "elapsed_ms": 79.529, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 31, + "elapsed_ms": 84.024, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 32, + "elapsed_ms": 82.681, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 33, + "elapsed_ms": 28.903, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 34, + "elapsed_ms": 29.254, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 35, + "elapsed_ms": 86.486, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 36, + "elapsed_ms": 96.679, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 37, + "elapsed_ms": 41.477, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 38, + "elapsed_ms": 82.386, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 39, + "elapsed_ms": 25.063, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 40, + "elapsed_ms": 27.84, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 41, + "elapsed_ms": 86.119, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 42, + "elapsed_ms": 89.284, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 43, + "elapsed_ms": 84.316, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 44, + "elapsed_ms": 86.972, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 45, + "elapsed_ms": 88.795, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 46, + "elapsed_ms": 47.265, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 47, + "elapsed_ms": 32.736, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 48, + "elapsed_ms": 93.95, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 49, + "elapsed_ms": 29.861, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 50, + "elapsed_ms": 25.674, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 51, + "elapsed_ms": 87.319, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 52, + "elapsed_ms": 83.632, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 53, + "elapsed_ms": 83.964, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 54, + "elapsed_ms": 83.345, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 55, + "elapsed_ms": 175.728, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 56, + "elapsed_ms": 92.189, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 57, + "elapsed_ms": 98.676, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 58, + "elapsed_ms": 84.905, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 59, + "elapsed_ms": 81.966, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 60, + "elapsed_ms": 87.203, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 61, + "elapsed_ms": 25.923, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 62, + "elapsed_ms": 29.165, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 63, + "elapsed_ms": 82.076, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 64, + "elapsed_ms": 128.506, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 65, + "elapsed_ms": 91.837, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 66, + "elapsed_ms": 25.832, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 67, + "elapsed_ms": 86.189, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 68, + "elapsed_ms": 83.351, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 69, + "elapsed_ms": 85.479, + "files": 2, + "allocated_bytes": 1052672 + }, + { + "edit": 70, + "elapsed_ms": 77.587, + "files": 2, + "allocated_bytes": 1052672 + } + ] + }, + "paged": { + "binary_sha256": "e1c12a2f5e736bb86737ceff7849fe95b1a9d13136e8c5eb3f3398cb3971c6f5", + "median_edit_ms": 18.858, + "samples": [ + { + "edit": 1, + "elapsed_ms": 16.412, + "files": 3, + "allocated_bytes": 1069056 + }, + { + "edit": 2, + "elapsed_ms": 17.281, + "files": 3, + "allocated_bytes": 1085440 + }, + { + "edit": 3, + "elapsed_ms": 32.037, + "files": 3, + "allocated_bytes": 1101824 + }, + { + "edit": 4, + "elapsed_ms": 29.739, + "files": 3, + "allocated_bytes": 1118208 + }, + { + "edit": 5, + "elapsed_ms": 28.746, + "files": 3, + "allocated_bytes": 1134592 + }, + { + "edit": 6, + "elapsed_ms": 31.822, + "files": 3, + "allocated_bytes": 1150976 + }, + { + "edit": 7, + "elapsed_ms": 16.937, + "files": 3, + "allocated_bytes": 1167360 + }, + { + "edit": 8, + "elapsed_ms": 16.845, + "files": 3, + "allocated_bytes": 1183744 + }, + { + "edit": 9, + "elapsed_ms": 17.18, + "files": 3, + "allocated_bytes": 1200128 + }, + { + "edit": 10, + "elapsed_ms": 18.422, + "files": 3, + "allocated_bytes": 1216512 + }, + { + "edit": 11, + "elapsed_ms": 18.672, + "files": 3, + "allocated_bytes": 1232896 + }, + { + "edit": 12, + "elapsed_ms": 16.399, + "files": 3, + "allocated_bytes": 1249280 + }, + { + "edit": 13, + "elapsed_ms": 18.911, + "files": 3, + "allocated_bytes": 1265664 + }, + { + "edit": 14, + "elapsed_ms": 71.604, + "files": 3, + "allocated_bytes": 1282048 + }, + { + "edit": 15, + "elapsed_ms": 18.821, + "files": 3, + "allocated_bytes": 1298432 + }, + { + "edit": 16, + "elapsed_ms": 16.746, + "files": 3, + "allocated_bytes": 1314816 + }, + { + "edit": 17, + "elapsed_ms": 17.354, + "files": 3, + "allocated_bytes": 1331200 + }, + { + "edit": 18, + "elapsed_ms": 15.468, + "files": 3, + "allocated_bytes": 1347584 + }, + { + "edit": 19, + "elapsed_ms": 15.872, + "files": 3, + "allocated_bytes": 1363968 + }, + { + "edit": 20, + "elapsed_ms": 18.347, + "files": 3, + "allocated_bytes": 1380352 + }, + { + "edit": 21, + "elapsed_ms": 17.311, + "files": 3, + "allocated_bytes": 1396736 + }, + { + "edit": 22, + "elapsed_ms": 18.997, + "files": 3, + "allocated_bytes": 1413120 + }, + { + "edit": 23, + "elapsed_ms": 17.267, + "files": 3, + "allocated_bytes": 1429504 + }, + { + "edit": 24, + "elapsed_ms": 18.52, + "files": 3, + "allocated_bytes": 1445888 + }, + { + "edit": 25, + "elapsed_ms": 34.127, + "files": 3, + "allocated_bytes": 1462272 + }, + { + "edit": 26, + "elapsed_ms": 86.489, + "files": 3, + "allocated_bytes": 1478656 + }, + { + "edit": 27, + "elapsed_ms": 29.105, + "files": 3, + "allocated_bytes": 1495040 + }, + { + "edit": 28, + "elapsed_ms": 37.131, + "files": 3, + "allocated_bytes": 1511424 + }, + { + "edit": 29, + "elapsed_ms": 15.478, + "files": 3, + "allocated_bytes": 1527808 + }, + { + "edit": 30, + "elapsed_ms": 19.623, + "files": 3, + "allocated_bytes": 1544192 + }, + { + "edit": 31, + "elapsed_ms": 90.312, + "files": 3, + "allocated_bytes": 1560576 + }, + { + "edit": 32, + "elapsed_ms": 17.365, + "files": 3, + "allocated_bytes": 1576960 + }, + { + "edit": 33, + "elapsed_ms": 17.109, + "files": 3, + "allocated_bytes": 1593344 + }, + { + "edit": 34, + "elapsed_ms": 126.006, + "files": 3, + "allocated_bytes": 1609728 + }, + { + "edit": 35, + "elapsed_ms": 17.457, + "files": 3, + "allocated_bytes": 1626112 + }, + { + "edit": 36, + "elapsed_ms": 15.908, + "files": 3, + "allocated_bytes": 1642496 + }, + { + "edit": 37, + "elapsed_ms": 18.896, + "files": 3, + "allocated_bytes": 1658880 + }, + { + "edit": 38, + "elapsed_ms": 16.535, + "files": 3, + "allocated_bytes": 1675264 + }, + { + "edit": 39, + "elapsed_ms": 17.568, + "files": 3, + "allocated_bytes": 1691648 + }, + { + "edit": 40, + "elapsed_ms": 71.184, + "files": 3, + "allocated_bytes": 1708032 + }, + { + "edit": 41, + "elapsed_ms": 16.619, + "files": 3, + "allocated_bytes": 1724416 + }, + { + "edit": 42, + "elapsed_ms": 29.265, + "files": 3, + "allocated_bytes": 1740800 + }, + { + "edit": 43, + "elapsed_ms": 21.163, + "files": 3, + "allocated_bytes": 1757184 + }, + { + "edit": 44, + "elapsed_ms": 27.305, + "files": 3, + "allocated_bytes": 1773568 + }, + { + "edit": 45, + "elapsed_ms": 29.526, + "files": 3, + "allocated_bytes": 1789952 + }, + { + "edit": 46, + "elapsed_ms": 27.936, + "files": 3, + "allocated_bytes": 1806336 + }, + { + "edit": 47, + "elapsed_ms": 87.552, + "files": 3, + "allocated_bytes": 1822720 + }, + { + "edit": 48, + "elapsed_ms": 30.512, + "files": 3, + "allocated_bytes": 1839104 + }, + { + "edit": 49, + "elapsed_ms": 17.81, + "files": 3, + "allocated_bytes": 1855488 + }, + { + "edit": 50, + "elapsed_ms": 70.4, + "files": 3, + "allocated_bytes": 1871872 + }, + { + "edit": 51, + "elapsed_ms": 17.115, + "files": 3, + "allocated_bytes": 1888256 + }, + { + "edit": 52, + "elapsed_ms": 18.79, + "files": 3, + "allocated_bytes": 1904640 + }, + { + "edit": 53, + "elapsed_ms": 21.637, + "files": 3, + "allocated_bytes": 1921024 + }, + { + "edit": 54, + "elapsed_ms": 16.47, + "files": 3, + "allocated_bytes": 1937408 + }, + { + "edit": 55, + "elapsed_ms": 53.194, + "files": 3, + "allocated_bytes": 1953792 + }, + { + "edit": 56, + "elapsed_ms": 219.485, + "files": 3, + "allocated_bytes": 1970176 + }, + { + "edit": 57, + "elapsed_ms": 24.517, + "files": 3, + "allocated_bytes": 1986560 + }, + { + "edit": 58, + "elapsed_ms": 16.725, + "files": 3, + "allocated_bytes": 2002944 + }, + { + "edit": 59, + "elapsed_ms": 19.628, + "files": 3, + "allocated_bytes": 2019328 + }, + { + "edit": 60, + "elapsed_ms": 17.158, + "files": 3, + "allocated_bytes": 2035712 + }, + { + "edit": 61, + "elapsed_ms": 72.424, + "files": 3, + "allocated_bytes": 2052096 + }, + { + "edit": 62, + "elapsed_ms": 16.894, + "files": 3, + "allocated_bytes": 2068480 + }, + { + "edit": 63, + "elapsed_ms": 18.918, + "files": 3, + "allocated_bytes": 2084864 + }, + { + "edit": 64, + "elapsed_ms": 16.879, + "files": 3, + "allocated_bytes": 2101248 + }, + { + "edit": 65, + "elapsed_ms": 35.067, + "files": 3, + "allocated_bytes": 1052672 + }, + { + "edit": 66, + "elapsed_ms": 83.189, + "files": 3, + "allocated_bytes": 1069056 + }, + { + "edit": 67, + "elapsed_ms": 16.607, + "files": 3, + "allocated_bytes": 1085440 + }, + { + "edit": 68, + "elapsed_ms": 19.566, + "files": 3, + "allocated_bytes": 1101824 + }, + { + "edit": 69, + "elapsed_ms": 17.47, + "files": 3, + "allocated_bytes": 1118208 + }, + { + "edit": 70, + "elapsed_ms": 20.338, + "files": 3, + "allocated_bytes": 1134592 + } + ] + } + } +} diff --git a/research/experiments/005-storage-edit-latency/copy-memory.json b/research/experiments/005-storage-edit-latency/copy-memory.json new file mode 100644 index 0000000..969250c --- /dev/null +++ b/research/experiments/005-storage-edit-latency/copy-memory.json @@ -0,0 +1,43 @@ +{ + "passed": true, + "failures": [], + "profile": "portable-measurement-no-budget", + "variant": "source-program", + "scope": "Child-process peak RSS for native CLI document creation, read and one-byte revision edit; includes libc and the selected program form, excludes filesystem cache, kernel buffers, TLS, GUI and other apps. No cross-platform memory ceiling is asserted.", + "samples": { + "small_edit_rss_kib": 1056, + "one_mib_edit_rss_kib": 2080, + "one_mib_show_rss_kib": 1104, + "one_mib_splice_rss_kib": 1056 + }, + "raw_samples": { + "small_edit_rss_kib": { + "exit_code": 0, + "max_rss_kib": 1056, + "raw_max_rss": 1056, + "raw_unit": "KiB" + }, + "one_mib_edit_rss_kib": { + "exit_code": 0, + "max_rss_kib": 2080, + "raw_max_rss": 2080, + "raw_unit": "KiB" + }, + "one_mib_show_rss_kib": { + "exit_code": 0, + "max_rss_kib": 1104, + "raw_max_rss": 1104, + "raw_unit": "KiB" + }, + "one_mib_splice_rss_kib": { + "exit_code": 0, + "max_rss_kib": 1056, + "raw_max_rss": 1056, + "raw_unit": "KiB" + } + }, + "budget_sha256": null, + "binary_sha256": "52c2b828b0cba3564a37e3874f60bec793d1dd7031aff77ba850cee7683977f9", + "binary_bytes": 178824, + "platform": "Linux-6.18.39+rpt-rpi-2712-aarch64-with-glibc2.41" +} diff --git a/research/experiments/005-storage-edit-latency/flat-memory.json b/research/experiments/005-storage-edit-latency/flat-memory.json new file mode 100644 index 0000000..3f45eb1 --- /dev/null +++ b/research/experiments/005-storage-edit-latency/flat-memory.json @@ -0,0 +1,43 @@ +{ + "passed": true, + "failures": [], + "profile": "portable-measurement-no-budget", + "variant": "source-program", + "scope": "Child-process peak RSS for native CLI document creation, read and one-byte revision edit; includes libc and the selected program form, excludes filesystem cache, kernel buffers, TLS, GUI and other apps. No cross-platform memory ceiling is asserted.", + "samples": { + "small_edit_rss_kib": 1056, + "one_mib_edit_rss_kib": 2080, + "one_mib_show_rss_kib": 1056, + "one_mib_splice_rss_kib": 1104 + }, + "raw_samples": { + "small_edit_rss_kib": { + "exit_code": 0, + "max_rss_kib": 1056, + "raw_max_rss": 1056, + "raw_unit": "KiB" + }, + "one_mib_edit_rss_kib": { + "exit_code": 0, + "max_rss_kib": 2080, + "raw_max_rss": 2080, + "raw_unit": "KiB" + }, + "one_mib_show_rss_kib": { + "exit_code": 0, + "max_rss_kib": 1056, + "raw_max_rss": 1056, + "raw_unit": "KiB" + }, + "one_mib_splice_rss_kib": { + "exit_code": 0, + "max_rss_kib": 1104, + "raw_max_rss": 1104, + "raw_unit": "KiB" + } + }, + "budget_sha256": null, + "binary_sha256": "23ebc0ce1df9c49216511bee658fd5b9e373509e296bd2c2f8e76e6d3081cded", + "binary_bytes": 178336, + "platform": "Linux-6.18.39+rpt-rpi-2712-aarch64-with-glibc2.41" +} diff --git a/research/experiments/005-storage-edit-latency/measure.py b/research/experiments/005-storage-edit-latency/measure.py new file mode 100644 index 0000000..b390c92 --- /dev/null +++ b/research/experiments/005-storage-edit-latency/measure.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python3 +"""Time the same durable one-MiB document creation and one-byte revision edit.""" +import argparse +import hashlib +import json +from pathlib import Path +import platform +import statistics +import subprocess +import tempfile +import time + +HERE = Path(__file__).resolve().parents[3] +PROGRAM = HERE / 'prototypes/connections/examples/editor.pure' +INITIAL = b'A' * 1_048_576 +EXPECTED = INITIAL[:-1] + b'Z' + + +def invoke(command): + started = time.monotonic_ns() + result = subprocess.run([str(arg) for arg in command], capture_output=True, timeout=30) + elapsed_ms = (time.monotonic_ns() - started) / 1_000_000 + if result.returncode: + raise AssertionError((command, result.returncode, result.stderr[-1000:])) + return result, elapsed_ms + + +def one(binary, root, initial, replacement): + base = [binary, '--program', PROGRAM, '--store', root] + created, create_ms = invoke([*base, 'edit', 'document', 0, 0, 0, initial]) + assert json.loads(created.stdout)['revision'] == '1' + edited, edit_ms = invoke([*base, 'edit', 'document', 1, 1_048_575, 1, replacement]) + assert json.loads(edited.stdout)['revision'] == '2' + shown, _ = invoke([*base, 'show', 'document']) + assert shown.stdout == EXPECTED + assert json.loads(shown.stderr)['revision'] == '2' + files = [path for path in root.iterdir() if path.is_file()] + return {'create_ms': round(create_ms, 3), 'edit_ms': round(edit_ms, 3), + 'store_files': len(files), + 'store_file_bytes': sum(path.stat().st_size for path in files), + 'store_allocated_bytes': sum(path.stat().st_blocks * 512 for path in files)} + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--flat', type=Path, required=True) + parser.add_argument('--copy', type=Path, required=True) + parser.add_argument('--paged', type=Path, required=True) + parser.add_argument('--scratch-parent', type=Path, required=True) + parser.add_argument('--trials', type=int, default=18) + parser.add_argument('--output', type=Path, required=True) + args = parser.parse_args() + if args.trials < 3 or args.trials % 3 or args.output.exists(): + parser.error('trials must be a positive multiple of three and output must be new') + variants = {'flat': args.flat.resolve(), 'copy': args.copy.resolve(), + 'paged': args.paged.resolve()} + for binary in variants.values(): + if not binary.is_file(): + parser.error(f'missing binary: {binary}') + args.scratch_parent.mkdir(parents=True, exist_ok=True) + with tempfile.TemporaryDirectory(prefix='pure-storage-timing-', + dir=args.scratch_parent.resolve()) as name: + root = Path(name) + (root / 'initial').write_bytes(INITIAL) + (root / 'replacement').write_bytes(b'Z') + filesystem = subprocess.run(['findmnt', '-T', str(root), '-no', 'FSTYPE,SOURCE'], + capture_output=True, text=True, check=True).stdout.strip() + samples = {name: [] for name in variants} + names = list(variants) + for trial in range(args.trials): + for name in names[trial % 3:] + names[:trial % 3]: + sample = one(variants[name], root / f'{name}-{trial}', + root / 'initial', root / 'replacement') + samples[name].append({'trial': trial, **sample}) + result = {'profile': 'native-cli-durable-one-mib-document-last-byte-edit', + 'platform': platform.platform(), 'filesystem': filesystem, + 'trials_per_variant': args.trials, + 'final_body_sha256': hashlib.sha256(EXPECTED).hexdigest(), + 'scope': ('Each sample starts a new CLI process; create and edit each ' + 'include program parsing, store initialization, file and ' + 'directory synchronization. Show verifies the final revision ' + 'but is outside the timed operations. The host page cache, ' + 'filesystem and device remain uncontrolled.'), + 'variants': {name: {'binary_sha256': hashlib.sha256(binary.read_bytes()).hexdigest(), + 'median_create_ms': round(statistics.median( + row['create_ms'] for row in samples[name]), 3), + 'median_edit_ms': round(statistics.median( + row['edit_ms'] for row in samples[name]), 3), + 'samples': samples[name]} + for name, binary in variants.items()}} + args.output.parent.mkdir(parents=True, exist_ok=True) + args.output.write_text(json.dumps(result, indent=2) + '\n') + print(json.dumps({name: {key: value for key, value in entry.items() + if key.startswith('median_')} + for name, entry in result['variants'].items()}, indent=2)) + + +if __name__ == '__main__': + main() diff --git a/research/experiments/005-storage-edit-latency/paged-memory.json b/research/experiments/005-storage-edit-latency/paged-memory.json new file mode 100644 index 0000000..a9bef53 --- /dev/null +++ b/research/experiments/005-storage-edit-latency/paged-memory.json @@ -0,0 +1,43 @@ +{ + "passed": true, + "failures": [], + "profile": "portable-measurement-no-budget", + "variant": "source-program", + "scope": "Child-process peak RSS for native CLI document creation, read and one-byte revision edit; includes libc and the selected program form, excludes filesystem cache, kernel buffers, TLS, GUI and other apps. No cross-platform memory ceiling is asserted.", + "samples": { + "small_edit_rss_kib": 1088, + "one_mib_edit_rss_kib": 2112, + "one_mib_show_rss_kib": 1088, + "one_mib_splice_rss_kib": 1056 + }, + "raw_samples": { + "small_edit_rss_kib": { + "exit_code": 0, + "max_rss_kib": 1088, + "raw_max_rss": 1088, + "raw_unit": "KiB" + }, + "one_mib_edit_rss_kib": { + "exit_code": 0, + "max_rss_kib": 2112, + "raw_max_rss": 2112, + "raw_unit": "KiB" + }, + "one_mib_show_rss_kib": { + "exit_code": 0, + "max_rss_kib": 1088, + "raw_max_rss": 1088, + "raw_unit": "KiB" + }, + "one_mib_splice_rss_kib": { + "exit_code": 0, + "max_rss_kib": 1056, + "raw_max_rss": 1056, + "raw_unit": "KiB" + } + }, + "budget_sha256": null, + "binary_sha256": "e1c12a2f5e736bb86737ceff7849fe95b1a9d13136e8c5eb3f3398cb3971c6f5", + "binary_bytes": 200704, + "platform": "Linux-6.18.39+rpt-rpi-2712-aarch64-with-glibc2.41" +} diff --git a/research/experiments/005-storage-edit-latency/sequence.py b/research/experiments/005-storage-edit-latency/sequence.py new file mode 100644 index 0000000..57ff835 --- /dev/null +++ b/research/experiments/005-storage-edit-latency/sequence.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 +"""Measure repeated durable edits and page-segment rebuilds on one real document.""" +import argparse +import hashlib +import json +from pathlib import Path +import platform +import statistics +import subprocess +import tempfile + +from measure import INITIAL, PROGRAM, invoke + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--flat', type=Path, required=True) + parser.add_argument('--paged', type=Path, required=True) + parser.add_argument('--scratch-parent', type=Path, required=True) + parser.add_argument('--edits', type=int, default=70) + parser.add_argument('--output', type=Path, required=True) + args = parser.parse_args() + if args.edits < 66 or args.output.exists(): + parser.error('at least 66 edits are needed to observe the current rebuild boundary; output must be new') + binaries = {'flat': args.flat.resolve(), 'paged': args.paged.resolve()} + args.scratch_parent.mkdir(parents=True, exist_ok=True) + with tempfile.TemporaryDirectory(prefix='pure-storage-sequence-', + dir=args.scratch_parent.resolve()) as name: + root = Path(name) + filesystem = subprocess.run(['findmnt', '-T', str(root), '-no', 'FSTYPE,SOURCE'], + capture_output=True, text=True, check=True).stdout.strip() + (root / 'initial').write_bytes(INITIAL) + patches = {'Y': root / 'Y', 'Z': root / 'Z'} + for label, file in patches.items(): + file.write_bytes(label.encode()) + bases = {variant: [binary, '--program', PROGRAM, '--store', root / variant] + for variant, binary in binaries.items()} + for base in bases.values(): + result, _ = invoke([*base, 'edit', 'document', 0, 0, 0, root / 'initial']) + assert json.loads(result.stdout)['revision'] == '1' + samples = {variant: [] for variant in binaries} + for edit in range(1, args.edits + 1): + patch = 'Z' if edit % 2 else 'Y' + order = ('flat', 'paged') if edit % 2 else ('paged', 'flat') + for variant in order: + base = bases[variant] + result, elapsed = invoke([*base, 'edit', 'document', edit, + len(INITIAL) - 1, 1, patches[patch]]) + assert json.loads(result.stdout)['revision'] == str(edit + 1) + files = [file for file in (root / variant).iterdir() if file.is_file()] + samples[variant].append({'edit': edit, 'elapsed_ms': round(elapsed, 3), + 'files': len(files), + 'allocated_bytes': sum(file.stat().st_blocks * 512 + for file in files)}) + expected = INITIAL[:-1] + patches[patch].read_bytes() + for base in bases.values(): + shown, _ = invoke([*base, 'show', 'document']) + assert shown.stdout == expected + assert json.loads(shown.stderr)['revision'] == str(args.edits + 1) + result = {'profile': 'repeated-durable-one-mib-document-last-byte-edit', + 'platform': platform.platform(), 'filesystem': filesystem, + 'edits_per_variant': args.edits, + 'final_body_sha256': hashlib.sha256(expected).hexdigest(), + 'scope': ('Same actual source-loaded CLI and editor.pure, two persistent ' + 'stores, alternating operation order. Timings include each ' + 'edit process, parser, store init and fsync; creation and ' + 'final show are not timed. Device state is uncontrolled.'), + 'variants': {variant: { + 'binary_sha256': hashlib.sha256(binary.read_bytes()).hexdigest(), + 'median_edit_ms': round(statistics.median(row['elapsed_ms'] + for row in samples[variant]), 3), + 'samples': samples[variant]} + for variant, binary in binaries.items()}} + args.output.parent.mkdir(parents=True, exist_ok=True) + args.output.write_text(json.dumps(result, indent=2) + '\n') + print(json.dumps({variant: {'median_edit_ms': row['median_edit_ms'], + 'max_edit_ms': max(sample['elapsed_ms'] + for sample in row['samples']), + 'max_allocated_bytes': max(sample['allocated_bytes'] + for sample in row['samples'])} + for variant, row in result['variants'].items()}, indent=2)) + + +if __name__ == '__main__': + main() diff --git a/research/experiments/006-native-save-latency/2026-09-24-ext4-linux-aarch64.json b/research/experiments/006-native-save-latency/2026-09-24-ext4-linux-aarch64.json new file mode 100644 index 0000000..0f2d215 --- /dev/null +++ b/research/experiments/006-native-save-latency/2026-09-24-ext4-linux-aarch64.json @@ -0,0 +1,221 @@ +{ + "platform": "Linux-6.18.39+rpt-rpi-2712-aarch64-with-glibc2.41", + "filesystem": "/dev/mmcblk0p2[/home/eunhhu/work/pure] ext4", + "workload": "one-byte final-character replacement, Ctrl+S to complete visible frame; includes full draft comparison, runtime, durable store and redraw; initial creation and final independent CLI read excluded", + "rounds": 3, + "edits_per_session": 8, + "binaries": { + "flat": { + "cli_sha256": "27d9ad1c83265cef24f5e756537a68692852145bfc7c1e31255e18c08fac6295", + "tui_sha256": "e8b224e3ce5f5d83d597418d4027ec36dd44bfe84d17f6e9224135dc457316c1" + }, + "paged": { + "cli_sha256": "e829bd6bad3b56bc319cdab03aba7f45c44afab53876e462ae57c35b82823e9a", + "tui_sha256": "09303ec33d07c12b07834b07fb5eeb836005c23fcb3a6b6cc2683631a9d4b13c" + } + }, + "runs": { + "flat": { + "256": [ + { + "samples_ns": [ + 5958081, + 7778966, + 6548524, + 19995479, + 62301450, + 9400518, + 5842210, + 8589502 + ], + "median_ns": 8184234, + "final_revision": 9, + "body_sha256": "e075f2f51cad23d0537186cfcd50f911ea954f9c2e32a437f45327f1b7899bbb" + }, + { + "samples_ns": [ + 9415093, + 16809059, + 8447428, + 8676279, + 6705838, + 9542795, + 10029758, + 6036581 + ], + "median_ns": 9045686, + "final_revision": 9, + "body_sha256": "e075f2f51cad23d0537186cfcd50f911ea954f9c2e32a437f45327f1b7899bbb" + }, + { + "samples_ns": [ + 7148893, + 10145461, + 7778114, + 6517728, + 62411765, + 50067253, + 7390504, + 8495113 + ], + "median_ns": 8136613, + "final_revision": 9, + "body_sha256": "e075f2f51cad23d0537186cfcd50f911ea954f9c2e32a437f45327f1b7899bbb" + } + ], + "1048576": [ + { + "samples_ns": [ + 145172249, + 96882586, + 40365568, + 349602121, + 39360237, + 89495933, + 183181933, + 87081031 + ], + "median_ns": 93189259, + "final_revision": 9, + "body_sha256": "4e29ad18ab9f42d7c233500771a39d7c852b200baf328fd00fbbe3fecea1eb56" + }, + { + "samples_ns": [ + 29222924, + 88900009, + 92498076, + 104674699, + 38498924, + 95164515, + 104447385, + 98216731 + ], + "median_ns": 93831295, + "final_revision": 9, + "body_sha256": "4e29ad18ab9f42d7c233500771a39d7c852b200baf328fd00fbbe3fecea1eb56" + }, + { + "samples_ns": [ + 150963793, + 89303082, + 89762414, + 128623245, + 37319148, + 93848499, + 101872780, + 90491636 + ], + "median_ns": 92170067, + "final_revision": 9, + "body_sha256": "4e29ad18ab9f42d7c233500771a39d7c852b200baf328fd00fbbe3fecea1eb56" + } + ] + }, + "paged": { + "256": [ + { + "samples_ns": [ + 8496650, + 19415609, + 6801246, + 9666703, + 10048962, + 6038507, + 8610260, + 7698300 + ], + "median_ns": 8553455, + "final_revision": 9, + "body_sha256": "e075f2f51cad23d0537186cfcd50f911ea954f9c2e32a437f45327f1b7899bbb" + }, + { + "samples_ns": [ + 9062278, + 62254117, + 6872783, + 9583444, + 50943122, + 6743320, + 9396814, + 9949258 + ], + "median_ns": 9490129, + "final_revision": 9, + "body_sha256": "e075f2f51cad23d0537186cfcd50f911ea954f9c2e32a437f45327f1b7899bbb" + }, + { + "samples_ns": [ + 9526426, + 8758853, + 6706653, + 97037325, + 5886063, + 20592941, + 9999906, + 6661357 + ], + "median_ns": 9142639, + "final_revision": 9, + "body_sha256": "e075f2f51cad23d0537186cfcd50f911ea954f9c2e32a437f45327f1b7899bbb" + } + ], + "1048576": [ + { + "samples_ns": [ + 20936773, + 33867655, + 20611237, + 21735235, + 20170997, + 34975172, + 20189182, + 22094974 + ], + "median_ns": 21336004, + "final_revision": 9, + "body_sha256": "4e29ad18ab9f42d7c233500771a39d7c852b200baf328fd00fbbe3fecea1eb56" + }, + { + "samples_ns": [ + 97702566, + 25086172, + 20087812, + 22047179, + 53326394, + 22037808, + 20212422, + 21726179 + ], + "median_ns": 22042493, + "final_revision": 9, + "body_sha256": "4e29ad18ab9f42d7c233500771a39d7c852b200baf328fd00fbbe3fecea1eb56" + }, + { + "samples_ns": [ + 19868442, + 22179308, + 21243699, + 30931198, + 21662716, + 68731271, + 23544638, + 26258818 + ], + "median_ns": 22861973, + "final_revision": 9, + "body_sha256": "4e29ad18ab9f42d7c233500771a39d7c852b200baf328fd00fbbe3fecea1eb56" + } + ] + } + }, + "median_ns": { + "flat": { + "256": 8542307, + "1048576": 93173287 + }, + "paged": { + "256": 9229546, + "1048576": 22042493 + } + } +} diff --git a/research/experiments/006-native-save-latency/measure.py b/research/experiments/006-native-save-latency/measure.py new file mode 100644 index 0000000..f1e2a00 --- /dev/null +++ b/research/experiments/006-native-save-latency/measure.py @@ -0,0 +1,139 @@ +#!/usr/bin/env python3 +"""Time durable one-byte saves in the actual native terminal document app.""" +import argparse +import fcntl +import hashlib +import json +import os +from pathlib import Path +import platform +import pty +import select +import statistics +import struct +import subprocess +import tempfile +import termios +import time + + +def run(*args): + return subprocess.run([str(arg) for arg in args], check=True, + capture_output=True, timeout=30) + + +def frame(master, process): + output = bytearray() + deadline = time.monotonic() + 15 + while time.monotonic() < deadline: + if select.select([master], [], [], 0.5)[0]: + output.extend(os.read(master, 65536)) + if b'\x1b[?25h' in output: + return bytes(output) + if process.poll() is not None: + break + raise AssertionError((process.poll(), output[-1000:])) + + +def one_session(cli, tui, root, size, iterations): + root.mkdir(parents=True) + store = root / 'store' + body = b'A' * size + insert = root / 'initial.bin' + insert.write_bytes(body) + assert json.loads(run(cli, '--store', store, 'edit', 'document', + 0, 0, 0, insert).stdout)['revision'] == '1' + master, slave = pty.openpty() + fcntl.ioctl(slave, termios.TIOCSWINSZ, struct.pack('HHHH', 24, 80, 0, 0)) + original = termios.tcgetattr(slave) + process = subprocess.Popen([str(tui), '--store', str(store), 'document'], + stdin=slave, stdout=slave, stderr=slave, + env={**os.environ, 'LANG': 'C.UTF-8', 'LC_ALL': 'C.UTF-8'}) + samples = [] + try: + assert b'Pure | document' in frame(master, process) + for index in range(iterations): + replacement = b'B' if index % 2 == 0 else b'A' + os.write(master, b'\x7f') + frame(master, process) + os.write(master, replacement) + frame(master, process) + start = time.perf_counter_ns() + os.write(master, b'\x13') + shown = frame(master, process) + elapsed = time.perf_counter_ns() - start + expected = f'Saved 1-byte edit at byte {size - 1}'.encode() + revision = f'revision {index + 2}'.encode() + assert expected in shown and revision in shown, shown[-1500:] + samples.append(elapsed) + os.write(master, b'\x11') + process.wait(timeout=8) + assert process.returncode == 0 + assert termios.tcgetattr(slave) == original + finally: + if process.poll() is None: + process.kill() + process.wait(timeout=5) + os.close(master) + os.close(slave) + final = run(cli, '--store', store, 'show', 'document') + expected_body = body[:-1] + (b'B' if iterations % 2 else b'A') + assert final.stdout == expected_body + assert json.loads(final.stderr)['revision'] == str(iterations + 1) + return {'samples_ns': samples, 'median_ns': int(statistics.median(samples)), + 'final_revision': iterations + 1, + 'body_sha256': hashlib.sha256(final.stdout).hexdigest()} + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--flat-cli', type=Path, required=True) + parser.add_argument('--flat-tui', type=Path, required=True) + parser.add_argument('--paged-cli', type=Path, required=True) + parser.add_argument('--paged-tui', type=Path, required=True) + parser.add_argument('--scratch-parent', type=Path, required=True) + parser.add_argument('--rounds', type=int, default=3) + parser.add_argument('--edits', type=int, default=8) + parser.add_argument('--output', type=Path) + args = parser.parse_args() + if args.rounds < 1 or args.edits < 1 or (args.output and args.output.exists()): + parser.error('rounds and edits must be positive; output must not exist') + binaries = {name: (cli.resolve(), tui.resolve()) for name, cli, tui in + (('flat', args.flat_cli, args.flat_tui), + ('paged', args.paged_cli, args.paged_tui))} + parent = args.scratch_parent.resolve() + parent.mkdir(parents=True, exist_ok=True) + filesystem = run('findmnt', '-T', parent, '-no', 'SOURCE,FSTYPE').stdout.decode().strip() + raw = {name: {'256': [], '1048576': []} for name in binaries} + with tempfile.TemporaryDirectory(prefix='pure-native-save-', dir=parent) as directory: + root = Path(directory) + for size in (256, 1_048_576): + for round_number in range(args.rounds): + order = ('flat', 'paged') if round_number % 2 == 0 else ('paged', 'flat') + for name in order: + cli, tui = binaries[name] + raw[name][str(size)].append(one_session( + cli, tui, root / f'{size}-{round_number}-{name}', size, args.edits)) + result = {'platform': platform.platform(), 'filesystem': filesystem, + 'workload': 'one-byte final-character replacement, Ctrl+S to complete visible frame; ' + 'includes full draft comparison, runtime, durable store and redraw; ' + 'initial creation and final independent CLI read excluded', + 'rounds': args.rounds, 'edits_per_session': args.edits, + 'binaries': {name: {'cli_sha256': hashlib.sha256(cli.read_bytes()).hexdigest(), + 'tui_sha256': hashlib.sha256(tui.read_bytes()).hexdigest()} + for name, (cli, tui) in binaries.items()}, + 'runs': raw, + 'median_ns': {name: {size: int(statistics.median( + sample for session in sessions for sample in session['samples_ns'])) + for size, sessions in sizes.items()} for name, sizes in raw.items()}} + encoded = json.dumps(result, indent=2) + '\n' + if args.output: + args.output.parent.mkdir(parents=True, exist_ok=True) + args.output.write_text(encoded) + print(json.dumps({'platform': result['platform'], 'filesystem': filesystem, + 'median_ns': result['median_ns'], 'rounds': args.rounds, + 'edits_per_session': args.edits})) + + +if __name__ == '__main__': + main() |
