Skip to content

Support importing memory in the main module in wit-component - #2599

Merged
alexcrichton merged 1 commit into
bytecodealliance:mainfrom
alexcrichton:wit-component-imported-memory
Aug 13, 2026
Merged

Support importing memory in the main module in wit-component #2599
alexcrichton merged 1 commit into
bytecodealliance:mainfrom
alexcrichton:wit-component-imported-memory

Conversation

@alexcrichton

@alexcrichton alexcrichton commented Aug 12, 2026

Copy link
Copy Markdown
Member

This commit updates the wit-component componentization process to
support inputs where memory is imported as opposed to requiring memory
to be exported. When this is the case it avoids the need for many shims
in the "shim module" generated by wit-component which means that lowered
functions can be directly imported into the main module. This in turn
can lead to possible speedups since less indirection is necessary when
going out to the host.

This support is on-by-default and activated by detecting when memory is
imported into the module. Actually generating a module that imports
memory requires custom compiler flags, such as
-Clink-arg=--import-memory in Rust, and this behavior continues to be
off-by-default. In the meantime though my intention here is that this
can provide a low-overhead opportunity to manually generate components
with fewer shims when doing performance analysis.

Internal refactorings as part of this commit revealed a preexisting
issue with tests related to the link command where a library expected
to be able to import another library's WIT functions. This only worked
in some situations however, such as when strings weren't present, so the
tests were updated to have the right WIT available at all times.

Note: this is built on #2598

@alexcrichton
alexcrichton requested a review from a team as a code owner August 12, 2026 16:45
@alexcrichton
alexcrichton requested review from pchickey and removed request for a team August 12, 2026 16:45
@alexcrichton
alexcrichton force-pushed the wit-component-imported-memory branch from b45f1f0 to b34be4c Compare August 12, 2026 22:40
This commit updates the `wit-component` componentization process to
support inputs where memory is imported as opposed to requiring memory
to be exported. When this is the case it avoids the need for many shims
in the "shim module" generated by wit-component which means that lowered
functions can be directly imported into the main module. This in turn
can lead to possible speedups since less indirection is necessary when
going out to the host.

This support is on-by-default and activated by detecting when memory is
imported into the module. Actually generating a module that imports
memory requires custom compiler flags, such as
`-Clink-arg=--import-memory` in Rust, and this behavior continues to be
off-by-default. In the meantime though my intention here is that this
can provide a low-overhead opportunity to manually generate components
with fewer shims when doing performance analysis.

Internal refactorings as part of this commit revealed a preexisting
issue with tests related to the `link` command where a library expected
to be able to import another library's WIT functions. This only worked
in some situations however, such as when strings weren't present, so the
tests were updated to have the right WIT available at all times.
@alexcrichton
alexcrichton force-pushed the wit-component-imported-memory branch from b34be4c to 78f0bc5 Compare August 12, 2026 23:34
@alexcrichton
alexcrichton added this pull request to the merge queue Aug 13, 2026
Merged via the queue into bytecodealliance:main with commit 6c79879 Aug 13, 2026
37 checks passed
@alexcrichton
alexcrichton deleted the wit-component-imported-memory branch August 13, 2026 02:43
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