module: cache compiled WebAssembly modules in the compile cache - #66191
guybedford wants to merge 3 commits into
Conversation
Original commit messages:
[wasm] Add WasmModuleObject::Compile overload with compile-time imports
Expose a public API to compile a Wasm module with compile-time imports
with a flag type for the builtins and a specifier name for imported
string constants.
The existing single-argument WasmModuleObject::Compile is refactored to
delegate to a shared helper, and a new overload accepts a CompileTimeImports
struct mirroring the `{ builtins, importedStringConstants }` constructor
options.
Bug: v8:14179
Change-Id: I9877e8ea4d620152e98954c948ff9dc5eeb6577c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7970437
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/main@{#108394}
[wasm] Generalize WasmModuleObject::Compile options with source URL
Replaces the recently-added WasmModuleObject::CompileTimeImports struct
with a CompileOptions struct carrying the compile-time import options
plus a new source_url option, threading through to the existing
source_url handling of SyncCompile for the script URL. This allows
embedders compiling modules synchronously from bytes to attach a
meaningful URL, as already possible for streaming compilation via
WasmStreaming::SetUrl, for use in stack traces and developer tooling.
Refactoring now to a single options struct mirrors the JS
`WebAssembly.Module(bytes, compileOptions)` API, while enabling
future compatibility.
Change-Id: I4052f4a97e072467c00082df388e2eb4cb504cf6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/8127096
Commit-Queue: Dan Carney <dcarney@chromium.org>
Reviewed-by: Dan Carney <dcarney@chromium.org>
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/main@{#109045}
The two commits are squashed since the second replaces the struct
introduced by the first. Adapted to MemorySpan (pre-std::span API) and
includes the optional source_url parameter of WasmEngine::SyncCompile
from c0f790f1379 that the second commit depends on.
Refs: v8/v8@5f8109f
Refs: v8/v8@7bd6db9
|
Review requested:
|
8f2675e to
f0680e2
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #66191 +/- ##
==========================================
- Coverage 90.37% 90.35% -0.02%
==========================================
Files 792 792
Lines 275446 275607 +161
Branches 52782 52815 +33
==========================================
+ Hits 248922 249023 +101
- Misses 16932 16986 +54
- Partials 9592 9598 +6
🚀 New features to boost your workflow:
|
This comment was marked as outdated.
This comment was marked as outdated.
Extends the module compile cache to WebAssembly modules loaded through the ES module integration. A new kWasm entry type is keyed on the module URL with the wire bytes as the hashed source, and stores the serialized CompiledWasmModule. On load, cached code is deserialized through v8::WasmModuleCompilation with the same compile options the translator uses (js-string builtins and imported string constants), falling back to compilation when V8 rejects it. As for JavaScript, the cache entry is generated right after compilation. V8 only serializes optimized tier code, so with the default lazy baseline compilation there is nothing to cache and no entry is written; a complete cache requires --no-liftoff --no-wasm-lazy-compilation, which is documented as the way to use the compile cache for WebAssembly.
f0680e2 to
728cf8c
Compare
|
This pull request has conflicts with its base branch, removing the |
|
This is very cool. |
|
To land this PR I'd like to first land the backports it relies on separately in #66190 for consistency when landing. @mcollina @jasnell @GeoffreyBooth if any of you could please approve that PR I will land that first to land this after. |
This extends the module compile cache (
module.enableCompileCache()/NODE_COMPILE_CACHE) to WebAssembly modules loaded through the ES module integration.kWasmcache entry type, keyed on the module URL with the wire bytes as the hashed source, stores V8'sCompiledWasmModuleserialization.v8::WasmModuleCompilationwith the same compile options the wasm translator uses (js-stringbuiltins and imported string constants), falling back tonew WebAssembly.Module()when V8 rejects it.CompileCacheHandler::GetOrInsertgains a raw-bytes overload used by the new entry type; the string overload delegates to it.As for JavaScript, the entry is captured right after compilation. V8 only serializes optimized-tier code, so with the default lazy baseline compilation there is nothing to cache and no entry is written. A complete cache requires
--no-liftoff --no-wasm-lazy-compilation, which compiles everything with the optimizing tier at module creation; since V8 flags are part of the cache key, all processes sharing the cache must use the same flags. This is documented in a new section ofmodule.md.The test covers both the eager-compilation case (entry written, then deserialized and accepted on the second run) and the default case (nothing serialized, no entry written).