Repository navigation
feat(bench): parsec-xml had no numbers against libxml2 or anyone - #200
Open
jamesconwaydev wants to merge 3 commits into
Open
jamesconwaydev wants to merge 3 commits into
jamesconwaydev wants to merge 3 commits into
Conversation
On 7,447 Material Design icons, about 450 bytes each, parsec-xml ran at 269 MB/s to roxmltree's 446: each document built three hash maps and interned the built-in prefixes and namespaces before reading a byte, and its text buffer grew by doubling. The built-in prefixes and URIs now have fixed ids and no entries, a document's first 16 names are found by comparing rather than hashing, and the text buffer starts at the input's size. The icons parse at 514 MB/s, and a 94 MB Wikipedia slice goes from 1,275 MB/s and 183 MB peak to 1,449 MB/s and 100 MB.
bench/fetch-xml.sh downloads 102 MB of real XML pinned by SHA-256: sitemaps and feeds from the Internet Archive, SVGs, the XML spec, and a slice of a dated Wikipedia dump. `-- xml` times Parsec against libxml2's C, built from a submodule at v2.15.4 with its allocations counted, roxmltree and quick-xml, giving MB/s and peak memory. Parsec parses 1,314 MB/s to libxml2's 495 and roxmltree's 327, ahead of both on every document. quick-xml, timed reading events without a tree, is ahead on the Wikipedia slice and the Hacker News feed.
Brings the branch onto its new base after the pull request below it merged.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #172.
Stacked on #199.
Problem.
parsec-xmlhad no numbers. Nothing said how it compares with libxml2, which most XML on the web goes through (lxml, nokogiri, PHP), or with roxmltree and quick-xml, the Rust parsers people pick today. Running the comparison also showed a real cost: on 7,447 Material Design icons, about 450 bytes each, Parsec ran at 269 MB/s to roxmltree's 446, because every document built three hash maps and interned the built-in names before reading a byte, and its text buffer grew by doubling.Change.
bench/libxml2, a submodule at v2.15.4, built by CMake as a Release static library without iconv, zlib, ICU or Python.bench/src/libxml2.rsdeclares the calls it needs (xmlReadMemorywithXML_PARSE_NONET,xmlFreeDoc) and routes libxml2's allocations through the benchmark's allocator withxmlMemSetup, so its peak memory is counted as Parsec's is.bench/xml.txtandbench/fetch-xml.sh: 102 MB of real XML pinned by SHA-256. Sitemaps (MDN, New York Times) and RSS and Atom feeds (BBC, Hacker News, the Rust blog, rust-lang/rust releases, r/programming) as raw Internet Archive snapshots; SVGs from a Wikimedia snapshot and two versioned npm packages; the XML spec's XML source; and the first 24 MB of the 1 November 2026 English Wikipedia dump, decompressed and cut after its last whole</page>.cargo run --release --manifest-path bench/Cargo.toml -- xmltimes Parsec, libxml2 and roxmltree building trees, and quick-xml reading every event with namespaces resolved and every value normalized (it builds no tree, and the table says so). MB/s and peak MB per document, then the total.perf(xml): the built-in prefixes and URIs get fixed ids with no map entries, a document's first 16 names are found by comparing rather than hashing, and the text buffer starts at the input's size. The icons go from 269 to 514 MB/s, and the Wikipedia slice from 1,275 MB/s and 183 MB peak to 1,449 MB/s and 100 MB.Results. Apple M2 Max, macOS 26.7, Rust 1.100, today, MB/s · peak MB:
Parsec is 2.66 times libxml2's speed over the whole set and four times roxmltree's, ahead of both on every document, and holds no more memory than libxml2 on any. quick-xml is ahead on the Wikipedia slice and the Hacker News feed, and level on the BBC feed, while doing less: no tree, nothing kept. It refuses the XML spec because it can't expand entities its DTD declares. A second run after the perf change agreed within 2% on most documents. The small feeds and the MDN sitemap moved by up to 8%, and on the BBC feed quick-xml came out ahead, 628 to 608. The load was around 4 from other builds.
Tests. The bench job in CI builds it, libxml2 included, and lints it with clippy, rustfmt and cargo-deny (quick-xml and roxmltree are MIT). The real documents aren't in the repository, so CI doesn't run the XML table.
cargo test -p parsec-xmlpasses after the perf change, with a new test for names found either side of the 16-name switch, and xmlconf still has 1,915 passing.Wiki patch: Benchmarks
In the first paragraph, after the CSS sentence, add:
Add this section after
## CSSand its subsections, before## The final boss: