diff --git a/apps/docs/src/content/docs/benchmarks.md b/apps/docs/src/content/docs/benchmarks.md index 6b9593f..4fdcab9 100644 --- a/apps/docs/src/content/docs/benchmarks.md +++ b/apps/docs/src/content/docs/benchmarks.md @@ -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 @@ -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/-/` 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. diff --git a/apps/docs/src/content/docs/real-world-benchmarks.md b/apps/docs/src/content/docs/real-world-benchmarks.md index 08cd004..11415d1 100644 --- a/apps/docs/src/content/docs/real-world-benchmarks.md +++ b/apps/docs/src/content/docs/real-world-benchmarks.md @@ -1,17 +1,17 @@ --- title: Real-world benchmarks -description: "Parsec, Lexbor and html5ever, run over 1,731 production pages as a crawler fetches them." +description: "Parsec, Lexbor and html5ever, run over 1,746 production pages as a crawler fetches them." --- -Parsec, Lexbor and html5ever, run over 1,731 production pages as a crawler fetches them. Each parser gets the raw bytes and the `Content-Type` charset. Parsec gets through the corpus at 933 MB/s and Lexbor at 523, so Parsec is 1.78 times as fast. Parsec's median page takes 0.20 ms and Lexbor's 0.35 ms. Neither parser crashed or timed out on any page, and the three parsers built the same number of elements on every page. Lexbor is faster on 13 pages, nearly all of them small, and html5ever's process peaks 2 MB lower than Parsec's. The tables below have the rest, broken down by encoding, by language and by size. +Parsec, Lexbor and html5ever, run over 1,746 production pages as a crawler fetches them. Each parser gets the raw bytes and the `Content-Type` charset. Parsec gets through the corpus at 1,007 MB/s and Lexbor at 543, so Parsec is 1.85 times as fast. Parsec's median page takes 0.19 ms and Lexbor's 0.33 ms. Neither parser crashed or timed out on any page, and the three parsers built the same number of elements on every page. Lexbor is faster on 8 pages, all under 70 KB, and html5ever's process peaks 9 MB lower than Parsec's. The tables below have the rest, broken down by encoding, by language and by size. :::note -These are one machine's numbers: an Apple M2 Max (12 cores, 32 GB), macOS 26.7.2 (Darwin 25.6.0), Rust 1.100.0, on 21 November 2026, with Parsec at 7006d31. The parsing itself takes about five seconds per run. Most of the wall time goes on waiting for a quiet machine. +These are one machine's numbers: an Apple M2 Max (12 cores, 32 GB), macOS 26.7.3, Rust 1.100.0, on 29 November 2026, with Parsec at 72d32f0. The parsing itself takes about five seconds per run. Most of the wall time goes on waiting for a quiet machine. Every figure here is also in [`bench/results/2026-11-29-m2-max/realworld.json`](https://github.com/parsec-html/parsec/blob/main/bench/results/2026-11-29-m2-max/realworld.json), which is where [parsec.tools](https://parsec.tools/benchmarks/) reads them from. ::: ## Why this page exists -The [Benchmarks](/benchmarks/) page times 13 hand-picked pages and the final boss's seeded batch. Both are chosen. This page is the web as it came back from a crawl on one day, with nothing chosen and nothing tidied. That covers the Shift_JIS novel and the 13.8 MB news home page as well as the 300-byte redirect stub that some sites serve as their home page. +The [Benchmarks](/benchmarks/) page times 13 hand-picked pages and the final boss's seeded batch. Both are chosen. This page is the web as it came back from a crawl on one day, with nothing chosen and nothing tidied. That covers the Shift_JIS novel and the 13.3 MB news home page as well as the 300-byte redirect stub that some sites serve as their home page. ## The corpus @@ -20,7 +20,7 @@ The pages come from Netweir's real-world harness, [`bench/realworld/`](https://g - **Home pages** from [Tranco list 46YVX](https://tranco-list.eu/list/46YVX/1000000), made on 20 November 2026. These come from the top 100,000 pay-level domains. Each public suffix gets a share of picks that grows with the square root of how many of those domains it has, so `.com` doesn't crowd out `.de`, `.co.jp` or `.gov.uk`. CDNs, trackers and adult sites are left out by name. - **Inner pages** picked by hand for the kinds of page a home page isn't: articles, docs, forum threads, product pages and legacy encodings. -Netweir's `run.py` fetched all 2,709 listed URLs on 21 November 2026. It followed robots.txt for every redirect, sent one request at a time to each host with a second between them, and named the project in its User-Agent. Of those URLs, 1,731 came back as `200` HTML: 1,417 home pages and 314 inner pages, 558.6 MB in all, with 1,686 distinct bodies. Some URLs redirect to the same page. The rest were left alone for robots.txt (97), were unreachable (564), returned a status other than 200 (313), or weren't HTML (4). +`bench/fetch-realworld.sh --urls` fetched all 2,709 listed URLs on 29 November 2026, the way Netweir's `run.py` does: robots.txt for every redirect, one request at a time to each host with a second between them, and the project named in its User-Agent. Of those URLs, 1,746 came back as `200` HTML, 563.4 MB in all, with 1,699 distinct bodies. Some URLs redirect to the same page. The rest were left alone for robots.txt (99), were unreachable or redirected more than five times (562), returned a status other than 200 (298), or weren't HTML (4). [`bench/realworld.tsv`](https://github.com/parsec-html/parsec/blob/main/bench/realworld.tsv) lists each page's URL, the SHA-256 of the body after `Content-Encoding`, the time it was fetched (UTC) and its `Content-Type` header. The pages belong to their sites, so the repository holds this list and never the bodies. @@ -32,7 +32,7 @@ Netweir's `run.py` fetched all 2,709 listed URLs on 21 November 2026. It followe - **Lexbor 3.0.1**, built from its release tag: its own BOM sniff, the transport label, its `` prescan of the first 1,024 bytes, then windows-1252. Lexbor's encoding module decodes anything that isn't UTF-8, and then `lxb_html_document_parse` parses the result. UTF-8, and ASCII in an encoding that keeps ASCII, go straight to the parser. - **html5ever 0.40.1** takes text, so encoding_rs decodes the bytes for it first, using Parsec's sniffing and no second parse. That decode is inside its time. -Each parser runs in its own processes. A feeder process sends the pages one at a time over a pipe to a worker. The worker times each page from bytes to a finished document, then counts its elements and frees it outside the timed part. A page still parsing after 10 seconds counts as a timeout. A crash or a timeout costs that one page, and a new worker picks up at the next one. Peak RSS is `getrusage(RUSAGE_CHILDREN)`'s `ru_maxrss` across one parser's workers. It includes the one buffer each worker reuses for every page, which grows to the biggest page, 13.8 MB. +Each parser runs in its own processes. A feeder process sends the pages one at a time over a pipe to a worker. The worker times each page from bytes to a finished document, then counts its elements and frees it outside the timed part. A page still parsing after 10 seconds counts as a timeout. A crash or a timeout costs that one page, and a new worker picks up at the next one. Peak RSS is `getrusage(RUSAGE_CHILDREN)`'s `ru_maxrss` across one parser's workers. It includes the one buffer each worker reuses for every page, which grows to the biggest page, 13.3 MB. Each parser does three runs. Before each run the bench waits for the one-minute load average to drop below 3, and a different parser goes first each time. A page's time is the median of its three runs. A parser's total is the median of its three run totals. MB/s is bytes over that total. In the breakdowns, MB/s is a group's bytes over the sum of its pages' median times. @@ -42,101 +42,99 @@ Each page is parsed once per run, the way a crawler meets it, not 30 times on a | Parser | Total | MB/s | p50 | p90 | p99 | Slowest | Peak RSS | Crashes | Timeouts | Refused | |---|--:|--:|--:|--:|--:|--:|--:|--:|--:|--:| -| Parsec | 0.60 s | 933 | 0.20 ms | 0.74 ms | 2.73 ms | 7.35 ms | 101 MB | 0 | 0 | 0 | -| Lexbor | 1.07 s | 523 | 0.35 ms | 1.40 ms | 5.00 ms | 15.83 ms | 123 MB | 0 | 0 | 0 | -| html5ever | 3.49 s | 160 | 1.12 ms | 4.65 ms | 14.64 ms | 40.67 ms | 99 MB | 0 | 0 | 0 | +| Parsec | 0.56 s | 1007 | 0.19 ms | 0.72 ms | 2.61 ms | 5.25 ms | 101 MB | 0 | 0 | 0 | +| Lexbor | 1.04 s | 543 | 0.33 ms | 1.35 ms | 4.64 ms | 14.60 ms | 113 MB | 0 | 0 | 0 | +| html5ever | 3.40 s | 166 | 1.11 ms | 4.50 ms | 14.38 ms | 30.37 ms | 92 MB | 0 | 0 | 0 | -p50, p90 and p99 are per-page times across the 1,731 pages. Slowest is the single slowest page. +p50, p90 and p99 are per-page times across the 1,746 pages. Slowest is the single slowest page. -Element counts: Lexbor and html5ever each built the same number of elements as Parsec on every page. None of the three refused a page, crashed or timed out. The load average was 2.45 to 2.90 at the start of each run. +Element counts: Lexbor and html5ever each built the same number of elements as Parsec on every page. None of the three refused a page, crashed or timed out. The load average was 1.74 to 1.93 at the start of each run. ### By encoding | | Pages | MB | Parsec MB/s | Lexbor MB/s | html5ever MB/s | Parsec vs Lexbor | |---|--:|--:|--:|--:|--:|--:| -| UTF-8 | 1508 | 538.9 | 964 | 529 | 161 | 1.82x | -| windows-1252 | 207 | 16.9 | 1659 | 608 | 252 | 2.73x | -| Shift_JIS | 8 | 1.6 | 252 | 125 | 70 | 2.01x | -| windows-1251 | 3 | 0.3 | 225 | 99 | 62 | 2.27x | -| windows-1250 | 2 | 0.4 | 380 | 128 | 71 | 2.97x | -| ISO-8859-15 | 1 | 0.5 | 815 | 163 | 139 | 5.01x | -| windows-1256 | 1 | 0.0 | 42 | 39 | 21 | 1.06x | -| KOI8-R | 1 | 0.0 | 134 | 75 | 40 | 1.78x | +| UTF-8 | 1525 | 544.1 | 1008 | 550 | 165 | 1.83x | +| windows-1252 | 205 | 16.5 | 1897 | 717 | 288 | 2.65x | +| Shift_JIS | 8 | 1.5 | 246 | 128 | 71 | 1.93x | +| windows-1251 | 3 | 0.3 | 200 | 91 | 60 | 2.19x | +| windows-1250 | 2 | 0.4 | 385 | 135 | 73 | 2.86x | +| KOI8-R | 1 | 0.0 | 132 | 76 | 40 | 1.74x | +| ISO-8859-15 | 1 | 0.5 | 812 | 159 | 146 | 5.11x | +| windows-1256 | 1 | 0.0 | 45 | 33 | 21 | 1.37x | ### By `` | | Pages | MB | Parsec MB/s | Lexbor MB/s | html5ever MB/s | Parsec vs Lexbor | |---|--:|--:|--:|--:|--:|--:| -| en | 955 | 279.8 | 1087 | 573 | 178 | 1.90x | -| none | 180 | 29.6 | 708 | 395 | 135 | 1.79x | -| es | 80 | 29.9 | 1066 | 494 | 174 | 2.16x | -| ja | 58 | 27.8 | 1025 | 520 | 177 | 1.97x | -| ru | 50 | 16.2 | 787 | 439 | 136 | 1.79x | -| pt | 37 | 13.9 | 966 | 544 | 155 | 1.77x | -| de | 36 | 22.2 | 844 | 470 | 128 | 1.80x | -| fr | 27 | 12.7 | 1232 | 635 | 187 | 1.94x | -| zh | 25 | 7.7 | 585 | 367 | 111 | 1.60x | -| ar | 25 | 9.0 | 838 | 505 | 154 | 1.66x | -| tr | 22 | 5.8 | 755 | 458 | 130 | 1.65x | -| ko | 21 | 8.5 | 673 | 415 | 120 | 1.62x | -| id | 17 | 3.1 | 706 | 425 | 120 | 1.66x | -| it | 15 | 8.0 | 856 | 491 | 136 | 1.74x | -| vi | 15 | 7.2 | 536 | 331 | 96 | 1.62x | -| pl | 13 | 7.5 | 953 | 556 | 165 | 1.71x | -| uk | 12 | 4.4 | 1126 | 616 | 198 | 1.83x | -| fa | 9 | 3.3 | 720 | 514 | 152 | 1.40x | -| th | 9 | 4.1 | 991 | 600 | 191 | 1.65x | -| nl | 8 | 3.0 | 1215 | 615 | 188 | 1.98x | -| he | 8 | 4.4 | 1169 | 599 | 189 | 1.95x | -| el | 7 | 4.3 | 660 | 414 | 117 | 1.60x | -| cs | 6 | 3.4 | 883 | 413 | 151 | 2.14x | -| da | 6 | 3.2 | 979 | 568 | 147 | 1.72x | -| sv | 5 | 2.0 | 879 | 509 | 136 | 1.73x | -| 39 more | 85 | 37.5 | 961 | 540 | 164 | 1.78x | +| en | 963 | 285.7 | 1118 | 588 | 180 | 1.90x | +| none | 183 | 31.6 | 758 | 421 | 147 | 1.80x | +| es | 80 | 30.7 | 1145 | 535 | 184 | 2.14x | +| ja | 57 | 27.0 | 1056 | 536 | 179 | 1.97x | +| ru | 50 | 16.2 | 823 | 462 | 136 | 1.78x | +| pt | 38 | 15.0 | 1026 | 576 | 164 | 1.78x | +| de | 35 | 22.3 | 877 | 498 | 132 | 1.76x | +| fr | 28 | 13.3 | 1229 | 651 | 187 | 1.89x | +| ar | 27 | 8.5 | 868 | 515 | 148 | 1.69x | +| zh | 25 | 6.9 | 656 | 404 | 123 | 1.62x | +| tr | 22 | 5.2 | 835 | 491 | 140 | 1.70x | +| ko | 21 | 8.3 | 709 | 430 | 123 | 1.65x | +| id | 17 | 3.1 | 710 | 429 | 122 | 1.66x | +| vi | 15 | 6.4 | 591 | 358 | 103 | 1.65x | +| it | 14 | 7.7 | 913 | 527 | 144 | 1.73x | +| pl | 13 | 7.4 | 1015 | 568 | 167 | 1.79x | +| uk | 13 | 4.5 | 1217 | 638 | 202 | 1.91x | +| fa | 10 | 2.6 | 795 | 490 | 141 | 1.62x | +| nl | 9 | 3.1 | 1292 | 650 | 196 | 1.99x | +| th | 8 | 3.3 | 921 | 564 | 171 | 1.63x | +| el | 8 | 4.4 | 659 | 412 | 116 | 1.60x | +| he | 7 | 3.2 | 1048 | 570 | 168 | 1.84x | +| hu | 6 | 7.2 | 1626 | 723 | 258 | 2.25x | +| da | 6 | 3.4 | 1022 | 594 | 153 | 1.72x | +| cs | 6 | 3.5 | 941 | 456 | 158 | 2.06x | +| 39 more | 85 | 32.7 | 943 | 539 | 157 | 1.75x | ### By size | | Pages | MB | Parsec MB/s | Lexbor MB/s | html5ever MB/s | Parsec vs Lexbor | |---|--:|--:|--:|--:|--:|--:| -| under 10 KB | 140 | 0.5 | 301 | 198 | 76 | 1.52x | -| 10-100 KB | 599 | 36.7 | 716 | 410 | 131 | 1.74x | -| 100 KB-1 MB | 873 | 304.9 | 820 | 462 | 140 | 1.77x | -| 1-10 MB | 118 | 202.6 | 1365 | 674 | 213 | 2.03x | -| over 10 MB | 1 | 13.8 | 2435 | 869 | 426 | 2.80x | +| under 10 KB | 137 | 0.5 | 285 | 186 | 76 | 1.53x | +| 10-100 KB | 617 | 37.8 | 722 | 420 | 135 | 1.72x | +| 100 KB-1 MB | 874 | 305.5 | 853 | 479 | 144 | 1.78x | +| 1-10 MB | 117 | 206.4 | 1465 | 710 | 216 | 2.06x | +| over 10 MB | 1 | 13.3 | 2529 | 910 | 437 | 2.78x | ### Parsec's slowest pages | Page | Size | Encoding | Parsec | Lexbor | html5ever | |---|--:|---|--:|--:|--:| -| https://kqbd.mobi/ | 2904 KB | UTF-8 | 7.35 ms | 11.57 ms | 40.67 ms | -| `https://web.nhk/` | 13764 KB | UTF-8 | 5.65 ms | 15.83 ms | 32.33 ms | -| https://nodejs.org/api/fs.html | 1109 KB | UTF-8 | 3.78 ms | 5.23 ms | 15.45 ms | -| https://ru.wikipedia.org/wiki/Москва | 2116 KB | UTF-8 | 3.76 ms | 6.28 ms | 19.58 ms | -| https://zh.wikipedia.org/wiki/北京市 | 1462 KB | UTF-8 | 3.59 ms | 5.15 ms | 17.36 ms | -| https://www.aozora.gr.jp/cards/000148/files/773_14560.html | 618 KB | Shift_JIS | 3.52 ms | 6.07 ms | 10.24 ms | -| https://cnn.com/ | 7433 KB | UTF-8 | 3.44 ms | 8.23 ms | 22.48 ms | -| https://ar.wikipedia.org/wiki/القاهرة | 1900 KB | UTF-8 | 3.43 ms | 5.31 ms | 17.78 ms | -| https://en.wikipedia.org/wiki/Tokyo | 1961 KB | UTF-8 | 3.42 ms | 5.94 ms | 18.81 ms | -| https://de.wikipedia.org/wiki/Berlin | 1666 KB | UTF-8 | 3.38 ms | 5.50 ms | 17.77 ms | +| https://web.nhk/ | 13283 KB | UTF-8 | 5.25 ms | 14.60 ms | 30.37 ms | +| https://kqbd.mobi/ | 2093 KB | UTF-8 | 4.74 ms | 7.80 ms | 27.25 ms | +| https://ru.wikipedia.org/wiki/Москва | 1977 KB | UTF-8 | 4.10 ms | 6.32 ms | 25.74 ms | +| https://de.wikipedia.org/wiki/Berlin | 1744 KB | UTF-8 | 3.84 ms | 6.48 ms | 23.25 ms | +| https://nodejs.org/api/fs.html | 1109 KB | UTF-8 | 3.74 ms | 5.40 ms | 15.59 ms | +| https://www.aozora.gr.jp/cards/000148/files/773_14560.html | 618 KB | Shift_JIS | 3.68 ms | 6.04 ms | 10.08 ms | +| https://en.wikipedia.org/wiki/Tokyo | 1786 KB | UTF-8 | 3.49 ms | 5.73 ms | 24.27 ms | +| https://www.chosun.com/ | 3084 KB | UTF-8 | 3.27 ms | 5.34 ms | 18.15 ms | +| https://cnn.com/ | 7295 KB | UTF-8 | 3.26 ms | 7.82 ms | 21.32 ms | +| https://www.allbirds.com/collections/mens | 3354 KB | UTF-8 | 3.24 ms | 5.85 ms | 29.30 ms | ### Where Lexbor is faster -Lexbor parses 13 of 1731 pages faster than Parsec; Parsec spends 0.05 ms more than Lexbor on them in all. Those that lose the most time: +Lexbor parses 8 of 1746 pages faster than Parsec; Parsec spends 0.04 ms more than Lexbor on them in all. Those that lose the most time: | Page | Size | Encoding | Parsec | Lexbor | html5ever | |---|--:|---|--:|--:|--:| -| https://quickconnect.to/ | 67 KB | UTF-8 | 0.11 ms | 0.10 ms | 0.17 ms | +| https://quickconnect.to/ | 67 KB | UTF-8 | 0.11 ms | 0.09 ms | 0.16 ms | +| https://nyaa.vc/ | 1 KB | UTF-8 | 0.02 ms | 0.01 ms | 0.02 ms | | https://mega.nz/ | 3 KB | UTF-8 | 0.03 ms | 0.02 ms | 0.05 ms | -| http://info.cern.ch/hypertext/WWW/TheProject.html | 2 KB | windows-1252 | 0.02 ms | 0.02 ms | 0.05 ms | +| https://verify.hn/ | 0 KB | windows-1252 | 0.01 ms | 0.00 ms | 0.00 ms | | https://www.cs.cmu.edu/~rgs/alice-table.html | 3 KB | windows-1252 | 0.02 ms | 0.01 ms | 0.04 ms | | https://imss.gob.mx/ | 0 KB | windows-1252 | 0.01 ms | 0.01 ms | 0.01 ms | -| https://korea.ac.kr/ | 1 KB | UTF-8 | 0.01 ms | 0.01 ms | 0.02 ms | -| https://cuhk.edu.hk/ | 0 KB | windows-1252 | 0.01 ms | 0.01 ms | 0.02 ms | -| https://examinationservices.nic.in/ | 1 KB | windows-1252 | 0.01 ms | 0.01 ms | 0.03 ms | +| http://info.cern.ch/hypertext/WWW/TheProject.html | 2 KB | windows-1252 | 0.03 ms | 0.03 ms | 0.06 ms | | https://blackrussia.online/ | 2 KB | windows-1252 | 0.01 ms | 0.01 ms | 0.02 ms | -| https://www.jd.com/ | 1 KB | UTF-8 | 0.01 ms | 0.01 ms | 0.01 ms | -html5ever parses 2 of 1731 pages faster than Parsec. +html5ever parses 4 of 1746 pages faster than Parsec. ### Element counts that differ from Parsec's @@ -146,17 +144,17 @@ html5ever: 0 pages. ## Where Parsec loses -- **Memory, against html5ever.** html5ever's workers peaked at 99 MB and Parsec's at 101 MB. Lexbor's peaked at 123 MB. That's one number per run, set by the biggest pages, so a 2 MB gap on 100 MB is close to a tie. Still, Parsec doesn't win it here, and on the [Benchmarks](/benchmarks/#real-pages) page html5ever holds less memory than Parsec on four of the 13 pages too. -- **Tiny pages, against Lexbor.** Lexbor is faster on 13 pages. The ten where Parsec loses the most are all under 70 KB, and most are under 3 KB. Parsec loses 0.05 ms on all 13 together, a few microseconds each, which is about the size of the timer's noise at this scale. The lead is narrowest under 10 KB (1.52 times, against 2.03 times from 1 to 10 MB). That's where fixed per-document costs weigh most. -- **windows-1256.** On its one page Parsec is only 1.06 times as fast as Lexbor, and both parsers run far below their usual MB/s. A single page under 50 KB proves little, but it's the narrowest group in the tables. -- **Against html5ever on two pages.** html5ever beat Parsec on 2 pages. +- **Memory, against html5ever.** html5ever's workers peaked at 92 MB and Parsec's at 101 MB. Lexbor's peaked at 113 MB. That's one number per run, set by the biggest pages, so it says little about a typical page. Still, Parsec doesn't win it here. +- **Tiny pages, against Lexbor.** Lexbor is faster on 8 pages, all under 70 KB and most under 3 KB. Parsec loses 0.04 ms on all 8 together, a few microseconds each, which is about the size of the timer's noise at this scale. The lead is narrowest under 10 KB (1.53 times, against 2.06 times from 1 to 10 MB). That's where fixed per-document costs weigh most. +- **windows-1256.** On its one page Parsec is only 1.37 times as fast as Lexbor, and both parsers run far below their usual MB/s. A single small page proves little, but it's the narrowest group in the tables. +- **Against html5ever on four pages.** html5ever beat Parsec on 4 pages. ## What this doesn't cover - **One day of the web.** Pages change by the hour. `google.com` served different bytes two hours later. Rerun `bench/fetch-realworld.sh` and some pages will have changed. Those are left out rather than replaced, so the comparison stays like for like. -- **Language comes from ``, as the page states it.** 180 pages have none, and some sites state the wrong one. The script family is not checked. +- **Language comes from ``, as the page states it.** 183 pages have none, and some sites state the wrong one. The script family is not checked. - **Encodings are as Parsec decided them.** Lexbor's sniffing can land on a different encoding, for example when a page needs UTF-8 detection, which Lexbor 3.0.1 doesn't have. The element counts still agreed on every page. -- **The pages are mostly UTF-8.** That is 1,508 of the 1,731. The legacy-encoding rows have few pages, and the [final boss](/benchmarks/#the-final-boss) covers those encodings on purpose. +- **The pages are mostly UTF-8.** That is 1,525 of the 1,746. The legacy-encoding rows have few pages, and the [final boss](/benchmarks/#the-final-boss) covers those encodings on purpose. ## Running it @@ -171,7 +169,7 @@ cargo run --release --manifest-path bench/Cargo.toml -- realworld > report.md To build a fresh list from Netweir's `bench/realworld/urls.txt`, run `bench/fetch-realworld.sh --urls urls.txt > list.tsv`. That fetches every URL, keeps what comes back as `200` HTML, and prints new manifest lines. Then point the benchmark at it with `-- realworld --manifest list.tsv`. `--runs N`, `--tools parsec,lexbor` and `--now` (don't wait for a quiet machine) change the rest. -The tables above are the benchmark's output as it printed it. You need CMake and a C compiler for Lexbor, and Python 3.11 or later for the fetch script. +The tables above are the benchmark's output as it printed it. Add `--json realworld.json` to write every figure in them, with the machine, the load and the versions, as `bench/results/` keeps them. You need CMake and a C compiler for Lexbor, and Python 3.11 or later for the fetch script. ## See also diff --git a/apps/site/src/data/benchmarks.ts b/apps/site/src/data/benchmarks.ts index 338d8b2..c8423a7 100644 --- a/apps/site/src/data/benchmarks.ts +++ b/apps/site/src/data/benchmarks.ts @@ -1,105 +1,273 @@ -// Benchmark figures the homepage quotes. They come from runs published on -// Parsec's Benchmarks docs page, which has the commands, the corpus and every -// per-page row; each figure here keeps its date, machine and source. -// shortcut: copied by hand from the Benchmarks docs page, not generated; when the -// bench writes machine-readable results, load them instead. +// Benchmark figures, read at build time from the newest run under +// bench/results/ on Parsec's main branch: each file is one mode of the +// bench, written with `--json`, holding every figure it printed with the +// machine, the load and the versions. Any claim a page makes about who +// wins is worked out here from those figures, so a new run can't leave a +// sentence behind that the numbers no longer back. + export const benchmarksSource = 'https://docs.parsec.tools/benchmarks/'; +export const realWorldSource = 'https://docs.parsec.tools/real-world-benchmarks/'; +export const resultsUrl = 'https://github.com/parsec-html/parsec/tree/main/bench/results'; +const resultsDir = 'https://api.github.com/repos/parsec-html/parsec/contents/bench/results'; -export const machine = 'an Apple M2 Max (12 cores, 32 GB), macOS 26.7'; +const userAgent = 'parsec.tools build (https://github.com/parsec-html/website)'; +const SCHEMA = 1; -export const htmlParse = { - date: '15 November 2026', - pages: 13, - megabytes: 24.36, - /** MB a second over all 13 pages. */ - parsec: 370, - lexbor: 242, - html5ever: 82, +type Figure = { bench: string; source: string; bytes: number; parser: string; metric: string; value: number }; +type Run = { + schema: number; + date: string; + commit: string; + machine: { cpu: string; cores: number; memory_bytes: number; os: string; arch: string }; + load_average: number[]; + versions: Record; + figures: Figure[]; }; -export const selectors = { - date: '15 November 2026', - count: 32, - /** Total milliseconds for all 32 selectors over the 13 pages. */ - parsec: 226, - lexbor: 728, -}; +async function get(url: string): Promise { + const response = await fetch(url, { headers: { 'User-Agent': userAgent, Accept: 'application/json' } }); + if (!response.ok) throw new Error(`${url}: ${response.status} ${response.statusText}`); + return (await response.json()) as T; +} -export const javascript = { - date: '28 November 2026', - megabytes: 11.58, - /** MB a second over the bench's bundles and inline scripts. */ - parsec: 380, - oxc: 363, - swc: 147, -}; +/** Fails the build when a results file isn't the format these pages read. */ +function check(name: string, run: Run): Run { + const bad = (what: string) => new Error(`bench/results ${name}: ${what}`); + if (run.schema !== SCHEMA) throw bad(`schema ${run.schema}, this site reads ${SCHEMA}`); + if (typeof run.date !== 'string' || !run.machine?.cpu || !Array.isArray(run.figures)) throw bad('missing date, machine or figures'); + for (const f of run.figures) { + const ok = + typeof f.bench === 'string' && + typeof f.source === 'string' && + typeof f.parser === 'string' && + typeof f.metric === 'string' && + typeof f.bytes === 'number' && + typeof f.value === 'number' && + Number.isFinite(f.value); + if (!ok) throw bad(`a figure isn't {bench, source, bytes, parser, metric, value}: ${JSON.stringify(f)}`); + } + return run; +} -// The figures below feed /benchmarks/ and /parsec-vs-lexbor/. Same caveat: -// shortcut: copied by hand from the Benchmarks and Real-world benchmarks -// docs pages, each with the date of its run; replace with the -// bench's own output once it writes machine-readable results. -export const realWorldSource = 'https://docs.parsec.tools/real-world-benchmarks/'; +/** Every file in the newest results directory, by mode. */ +async function newestRun(): Promise<{ dir: string; runs: Record }> { + // A run that isn't on Parsec's main yet, to check the pages against it locally. + const local = process.env.PARSEC_BENCH_RESULTS; + if (local) { + const { readdir, readFile } = await import('node:fs/promises'); + const runs: Record = {}; + for (const name of (await readdir(local)).filter((n) => n.endsWith('.json'))) { + runs[name.replace(/\.json$/, '')] = check(name, JSON.parse(await readFile(`${local}/${name}`, 'utf8'))); + } + return { dir: local, runs }; + } + const dirs = (await get<{ name: string; type: string }[]>(resultsDir)).filter((d) => d.type === 'dir').map((d) => d.name).sort(); + const dir = dirs.at(-1); + if (!dir) throw new Error('bench/results on Parsec main has no runs'); + const files = await get<{ name: string; download_url: string }[]>(`${resultsDir}/${dir}`); + const runs: Record = {}; + for (const f of files.filter((f) => f.name.endsWith('.json'))) { + runs[f.name.replace(/\.json$/, '')] = check(`${dir}/${f.name}`, await get(f.download_url)); + } + return { dir, runs }; +} -export const realWorld = { - date: '21 November 2026', - machine: 'an Apple M2 Max (12 cores, 32 GB), macOS 26.7.2', - pages: 1731, - megabytes: 558.6, - parsec: { mbs: 933, p50: '0.20 ms', peak: '101 MB' }, - lexbor: { mbs: 523, p50: '0.35 ms', peak: '123 MB' }, - /** Pages where Lexbor was faster, nearly all small. */ - lexborFaster: 13, -}; +const longDate = (iso: string) => + new Date(iso).toLocaleDateString('en-GB', { day: 'numeric', month: 'long', year: 'numeric', timeZone: 'UTC' }); -export const finalBoss = { - date: '20 November 2026', - pages: 1000, - rows: [ - { parser: 'Parsec', seconds: 1.02, slowest: '0.163 s', peak: '516 MB' }, - { parser: 'Lexbor 3.0.1', seconds: 1.94, slowest: '0.247 s', peak: '952 MB' }, - { parser: 'html5ever 0.40.1', seconds: 5.99, slowest: '0.804 s', peak: '708 MB' }, - ], -}; +const describe = (m: Run['machine']) => `an ${m.cpu} (${m.cores} cores, ${Math.round(m.memory_bytes / 2 ** 30)} GB), ${m.os}`; -export const hostile = { - date: '15 November 2026', - /** 80,000 unclosed divs: Parsec in MB/s, the others in seconds per parse. */ - unclosedDivs: { parsec: '131 MB/s', lexbor: '5.2 s', html5ever: '8.8 s' }, - inputs: 8, -}; +/** A view over one file's figures that fails the build on a missing one. */ +function figures(name: string, run: Run | undefined) { + if (!run) throw new Error(`bench/results: the newest run has no ${name}.json`); + const all = run.figures; + const find = (bench: string, source: string, parser: string, metric: string) => + all.find((f) => f.bench === bench && f.source === source && f.parser === parser && f.metric === metric); + const one = (bench: string, source: string, parser: string, metric: string) => { + const f = find(bench, source, parser, metric); + if (!f) throw new Error(`bench/results ${name}.json has no ${bench} / ${source} / ${parser} / ${metric}`); + return f; + }; + const sources = (bench: string, metric = 'seconds') => [ + ...new Set(all.filter((f) => f.bench === bench && f.metric === metric).map((f) => f.source)), + ]; + return { run, find, one, sources, date: longDate(run.date) }; +} -export const urls = { - date: '18 November 2026', - links: 83113, - /** Nanoseconds per URL on the real pages' links. */ - parsec: 107, - lexbor: 243, - ada: 142, -}; +const mbs = (f: Figure) => Math.round(f.bytes / 1e6 / f.value); +const mb = (bytes: number) => Math.round(bytes / 1e6); -export const css = { - /** MB/s over ten stylesheets, 1.87 MB. */ - tokenizing: { parsec: 389, lexbor: 210, cssparser: 318 }, - parsing: { parsec: 211, lexbor: 112, cssparser: 196 }, -}; +let loaded: ReturnType | undefined; -export const decoding = { - /** GB/s for Parsec and MB/s for Lexbor on real pages transcoded to legacy encodings. */ - parsec: '8 to 10 GB/s', - lexbor: '240 to 377 MB/s', -}; +/** Every figure the pages quote, from the newest committed run. */ +export function benchmarks() { + loaded ??= build(); + return loaded; +} -export const jsLexer = { - date: '22 November 2026', - /** MB/s over the same 11.58 MB. */ - parsec: 347, - oxc: 568, - swc: 328, -}; +async function build() { + const { dir, runs } = await newestRun(); + const pages = figures('pages', runs.pages); + const machine = describe(pages.run.machine); + + // The real pages: totals, and who's ahead on each one. + const realPages = pages.sources('html').filter((s) => s !== 'all real pages'); + const secs = (s: string, p: string) => pages.one('html', s, p, 'seconds').value; + const peak = (s: string, p: string) => pages.one('html', s, p, 'peak_bytes').value; + const total = (p: string) => pages.one('html', 'all real pages', p, 'seconds'); + const htmlParse = { + date: pages.date, + pages: realPages.length, + megabytes: +(total('Parsec').bytes / 1e6).toFixed(2), + parsec: mbs(total('Parsec')), + lexbor: mbs(total('Lexbor')), + html5ever: mbs(total('html5ever')), + lexborVersion: pages.run.versions.lexbor, + html5everVersion: pages.run.versions.html5ever, + /** Pages where Parsec is faster than both others. */ + aheadOn: realPages.filter((s) => secs(s, 'Parsec') < secs(s, 'Lexbor') && secs(s, 'Parsec') < secs(s, 'html5ever')).length, + /** Pages where Parsec's peak memory is below Lexbor's. */ + lessMemoryThanLexbor: realPages.filter((s) => peak(s, 'Parsec') < peak(s, 'Lexbor')).length, + /** Pages where html5ever's tree is smaller than Parsec's. */ + html5everSmaller: realPages.filter((s) => peak(s, 'html5ever') < peak(s, 'Parsec')), + }; + + const battery = pages.sources('selectors').filter((s) => s !== 'all selectors'); + const sel = (s: string, p: string) => pages.one('selectors', s, p, 'seconds').value; + const selectors = { + date: pages.date, + count: battery.length, + parsec: Math.round(sel('all selectors', 'Parsec') * 1e3), + lexbor: Math.round(sel('all selectors', 'Lexbor') * 1e3), + aheadOn: battery.filter((s) => sel(s, 'Parsec') < sel(s, 'Lexbor')).length, + }; + + const links = pages.sources('urls', 'ns_per_url').find((s) => s.startsWith('hrefs')); + if (!links) throw new Error("bench/results pages.json has no URL run over the pages' links"); + const url = (p: string) => pages.one('urls', links, p, 'ns_per_url'); + const differ = (p: string) => pages.one('urls', links, p, 'disagrees_with_parsec').value; + const urls = { + date: pages.date, + links: url('Parsec').bytes, + parsec: Math.round(url('Parsec').value), + lexbor: Math.round(url('Lexbor').value), + ada: Math.round(url('Ada').value), + /** Links whose href Lexbor or Ada resolves differently from Parsec. */ + disagree: differ('Lexbor') + differ('Ada'), + }; + + const sheet = (bench: string, p: string) => pages.one(bench, 'all stylesheets', p, 'seconds'); + const css = { + sheets: pages.sources('css-tokenize').filter((s) => s !== 'all stylesheets').length, + megabytes: +(sheet('css-parse', 'Parsec').bytes / 1e6).toFixed(2), + tokenizing: { parsec: mbs(sheet('css-tokenize', 'Parsec')), lexbor: mbs(sheet('css-tokenize', 'Lexbor')), cssparser: mbs(sheet('css-tokenize', 'cssparser')) }, + parsing: { parsec: mbs(sheet('css-parse', 'Parsec')), lexbor: mbs(sheet('css-parse', 'Lexbor')), cssparser: mbs(sheet('css-parse', 'cssparser')) }, + }; + + // Hostile inputs: a parser that took over two minutes has no figure. + const hostileInputs = pages.sources('html-hostile'); + const hostileSecs = (s: string, p: string) => pages.find('html-hostile', s, p, 'seconds'); + const divs = hostileInputs.find((s) => s === 'unclosed divs'); + if (!divs) throw new Error('bench/results pages.json has no "unclosed divs" input'); + const seconds = (f: Figure | undefined) => (!f ? 'over two minutes' : f.value < 10 ? `${f.value.toFixed(1)} s` : `${Math.round(f.value)} s`); + const hostile = { + date: pages.date, + inputs: hostileInputs.length, + /** Inputs where Parsec finished before both others. */ + aheadOn: hostileInputs.filter((s) => + ['Lexbor', 'html5ever'].every((p) => { + const theirs = hostileSecs(s, p); + return !theirs || pages.one('html-hostile', s, 'Parsec', 'seconds').value < theirs.value; + }), + ).length, + unclosedDivs: { + parsec: `${mbs(pages.one('html-hostile', divs, 'Parsec', 'seconds'))} MB/s`, + lexbor: seconds(hostileSecs(divs, 'Lexbor')), + html5ever: seconds(hostileSecs(divs, 'html5ever')), + }, + }; + + // Decoding: real pages in the legacy encodings, not UTF-8 or the generated text. + const dec = figures('decode', runs.decode); + const legacy = dec.sources('decode').filter((s) => !s.startsWith('UTF-8') && !s.includes('generated')); + const rate = (s: string, p: string) => { + const f = dec.one('decode', s, p, 'seconds'); + return f.bytes / 1e6 / f.value; + }; + const range = (p: string, scale: number, unit: string) => { + const r = legacy.map((s) => rate(s, p) / scale); + return `${Math.round(Math.min(...r))} to ${Math.round(Math.max(...r))} ${unit}`; + }; + const denseGbk = dec.sources('decode').find((s) => s.startsWith('GBK') && s.includes('generated')); + const decoding = { + date: dec.date, + parsec: range('Parsec', 1e3, 'GB/s'), + lexbor: range('Lexbor (UTF-8)', 1, 'MB/s'), + /** Whether Lexbor's decoders alone, before encoding to UTF-8, beat Parsec on dense GBK text. */ + lexborDecodersAheadOnDenseGbk: !!denseGbk && rate(denseGbk, 'Lexbor (code points)') > rate(denseGbk, 'Parsec'), + }; + + const jsRun = figures('js', runs.js); + const scripts = jsRun.sources('js').filter((s) => s !== 'all'); + const js = (s: string, p: string, metric = 'seconds') => jsRun.one('js', s, p, metric); + const javascript = { + date: jsRun.date, + megabytes: +(js('all', 'Parsec').bytes / 1e6).toFixed(2), + parsec: mbs(js('all', 'Parsec')), + oxc: mbs(js('all', 'oxc')), + swc: mbs(js('all', 'swc')), + /** Sources where Parsec's peak memory is below both others'. */ + lessMemoryOn: scripts.filter((s) => ['oxc', 'swc'].every((p) => js(s, 'Parsec', 'peak_bytes').value < js(s, p, 'peak_bytes').value)).length, + sources: scripts.length, + }; + /** Sources where oxc parses faster than Parsec, Parsec's speed as a fraction of oxc's, furthest behind first. */ + const jsSmallScripts = scripts + .map((s) => ({ source: s, ratio: +(js(s, 'oxc').value / js(s, 'Parsec').value).toFixed(2) })) + .filter((s) => s.ratio < 1) + .sort((a, b) => a.ratio - b.ratio); + + const lex = figures('js-lex', runs['js-lex']); + const lexAll = (p: string) => lex.one('js-lex', 'all', p, 'seconds'); + const jsLexer = { date: lex.date, parsec: mbs(lexAll('Parsec')), oxc: mbs(lexAll('oxc')), swc: mbs(lexAll('swc')) }; + + const rw = figures('realworld', runs.realworld); + const rwSource = rw.sources('realworld').find((s) => /^\d+ pages$/.test(s)); + if (!rwSource) throw new Error('bench/results realworld.json has no page totals'); + const rwf = (p: string, metric: string) => rw.one('realworld', rwSource, p, metric); + const tool = (p: string) => ({ + mbs: mbs(rwf(p, 'seconds')), + p50: `${(rwf(p, 'p50_seconds').value * 1e3).toFixed(2)} ms`, + peak: `${mb(rwf(p, 'peak_bytes').value)} MB`, + peakBytes: rwf(p, 'peak_bytes').value, + failures: rwf(p, 'crashes').value + rwf(p, 'timeouts').value, + }); + const realWorld = { + date: rw.date, + machine: describe(rw.run.machine), + pages: parseInt(rwSource, 10), + megabytes: +(rwf('Parsec', 'seconds').bytes / 1e6).toFixed(1), + parsec: tool('Parsec'), + lexbor: tool('Lexbor'), + html5ever: tool('html5ever'), + lexborFaster: rw.one('realworld', 'pages Lexbor parses faster', 'Lexbor', 'pages').value, + lexborElementsDiffer: rw.one('realworld', "pages whose element count differs from Parsec's", 'Lexbor', 'pages').value, + }; + + const boss = figures('boss', runs.boss); + const bossSource = boss.sources('boss', 'seconds_per_1000_pages')[0]; + const bf = (p: string, metric: string) => boss.one('boss', bossSource, p, metric).value; + const version: Record = { Lexbor: ` ${boss.run.versions.lexbor}`, html5ever: ` ${boss.run.versions.html5ever}` }; + const finalBoss = { + date: boss.date, + pages: parseInt(bossSource, 10), + rows: ['Parsec', 'Lexbor', 'html5ever'].map((p) => ({ + parser: `${p}${version[p] ?? ''}`, + seconds: +bf(p, 'seconds_per_1000_pages').toFixed(2), + slowest: `${bf(p, 'slowest_seconds').toFixed(3)} s`, + peak: `${mb(bf(p, 'peak_bytes'))} MB`, + failures: ['crashes', 'timeouts', 'refused', 'no_document'].reduce((n, metric) => n + bf(p, metric), 0), + })), + }; -/** The inline scripts where oxc is still ahead of Parsec's parser, as a fraction of its speed. */ -export const jsSmallScripts = [ - { source: 'mdn-html, 0.3 KB', ratio: 0.79 }, - { source: 'python-stdtypes', ratio: 0.81 }, - { source: 'whatwg-parsing, 0.2 KB', ratio: 0.84 }, -]; + return { dir, machine, htmlParse, selectors, urls, css, hostile, decoding, javascript, jsSmallScripts, jsLexer, realWorld, finalBoss }; +} diff --git a/apps/site/src/pages/benchmarks/index.astro b/apps/site/src/pages/benchmarks/index.astro index 2fef1e8..a3b1506 100644 --- a/apps/site/src/pages/benchmarks/index.astro +++ b/apps/site/src/pages/benchmarks/index.astro @@ -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'); @@ -32,32 +24,38 @@ const fmt = (n: number) => n.toLocaleString('en-GB');

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 Benchmarks and{" "} - Real-world benchmarks pages, and How it's measured has the method. + Real-world benchmarks pages, the raw figures are in bench/results, and{" "} + How it's measured has the method. Where Parsec loses, it's here too.

