Skip to content

feat(url): Parsec had no WHATWG URL module - #77

Merged
jamesconwaydev merged 5 commits into
mainfrom
url
Nov 18, 2026
Merged

jamesconwaydev merged 5 commits into
mainfrom
url

Conversation

@jamesconwaydev

@jamesconwaydev jamesconwaydev commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Parsec had no URL module, so there was nothing to set against Lexbor's lxb_url_*, no WPT URL counts, and no URL benchmark (#26, #27).

Change

  • crates/parsec-url: Servo's url 2.5.8 and idna 1.1.0 behind the URL Standard's own API. Parse with an optional base, every getter and setter of URL, URLSearchParams (parse, get, getAll, append, set, delete, has, sort by UTF-16 code units, toString), domain to ASCII and to Unicode, Host::parse, and Punycode.
  • WPT's url/resources data pinned in crates/parsec-url/tests/wpt at 6dac967, with WPT's BSD-3 licence, run by tests/wpt.rs the way WPT's .any.js files run it. Counts go into the CI summary with the HTML suites.
  • Every failing case is named in tests/wpt/known-failures.txt; the run fails on a new failure or on a listed one that starts passing. 795 of the 875 are one IDNA rule the standard changed in June 2026 (an ASCII xn-- label that isn't valid Punycode is now kept); the rest are recent file:, blob: and opaque-path changes. They're inside the crate's parsers, so they stay listed. One that a wrapper could fix, the port setter given only tabs and newlines, is fixed here.
  • bench/: a URL table, Parsec against Lexbor's lxb_url_parse and Ada 4.0.0 (new submodule at the release tag, built with cc; a small C++ shim parses against a pre-parsed base, since Ada's C API re-parses the base on every call).

On an M2 Max, two runs with the one-minute load under 3:

List URLs Parsec Lexbor Ada
href/src on the 13 bench pages 83,113 178 / 181 ns 243 / 240 ns 145 / 142 ns
WPT urltestdata.json inputs 904 175 / 181 ns 180 / 184 ns 146 / 155 ns

Parsec is 1.33 times as fast as Lexbor on real links, and all three agree on every href. Ada is about 1.25 times as fast as Parsec. As the design says, I haven't written a new parser here; that's the next issue.

Tests

cargo test -p parsec-url:

urltestdata.json: 839 passed, 65 failed, 0 skipped
urltestdata.json origin: 410 passed, 11 failed, 0 skipped
setters_tests.json: 263 passed, 21 failed, 0 skipped
toascii.json: 240 passed, 21 failed, 522 skipped (the <a> and <area> halves test HTML elements, not URL parsing)
IdnaTestV2.json: 1918 passed, 757 failed, 1 skipped (an empty input can't go through new URL())
IdnaTestV2-removed.json: 20 passed, 0 failed, 0 skipped

plus tests/search_params.rs, with the cases from WPT's urlencoded-parser, urlsearchparams-sort and -stringifier tests. fmt, clippy -D warnings, cargo deny check and the bench's clippy and deny pass.

Closes #26
Closes #27

Add crates/parsec-url, which wraps Servo's url and idna crates in the
URL Standard's own API: parse with an optional base, every getter and
setter the URL interface has, URLSearchParams (parse, get, getAll,
append, set, delete, has, sort by UTF-16 code units, and the
x-www-form-urlencoded serializer), domain to ASCII and to Unicode, and
Punycode.

tests/wpt.rs runs WPT's url/resources data (urltestdata, setters,
toascii, IdnaTestV2 and IdnaTestV2-removed, pinned at 6dac967 with
WPT's licence) the way WPT's .any.js files do, and writes the counts
for the CI summary: 3,690 of 4,565 pass. The 875 failures are listed
in tests/wpt/known-failures.txt, so a new failure or a fixed one fails
the run.

795 of them are one spec change from June 2026 that url 2.5.8 hasn't
made: an ASCII domain whose xn-- label isn't valid Punycode is now
kept, not rejected. The rest are recent file:, blob: and opaque path
changes. They're inside the crate's host and path parsers, out of a
wrapper's reach, so they stay listed. The one that wasn't, a port
setter given only tabs and newlines, is fixed here.
Add a URL table to bench/: Parsec's parsec-url against Lexbor's
lxb_url_parse and Ada 4.0.0, over every href and src on the 13 real
pages (83,113 strings, each against its page's address) and over the
904 inputs of WPT's urltestdata.json. Each parser has its bases parsed
beforehand, and builds and frees every URL. A time is the median of 30
passes.

Ada comes in as a submodule at v4.0.0 and is compiled by cc at -O3 with
NDEBUG, as its CMake release build is. Its C API parses the base again
on every call, so a few lines of C++ in bench/src/ada.cpp call its C++
parse with a base already parsed instead.

The table also counts where Lexbor's and Ada's hrefs differ from
Parsec's, so a time is never compared across different answers. Run
only this table with `-- urls`.
The README's table and list now say parsec-url ships, with its WPT
count (3,690 of 4,565) and what the 875 failures are, and the speed on
the links in the 13 benchmark pages: 180 ns a URL against Lexbor's 240
and Ada's 143. The roadmap ticks off the URL crate and the benchmark
under M6 and says what's left: Unicode normalization, and a URL parser
of Parsec's own.
# Conflicts:
#	Cargo.lock
#	Cargo.toml
#	README.md
#	bench/Cargo.lock
#	bench/Cargo.toml
#	bench/src/main.rs
@jamesconwaydev
jamesconwaydev merged commit 1cd6092 into main Nov 18, 2026
26 checks passed
@jamesconwaydev
jamesconwaydev deleted the url branch November 18, 2026 23:59
@jamesconwaydev jamesconwaydev mentioned this pull request Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Benchmark URL parsing against Lexbor and Ada WHATWG URL with published WPT pass counts

1 participant