Skip to content

ref: Use pre-instantiated components#124

Merged
Mossaka merged 1 commit into
microsoft:mainfrom
thomastaylor312:ref/preinstantiate
Aug 9, 2025
Merged

ref: Use pre-instantiated components#124
Mossaka merged 1 commit into
microsoft:mainfrom
thomastaylor312:ref/preinstantiate

Conversation

@thomastaylor312

Copy link
Copy Markdown
Collaborator

This updates our loading to preinstantiate components and to use a shared linker. This allows for fairly fast startup time, and the ability to handle higher load (as each request spawns its own component)

Closes #32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the component loading architecture to use pre-instantiated components with a shared linker, improving startup time and enabling better performance under high load by spawning individual component instances per request.

  • Introduces pre-instantiated components using InstancePre for faster execution
  • Implements a shared Linker to avoid repeated linker setup overhead
  • Replaces direct Component storage with ComponentInstance struct containing both component and pre-instantiated instance

let mut store = Store::new(self.engine.as_ref(), state);

let instance = linker.instantiate_async(&mut store, &component).await?;
let instance = component

Copilot AI Aug 9, 2025

Copy link

Choose a reason for hiding this comment

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

The error context "Failed to instantiate component" is generic and doesn't provide useful debugging information. Consider including the component_id or more specific error details to help with troubleshooting.

Copilot uses AI. Check for mistakes.
Ok(Some((component, name)))
let instance_pre = linker
.instantiate_pre(&component)
.context("failed to instantiate component")?;

Copilot AI Aug 9, 2025

Copy link

Choose a reason for hiding this comment

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

The error message "failed to instantiate component" lacks context about which component failed. Consider including the component name or path in the error message for better debugging.

Suggested change
.context("failed to instantiate component")?;
.with_context(|| format!("failed to instantiate component '{}'", name))?;

Copilot uses AI. Check for mistakes.

@Mossaka Mossaka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

Comment thread crates/wassette/src/lib.rs Outdated
This updates our loading to preinstantiate components and to use a shared
linker. This allows for fairly fast startup time, and the ability to
handle higher load (as each request spawns its own component)

Closes microsoft#32

Signed-off-by: Taylor Thomas <taylor@oftaylor.com>
@Mossaka Mossaka merged commit d7bcaa9 into microsoft:main Aug 9, 2025
4 checks passed
@thomastaylor312 thomastaylor312 deleted the ref/preinstantiate branch August 9, 2025 00:55
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.

cache the linker and preinstantiated component for reuse

3 participants