-

Thirteen real pages

+

{count(htmlParse.pages).replace(/^./, (c) => c.toUpperCase())} real pages

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}.

- +
- - + +
ParserMB/sParsec vs
Parsec{htmlParse.parsec}
Lexbor 3.0.1{htmlParse.lexbor}{x(htmlParse.parsec, htmlParse.lexbor)}×
html5ever 0.40.1{htmlParse.html5ever}{x(htmlParse.parsec, htmlParse.html5ever)}×
Lexbor {htmlParse.lexborVersion}{htmlParse.lexbor}{x(htmlParse.parsec, htmlParse.lexbor)}×
html5ever {htmlParse.html5everVersion}{htmlParse.html5ever}{x(htmlParse.parsec, htmlParse.html5ever)}×

- 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. + + )}

The web as a crawl found it

@@ -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.

- +
- +
ParserMB/sMedian pagePeak memory
Parsec{realWorld.parsec.mbs}{realWorld.parsec.p50}{realWorld.parsec.peak}
Lexbor 3.0.1{realWorld.lexbor.mbs}{realWorld.lexbor.p50}{realWorld.lexbor.peak}
Lexbor {htmlParse.lexborVersion}{realWorld.lexbor.mbs}{realWorld.lexbor.p50}{realWorld.lexbor.peak}

