Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions apps/docs/src/content/docs/benchmarks.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ title: Benchmarks
description: "Parsec against Lexbor's own C and html5ever, in one process, on the same strings."
---

Parsec against Lexbor's own C and html5ever, in one process, on the same strings. On 13 real pages Parsec parses 1.5 times as many megabytes a second as Lexbor, is ahead on every page, and holds less memory on each. Over the same pages its selectors are 3.2 times as fast as Lexbor's. On the links in those pages, its URL parser is 2.28 times as fast as Lexbor's and 1.33 times as fast as Ada's. On real stylesheets it tokenizes 1.85 times as fast as Lexbor's CSS module and parses 1.9 times as fast, and parses 1.08 times as fast as Servo's cssparser. Its JavaScript parser is 1.05 times as fast as oxc's and 2.6 times as fast as swc's over its corpus, with less memory than either, though oxc is still ahead on the smallest inline scripts; its lexer alone is 1.06 times as fast as swc's and 0.61 times as fast as oxc's. It's ahead on all eight hostile inputs too, and they're in the tables below with the rest.
Parsec against Lexbor's own C and html5ever, in one process, on the same strings. On 13 real pages Parsec parses 1.5 times as many megabytes a second as Lexbor and is ahead on every page, though it holds more memory than Lexbor on four of them. Over the same pages its selectors are 2.9 times as fast as Lexbor's. On the links in those pages, its URL parser is 2.3 times as fast as Lexbor's and level with Ada's. On real stylesheets it tokenizes 1.6 times as fast as Lexbor's CSS module and parses 1.9 times as fast, and parses 1.12 times as fast as Servo's cssparser. Its JavaScript parser is 1.04 times as fast as oxc's and 2.4 times as fast as swc's over its corpus, though oxc is still ahead on ten of the sources, nine of them inline scripts. Its lexer alone is 1.06 times as fast as oxc's and 1.85 times swc's. It's ahead on all eight hostile inputs too.

