Open Source

Parsec: 16 Days to Beat Lexbor, and What I'm Building Next

#Parsec#Rust#HTML#JavaScript#Parsing#Lexbor#Open Source#Netweir
James Conway11 min read

TL;DR: Parsec is the HTML parser I wrote for Netweir, pulled out into its own project on 4 November. Sixteen days later it shipped on crates.io, PyPI and npm, parsing real pages at 370 MB a second to Lexbor's 242. That was the goal. It isn't the finish line. A JavaScript parser of its own and an XML parser are already working on the main branch, and Parsec is on its way to being the parsing foundation for the web: HTML, CSS, JavaScript and XML, one crate at a time.

See Parsec on GitHub

Every scraper eventually spends most of its time parsing. You don’t notice at first. The network is slow, so the network gets the blame. Then you fix the network, and the profiler points at the HTML parser and doesn’t stop pointing.

That’s where I was with Netweir. I’d built the fetching, the crawl queue and the browser driving, and under all of it sat a parser that was quick but not quick enough. The one to beat was Lexbor, a C library that’s fast and follows the spec. So I set myself a slightly ridiculous target: write one in Rust that beats it, page for page.

Where It Started

One parser, two homes

Parsec isn’t a rewrite of anything. It’s the parser inside Netweir, copied into a repository of its own with a script that keeps the two in step. A CI check fails the moment they drift. Netweir stays the proving ground, and Parsec is where everyone else can use it, under Apache-2.0.

I made one rule on day one: nothing goes in the “done” column of the README until it ships with its tests. A claim either has a test behind it, or it says “planned”. That rule has saved me from myself more than once.

What Sixteen Days Bought

Numbers first, since that's the point

I didn’t want to borrow anyone else’s benchmark, so an early milestone built one. The bench compiles Lexbor from a pinned release and runs it, html5ever and Parsec on the same input in one process, on the same machine.

On 13 real pages, 24 MB of Wikipedia, MDN, GitHub, the BBC, the New York Times, the HTML spec and others, Parsec parses 370 MB a second. Lexbor manages 242, html5ever 82. Parsec is ahead on every one of the 13, and holds less memory than Lexbor on each.

Selectors were a bigger gap than I expected. Thirty-two of them over those pages take Parsec 226 ms in all and Lexbor 728. One, p:nth-child(2n+1), costs Lexbor 339 ms; Parsec does it 31 times faster.

Then there’s what I call the final boss. A crawl doesn’t hand you tidy pages one at a time. It hands you a thousand at once: 46 real pages as they were served, 900 broken fragments with misnested tags and NUL bytes and comments left open, 44 pages in Shift_JIS and GBK and UTF-16, a few of them with a <meta> that lies about it, and ten giants of 10 to 30 MB. Parsec gets through all 1,000 in 1.02 seconds. Lexbor takes 1.94, and peaks at 952 MB of memory to Parsec’s 516.

Chart: Parsec against Lexbor and html5ever, from the Parsec wiki’s Benchmarks page. Headline: Parsec 370 MB/s on 13 real pages. Lexbor 242, html5ever 82. Two panels of horizontal bars. Throughput over 13 real pages, 24.4 MB, higher is better: Parsec 370 MB/s, Lexbor 242, html5ever 82. 1,000-page crawl, 265 MB, seconds, lower is better, with peak memory: Parsec 1.02 s and 516 MB peak, Lexbor 1.94 s and 952 MB peak, html5ever 5.99 s and 708 MB peak. Rig: Apple M2 Max (12 cores, 32 GB), macOS 26.7, Rust 1.100, Lexbor 3.0.1, html5ever 0.40.1 (RcDom). Pages are the median of 30 or more runs on 15 Nov 2026; the crawl is the median of 3 on 20 Nov 2026. Source github.com/parsec-html/parsec/wiki/Benchmarks.

