Field notes/Memoryrusty_xmlperformance

rusty_xml 0.10: Streaming SAX, Inline Strings and Linear Validation

Eight rusty_xml releases in one weekend: SAX that builds no tree, short names stored inline, arenas sized from the markup, and validators that stop multiplying their work.

Signed by M·
Painted canal lock at dawn where a keeper guides a narrow boat through the gate while a single lantern lights the misty water
What changed in rusty_xml 0.10?

Between November 13 and 15, 2026, rusty_xml went from 0.8.5 to 0.10.1. SAX with XML_PARSE_NO_TREE now streams without building a tree, node names and text are stored inline as CompactString, arenas are sized from the markup, and DTD and RelaxNG validation no longer multiply their work. Node field types changed, so 0.10 is a breaking upgrade.

Between Friday, November 13 and Sunday night, November 15, 2026 (Pacific time), rusty_xml moved from 0.8.5 to 0.10.1 on crates.io. That is eight releases in one weekend, most of them performance work, and each one carries its measurement in a commit message or pull request rather than on a slide. This note walks the parts of rusty_xml 0.10 that change how the crate spends memory and time, and the parts that change your code.

Every number below is copied from the public rusty_xml repository, with its baseline. We did not re-run any of it. Instruction counts come from callgrind, part of the Valgrind tool suite. Wall-clock figures were taken on Windows, and the commits do not name the CPU. Each comparison is against the previous rusty_xml release, not against libxml2.

If the crate is new to you, start with the rusty_xml field note and the case for a pure Rust alternative for libxml2. It lives in the Memory band.

What rusty_xml 0.10 changed in one weekend

The releases arrived in this order, with crates.io publish times in Pacific time:

  • 0.9.0, Friday afternoon. Node shrinks from 184 to 88 bytes, and the HTML arena is reserved up front and shrunk after the parse.
  • 0.9.1, early Saturday. Entity expansion is bounded as libxml2 bounds it, XPath gets an operation limit, DTD content models match in linear time, and long calls can be cancelled.
  • 0.9.2, Saturday morning. HTML stops at libxml2's nesting cap and sizes its arena from the markup.
  • 0.9.3 and 0.9.4, Saturday night. SAX without a tree streams, and RelaxNG remembers what it already tried.
  • 0.9.5, Sunday morning. DTD and RelaxNG validation stop scaling with the product of two input sizes. TEI P5 and DocBook 4.5 DTDs now load.
  • 0.10.0, Sunday morning. Short node names and text are stored inline with compact_str.
  • 0.10.1, Sunday night. End-tag names come from a pool, the XML arena is sized from the markup, and one settings type carries limits and cancellation.

Correctness held while this happened. The commits report output identical to the previous release, and the W3C XML Conformance Test Suite table unchanged at 2034 of 2036 scored cases. That suite tests parsers against the XML 1.0 specification.

Where the parser stopped spending memory

Most of the weekend went into one question: how many bytes does a parse hold that no node will ever use?

Streaming SAX in rusty_xml 0.9.3

Before 0.9.3, a SAX parse with XML_PARSE_NO_TREE still allocated, linked and kept an element node for every element. Pull request #53 removed that. No element node is built, the end tag's namespace comes from the scope that is still open, and no arena is reserved. Names are read in place after one UTF-8 validation of the buffer, and attribute names and values reuse pooled buffers.

The test file was a generated 138 MB 3MF model part with 3 million elements. On Windows, a run went from 2.04 to 2.10 seconds down to 0.57 to 0.60 seconds. Peak working set fell from 434 MB to 136 MB, and peak commit from 543 MB to 132 MB. Under callgrind, a 25,000 vertex harness fell 44.9 percent, from 460.7 million instructions to 253.7 million.

quick-xml 0.41 is still quicker on that harness, at 0.32 to 0.33 seconds and 135 MB. Memory is now level. Time is not, and rusty_xml checks name characters, namespace bindings, duplicate attributes and attribute normalization that quick-xml leaves to the caller. The same change made ordinary tree parsing 15.5 percent cheaper in instructions across eight real files.

Smaller nodes and inline strings

The 0.9.0 change cut Node from 184 to 88 bytes. Seven links became 4-byte ids with a niche, and namespace prefixes and URIs are interned per document. Then 0.10.0 made Node::name and Node::content a CompactString: 24 bytes, the size of a String, holding up to 24 bytes inline. Most names and text runs in a real tree are short, and each one used to be its own heap block.

On 197 real HTML pages parsed five times with the Windows system allocator, parse time went from 188 to 208 ms down to 148 to 168 ms. Dropping the trees went from 47 to 48 ms to 25 to 29 ms, and memory held fell from 188.9 MiB to 155.0 MiB. Callgrind put the XML benchmark 5.8 percent lower and XPath 4.6 percent lower.

Arenas sized from the markup

The node arena used to be reserved from input length, which is a poor guess. Script-heavy pages carry many bytes per node and dense fragments very few. In 0.9.2, HTML began counting the < characters it already scans and reserving two nodes per tag, and a 1.54 MB script-heavy page went from 14.6 MiB of peak commit to 3.4 MiB on Windows. In 0.9.5 the ratio became 17/8, because at two per tag 428 of 1,017 test pages overflowed and copied a doubled arena. A 1.6 MB page that just overflowed went from 19.1 MiB to 8.7 MiB.

In 0.10.1, XML follows with 3/2 nodes per < or =. A 3.5 MB sparse document peaked at 32.8 MiB of commit and now peaks at 5.8 MiB. Push parsing shrinks its result like the one-shot path, so a 4.8 MB pushed document holds 50.7 MiB instead of 71.2 MiB.

Upgrading to rusty_xml 0.10 without surprises

Most of the new release needs no code change. Validation got faster on its own, while the node fields and two behaviour changes need a look before you bump the version.

Validators in rusty_xml that stop multiplying

Four validation paths scaled with the product of two input sizes. DTD validation now builds an index from element type to declared attributes once per run: 20,000 elements against 8,000 declared types went from 1,675 ms to 17.6 ms. Content models share one follow set per group instead of copying it to every position, so 64 large repeated models went from 4,266 ms and 2,093 MiB to 65 ms and 20 MiB.

RelaxNG matching now reads each element's children once and moves a small state over them. In release builds on Windows, 100,000 siblings under zeroOrMore(element) went from 1,117 ms to 4.6 ms, and a choice of three repeated 100,000 times went from 20,735 ms to 28.9 ms. Agreement with xmllint on libxml2's own RelaxNG tests rose from 95 to 106 cases. External DTDs also read the way libxml2 reads them now, so TEI P5 and DocBook 4.5 load where 0.9.3 refused both.

Breaking changes to check first

The compile error is the node fields. Node::name and Node::content are CompactString, re-exported as rusty_xml::CompactString. Reading is unchanged, because both deref to &str and compare with str and String. Writing needs .into(), and an owned copy needs .to_string(). Since Cargo treats a 0.x minor bump as breaking, a requirement of "0.8" will not pick up 0.10 on its own.

[dependencies]
rusty_xml = "0.10"

Two quieter behaviour changes landed on the way. In 0.9.1, xml_xpath_cmp_nodes flipped its sign to return libxml2's values, so a sort built on it should be checked. In 0.9.2, HTML parsing stops at 256 levels of nesting, or 2048 under XML_PARSE_HUGE, and records a resource-limit warning. In 0.10.1, xml_parse_dtd honours a text declaration's encoding and refuses undeclared invalid UTF-8 instead of substituting U+FFFD.

Cancellation and limits in one rusty_xml settings type

Parsing, XPath, the validators, C14N and save all have _interruptible variants that take an Interrupt: an AtomicBool, a closure or NeverInterrupt. As of 0.10.1, DTD loading, XInclude and the reader take one through ParseSettings, which also carries the depth cap and the amplification limit. Past 1,000,000 bytes, entity expansion may not exceed five times the input consumed.

For adoption notes, read how to use rusty_xml with AI assisted coding and the rusty_xml repo landing. The crate's in-the-wild user, RAG Converter, reads Office files through the 0.8 line today, so moving it to 0.10 is its own change with its own measurement. The privacy case for a memory-safe XML parser is made in a safer XML parser for files that stay on your device. The program thesis is The Importance of Remade With Rust.

FAQ

Quick answers for builders evaluating this technology.

How much did streaming SAX in rusty_xml 0.9.3 save?

On a generated 138 MB 3MF model part with 3 million elements, the pull request reports Windows times of 2.04 to 2.10 seconds in 0.9.2 and 0.57 to 0.60 seconds in 0.9.3, with peak working set falling from 434 MB to 136 MB. Output was byte-identical across 399 corpus runs.

Is rusty_xml now faster than quick-xml?

Not on that SAX harness. quick-xml 0.41 took 0.32 to 0.33 seconds and 135 MB on the same 138 MB file, against 0.57 to 0.60 seconds and 136 MB for rusty_xml 0.9.3. The README notes rusty_xml still checks name characters, namespace bindings, duplicate attributes and attribute normalization.

Which rusty_xml 0.10 changes can break my build?

Node::name and Node::content are CompactString instead of String, so assignments need .into() and owned copies need .to_string(). Earlier in the weekend, xml_xpath_cmp_nodes flipped its sign to match libxml2 and HTML parsing gained a 256-level nesting cap by default.

Does rusty_xml still forbid unsafe code after adopting compact_str?

rusty_xml's own crates stay at zero unsafe. The new dependency, compact_str, is pinned to an exact version and has internal unsafe that its maintainers fuzz and check with Miri and Kani. The commit says it passed cargo audit, cargo deny and a checksum scan before adoption.

Were the rusty_xml 0.10 numbers measured against libxml2?

No. Each weekend figure compares a rusty_xml release with the one before it, using callgrind instruction counts or Windows wall-clock runs. The libxml2 comparison in the README is an older board measured on an earlier release, and the commits do not name the CPU used.