Skip to content

port(wasm): Coalesce identical host imports across objects - #2313

Merged
lapla-cogito merged 2 commits into
wild-linker:mainfrom
lapla-cogito:wasm_asyncify_imports
Aug 2, 2026
Merged

lapla-cogito merged 2 commits into
wild-linker:mainfrom
lapla-cogito:wasm_asyncify_imports

Conversation

@lapla-cogito

Copy link
Copy Markdown
Member

Unresolved function and global imports are now merged by module/name so each unique host import appears once in the output. Previously each object that referenced the same import got its own import row.

Part of #1431

@lapla-cogito

lapla-cogito commented Aug 2, 2026

Copy link
Copy Markdown
Member Author

Binaryen's Asyncify pass renames these asyncify.* imports to fixed internal names. This patch enables running CRuby linked with Wild on wasmtime. Asyncify is applied after the linking process is complete.

(▰╹◡╹)❯  wasmtime ruby.wild.wasm -e 'puts 3+5'
8

(▰╹◡╹)❯  cat test.rb
print "Enter your name: "
name = gets.chomp

puts "Hello, #{name}!"

(▰╹◡╹)❯  wasmtime --dir=/tmp ./ruby.wild.wasm /tmp/wild-ruby-out/test.rb
Enter your name: aaa
Hello, aaa!

(▰╹◡╹)❯  wasmtime ruby.wild.wasm --version
ruby 4.0.6 (2026-07-14 revision 03b6d3f889) +PRISM [wasm32-wasi]

@lapla-cogito

Copy link
Copy Markdown
Member Author

Additionally, I'd like to share some performance metrics regarding link time performance. Below are the comparison results with wasm-ld. Note that, since Wild has not yet implemented section GC and debug information handling, I passed --no-gc-sections (--gc-sections is default for wasm-ld unlike lld) and --strip-debug options to wasm-ld. These results are from measurements conducted with CRuby, but similar wall time trends are observed with other software under test (including SQLite, ripgrep, etc.).

Benchmark 1: wild
  Time (mean ± σ):      36.9 ms ±   2.6 ms    [User: 33.5 ms, System: 29.1 ms]
  Range (min … max):    32.0 ms …  43.6 ms    86 runs

Benchmark 2: wasm-ld --strip-debug --no-gc-sections
  Time (mean ± σ):     132.1 ms ±   4.2 ms    [User: 100.5 ms, System: 36.2 ms]
  Range (min … max):   122.3 ms … 140.9 ms    22 runs

Summary
  wild ran
    3.58 ± 0.28 times faster than wasm-ld --strip-debug --no-gc-sections

Comment thread libwild/src/wasm.rs
needs_stack_pointer |= absorption.needs_stack_pointer;
needs_tls_base |= absorption.needs_tls_base;

function_import_count = function_import_count

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.

Are unresolved_function_count and unresolved_global_count still needed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Didn't notice that, thanks.

@lapla-cogito
lapla-cogito merged commit cae246a into wild-linker:main Aug 2, 2026
24 checks passed
@lapla-cogito
lapla-cogito deleted the wasm_asyncify_imports branch August 2, 2026 11:59
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