Throughput over 13 real pages, then the 1,000-page crawl with peak memory. One M2 Max, Lexbor 3.0.1, html5ever 0.40.1; the numbers are from the Benchmarks page, runs on 15 and 20 Nov 2026.
Read the chart as text
  • 13 real pages, 24.4 MB in all: Parsec 370 MB/s, Lexbor 242 MB/s, html5ever 82 MB/s. That’s total bytes over the sum of the per-page medians, so the 15.8 MB HTML Standard page weighs most.
  • 1,000-page crawl, 265 MB: Parsec 1.02 s with 516 MB peak memory, Lexbor 1.94 s with 952 MB, html5ever 5.99 s with 708 MB. No crashes or timeouts for any of the three.
  • The rig: Apple M2 Max (12 cores, 32 GB), macOS 26.7, Rust 1.100. Lexbor 3.0.1 built with CMake Release at -O2; html5ever 0.40.1 with RcDom. Pages are the median of at least 30 runs after 3 warm-ups, 15 Nov 2026; the crawl is the median of 3, 20 Nov 2026. Source: Parsec wiki, Benchmarks.

And the inputs built to make a parser crawl? There are eight in the bench. Parsec wins all eight. 80,000 unclosed <div>s take it 3 ms. They take Lexbor 5.2 seconds.

Chart: Parsec’s hostile-input benchmark against Lexbor 3.0.1, run 15 Nov 2026. Headline: 80,000 unclosed div tags. Parsec 3 ms. Lexbor 5.2 seconds. Two horizontal bars on one scale: Lexbor’s runs most of the width at 5.2 s; Parsec’s, at 3 ms, would be half a pixel wide and is drawn at 2 px. A strip below lists Parsec’s lead on all eight hostile inputs, Parsec 8 of 8: 1,705x on 80,000 unclosed div; 241x on 10,000 b div b div (the adoption agency); 2.33x on 300 b then 3,000 p; 1.66x on 40,000 unclosed table; 1.57x on 20,000 misnested a p a; 1.48x on 50,000 foster-parented td; 1.45x on 80,000 nested span; 1.11x on 5,000 p with 12 formatting tags each.

The input that hurts most: 80,000 <div>s nobody closed. Parsec gets through it in 3 ms, Lexbor 3.0.1 in 5.2 s, and the strip shows the other seven. Numbers from the Parsec benchmarks page, run 15 Nov 2026 on an M2 Max.
Read the chart as text
  • 80,000 unclosed <div>s (0.40 MB): Parsec 3 ms, Lexbor 3.0.1 5.2 s. The bars share one scale, so Parsec’s would be half a pixel wide; it is drawn at 2 px.
  • Parsec’s lead over Lexbor on all eight hostile inputs, Parsec 8 of 8:
    • 80,000 unclosed <div>: 1,705x
    • 10,000 <b><div><b><div> (the adoption agency): 241x
    • 300 <b class=cN>, then 3,000 <p>x: 2.33x
    • 40,000 unclosed <table>: 1.66x
    • 20,000 misnested <a><p><a>x</p>: 1.57x
    • <table>, then 50,000 x<td>y (foster parenting): 1.48x
    • 80,000 nested <span>: 1.45x
    • 5,000 <p> with 12 formatting tags each: 1.11x
  • Parsec’s 3 ms is 0.40 MB at the published 131 MB/s. Source: Parsec wiki, Benchmarks, run 15 Nov 2026 on an Apple M2 Max, Lexbor 3.0.1 built with CMake Release at -O2.

It’s not only speed. Along the way Parsec picked up the things people keep asking Lexbor for:

  • Where a node came from. Byte ranges, lines and columns on nodes and attributes, whenever you ask for them.
  • Parse errors by name. All 7,042 of html5lib’s tokenizer error cases match.
  • A node you still hold after it’s removed. In Lexbor that’s a dangling pointer. In Parsec it reads as nothing, and you can ask whether it was removed.
  • XPath 1.0, passing libxml2’s expression tests.
  • Selectors Lexbor parses and never matches, like :lang(), :dir() and :valid.
  • CSS through the cascade, with all 822 properties in the specs typed and computed values worked out.
  • The WHATWG URL Standard, all 4,565 web-platform-tests cases passing, and 1.33 times as fast as Ada, the parser inside Node.js.

