Skip to content

Add WasmVm::serialize method to get serialized AOT compiled module#543

Open
leonm1 wants to merge 8 commits into
proxy-wasm:mainfrom
leonm1:wasmtime/deserialize
Open

Add WasmVm::serialize method to get serialized AOT compiled module#543
leonm1 wants to merge 8 commits into
proxy-wasm:mainfrom
leonm1:wasmtime/deserialize

Conversation

@leonm1
Copy link
Copy Markdown
Contributor

@leonm1 leonm1 commented May 22, 2026

This PR contains both serialization and deserialization since we had no testing surface for deserialization, as pointed out in https://github.com/proxy-wasm/proxy-wasm-cpp-host/pull/522/changes#r2921882220.

This implements serialization and deserialization for wasmtime and V8.

leonm1 and others added 2 commits May 22, 2026 14:58
Co-Authored-By: Rachel Green <rachgreen@google.com>
Signed-off-by: Matt Leon <mattleon@google.com>
Signed-off-by: Matt Leon <mattleon@google.com>
Copy link
Copy Markdown
Member

@PiotrSikora PiotrSikora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

Comment thread test/runtime_test.cc Outdated
TestWasm wasm(std::move(vm_));

std::chrono::time_point<std::chrono::system_clock> unprecompiled_load_start =
std::chrono::system_clock::now();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use steady_clock instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread test/runtime_test.cc
Comment on lines +225 to +226
EXPECT_LT((precompiled_load_end - precompiled_load_start) * 2,
(unprecompiled_load_end - unprecompiled_load_start));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect that 2x is not a large enough multiplier here in terms of expected improvements, but I don't have an actual data to back this up. Could you print the numbers from a local test runs?

Also, I think it would be good to have an upper limit in tests for precompiled option to catch serious degradations is load times.

See: TestVm::Init test for similar checks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also expect this to be closer to 4x improvement for V8 and 300x improvement for wasmtime; however, when running with --runs_per_test=1000, I found that 2x was enough to eliminate flakes, even in exceptional cases.

I'm not quite sure about how upper limits will translate to tests -- since the CI runs on shared github runners and, for s390x, on a virtualized environment on said shared runner.

If it provides any relief, Google has automated benchmark regression testing for the speed of loading modules into proxy-wasm-cpp-host on a specialized cluster for benchmarking. However, I don't see those benchmarks ever covering beyond V8 and wasmtime.

Comment thread src/wasmtime/wasmtime.cc Outdated
Comment on lines +451 to +452
// Wasmtime sticks
std::string_view Wasmtime::getPrecompiledSectionName() { return "precompiled_wasmtime_bytecode"; }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're providing a serialize() interface now, do we expect the precompilation to happen using this function in a proxy-wasm-cpp-host based tool, or using the engine's native tooling? (Ideal answer would be: former with a fallback to latter)

Notably, it looks that the native tools always use a single hardcoded section, which means that you can only include a single precompiled variant for each engine version in Wasm module, which makes this problematic across data plane version upgrades.

What we did for V8 is that V8::getPrecompiledSectionName() contains V8 version number and platform, and it can embed precompiled versions for multiple V8 engines and platforms in a single Wasm module.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect any user doing AOT compilation will embed proxy-wasm-cpp-host as the interface to interact with the wasm runtime, since our precompiled section name is effectively bespoke to our implementation. If someone wants to create a tool (such as Envoy's wee8_compile), that's fine by me, as long as they can conform to the section name.

I now understand the meaning behind the V8 precompilation section name! I have made the wasmtime precompiled section name match.

leonm1 added 5 commits May 27, 2026 17:19
Signed-off-by: Matt Leon <mattleon@google.com>
Signed-off-by: Matt Leon <mattleon@google.com>
Signed-off-by: Matt Leon <mattleon@google.com>
Signed-off-by: Matt Leon <mattleon@google.com>
@leonm1 leonm1 requested a review from PiotrSikora May 27, 2026 21:26
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