feat: Implement fast startup + lazy and cached loading for WebAssembly components#235
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR implements fast startup and lazy loading for WebAssembly components by introducing an unloaded lifecycle manager, component metadata persistence, and background component loading with notification capabilities.
- Creates unloaded lifecycle manager for instant startup without component compilation
- Adds metadata caching system with validation stamps to avoid recompilation
- Implements background component loading with bounded parallelism and client notifications
Reviewed Changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main.rs | Adds peer storage, background loading coordination, and startup messaging updates |
| crates/wassette/src/lib.rs | Core implementation of unloaded manager, metadata persistence, and optimized loading |
| crates/wassette/Cargo.toml | Adds dependencies for CPU detection and SHA256 hashing |
| crates/component2json/src/lib.rs | Makes FunctionIdentifier serializable for metadata persistence |
| crates/component2json/Cargo.toml | Adds serde derive feature for serialization support |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
|
||
| // Try to load from precompiled cache first | ||
| if precompiled_path.exists() { | ||
| match unsafe { Component::deserialize_file(&self.engine, &precompiled_path) } { |
There was a problem hiding this comment.
Using unsafe for component deserialization introduces potential security risks. Ensure the precompiled files are from trusted sources and consider adding integrity verification before deserialization.
…oading Signed-off-by: Jiaxiao Zhou <duibao55328@gmail.com>
- Added ComponentMetadata structure with tool schemas, function identifiers,
normalized tool names, and validation stamps
- Implemented ValidationStamp with file size, modification time, and optional
SHA256 hash for detecting changes
- Added methods to save/load component metadata to {component_id}.metadata.json
files
- Implemented .cwasm precompiled component files using
engine.precompile_component()
- Added load_component_optimized() method that tries precompiled cache first,
falls back to compilation
- Components are now saved as precompiled artifacts for faster subsequent loads
- Used unsafe { Component::deserialize_file() } for loading precompiled
components
- Added (commented) Wasmtime's built-in compilation cache configuration
- This would provide additional caching across process restarts
- Implemented populate_registry_from_metadata() to quickly populate tool
registry from cached metadata without compilation
- Tools are registered immediately from metadata during startup phase
- Components are loaded in memory later during background phase
Signed-off-by: Jiaxiao Zhou <duibao55328@gmail.com>
Signed-off-by: Jiaxiao Zhou <duibao55328@gmail.com>
…on tests Signed-off-by: Jiaxiao Zhou <duibao55328@gmail.com>
Signed-off-by: Jiaxiao Zhou <duibao55328@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Close #204