Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use web_sys::Url for IDN conversion on wasm32-unknown-unknown #887

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

micolous
Copy link
Contributor

@micolous micolous commented Nov 28, 2023

This pull request is based on #886. Merging this PR will also merge #886.

This removes the dependency on idna on wasm32-unknown-unknown, replacing it with a small shim which calls out to web_sys::Url.

With a small yew demo app (which calls Url::parse()), this reduces binary size by 228 KiB on a release build and by 425 KiB on a debug build. These savings should go a lot of the way towards addressing #557, while retaining IDN support.

API changes

The deprecations could be split out from this, I've included them as related work.

Alternatives considered

  • Downstream libraries could adopt web_sys::Url on wasm32-unknown-unknown.

    This is API-breaking, and complicated to handle, for reasons I've covered in WASM file size #557 and Use web_sys::Url instead of url::Url on wasm32 targets seanmonstar/reqwest#2050.

    There are similar pains discussed in Use url::Url instead of http::Uri sagebind/isahc#382 for a http::Uri to url::Url migration.

  • Shimming out every single piece of functionality to JavaScript's Url type (via web_sys::Url) on wasm32-unknown-unknown.

    This would probably make things smaller again, but there are enough subtle API differences to make this a problem. For example, url::Url::host() returns a url::Host, but web_sys::Url::hostname() returns a String.

  • Shimming in idna.

    Not all the functionality required is supported in web APIs (domain_to_unicode), and so it needs changes to Url anyway.

    This also allows one to continue using the idna crate directly on wasm32-unknown-unknown with its normalisation database.

Known issues

  • There are a few extra test failures (see expected_failures_{chromium,firefox,safari}.txt) – I'm not certain which of these are browser bugs or url::Host bugs.

    In any case, I don't think I can fix them, and I don't know how much one should care.

  • I haven't tried this on redox or wasi targets – they don't appear to be covered by CI, and so I've left them as-is.

    It may be possible to get similar binary size savings on those targets, but I'm keeping them out of scope for now.

@micolous
Copy link
Contributor Author

micolous commented Apr 3, 2024

While this is based on #886, I've marked it as "ready for review", as this isn't really a work in progress – it's just blocked.

* remove `Url::socket_addrs` on wasm32-unknown-unknown (it won't work, those
  platform API calls are not supported)

* disable unit tests which won't work on wasm32-unknown-unknown

* run tests in `wasm_bindgen_test` on wasm32-unknown-unknown

* remove `panic::catch_unwind` from wpt tests, as that conflicts with
  wasm-bindgen's panic handler

* run the tests in CI
Copy link

codecov bot commented Apr 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (main@a4dd58b). Click here to learn what that means.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #887   +/-   ##
=======================================
  Coverage        ?   81.88%           
=======================================
  Files           ?       20           
  Lines           ?     3545           
  Branches        ?        0           
=======================================
  Hits            ?     2903           
  Misses          ?      642           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

1 participant