Architecture & Benchmark Glossary

YAML parsing modes explained

YAML benchmarks compare very different output representations: raw token scanners, streaming event iterators, flat-array zero-copy tapes, owned dynamic trees, typed Serde decoders, and unsafe C++ mutable arenas. This visual guide explains what each label means, what work it performs in memory, and which ayaml API fits your workload.

1 · Work performed per layer

From raw UTF-8 bytes to typed structs or DOMs

Every stage adds structure, validation, and ownership guarantees. Comparing a raw scanner or an unsafe C++ arena directly against an owned Rust Value tree without accounting for these layers mixes very different amounts of per-node work.

YAML parsing pipeline and mode spectrum Two-track architecture diagram showing ayaml's safe Rust pipeline (UTF-8 bytes to Scanner to Pull Events to Typed Serde, Tape DOM, SpannedTree, and Value DOM) alongside unsafe C and C++ parser paths (libyaml, libfyaml, and rapidyaml mutable arenas). Safe Rust pipeline (ayaml · #![forbid(unsafe_code)] · single YAML 1.2.2 grammar) YAML Input &str UTF-8 immutable bytes 1. Scanner scanner only tokens, 0 retained 2. Pull Events parse_events ~42.0 KiB block stream Typed Serde from_str_borrowed Streams into structs; zero DOM; borrows &str Tape DOM & ParserBuf parse_tape Flat 16 B array; zero-copy &str; reusable buf SpannedTree SpannedTree::parse Byte-accurate Span per node for linters/edits Value DOM (Baseline) parse_value Owned mutable Mapping / Vec / String tree Unsafe C / C++ peer architectures (FFI · raw pointers or mutable byte arenas) C Pull Events & Docs libyaml & libfyaml (events / doc) C++ Mutable / Flat Arena rapidyaml: in-place / arena / reuse C++ Typed Arena Walk rapidyaml: resolve-typed walk
Upper track: every ayaml API builds on the same safe-Rust YAML 1.2.2 scanner and pull-event grammar with explicit DoS limits and duplicate-key rejection. Lower track: C and C++ peers use unsafe FFI and distinct memory representations.
2 · How data lives in memory

Owned Value DOM vs. Safe Tape DOM vs. Unsafe C++ Arena

Consider the same small YAML document: host: api.internal and ports: [8080, 8443]. The three architectures store that identical document in fundamentally different heap layouts.

Memory layout comparison across Value DOM, Tape DOM, and C++ arena Three side-by-side memory diagrams comparing per-node heap allocations in an owned Value DOM, a single contiguous 16-byte flat array borrowing slices in ayaml Tape DOM, and caller buffer mutation in rapidyaml C++ parse-in-place arena mode. 1. Owned Value DOM parse_value, yaml-rust2, saphyr Mapping (root) hash buckets + entry table (heap #1) String "host" heap alloc #2 "api.internal" heap alloc #3 String "ports" heap alloc #4 Vec[8080,8443] heap alloc #5 + Easy to mutate, drop input, 'static + Order-preserving + dup-key checks - Many small per-node allocations 100% safe Rust 2. Safe Tape DOM (ayaml) parse_tape & ParserBuf reuse Input &str (untouched) host: api.internal \n ports: ... zero-copy &str 1 flat Vec<Node> (16 B / node) Map(2) Str 0..4 Str 6..18 Str 19..24 | Seq(2) | 8080,8443 + 140x fewer allocs; 0 with ParserBuf + 3.75x less peak heap than rapidyaml - Read-only (or 'static OwnedTape) Safe Rust: #![forbid(unsafe_code)] 3. Unsafe C++ Arena rapidyaml (parse-in-place / arena) Mutable char* input buffer mutated in place when unescaping length-sliced views C++ NodeData[] arena Linked sibling/child integer indices Raw unparsed scalar slices until resolve-typed walk converts types + Very fast raw structural parse - Skips dup-key hash & Rust UTF-8 - Higher peak arena bytes (3.75x vs Tape) Unsafe C++ FFI
Why ayaml (Tape DOM) closes most of the speed gap to C++ rapidyaml while using 3.75x less peak heap: a single flat 16-byte array eliminates per-node heap churn without mutating caller memory or using unsafe.
3 · Term-by-term reference

What every benchmark label means

Every chart and table on the homepage and Benchmarks & Performance uses these exact mode names. Jump directly to any label below.

Tier 1 · ayaml scanner only / ayaml scan

Lexical scanner (tokenizer only)

Scans UTF-8 YAML bytes into low-level lexical tokens (block indicators, quoted/plain scalar boundaries, flow punctuation, anchors) without building a syntax tree or validating mapping keys. Exposed behind the unstable bench-internals feature strictly to measure the raw byte-scanning ceiling; on 14 of 26 fixtures it allocates zero heap bytes.

Tier 1 Baseline · ayaml pull events / ayaml::parse_events

Streaming pull-event parser

Public YAML 1.2.2 pull iterator yielding semantic events (DocumentStart, MappingStart, Scalar, SequenceEnd, ...) one at a time on demand. Callers consume and drop each event immediately (live_bytes = 0), keeping peak heap flat around 42.0 KiB on multi-line block documents from 10 KiB to 1 MiB. Reaches 2456.2 MiB/s on 1 MiB plain scalars.

Tier 1 & Tier 2 · ayaml Tape DOM / parse_tape

Safe flat-array zero-copy DOM

Builds a read-only, cache-friendly tree inside a single contiguous 16-byte-per-node Vec while borrowing unmodified scalars as zero-copy &str slices from the original input buffer. Enforces full YAML 1.2.2 Core schema typing, duplicate-key rejection, and DoS limits in pure safe Rust. Cold parse_tape is 1.43x faster than Value DOM with 1.51x less peak heap and 140x fewer heap allocations.

Tier 1 & Tier 2 · ayaml Tape + ParserBuf / ayaml tape-reuse

Warm buffer recycling for bulk loops

Pairs Tape, OwnedTape, or EventStream with a reusable ParserBuf scratch buffer via buf.parse_tape(input), buf.parse_events(input), and recycle_into(&mut buf). When parsing thousands of YAML documents in a loop, internal vectors retain their allocated capacity for zero-allocation steady-state parsing (1.46x faster than Value DOM). Timed-only in tables (matching rapidyaml parse-reuse) so cold memory ratios stay apples-to-apples.

Tier 2 Baseline · Rust / C++ DOMs Value DOM / parse_value

Owned mutable dynamic tree

Parses YAML into an owned, mutable in-memory value enum (Value::Mapping, Value::Sequence, Value::String, integers, floats, booleans, null). In ayaml, Mapping preserves key insertion order (backed privately by indexmap) and rejects duplicate keys. Peers in this tier include yaml-rust2, saphyr, noyalib, fast-yaml-core, yaml-serde, and C++ fkYAML.

Typed & Compat Serde from_str_borrowed / serde Value / compat serde

Direct Serde struct decoding & compatibility profiles

ayaml::from_str and ayaml::from_str_borrowed stream directly from pull events into your Rust struct with zero intermediate DOM; from_str_borrowed borrows unescaped &'a str fields in place. ayaml (serde Value) deserializes into ayaml::Value via Serde to measure Serde dispatch overhead. ayaml (compat serde) enables the additive libyaml-compat profile for libyaml-compatible legacy inputs (duplicate keys, under-indented flow continuations, and optional global-tag dropping while keeping YAML 1.2.2 scalar resolution). serde-saphyr (JSON Value) targets serde_json::Value because serde-saphyr does not expose a native YAML Value DOM.

Tier 1 · Diagnostics & Editing SpannedTree / Spanned<T>

Byte-accurate source spans on every node

Attaches exact byte-offset Span ranges (start..end) to every node in a parsed tree (SpannedTree::parse, with full read-only SpannedNode traversal) or to individual typed Serde fields (Spanned<T>). Combined with LineIndex (UTF-8, Unicode scalar, or LSP UTF-16 columns) and ayaml-edit, this powers diagnostic underlines, config validators, and verified comment-preserving edits.

Tier 1 · Unsafe C Peers libyaml / libfyaml (events, load, doc)

Reference C event streams and C document trees

libyaml events and libfyaml events are C pull-event APIs comparable to ayaml::parse_events (each event is pulled and discarded immediately). libyaml load and libfyaml doc materialize C document node structures in memory without Rust ownership or typed Value conversion (libfyaml is compiled with portable C flags HAVE_PORTABLE_TARGET=1).

Tier 1 & Tier 2 · Unsafe C++ Arena rapidyaml (C++ arena)

Four rapidyaml C++ arena benchmark modes

rapidyaml parses raw bytes into a flat unsafe C++ index array with coarse arena allocations, skipping Rust UTF-8 ownership checks and duplicate-key hashing. Our benchmarks measure all four of its documented modes transparently:

parse-in-place
Mutates and overwrites the caller's input byte buffer in place during unescaping so scalar strings need not be copied. Fastest raw structural parse, but requires mutable input ownership and destroys the original YAML text.
parse-arena
Cold structural parse from an immutable input buffer into a freshly allocated C++ flat arena (copies input bytes into the arena without resolving scalar types).
parse-reuse
Reuses an already-warmed C++ arena across parses (analogous to ayaml's safe Tape + ParserBuf). Timed-only so cold heap numbers are not skewed.
resolve-typed
Walks the parsed C++ arena and resolves scalar types (null, bool, int, float, string). Closest Tier 2 comparison to DOM parsers, though still without owned Rust Value trees, duplicate-key rejection, or memory safety.
Serialization emit / to_string / ayaml-edit

Deterministic YAML emission vs. source-preserving edits

Emission benchmarks measure serializing an already-parsed document back into canonical YAML text. ayaml quotes YAML 1.2 Core-schema scalars (null, true, false, numbers) and YAML 1.1 leading-zero numerals (such as 0644) so emitted strings round-trip unambiguously across YAML 1.1 and YAML 1.2 consumers, reaching up to 242.0 MiB/s. When you need to update a field while preserving existing comments, blank lines, and formatting, use the companion ayaml-edit crate instead of full re-emission.

4 · Practical decision guide

Which ayaml API should you choose?

Workload Recommended API Why it fits
Config files & typed Rust structs ayaml::from_str_borrowed / from_str Streams directly from events with zero intermediate DOM and minimal peak heap.
Read-only DOM inspection or bulk loops ayaml::parse_tape + ParserBuf Flat 16-byte nodes, zero-copy strings, 1.51x lower peak heap, and zero-alloc steady-state reuse.
Mutating, building, or re-emitting dynamic YAML ayaml::parse_value / to_string Owned, 'static, insertion-ordered Mapping tree with duplicate-key rejection.
Huge streams or custom low-memory pipelines ayaml::parse_events Flat ~42.0 KiB streaming heap on multi-line block documents and up to 2456 MiB/s plain-scalar throughput.
Linters, LSPs, rich error underlines Spanned<T> / SpannedTree::parse + LineIndex Exact byte offsets on every field/node convertible to UTF-8, scalar, or UTF-16 columns.
Surgical edits keeping comments & style ayaml-edit Patch-based edits verified against both the Value tree and canonical event diff.