feat: router-based wasm bundle splitting (#3683)

* feat: wasm-split base implementation

* kinda sorta works with the cli

* okay great it actually works

* fix: cache busting for chunks

* cleaned up version

* it works with the router

* wip: migrate to a faster linear solution using id remapping

* add a good harness

* it works completely on the docsite

* the super tight build works too

* make parallelizable

* works on the docsite but not the harness

* light cleanups, fix for both harness and docsite

* make codegen smaller by extract some shared functions to prevent monos

* chunking works, but tbd on tuning heuristics

* extract used module

* wip: cleaning up module

* wip: much better understanding of how imports work

* fix the call graph

* working again...

* wip: thinking about ifuncs

* ifunc approach works

* yes the ifunc approach works!!

* it all works completely even with chunks

* small cleanups

* comments

* actually locate all of the symbols

* clean up final implementation

* clean up tomls, revert some mono changs

* clean up, add some more comments / docs in places

* hoist more packages

* clean up impl a bit more

* clean cli

* move harness to playwright

* update playwright

* extract codgen

* add lazy to components

* Add docs to split loader

* clippy

* typos

* clippy, don't generate splits if not on wasm

* whoops, const

* Typos and docs

* enable optimizations in ci

* add optimizations to ci

* add wasm-split router feature

* parallel playwright?

* fix no case check

* disable pre-compress... think that might be the issue

* better logging, no default pre-compress, caching of shared symbols
* Fix: compressing assets

* fix non-interactive logging for serve

* cache playwright even on failure, use the cli with optimizations

* fix prebuild

* fix playwright webserver
This commit is contained in:
Jonathan Kelley authored and GitHub committed 2025-02-13 18:54:38 -08:00
1 parent 14eb7597df
commit bdeedc13eb
59 files changed
+4249 -299

No files matched your search

+26 -11
View File
@@ -18,10 +18,11 @@ pub(crate) struct WasmBindgen {
demangle: bool,
remove_name_section: bool,
remove_producers_section: bool,
keep_lld_exports: bool,
}
impl WasmBindgen {
pub fn new(version: &str) -> Self {
pub(crate) fn new(version: &str) -> Self {
Self {
version: version.to_string(),
input_path: PathBuf::new(),
@@ -33,65 +34,73 @@ impl WasmBindgen {
demangle: true,
remove_name_section: false,
remove_producers_section: false,
keep_lld_exports: false,
}
}
pub fn input_path(self, input_path: &Path) -> Self {
pub(crate) fn input_path(self, input_path: &Path) -> Self {
Self {
input_path: input_path.to_path_buf(),
..self
}
}
pub fn out_dir(self, out_dir: &Path) -> Self {
pub(crate) fn out_dir(self, out_dir: &Path) -> Self {
Self {
out_dir: out_dir.to_path_buf(),
..self
}
}
pub fn out_name(self, out_name: &str) -> Self {
pub(crate) fn out_name(self, out_name: &str) -> Self {
Self {
out_name: out_name.to_string(),
..self
}
}
pub fn target(self, target: &str) -> Self {
pub(crate) fn target(self, target: &str) -> Self {
Self {
target: target.to_string(),
..self
}
}
pub fn debug(self, debug: bool) -> Self {
pub(crate) fn debug(self, debug: bool) -> Self {
Self { debug, ..self }
}
pub fn keep_debug(self, keep_debug: bool) -> Self {
pub(crate) fn keep_debug(self, keep_debug: bool) -> Self {
Self { keep_debug, ..self }
}
pub fn demangle(self, demangle: bool) -> Self {
pub(crate) fn demangle(self, demangle: bool) -> Self {
Self { demangle, ..self }
}
pub fn remove_name_section(self, remove_name_section: bool) -> Self {
pub(crate) fn remove_name_section(self, remove_name_section: bool) -> Self {
Self {
remove_name_section,
..self
}
}
pub fn remove_producers_section(self, remove_producers_section: bool) -> Self {
pub(crate) fn remove_producers_section(self, remove_producers_section: bool) -> Self {
Self {
remove_producers_section,
..self
}
}
pub(crate) fn keep_lld_sections(self, keep_lld_sections: bool) -> Self {
Self {
keep_lld_exports: keep_lld_sections,
..self
}
}
/// Run the bindgen command with the current settings
pub async fn run(&self) -> Result<()> {
pub(crate) async fn run(&self) -> Result<()> {
let binary = self.get_binary_path().await?;
let mut args = Vec::new();
@@ -121,6 +130,10 @@ impl WasmBindgen {
args.push("--remove-producers-section");
}
if self.keep_lld_exports {
args.push("--keep-lld-exports");
}
// Out name
args.push("--out-name");
args.push(&self.out_name);
@@ -144,6 +157,8 @@ impl WasmBindgen {
.expect("input_path should be valid utf8");
args.push(input_path);
tracing::debug!("wasm-bindgen args: {:#?}", args);
// Run bindgen
Command::new(binary)
.args(args)