Skip to content

YAMLRocks vs fast-yaml

fast-yaml (the fastyaml-rs package) is a Rust-backed YAML 1.2 parser built on the saphyr crate, with a PyYAML-style safe_load/safe_dump API and built-in linting. It is a capable, fast reader, and of the newer Rust parsers it gets the most right. But it is still a one-way parser: it does not edit YAML, resolve includes, or validate against a schema, and YAMLRocks is both more complete and faster.

Featurefast-yamlYAMLRocks
Comment-preserving round-tripNoYes (byte-for-byte)
Native !include + writebackNoYes
JSON Schema validationNoYes (line-numbered)
Source line/columnNoYes (annotated mode)
Custom tag handlingUnverifiedYes
Verified vs the YAML suiteNot statedYes, in full
Merge keys (<<)YesYes
Anchors/aliases resolvedYesYes
Multi-document streamsYesYes
ImplementationRust (saphyr)Rust (own scanner/emitter)
Speed (parse / dump)baseline~1.7x / ~1.7x faster

fast-yaml reads YAML into Python and lints it. YAMLRocks does that and the rest of what a real configuration workflow needs:

  • Comment-preserving round-trip. Load with OPT_ROUND_TRIP, change a value, and re-emit with comments, anchors, and formatting intact; an unmodified document comes back byte-for-byte. fast-yaml explicitly does not preserve comments, so it can read a file but not edit one.
  • Native !include with file-aware write-back across a split configuration.
  • JSON Schema validation with line-numbered errors.
  • Annotated mode with the source line and column on every node.
  • Custom tag handling, and safe-by-default loading.

See round-trip editing, includes, schema validation, and annotated mode.

Both are Rust extensions built on strict YAML 1.2. YAMLRocks is faster on both directions.

YAMLRocks vs fast-yaml on reading and writing: YAMLRocks is faster on both loads and dumps.

Operationfast-yamlYAMLRocksYAMLRocks is
Reading~2.9 ms~1.7 ms~1.7x faster
Writing~1.7 ms~1.0 ms~1.7x faster

fast-yaml is the most correct of the newer Rust parsers, it resolves merge keys, where yaml-rs, ryaml, and py-yaml12 leave << as a literal key. That makes the remaining difference the interesting one: YAMLRocks checks its parsing against the entire official YAML test suite on every change (load, round-trip, and canonical result), and fast-yaml still misreads a leading-zero integer:

import yamlrocks
# `0777` is a string in YAML 1.2 (the octal form is `0o777`), not the number 777.
yamlrocks.loads(b"mode: 0777")
# {'mode': '0777'}
# fast-yaml returns {'mode': 777}.

The point is not one scalar; it is that “verified against the whole suite” is a guarantee fast-yaml does not make, and the edges are where that shows.

fast-yaml is a fast, dual-licensed (MIT/Apache-2.0) 1.2 parser with a familiar safe_load/safe_dump surface and a handy built-in linter. If you want a quick, drop-in-flavored reader for trusted YAML and never write edited files back, it is a reasonable choice, and more faithful than its Rust peers.

Choose YAMLRocks when YAML is something you edit, include, validate, and depend on: comment-preserving round-trip, native includes, schema validation, and source locations, on a parser that is verified correct against the full YAML test suite and is faster too.