-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Refactor WASM module instantiation #10480
Refactor WASM module instantiation #10480
Conversation
...look like our CI machines are failing due to the I do wonder though if it'd be possible to perhaps close the speed gap here and get the benefits of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brief glance
Oh what a shame. Well, yeah, maybe it is a sign. I was really under impression that COW should improve the situation. In fact, I actually did some experiments. What I did is that I created a file, set the right size and filled it with the initial data: i.e. data segments on top of zeroed data. Then for each instance I UPDATE: I did find the lead to those experiments #3011 (review) Also, I was surprised that wasmtime folks went with Ideally, wasmtime provides an API similar (or maybe equivalent) to I am not sure about big pages though. They can help in case we have TLB pressure, but do we? If we mix UFFD or COW with 2MiB pages we may risk handling page faults that 2 MiB even though only a part of it was actually used. |
Hmm... well, now that I've looked through Anyway, I did some experiments on [edit]After switching to preinitializing the module the invocation time with COW'd memory goes down to ~14us.[/edit] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for taking soo long 🙈
bot merge |
Bot will approve on the behalf of @bkchr, since they are a team lead, in an attempt to reach the minimum approval count |
* Refactor WASM module instantiation; enable WASM instance pooling * Disable the `uffd` feature on `wasmtime` * Restore the original behavior regarding the initial WASM memory size * Adjust error message * Remove unnecessary import in the benchmarks * Preinstantiate the WASM runtime for a slight speedup * Delete the asserts in `convert_memory_import_into_export` * `return` -> `break` * Revert WASM instance pooling for now * Have `convert_memory_import_into_export` return an error instead of panic * Update the warning when an import is missing * Rustfmt and clippy fix * Fix executor benchmarks' compilation without `wasmtime` being enabled * rustfmt again * Align to review comments * Extend tests so that both imported and exported memories are tested * Increase the number of heap pages for exported memories too * Fix `decommit_works` test
* Refactor WASM module instantiation; enable WASM instance pooling * Disable the `uffd` feature on `wasmtime` * Restore the original behavior regarding the initial WASM memory size * Adjust error message * Remove unnecessary import in the benchmarks * Preinstantiate the WASM runtime for a slight speedup * Delete the asserts in `convert_memory_import_into_export` * `return` -> `break` * Revert WASM instance pooling for now * Have `convert_memory_import_into_export` return an error instead of panic * Update the warning when an import is missing * Rustfmt and clippy fix * Fix executor benchmarks' compilation without `wasmtime` being enabled * rustfmt again * Align to review comments * Extend tests so that both imported and exported memories are tested * Increase the number of heap pages for exported memories too * Fix `decommit_works` test
* Refactor WASM module instantiation; enable WASM instance pooling * Disable the `uffd` feature on `wasmtime` * Restore the original behavior regarding the initial WASM memory size * Adjust error message * Remove unnecessary import in the benchmarks * Preinstantiate the WASM runtime for a slight speedup * Delete the asserts in `convert_memory_import_into_export` * `return` -> `break` * Revert WASM instance pooling for now * Have `convert_memory_import_into_export` return an error instead of panic * Update the warning when an import is missing * Rustfmt and clippy fix * Fix executor benchmarks' compilation without `wasmtime` being enabled * rustfmt again * Align to review comments * Extend tests so that both imported and exported memories are tested * Increase the number of heap pages for exported memories too * Fix `decommit_works` test
* Refactor WASM module instantiation; enable WASM instance pooling * Disable the `uffd` feature on `wasmtime` * Restore the original behavior regarding the initial WASM memory size * Adjust error message * Remove unnecessary import in the benchmarks * Preinstantiate the WASM runtime for a slight speedup * Delete the asserts in `convert_memory_import_into_export` * `return` -> `break` * Revert WASM instance pooling for now * Have `convert_memory_import_into_export` return an error instead of panic * Update the warning when an import is missing * Rustfmt and clippy fix * Fix executor benchmarks' compilation without `wasmtime` being enabled * rustfmt again * Align to review comments * Extend tests so that both imported and exported memories are tested * Increase the number of heap pages for exported memories too * Fix `decommit_works` test
* Refactor WASM module instantiation; enable WASM instance pooling * Disable the `uffd` feature on `wasmtime` * Restore the original behavior regarding the initial WASM memory size * Adjust error message * Remove unnecessary import in the benchmarks * Preinstantiate the WASM runtime for a slight speedup * Delete the asserts in `convert_memory_import_into_export` * `return` -> `break` * Revert WASM instance pooling for now * Have `convert_memory_import_into_export` return an error instead of panic * Update the warning when an import is missing * Rustfmt and clippy fix * Fix executor benchmarks' compilation without `wasmtime` being enabled * rustfmt again * Align to review comments * Extend tests so that both imported and exported memories are tested * Increase the number of heap pages for exported memories too * Fix `decommit_works` test
This PR refactors WASM module instantiation slightly to register the host callbacks through the
Linker
instead of doing it directly on theStore
, which is slightly cleaner and is necessary to switch to nativewasmtime
instance pooling without sacrificing (too much) performance.I've also enabled the instance pooling here and added the relevant benchmarks; with this PR merged the performance should be inline with the numbers I've posted here.I've enabled theuffd
feature onwasmtime
here, however according to @pepyakin this does impose a minimum requirement of Linux 4.11, so we should decide before merging whether we want to keep that enabled or not. (If we do keep it then this should be bumped fromB0-silent
toB5-clientnoteworthy
.)The switch to instance pooling was postponed. (See #10244 (comment) for details.)