Crate kdlite

Crate kdlite 

Source
Expand description

Repository Crates.io docs.rs MIT OR Apache-2.0

Small streaming KDL v2.0.0 parser, based on just-kdl crate

Designed for reasonable performance and memory efficiency, at the expense (or benefit, depending on use) of not storing formatting information.

§Why?

The official Rust implementation is designed to support editing of kdl files. While this is normally useful, my main use of KDL is to just parse the values into some internal data structure (configuration, document trees, etc.) where formatting information is entirely redundant and just wasteful of parsing time and memory.

This parser is based on just-kdl crate, with opaque number type replaced with f64 and i128.

Additionally, this implementation has a few other benefits:

  • Full v2.0.0 compliance
  • Significantly fewer dependencies!

§Benchmarks

On AMD Ryzen 7 8700G:

Opt.ParserBenchmarkTimeAllocResizeFreeNet
Releasekdl-org/kdlhtml-standard.kdl5.777s7.2GiB205.0MiB5.9GiB1.5GiB
Releaseferronweb/kdlitehtml-standard.kdl0.233s289.0MiB34.1MiB768B323.1MiB
Releasekdl-org/kdlhtml-standard-compact.kdl3.750s4.5GiB163.1MiB3.9GiB871.4MiB
Releaseferronweb/kdlitehtml-standard-compact.kdl0.149s164.2MiB27.2MiB768B191.4MiB
Debugkdl-org/kdlhtml-standard.kdl69.347s7.2GiB205.0MiB5.9GiB1.5GiB
Debugferronweb/kdlitehtml-standard.kdl1.895s289.0MiB34.1MiB768B323.1MiB
Debugkdl-org/kdlhtml-standard-compact.kdl49.440s4.5GiB163.1MiB3.9GiB871.4MiB
Debugferronweb/kdlitehtml-standard-compact.kdl1.350s164.2MiB27.2MiB768B191.4MiB

In summary:

  • roughly 30 times faster
  • significantly fewer temporary allocations
  • smaller final output allocations

Modules§

dom
document tree structures, start at Document
stream
The actual parser