ref: Use pre-instantiated components#124
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
InstancePrefor faster execution - Implements a shared
Linkerto avoid repeated linker setup overhead - Replaces direct
Componentstorage withComponentInstancestruct 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 |
There was a problem hiding this comment.
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.
| Ok(Some((component, name))) | ||
| let instance_pre = linker | ||
| .instantiate_pre(&component) | ||
| .context("failed to instantiate component")?; |
There was a problem hiding this comment.
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))?; |
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>
c88a6c6 to
6bb144b
Compare
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.
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