:::note
These are one machine's numbers: an Apple M2 Max (12 cores, 32 GB), macOS 26.7, Rust 1.100, on 15 November 2026, Parsec at the commit that added `bench/` for the parse tables, and with netweir-html at 6034a8e synced in for the selector table. Run it on yours: it takes about five minutes.
The summary above, and every figure on [parsec.tools](https://parsec.tools/benchmarks/), comes from one run on 29 November 2026: an Apple M2 Max (12 cores, 32 GB), macOS 26.7.3, Rust 1.100, Parsec at 72d32f0, with the one-minute load between 1.8 and 3.2 as each mode finished. Its figures are in [`bench/results/2026-11-29-m2-max/`](https://github.com/parsec-html/parsec/tree/main/bench/results/2026-11-29-m2-max). The sections below keep the full tables of the runs they were first published with, each with its own date, so where Parsec has changed since, their numbers differ from the summary. Run it on yours: it takes about five minutes.
:::

## The method
Expand Down Expand Up @@ -647,6 +647,16 @@ You need CMake and a C compiler for Lexbor, and a C++20 compiler for Ada. `bench

The table's first line names the versions and the machine. `bench/fetch-pages.sh --print` prints the hashes of what it downloaded, for adding a page to `bench/pages.txt`.

Add `--json PATH` to any of these, `boss`, `realworld`, `js` and the rest included, and the bench also writes every figure it printed to PATH as JSON, with the machine, the load average, the commit and each parser's version. `bench/results/<date>-<machine>/` keeps one file a mode, and parsec.tools reads the newest of those directories when it's built. To publish a new run, run each mode with `--json` into a new directory and commit it:

```sh
D=bench/results/$(date -u +%F)-m2-max
mkdir -p $D
B="cargo run --release --manifest-path bench/Cargo.toml --"
$B --json $D/pages.json
for mode in encoding js js-lex boss realworld; do $B $mode --json $D/${mode/encoding/decode}.json; done
```

## Netweir's end-to-end number

Before `bench/`, the only number was Netweir's [`bench/parse.py`](https://github.com/netweir/netweir/blob/main/bench/parse.py): parse a generated shop page from Python and pull out every price, title and link, against selectolax (Lexbor inside). It reports 3.0 ms against 5.7 ms at 1 MB and 31 ms against 64 ms at 10 MB. That includes Python and the queries, and the two libraries do the queries differently, so it's a scraper's number, not a parser's.
Expand Down
148 changes: 73 additions & 75 deletions apps/docs/src/content/docs/real-world-benchmarks.md

Large diffs are not rendered by default.

348 changes: 258 additions & 90 deletions apps/site/src/data/benchmarks.ts

Large diffs are not rendered by default.

93 changes: 51 additions & 42 deletions apps/site/src/pages/benchmarks/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@
import InnerPage from '../../layouts/InnerPage.astro';
import Prose from '../../components/Prose.astro';
import Table from '../../components/Table.astro';
import {
benchmarksSource,
realWorldSource,
machine,
htmlParse,
selectors,
javascript,
realWorld,
finalBoss,
hostile,
urls,
css,
decoding,
jsLexer,
jsSmallScripts,
} from '../../data/benchmarks';
import { benchmarks, benchmarksSource, realWorldSource, resultsUrl } from '../../data/benchmarks';

const { machine, htmlParse, selectors, javascript, realWorld, finalBoss, hostile, urls, css, decoding, jsLexer, jsSmallScripts } =
await benchmarks();
const words = ['no', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen'];
const count = (n: number) => words[n] ?? String(n);
const ofAll = (n: number, of: number) => (n === of ? (of === 2 ? 'both' : `all ${count(of)}`) : `${count(n)} of the ${count(of)}`);
const list = (xs: string[]) => (xs.length < 2 ? xs.join('') : `${xs.slice(0, -1).join(', ')} and ${xs.at(-1)}`);

const x = (a: number, b: number) => (a / b).toFixed(2);
const fmt = (n: number) => n.toLocaleString('en-GB');
Expand All @@ -32,32 +24,38 @@ const fmt = (n: number) => n.toLocaleString('en-GB');
<p>
Every figure here is a project benchmark: I ran it, on {machine}, and nobody independent has checked it yet. Each section says when
it ran. The full tables, every page and the raw output are on the <a href={benchmarksSource}>Benchmarks</a> and{" "}
<a href={realWorldSource}>Real-world benchmarks</a> pages, and <a href="/benchmarks/methodology/">How it's measured</a> has the method.
<a href={realWorldSource}>Real-world benchmarks</a> pages, the raw figures are in <a href={resultsUrl}>bench/results</a>, and{" "}
<a href="/benchmarks/methodology/">How it's measured</a> has the method.
Where Parsec loses, it's here too.
</p>

<h2 id="real-pages">Thirteen real pages</h2>
<h2 id="real-pages">{count(htmlParse.pages).replace(/^./, (c) => c.toUpperCase())} real pages</h2>
<p>
Snapshots of Wikipedia, MDN, GitHub, the BBC, Hacker News, Stack Overflow, the Python docs, the New York Times, Reddit, eBay and the
HTML Standard, {htmlParse.megabytes} MB in all, parsed from memory with scripting off. Run on {htmlParse.date}.
</p>
</Prose>
<Table label="HTML parsing speed on 13 real pages">
<Table label={`HTML parsing speed on ${htmlParse.pages} real pages`}>
<table>
<thead>
<tr><th scope="col">Parser</th><th scope="col" class="n">MB/s</th><th scope="col" class="n">Parsec vs</th></tr>
</thead>
<tbody>
<tr><th scope="row">Parsec</th><td class="n">{htmlParse.parsec}</td><td class="n"></td></tr>
<tr><th scope="row">Lexbor 3.0.1</th><td class="n">{htmlParse.lexbor}</td><td class="n">{x(htmlParse.parsec, htmlParse.lexbor)}×</td></tr>
<tr><th scope="row">html5ever 0.40.1</th><td class="n">{htmlParse.html5ever}</td><td class="n">{x(htmlParse.parsec, htmlParse.html5ever)}×</td></tr>
<tr><th scope="row">Lexbor {htmlParse.lexborVersion}</th><td class="n">{htmlParse.lexbor}</td><td class="n">{x(htmlParse.parsec, htmlParse.lexbor)}×</td></tr>
<tr><th scope="row">html5ever {htmlParse.html5everVersion}</th><td class="n">{htmlParse.html5ever}</td><td class="n">{x(htmlParse.parsec, htmlParse.html5ever)}×</td></tr>
</tbody>
</table>
</Table>
<Prose>
<p>
Parsec is ahead on all thirteen and holds less memory than Lexbor on every one. It doesn't on memory against html5ever, though: on
BBC News, the New York Times, Reddit and eBay, html5ever's tree is smaller.
Parsec is ahead on {ofAll(htmlParse.aheadOn, htmlParse.pages)} and holds less memory than Lexbor on{" "}
{htmlParse.lessMemoryThanLexbor === htmlParse.pages ? 'every one' : `${count(htmlParse.lessMemoryThanLexbor)} of them`}.
{htmlParse.html5everSmaller.length > 0 && (
<>
{" "}It doesn't always win on memory against html5ever, though: on {list(htmlParse.html5everSmaller)}, html5ever's tree is smaller.
</>
)}
</p>

<h2 id="real-web">The web as a crawl found it</h2>
Expand All @@ -66,21 +64,24 @@ const fmt = (n: number) => n.toLocaleString('en-GB');
as Netweir's crawler fetched them on {realWorld.date}: raw bytes and the server's charset, every encoding and size the web sent.
</p>
</Prose>
<Table label="Speed and memory over 1,731 production pages">
<Table label={`Speed and memory over ${fmt(realWorld.pages)} production pages`}>
<table>
<thead>
<tr><th scope="col">Parser</th><th scope="col" class="n">MB/s</th><th scope="col" class="n">Median page</th><th scope="col" class="n">Peak memory</th></tr>
</thead>
<tbody>
<tr><th scope="row">Parsec</th><td class="n">{realWorld.parsec.mbs}</td><td class="n">{realWorld.parsec.p50}</td><td class="n">{realWorld.parsec.peak}</td></tr>
<tr><th scope="row">Lexbor 3.0.1</th><td class="n">{realWorld.lexbor.mbs}</td><td class="n">{realWorld.lexbor.p50}</td><td class="n">{realWorld.lexbor.peak}</td></tr>
<tr><th scope="row">Lexbor {htmlParse.lexborVersion}</th><td class="n">{realWorld.lexbor.mbs}</td><td class="n">{realWorld.lexbor.p50}</td><td class="n">{realWorld.lexbor.peak}</td></tr>
</tbody>
</table>
</Table>
<Prose>
<p>
Neither crashed or timed out, and both built the same number of elements on every page. Lexbor was faster on {realWorld.lexborFaster}
of them, nearly all small. html5ever's process peaked 2 MB lower than Parsec's.
{realWorld.parsec.failures + realWorld.lexbor.failures === 0 ? 'Neither crashed or timed out' : 'Not every page parsed: the Real-world benchmarks page lists which'},
and {realWorld.lexborElementsDiffer === 0 ? 'both built the same number of elements on every page' : `they built different numbers of elements on ${fmt(realWorld.lexborElementsDiffer)} pages`}.
Lexbor was faster on {fmt(realWorld.lexborFaster)} of them. html5ever's process peaked{" "}
{Math.abs(Math.round((realWorld.parsec.peakBytes - realWorld.html5ever.peakBytes) / 1e6))} MB{" "}
{realWorld.html5ever.peakBytes < realWorld.parsec.peakBytes ? 'lower' : 'higher'} than Parsec's.
</p>

<h2 id="final-boss">A crawler's bad day</h2>
Expand All @@ -89,7 +90,7 @@ const fmt = (n: number) => n.toLocaleString('en-GB');
their encoding, and the odd 25 MB table. It asks whether anything falls over and what the whole batch costs. Run on {finalBoss.date}.
</p>
</Prose>
<Table label="The final boss: 1,000 seeded pages">
<Table label={`The final boss: ${fmt(finalBoss.pages)} seeded pages`}>
<table>
<thead>
<tr><th scope="col">Parser</th><th scope="col" class="n">Seconds</th><th scope="col" class="n">Slowest page</th><th scope="col" class="n">Peak memory</th></tr>
Expand All @@ -100,33 +101,39 @@ const fmt = (n: number) => n.toLocaleString('en-GB');
</table>
</Table>
<Prose>
<p>No crashes, timeouts or refused pages from any of the three.</p>
<p>
{finalBoss.rows.every((r) => r.failures === 0)
? 'No crashes, timeouts or refused pages from any of the three.'
: `Not everything got through: ${finalBoss.rows.filter((r) => r.failures > 0).map((r) => `${r.parser} failed ${r.failures}`).join(', ')}.`}
</p>

<h2 id="hostile">Hostile input</h2>
<p>
Eight inputs built to hurt an HTML parser: thousands of unclosed tags, misnested formatting, the adoption agency algorithm at its
worst. Parsec is ahead on all {hostile.inputs}. The widest gap is 80,000 unclosed <code>&lt;div&gt;</code>s, where Lexbor's work grows
{count(hostile.inputs).replace(/^./, (c) => c.toUpperCase())} inputs built to hurt an HTML parser: thousands of unclosed tags, misnested formatting, the adoption agency algorithm at its
worst. Parsec is ahead on {ofAll(hostile.aheadOn, hostile.inputs)}. The widest gap is 80,000 unclosed <code>&lt;div&gt;</code>s, where Lexbor's work grows
with the square of the depth: Parsec parses them at {hostile.unclosedDivs.parsec}, and Lexbor takes {hostile.unclosedDivs.lexbor} a
parse, html5ever {hostile.unclosedDivs.html5ever}. Run on {hostile.date}.
</p>

<h2 id="selectors">Selectors</h2>
<p>
{selectors.count} CSS selectors over the same thirteen pages: Parsec takes {selectors.parsec} ms for all of them and Lexbor
{" "}{selectors.lexbor}, so Parsec is {x(selectors.lexbor, selectors.parsec)} times as fast and ahead on every selector. html5ever has
{selectors.count} CSS selectors over the same {count(htmlParse.pages)} pages: Parsec takes {selectors.parsec} ms for all of them and Lexbor
{" "}{selectors.lexbor}, so Parsec is {x(selectors.lexbor, selectors.parsec)} times as fast and ahead on{" "}
{selectors.aheadOn === selectors.count ? 'every selector' : `${selectors.aheadOn} of them`}. html5ever has
no selector engine of its own, so it isn't in this one. Run on {selectors.date}.
</p>

<h2 id="urls">URLs</h2>
<p>
Every <code>href</code> and <code>src</code> on those pages, {fmt(urls.links)} links, each resolved against its page: Parsec takes
{" "}{urls.parsec} ns a URL, Ada, the parser inside Node.js, {urls.ada}, and Lexbor {urls.lexbor}. All three agree on every one. Run on
{" "}{urls.parsec} ns a URL, Ada, the parser inside Node.js, {urls.ada}, and Lexbor {urls.lexbor}.{" "}
{urls.disagree === 0 ? 'All three agree on every one.' : `They disagree on ${fmt(urls.disagree)}.`} Run on
{" "}{urls.date}.
</p>

<h2 id="css">CSS</h2>
<p>
Ten real stylesheets, 1.87 MB, Bootstrap and Bulma among them. Tokenizing, Parsec does {css.tokenizing.parsec} MB/s, Servo's
{count(css.sheets).replace(/^./, (c) => c.toUpperCase())} real stylesheets, {css.megabytes} MB, Bootstrap and Bulma among them. Tokenizing, Parsec does {css.tokenizing.parsec} MB/s, Servo's
cssparser {css.tokenizing.cssparser} and Lexbor {css.tokenizing.lexbor}. Parsing every block, it's {css.parsing.parsec}, against{" "}
{css.parsing.cssparser} and {css.parsing.lexbor}. Lexbor also parses the values of the 105 properties it knows in that run, which is
more work, so read its parsing figure with that in mind.
Expand All @@ -135,23 +142,25 @@ const fmt = (n: number) => n.toLocaleString('en-GB');
<h2 id="decoding">Decoding</h2>
<p>
Real pages transcoded to Shift_JIS, windows-1251 and GBK, decoded to UTF-8: Parsec at {decoding.parsec}, Lexbor at {decoding.lexbor}.
Lexbor's figure includes encoding its output to UTF-8, since it decodes to code points. Its decoders on their own, before that step,
beat Parsec's on dense GBK text.
Lexbor's figure includes encoding its output to UTF-8, since it decodes to code points.
{decoding.lexborDecodersAheadOnDenseGbk && " Its decoders on their own, before that step, beat Parsec's on dense GBK text."}
</p>

<h2 id="javascript">JavaScript</h2>
<p>
{javascript.megabytes} MB of real JavaScript: react-dom, three.js, typescript.js and every page's inline scripts. Parsec's parser
does {javascript.parsec} MB/s, oxc_parser {javascript.oxc} and swc {javascript.swc}, with less memory than either on every source.
Run on {javascript.date}.
does {javascript.parsec} MB/s, oxc_parser {javascript.oxc} and swc {javascript.swc}, with less memory than either on{" "}
{javascript.lessMemoryOn === javascript.sources ? 'every source' : `${javascript.lessMemoryOn} of the ${javascript.sources} sources`}. Run on{" "}
{javascript.date}.
</p>
<p>
That total hides where oxc still wins. On the smallest inline scripts, each parse's fixed cost counts most, and Parsec is behind:
That total hides where oxc still wins. On {jsSmallScripts.length === 1 ? 'one source' : `${count(jsSmallScripts.length)} sources`},
mostly small inline scripts where each parse's fixed cost counts most, Parsec is behind:
</p>
<ul>{jsSmallScripts.map((s) => <li>{s.source}: {s.ratio}× oxc's speed</li>)}</ul>
<p>
The lexer alone is further behind: {jsLexer.parsec} MB/s against oxc's {jsLexer.oxc}, ahead of swc's {jsLexer.swc} (run on{" "}
{jsLexer.date}). Closing the gap needs a smaller token type, which changes the public API, so it's planned for 0.4.0 in{" "}
The lexer alone: {jsLexer.parsec} MB/s against oxc's {jsLexer.oxc} and swc's {jsLexer.swc} (run on {jsLexer.date}). Closing the gap on the small scripts needs a smaller token type, which changes the public API, so it's
planned for 0.4.0 in{" "}
<a href="https://github.com/parsec-html/parsec/issues/190">#190</a>.
</p>

Expand Down
11 changes: 9 additions & 2 deletions apps/site/src/pages/benchmarks/methodology.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import InnerPage from '../../layouts/InnerPage.astro';
import Prose from '../../components/Prose.astro';
import Table from '../../components/Table.astro';
import CodeBlock from '../../components/CodeBlock.astro';
import { benchmarksSource, realWorldSource, machine } from '../../data/benchmarks';
import { benchmarks, benchmarksSource, realWorldSource, resultsUrl } from '../../data/benchmarks';

const { machine, realWorld } = await benchmarks();

const bench = 'https://github.com/parsec-html/parsec/blob/main/bench';
const run = `git clone --recurse-submodules https://github.com/parsec-html/parsec
Expand Down Expand Up @@ -54,7 +56,7 @@ cargo run --release --manifest-path bench/Cargo.toml`;
<a href={`${bench}/pages.txt`}><code>bench/pages.txt</code></a>. The repository holds their addresses, never the pages.
</li>
<li>
<strong>1,731 production pages:</strong> one day's crawl by Netweir's harness, home pages from a Tranco top-sites list and inner
<strong>{realWorld.pages.toLocaleString('en-GB')} production pages:</strong> one day's crawl by Netweir's harness, home pages from a Tranco top-sites list and inner
pages picked by hand for articles, docs, forums, shops and legacy encodings.{" "}
<a href={`${bench}/realworld.tsv`}><code>bench/realworld.tsv</code></a> lists each URL and the hash of its body.
</li>
Expand Down Expand Up @@ -93,6 +95,11 @@ cargo run --release --manifest-path bench/Cargo.toml`;
run on a quiet machine: a build or a browser in the background moves these numbers by a fifth or more. The first line of the output
names the versions and the machine, so paste it whole when you send it to me.
</p>
<p>
Add <code>--json results.json</code> to any of these and the bench also writes every figure it printed, with the machine, the load
average, the commit and each parser's version. The figures on this site come from the newest run in{" "}
<a href={resultsUrl}>bench/results</a>, read when the site is built, not copied by hand.
</p>
</Prose>
</InnerPage>

Expand Down
Loading