Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat: replace C++ FFI with native Rust parser - #119

#119
Open
countradooku wants to merge 3 commits into
ada-url:mainada-url/rust:mainfrom
countradooku:feat/native-rust-portcountradooku/rust:feat/native-rust-portCopy head branch name to clipboard
Open

feat: replace C++ FFI with native Rust parser#119
countradooku wants to merge 3 commits into
ada-url:mainada-url/rust:mainfrom
countradooku:feat/native-rust-portcountradooku/rust:feat/native-rust-portCopy head branch name to clipboard

Conversation

@countradooku

Copy link
Copy Markdown

Summary

  • replace the bundled C++ implementation and C ABI wrapper with a memory-safe native Rust parser
  • retain the existing ada-url public API, no_std support, serde behavior, and the former bundled / libcpp feature names as compatibility no-ops
  • use a single normalized buffer with compact component offsets and conservative optimized fast paths
  • add URLPattern behind an optional feature and add Radu Diaconu as an author
  • pin and exercise the current ada-url/ada fixtures at 30f3f3020c5a979b62f90dc9c37fd45de3cc84d7

Impact

This removes build.rs, the C/C++ FFI layer, and the vendored Ada sources. Most of the apparent diff size is the deletion of roughly 27,000 lines from ada.cpp and ada.h; the native implementation is roughly 5,000 lines of Rust.

The packaged crate verifies successfully at 132.7 KiB compressed. Existing benchmark targets remain available, and smoke runs cover both the focused parser corpus and all 891 WPT URL entries.

Conformance

The test suite now directly covers:

  • URL parsing and base resolution
  • transactional setters
  • the latest IDNA/UTS Test script fails on macOS #46 data
  • percent encoding
  • DNS-length validation
  • URLSearchParams
  • URLPattern WPT fixtures

The current fixtures are recorded in tests/wpt/UPSTREAM.

Validation

  • rustup run 1.96.1 cargo test --all-features --locked
  • rustup run 1.96.1 cargo test --no-default-features --locked
  • cargo clippy --all-targets --all-features --locked -- -D warnings
  • RUSTDOCFLAGS='-D warnings' cargo doc --all-features --no-deps --locked
  • cargo fmt --all -- --check
  • cargo package --allow-dirty --locked
  • cargo bench --bench parse -- --quick
  • cargo bench --bench wpt -- --quick

@countradooku
countradooku marked this pull request as ready for review July 29, 2026 00:49
Comment thread .github/workflows/ci.yml
# instrumented. LeakSanitizer is enabled by default under ASan on Linux;
# this catches regressions like https://github.com/ada-url/rust/issues/101
# where the failed-parse path leaked the allocation from `ada_parse`.
- name: Test under AddressSanitizer + LeakSanitizer

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep the workflows?

if: matrix.env.CARGO_BUILD_TARGET == 'wasm32-wasip1'
run: |
rustup target add wasm32-wasip1
curl -LO https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-33/wasi-sdk-33.0-x86_64-linux.deb

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep this and make sure it works with wasm etc...

@codspeed-hq

codspeed-hq Bot commented Jul 29, 2026

Copy link
Copy Markdown

Merging this PR will regress 1 benchmark

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 6 improved benchmarks
❌ 1 regressed benchmark
✅ 9 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation ada_url 3.7 µs 4.9 µs -24.91%
Simulation ada_url 4.8 ms 2.3 ms ×2.1
Simulation ada_url 14.4 µs 7.5 µs +91.06%
Simulation ada_url_parse 165.6 ms 98.5 ms +68.13%
Simulation ada_url 830.7 µs 515.3 µs +61.22%
Simulation ada_url 3.4 ms 2.6 ms +33.02%
Simulation ada_url 24.8 µs 22.2 µs +11.75%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing countradooku:feat/native-rust-port (6269893) with main (af35063)

Open in CodSpeed

@countradooku

countradooku commented Jul 29, 2026

Copy link
Copy Markdown
Author

i think I need to tae a look at CodSpeed Performance Analysis

@countradooku

Copy link
Copy Markdown
Author

Performance follow-up is pushed in 6269893.

Side-by-side release benchmarks against af35063 on the same machine (lower is better) now show the native Rust implementation ahead across every measured group:

  • basic href: 804 ns vs 955 ns (~16% faster)
  • basic can_parse: 270 ns vs 438 ns (~38% faster)
  • BBC href: 706 ns vs 759 ns (~7% faster)
  • BBC can_parse: 256 ns vs 279 ns (~8% faster)
  • IPv4 decimal: 348 µs vs 369 µs (~6% faster)
  • IPv4 non-decimal: 313 µs vs 553 µs (~43% faster)
  • DNS: 76.2 µs vs 91.7 µs (~17% faster)
  • URLSearchParams: 11.2 µs vs 14.4 µs (~22% faster)

Validation is green locally: all features, no-default-features, full WPT/IDNA/URLPattern corpora, Clippy, docs, Miri, package verification, and WASI compilation. I also fixed the pinned-toolchain Miri invocation.

The new GitHub Actions/CodSpeed runs are currently marked action_required with no jobs; they need maintainer approval because the fork PR changes a workflow file.

Comment thread .github/workflows/ci.yml
- run: cargo clippy --all-targets --all-features --locked -- -D warnings

miri:
name: Miri

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is Miri?

- os: ubuntu-latest
env:
CARGO_BUILD_TARGET: wasm32-wasip1
CARGO_TARGET_WASM32_WASI_RUNNER: /home/runner/.wasmtime/bin/wasmtime --dir=.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we keep this

Comment thread Cargo.toml
"LongYinan <github@lyn.one>",
"Boshen <boshenc@gmail.com>"
"Boshen <boshenc@gmail.com>",
"Diaconu Radu-Mihai <52667211+countradooku@users.noreply.github.com>"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the email you want to keep?

Comment thread Cargo.toml
repository = "https://github.com/ada-url/rust"
homepage = "https://ada-url.com"
license = "MIT OR Apache-2.0"
links = "ada-url"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did we remove this

Comment thread Cargo.toml
url-pattern = ["dep:urlpattern", "std"]

[dependencies]
idna = "1.1.0"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't have any dependency at all

Comment thread Cargo.toml
[dependencies]
idna = "1.1.0"
memchr = "2.8.0"
percent-encoding = "2.3.2"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't use a dependency for this

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

percent encoding?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ada doesn't have any dependencies. we should keep the same.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can i keep idna?

Comment thread Cargo.toml

[dev-dependencies]
criterion = { package = "codspeed-criterion-compat", version = "4", default-features = false, features = ["cargo_bench_support"] }
url = "2" # Used by benchmarks

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please keep this

@countradooku

Copy link
Copy Markdown
Author

The final CodSpeed regression is addressed in 7f829ba.

BBC_BasicBench_AdaURL_CanParse now validates simple HTTPS authorities in one bounded pass instead of rescanning for backslashes, credentials, ports, numeric-host rules, and domain bytes. Same-machine release results:

  • native Rust before: ~256 ns
  • native Rust after: ~98 ns
  • upstream baseline: ~296 ns

That is ~62% lower than the previous native result and ~67% lower than upstream. The mixed BasicBench_AdaURL_CanParse result is also ~59% below upstream. Full tests, no-default-features, WPT plus DNS-length can_parse parity, Clippy, formatting, and Miri pass.

The new CI and CodSpeed runs are awaiting maintainer approval again because this is a fork PR.

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.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.