Stream: git-wasmtime

Topic: wasmtime / PR #5160 Implement AOT compilation for components


view this post on Zulip Wasmtime GitHub notifications bot (Oct 31 2022 at 14:38):

alexcrichton opened PR #5160 from refactor-compilation to main:

This series of commits is an implementation of AOT-compiling components, namely creating a byte-based artifact from a Component which can, at a later date, be fed back into Wasmtime. The intention of this support is to match the AOT support for Module, only with components instead.

At a high level the serialized artifact is the same for modules. The artifact is an ELF object file with standard .text/data sections as well as Wasmtime-specific sections with bincode-encoded data or otherwise binary-encoded data. The difference with normal modules is that a component squashes together all of its component modules, so the .text section contains all executable code for all modules contained within. Additionally the .rodata section contains the concatenation of all module data segments. This enables having one mmap for the entire component, including all modules contained within.

Lots of refactoring internally was necessary for this, namely around the end-part of compilation where an object is emitted and loaded into modules/components. The general shape of the Module compilation pipeline is now quite similar to the Component compilation pipeline. There were two caveats from this implementation, however:

Otherwise this is quite a large change so I've tried to break apart the commits as best I could. Each individual one should pass at least cargo test and represents an incremental step towards AOT-compiling components. If desired I can further split out commits into separate PRs as well.

As a final note, the route I've chosen here of squashing everything into one object file is notably distinct from previously intended strategies. For example with module linking modules were serialized by concatenating all of their objects together. This was not easily introspectable so my other idea was to use an ar archive for storing a concatenation of objects. In the end I settled on the "one object file" approach for a few reasons:

Of course the serialization format is just an internal detail of Wasmtime and if necessitated we can change it in the future as well.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 31 2022 at 14:38):

alexcrichton edited PR #5160 from refactor-compilation to main:

This series of commits is an implementation of AOT-compiling components, namely creating a byte-based artifact from a Component which can, at a later date, be fed back into Wasmtime. The intention of this support is to match the AOT support for Module, only with components instead.

At a high level the serialized artifact is the same for modules. The artifact is an ELF object file with standard .text/data sections as well as Wasmtime-specific sections with bincode-encoded data or otherwise binary-encoded data. The difference with normal modules is that a component squashes together all of its component modules, so the .text section contains all executable code for all modules contained within. Additionally the .rodata section contains the concatenation of all module data segments. This enables having one mmap for the entire component, including all modules contained within.

Lots of refactoring internally was necessary for this, namely around the end-part of compilation where an object is emitted and loaded into modules/components. The general shape of the Module compilation pipeline is now quite similar to the Component compilation pipeline. There were two caveats from this implementation, however:

Otherwise this is quite a large change so I've tried to break apart the commits as best I could. Each individual one should pass at least cargo test and represents an incremental step towards AOT-compiling components. If desired I can further split out commits into separate PRs as well.

As a final note, the route I've chosen here of squashing everything into one object file is notably distinct from previously intended strategies. For example with module linking modules were serialized by concatenating all of their objects together. This was not easily introspectable so my other idea was to use an ar archive for storing a concatenation of objects. In the end I settled on the "one object file" approach for a few reasons:

Of course the serialization format is just an internal detail of Wasmtime and if necessitated we can change it in the future as well.

Closes #5119

view this post on Zulip Wasmtime GitHub notifications bot (Oct 31 2022 at 15:15):

alexcrichton updated PR #5160 from refactor-compilation to main.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 31 2022 at 16:30):

alexcrichton updated PR #5160 from refactor-compilation to main.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 31 2022 at 16:57):

alexcrichton requested fitzgen for a review on PR #5160.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 01 2022 at 23:37):

fitzgen created PR review comment:

Not totally clear to me what the motivation for changing this was. Not saying its necessarily wrong or anything but I'm just curious.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 01 2022 at 23:37):

fitzgen created PR review comment:

    /// Appends a list of compiled functions to an in-memory object.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 01 2022 at 23:37):

fitzgen created PR review comment:

I guess its just because we are passing in .len()-ish things as input? And isn't necessarily tied to a single u32-sized index space anymore?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 01 2022 at 23:37):

fitzgen submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 01 2022 at 23:37):

fitzgen submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 02 2022 at 14:30):

alexcrichton created PR review comment:

Yeah there ended up being a lot of casts around this and having everything be usize removed all the casts, so I went ahead and updated this to usize.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 02 2022 at 14:30):

alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 02 2022 at 14:30):

alexcrichton updated PR #5160 from refactor-compilation to main.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 02 2022 at 14:30):

alexcrichton has enabled auto merge for PR #5160.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 02 2022 at 15:26):

alexcrichton merged PR #5160.


Last updated: Dec 23 2024 at 13:07 UTC