Skip to content

Commit 4a47530

Browse files
A warning will be shown if WASM components loading is slothful
Signed-off-by: Archisman Mridha <[email protected]>
1 parent 260970b commit 4a47530

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

crates/loader/src/local.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
33
use anyhow::{bail, ensure, Context, Result};
44
use futures::future::try_join_all;
55
use reqwest::Url;
6-
use spin_common::{paths::parent_dir, ui::quoted_path};
6+
use spin_common::{paths::parent_dir, sloth, ui::quoted_path};
77
use spin_locked_app::{
88
locked::{
99
self, ContentPath, ContentRef, LockedApp, LockedComponent, LockedComponentSource,
@@ -94,6 +94,8 @@ impl LocalLoader {
9494
})
9595
.collect::<Result<Vec<_>>>()?;
9696

97+
warn_if_component_load_slothful();
98+
9799
// Load all components concurrently
98100
let components = try_join_all(components.into_iter().map(|(id, c)| async move {
99101
self.load_component(&id, c)
@@ -516,3 +518,10 @@ fn file_url(path: impl AsRef<Path>) -> Result<String> {
516518
.with_context(|| format!("Couldn't resolve `{}`", path.display()))?;
517519
Ok(Url::from_file_path(abs_path).unwrap().to_string())
518520
}
521+
522+
const SLOTH_WARNING_DELAY_MILLIS: u64 = 1250;
523+
524+
fn warn_if_component_load_slothful() -> sloth::SlothGuard {
525+
let message = "WASM components loading is taking a few seconds...";
526+
sloth::warn_if_slothful(SLOTH_WARNING_DELAY_MILLIS, format!("{message}\n"))
527+
}

0 commit comments

Comments
 (0)