MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / make_module_host

Function make_module_host

crates/core/src/host/host_controller.rs:694–736  ·  view source on GitHub ↗
(
    runtimes: Arc<HostRuntimes>,
    replica_ctx: Arc<ReplicaContext>,
    scheduler: Scheduler,
    program: Program,
    energy_monitor: Arc<dyn EnergyMonitor>,
    unregister: impl Fn() + Send + 

Source from the content-addressed store, hash-verified

692/// The passed replica_ctx may not be configured for this version of the program's database schema yet.
693#[allow(clippy::too_many_arguments)]
694async fn make_module_host(
695 runtimes: Arc<HostRuntimes>,
696 replica_ctx: Arc<ReplicaContext>,
697 scheduler: Scheduler,
698 program: Program,
699 energy_monitor: Arc<dyn EnergyMonitor>,
700 unregister: impl Fn() + Send + Sync + 'static,
701 core: AllocatedJobCore,
702) -> anyhow::Result<(Program, ModuleHost)> {
703 // `make_actor` is blocking, as it needs to compile the wasm to native code,
704 // which may be computationally expensive - sometimes up to 1s for a large module.
705 // TODO: change back to using `spawn_rayon` here - asyncify runs on tokio blocking
706 // threads, but those aren't for computation. Also, wasmtime uses rayon
707 // to run compilation in parallel, so it'll need to run stuff in rayon anyway.
708 let database_identity = replica_ctx.database_identity;
709
710 let mcc = ModuleCreationContext {
711 replica_ctx,
712 scheduler,
713 program_hash: program.hash,
714 energy_monitor,
715 };
716
717 match HostType::from(program.kind) {
718 HostType::Wasm => {
719 asyncify(move || {
720 let start = Instant::now();
721 let module = runtimes.wasmtime.make_actor(mcc, &program.bytes, core)?;
722 trace!("wasmtime::make_actor blocked for {:?}", start.elapsed());
723 let module_host = ModuleHost::new(module, unregister, database_identity);
724 Ok((program, module_host))
725 })
726 .await
727 }
728 HostType::Js => {
729 let start = Instant::now();
730 let module = runtimes.v8.make_actor(mcc, &program.bytes, core).await?;
731 trace!("v8::make_actor blocked for {:?}", start.elapsed());
732 let module_host = ModuleHost::new(module, unregister, database_identity);
733 Ok((program, module_host))
734 }
735 }
736}
737
738async fn load_program(storage: &ProgramStorage, hash: Hash) -> anyhow::Result<Box<[u8]>> {
739 storage

Callers 2

launch_moduleMethod · 0.85
update_moduleMethod · 0.85

Calls 4

asyncifyFunction · 0.50
newFunction · 0.50
OkFunction · 0.50
make_actorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…