You can use it from Rust, C, Python (free-threaded too) and JavaScript through WebAssembly. cargo add parsec-html, pip install parsec-html or npm install parsec-html. If you’re coming from selectolax, the Python package speaks its API, and it parses those 13 pages in 66 ms to selectolax’s 106.

The Part Where I Was Wrong

Better you hear it from me

When I posted the numbers in a selectolax discussion, the pushback came fast, and from Lexbor’s own author. The benchmark wasn’t level, I was told, and Parsec could be crashed.

Fair. So I went looking. I found a page that really did crash Parsec: <template> tags nested deep enough to overflow the stack at the end of the input. Netweir had the same bug, since it’s the same parser. Both got fixed in the open, and 0.2.0 shipped on 21 November with a published advisory and a handful of other hardening fixes alongside it.

I’d rather have found it before anyone else did. I’d much rather have found it than not.

Parsec now has a second maintainer, a security policy, signed releases and the OpenSSF Best Practices silver badge, with gold one criterion away.

Lexbor Was Never the Finish Line

Beating it showed me what I actually needed

Here’s the thing I didn’t see until it was done. I didn’t need a faster HTML parser. I needed the parsing foundation I wish had existed when I started Netweir.

A scraper doesn’t only meet HTML. It meets CSS, which Parsec now handles. It meets XML in every sitemap and RSS feed. And more and more, it meets data that isn’t in the HTML at all. Open the source of a Next.js or Nuxt site and the product you’re after is sitting in a <script> tag, as a JavaScript object assigned to window.__NUXT__ or pushed into self.__next_f. Today you either start a browser to run that script, or write a regex that breaks on the first nested brace.

What if you could just parse it?

What’s Next

JavaScript and XML, a crate each

So that’s the plan, one crate per language. Some of it moved faster than this post: since 0.2.0 came out, the first JavaScript pieces and an XML parser landed on the main branch.

  • JavaScript, written from scratch. A parser, not an engine; nothing in it will ever run code. The lexer is done, and so is the script parser, which already parses all 47,895 scripts in test262, the official ECMAScript test suite, that should parse. Modules are what I’m on now. After that come scopes and bindings, and a benchmark against oxc and swc, the two to beat in Rust.
  • Data from scripts, without running them. The payoff for scraping. Hand Parsec a page and get back the JSON hidden in its scripts. Netweir will be the first to use it.
  • XML, with XML’s rules. HTML forgives everything and XML forgives nothing, so they don’t share a tree builder. The first version runs 1,915 cases from the W3C’s XML test suite and fails none. Namespaces are done properly, entity expansion is capped so a billion-laughs file stops with an error, and nothing is ever fetched from the network.
  • Every language, every way in. JavaScript and XML in C, Python and WebAssembly, the way HTML is today. A native Node.js package is built too, at about one and a half times the speed of the WebAssembly one.

The design rule underneath all of it: each language keeps its own tree and its own error handling, and they share only the plumbing. If you only parse HTML, you’ll never compile a JavaScript parser. If you parse XML, you get XML’s semantics, not HTML’s recovery.

None of that is in a release yet, and the README says so. 0.3.0 will be the first with the JavaScript parser in it. The roadmap has the order, and the project board has every piece.

If You Want to Help

There's a lot of road left

If you parse HTML for a living, through selectolax, PHP’s Dom\HTMLDocument, nokolexbor or Lexbor itself, try Parsec on your worst pages and tell me where it falls over. That’s the most useful thing anyone can do right now.

If you’d rather write code, a few issues are marked good first issue and help wanted, from a CI check to benchmarks against oxc, swc and libxml2. And if you just want to follow along, a star on GitHub is how I know you’re there.

I’ll post here again when 0.3.0 ships with the JavaScript parser inside.

// Let's talk

You have ideas.
I have IT solutions.

Fifteen minutes on Zoom is usually enough to tell whether I'm the right person for what you're building.

Denver, CO · Available for architecture, infrastructure, and DevOps engagements