Skip to content

Lightweight allocation for temporary strings for use with WASI #1706

Open
@sunfishcode

Description

@sunfishcode

@dcodeIO Thinking about WebAssembly/WASI#402 (comment), I had an idea for how AssemblyScript might implement a call to a non-AS function which uses a different string representation, using temporary storage that doesn't need a GC or even a malloc heap and that may also avoid interfering with the GC's stack scanning.

The idea is, allocate the temporary string at the end of the shadow stack, but don't adjust the stack pointer. I assume the GC's stack scan stops when it reaches the stack pointer, so it wouldn't scan the temporary string data. Then after the call, there'd be no cleanup to do.

This technique has limitations. It assumes that the callee doesn't capture the pointer. And it assumes that the callee isn't using AS's shadow stack. So it isn't fully general-purpose, but in particular, it would be enough for calling WASI APIs, as no current WASI APIs capture pointers or use the caller's shadow stack.

And of course, this technique doesn't eliminate the conversion overhead. But on one hand, it'd only be temporary, as WebAssembly is already working on a better answer, and (b) it would avoid the code size of either a GC or a malloc.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions