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 object URLs for inlined linked modules #4067

Merged
merged 1 commit into from
Aug 12, 2024

Conversation

daxpedda
Copy link
Collaborator

Currently link_to!() without --split-linked-modules would build a encoded URL and return it as a String when accessed.
This makes link_to!() quite pointless in this case as its not much better then using include_str!() in Rust.

This PR changes this case to use object URLs instead. The resulting URL is also cached on the Rust side with the help of once_cell (which was a dependency already), so we don't keep creating new object URLs over and over, which would be a memory leak.

A fallback is built-in for service-workers, where the API isn't present.

So this change is a trade-off, the URL is now permanently stored in Wasm memory once called, but the URL is always guaranteed to be quite short, except in the case of service workers. In contrast, when not using --split-linked-modules, the whole file was transferred into Wasm memory.

Follow-up to #3069.

@daxpedda daxpedda merged commit e845f51 into rustwasm:main Aug 12, 2024
40 checks passed
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