- 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.

A crawler's bad day

@@ -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}.

- +
@@ -100,33 +101,39 @@ const fmt = (n: number) => n.toLocaleString('en-GB');
ParserSecondsSlowest pagePeak memory
-

No crashes, timeouts or refused pages from any of the three.

+

+ {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(', ')}.`} +

Hostile input

- 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 <div>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 <div>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}.

Selectors

- {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}.

URLs

Every href and src 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}.

CSS

- 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. @@ -135,23 +142,25 @@ const fmt = (n: number) => n.toLocaleString('en-GB');

Decoding

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."}

JavaScript

{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}.

- 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:

    {jsSmallScripts.map((s) =>
  • {s.source}: {s.ratio}× oxc's speed
  • )}

- 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{" "} #190.

diff --git a/apps/site/src/pages/benchmarks/methodology.astro b/apps/site/src/pages/benchmarks/methodology.astro index 737f9b5..feece2c 100644 --- a/apps/site/src/pages/benchmarks/methodology.astro +++ b/apps/site/src/pages/benchmarks/methodology.astro @@ -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 @@ -54,7 +56,7 @@ cargo run --release --manifest-path bench/Cargo.toml`; bench/pages.txt. The repository holds their addresses, never the pages.
  • - 1,731 production pages: one day's crawl by Netweir's harness, home pages from a Tranco top-sites list and inner + {realWorld.pages.toLocaleString('en-GB')} production pages: 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.{" "} bench/realworld.tsv lists each URL and the hash of its body.
  • @@ -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.

    +

    + Add --json results.json 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{" "} + bench/results, read when the site is built, not copied by hand. +

    diff --git a/apps/site/src/pages/index.astro b/apps/site/src/pages/index.astro index 5909ad4..c0bf604 100644 --- a/apps/site/src/pages/index.astro +++ b/apps/site/src/pages/index.astro @@ -5,10 +5,11 @@ import hero from '../data/hero.json'; import { pages, softwareSourceCode, repo } from '../lib/site'; import { getVersions, getConformance, suite, baselineUrl, getCrateRows } from '../lib/data'; import { crateRoles, reachPhrase } from '../data/crates'; -import { benchmarksSource, machine, htmlParse, selectors, javascript } from '../data/benchmarks'; +import { benchmarks, benchmarksSource } from '../data/benchmarks'; import { getStartedUrl, docsUrl } from '@parsec/brand/nav'; const page = pages.home; +const { machine, htmlParse, selectors, javascript, jsSmallScripts } = await benchmarks(); const versions = await getVersions(); const all = await getConformance(); const fmt = (n: number) => n.toLocaleString('en-GB'); @@ -223,13 +224,13 @@ const installs = [
    JavaScript, {javascript.megabytes} MB of bundles and inline scripts
    - {javascript.parsec} MB/s, against {javascript.oxc} for oxc and {javascript.swc} for swc; oxc is still ahead on the - smallest inline scripts + {javascript.parsec} MB/s, against {javascript.oxc} for oxc and {javascript.swc} for swc{jsSmallScripts.length > 0 ? '; oxc is still ahead on the smallest inline scripts' : ''}

    - One machine's numbers: {machine}, on {htmlParse.date} for HTML and selectors and {javascript.date} for JavaScript. The{" "} + One machine's numbers: {machine},{" "} + {htmlParse.date === javascript.date ? `on ${htmlParse.date}` : `on ${htmlParse.date} for HTML and selectors and ${javascript.date} for JavaScript`}. The{" "} Benchmarks page has every row, the corpus and the commands to run it yourself in about five minutes.

    diff --git a/apps/site/src/pages/netweir.astro b/apps/site/src/pages/netweir.astro index ad3e734..7ca245e 100644 --- a/apps/site/src/pages/netweir.astro +++ b/apps/site/src/pages/netweir.astro @@ -1,7 +1,9 @@ --- import InnerPage from '../layouts/InnerPage.astro'; import Prose from '../components/Prose.astro'; -import { realWorld, realWorldSource } from '../data/benchmarks'; +import { benchmarks, realWorldSource } from '../data/benchmarks'; + +const { realWorld } = await benchmarks(); const netweir = 'https://github.com/netweir/netweir'; --- @@ -41,7 +43,7 @@ const netweir = 'https://github.com/netweir/netweir';

    The same pages, as a benchmark

    One day's crawl of that list, {realWorld.pages.toLocaleString('en-GB')} pages that came back as HTML, is also the real-world - benchmark: Parsec at {realWorld.parsec.mbs} MB/s, Lexbor at {realWorld.lexbor.mbs}, neither crashing on any page. The{" "} + benchmark: Parsec at {realWorld.parsec.mbs} MB/s, Lexbor at {realWorld.lexbor.mbs}{realWorld.parsec.failures + realWorld.lexbor.failures === 0 ? ', neither crashing on any page' : ''}. The{" "} Real-world benchmarks page has the method, and the repository keeps the list of URLs and hashes, never the pages, which belong to their sites.

    diff --git a/apps/site/src/pages/parsec-vs-lexbor.astro b/apps/site/src/pages/parsec-vs-lexbor.astro index c57c213..5ee355b 100644 --- a/apps/site/src/pages/parsec-vs-lexbor.astro +++ b/apps/site/src/pages/parsec-vs-lexbor.astro @@ -2,7 +2,9 @@ import InnerPage from '../layouts/InnerPage.astro'; import Prose from '../components/Prose.astro'; import Table from '../components/Table.astro'; -import { htmlParse, selectors, realWorld, hostile, machine } from '../data/benchmarks'; +import { benchmarks } from '../data/benchmarks'; + +const { htmlParse, selectors, realWorld, hostile, decoding, machine } = await benchmarks(); const compare = 'https://docs.parsec.tools/comparison-with-lexbor/'; const lexbor = 'https://github.com/lexbor/lexbor/blob/145872a2e5d6c22d923afcd3c386a21e59f9a0e2'; @@ -46,7 +48,7 @@ const rows: [string, string, string][] = [
  • Some pages, some workloads. Across {realWorld.pages.toLocaleString('en-GB')} production pages, Lexbor parsed{" "} - {realWorld.lexborFaster} faster than Parsec, nearly all of them small. Its decoders, on their own, beat Parsec's on dense GBK text. + {realWorld.lexborFaster} faster than Parsec.{decoding.lexborDecodersAheadOnDenseGbk && " Its decoders, on their own, beat Parsec's on dense GBK text."}
  • Packaging. You can install Lexbor from vcpkg, Homebrew and Debian today. Parsec is on crates.io, PyPI and npm, with C packages on GitHub.
  • @@ -73,12 +75,12 @@ const rows: [string, string, string][] = [

    Speed and memory

    - Lexbor 3.0.1, built with its own Release flags, against Parsec in the same process on the same input, on {machine}: + Lexbor {htmlParse.lexborVersion}, built with its own Release flags, against Parsec in the same process on the same input, on {machine}:

      -
    • Thirteen real pages: {htmlParse.parsec} MB/s against {htmlParse.lexbor}, {x(htmlParse.parsec, htmlParse.lexbor)} times as fast, with less memory on every page.
    • +
    • {htmlParse.pages} real pages: {htmlParse.parsec} MB/s against {htmlParse.lexbor}, {x(htmlParse.parsec, htmlParse.lexbor)} times as fast, with less memory on {htmlParse.lessMemoryThanLexbor === htmlParse.pages ? 'every page' : `${htmlParse.lessMemoryThanLexbor} of them`}.
    • {realWorld.pages.toLocaleString('en-GB')} production pages as a crawler fetched them: {realWorld.parsec.mbs} MB/s against {realWorld.lexbor.mbs}.
    • -
    • {selectors.count} selectors over the thirteen pages: {selectors.parsec} ms against {selectors.lexbor}.
    • +
    • {selectors.count} selectors over the {htmlParse.pages} pages: {selectors.parsec} ms against {selectors.lexbor}.
    • 80,000 unclosed <div>s: Parsec at {hostile.unclosedDivs.parsec}, Lexbor at {hostile.unclosedDivs.lexbor} a parse, because its work there grows with the square of the depth.