Skip to content

Lift component byte lists in bulk from Wasm to Elixir - #1043

Merged
tessi merged 1 commit into
mainfrom
tessi/component-byte-list-lifting
Nov 23, 2026
Merged

tessi merged 1 commit into
mainfrom
tessi/component-byte-list-lifting

Conversation

@tessi

@tessi tessi commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Use Wasmtime's typed lifting for bare list<u8> and result<list<u8>, string> export results when the existing binary_byte_lists: true option is enabled. The returned binary owns the buffer copied before the guest post-return hook.
  • Lift a single byte-list callback argument as WasmList<u8> for common reply types and copy it directly into a BEAM binary. Existing list mode and unmatched signatures continue through dynamic conversion.
  • Keep Wasmtime's bounds checks and hostcall fuel budget. Typed lifting charges for bytes instead of one full dynamic value per byte.

Reproduction

Build the release NIF in both checkouts with WASMEX_BUILD=1 mix compile. The baseline is 9a571f4 (Wasmex main after PR #1042). Run the benchmark script and fixture from this PR's checkout for both builds. Set build to the absolute path of the checkout whose NIF you want to measure. Each command starts a fresh VM. On macOS, /usr/bin/time -l reports peak RSS.

build=/path/to/baseline-or-pr-checkout
for size in 1 8; do
  for operation in read call-consume read-result; do
    /usr/bin/time -l elixir -pa "$build/_build/dev/lib/*/ebin" bench/component_byte_list_lifting.exs "$operation" "$size"
  done
done

Medians of five fresh VMs per case on arm64 macOS, interleaving the previous and optimized release NIFs.

Shape Bytes Before After Peak RSS before → after
Bare export result 1 MiB 16.49 ms 0.196 ms 156.3 → 107.9 MiB
Callback argument 1 MiB 15.78 ms 0.260 ms 154.9 → 107.0 MiB
Existing typed export result 1 MiB 0.218 ms 0.205 ms 107.3 → 107.0 MiB
Bare export result 8 MiB Hostcall fuel trap 1.25 ms —
Callback argument 8 MiB Hostcall fuel trap 1.40 ms —
Existing typed export result 8 MiB 1.21 ms 1.25 ms 122.1 → 122.0 MiB

The benchmark checks payload length and the first and last bytes. The tests check full payload equality after guest cleanup and memory reuse, empty binaries, list mode, and bounds failure before callback invocation.

Verification

  • All 325 Elixir tests and doctests passed, including 12 focused byte-list tests.
  • Rust formatting and Clippy with CI flags passed.

@tessi
tessi marked this pull request as ready for review November 23, 2026 10:59
@tessi
tessi merged commit 0b6fbd4 into main Nov 23, 2026
11 checks passed
@tessi
tessi deleted the tessi/component-byte-list-lifting branch November 23, 2026 10: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.

1 participant