Skip to content

Add Engine::serialization_compatibility_hash #5802

@lann

Description

@lann

Feature

Add a new Engine::serialization_compatibility_hash method that returns a hash of the "compiler info" appended to precompiled Wasm binaries.

Benefit

This would allow precompiled Wasm from multiple configurations/versions of Wasmtime to be safely and efficiently stored together by, for example, keying its storage on (Hash(wasm), serialization_compat_hash). This may still be a little pessimistic compared with Wasmtime's actual compatibility checks but would be better than the conservative approach of only reusing precompiled binaries on a single host.

Implementation

Extract the following section from append_compiler_info and reuse it to compute a sha-256 digest of the "compiler info":

let mut data = Vec::new();
data.push(VERSION);
let version = match &engine.config().module_version {
ModuleVersionStrategy::WasmtimeVersion => env!("CARGO_PKG_VERSION"),
ModuleVersionStrategy::Custom(c) => c,
ModuleVersionStrategy::None => "",
};
// This precondition is checked in Config::module_version:
assert!(
version.len() < 256,
"package version must be less than 256 bytes"
);
data.push(version.len() as u8);
data.extend_from_slice(version.as_bytes());
bincode::serialize_into(&mut data, &Metadata::new(engine)).unwrap();

Alternatives

  • There is some overlap between the features this would be used for and Wasmtime's cache system, but the cache system is currently somewhat opaque and difficult to reason about wrt shared storage and the cache "worker"'s performance characteristics.
  • This could be done today without changes to Wasmtime by precompiling a dummy module and hashing its .wasmtime.engine section, which seems fragile.
  • Cranelift: split out a "settings" / flags infrastructure that works without the compiler proper #3900 suggests splitting out compatibility data into a separate structure, which appears to require a larger effort.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions