Repository navigation
feat(url): Parsec had no WHATWG URL module - #77
Merged
Merged
Conversation
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.
jamesconwaydev
enabled auto-merge (squash)
November 18, 2026 23:55
# Conflicts: # Cargo.lock # Cargo.toml # README.md # bench/Cargo.lock # bench/Cargo.toml # bench/src/main.rs
# Conflicts: # README.md
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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'surl2.5.8 andidna1.1.0 behind the URL Standard's own API. Parse with an optional base, every getter and setter ofURL,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.url/resourcesdata pinned incrates/parsec-url/tests/wptat6dac967, with WPT's BSD-3 licence, run bytests/wpt.rsthe way WPT's.any.jsfiles run it. Counts go into the CI summary with the HTML suites.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 ASCIIxn--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, theportsetter given only tabs and newlines, is fixed here.bench/: a URL table, Parsec against Lexbor'slxb_url_parseand Ada 4.0.0 (new submodule at the release tag, built withcc; 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:
href/srcon the 13 bench pagesurltestdata.jsoninputsParsec 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:plus
tests/search_params.rs, with the cases from WPT'surlencoded-parser,urlsearchparams-sortand-stringifiertests. fmt, clippy-D warnings,cargo deny checkand the bench's clippy and deny pass.Closes #26
Closes #27