From ca98739daeea000f7cfd536c1fab65817980cce4 Mon Sep 17 00:00:00 2001 From: Zhiwei Liang Date: Sat, 18 Jul 2026 13:12:19 -0400 Subject: [PATCH 1/5] Cache the OTel logs enablement check so it is not re-read from the environment on every guest log write. Signed-off-by: Zhiwei Liang --- crates/telemetry/src/logs.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/telemetry/src/logs.rs b/crates/telemetry/src/logs.rs index 299c261f6b..db9947e287 100644 --- a/crates/telemetry/src/logs.rs +++ b/crates/telemetry/src/logs.rs @@ -26,7 +26,8 @@ pub fn handle_app_log(buf: &[u8], component_id: &str) { /// Forward the app log to OTel. fn app_log_to_otel(buf: &[u8], component_id: &str) { - if !otel_logs_enabled() { + static CELL: OnceLock = OnceLock::new(); + if !*CELL.get_or_init(otel_logs_enabled) { return; } From f8a4c2a399678f05967616cf94399feb129be4f6 Mon Sep 17 00:00:00 2001 From: Zhiwei Liang Date: Sat, 18 Jul 2026 13:12:19 -0400 Subject: [PATCH 2/5] Resolve the application name once at HTTP server construction instead of deserializing it from metadata on every request. Signed-off-by: Zhiwei Liang --- crates/trigger-http/src/server.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/trigger-http/src/server.rs b/crates/trigger-http/src/server.rs index ad4fd3e7f3..a6f75ebb63 100644 --- a/crates/trigger-http/src/server.rs +++ b/crates/trigger-http/src/server.rs @@ -98,6 +98,8 @@ pub struct HttpServer { router: Router, /// The app being triggered. trigger_app: Arc>, + /// The application name, resolved once for use as the `app_id` telemetry attribute. + app_id: String, // Component ID -> component trigger config component_trigger_configs: HashMap, // Component ID -> handler type @@ -158,6 +160,11 @@ impl HttpServer { let trigger_app = Arc::new(trigger_app); + let app_id = trigger_app + .app() + .get_metadata(APP_NAME_KEY)? + .unwrap_or_else(|| "".into()); + let component_handler_types = component_trigger_configs .iter() .filter_map(|(key, trigger_config)| match key { @@ -180,6 +187,7 @@ impl HttpServer { find_free_port, router, trigger_app, + app_id, http1_max_buf_size, component_trigger_configs, component_handler_types, @@ -350,18 +358,12 @@ impl HttpServer { client_addr: SocketAddr, ) -> anyhow::Result> { set_req_uri(&mut req, server_scheme)?; - let app_id = self - .trigger_app - .app() - .get_metadata(APP_NAME_KEY)? - .unwrap_or_else(|| "".into()); - let lookup_key = route_match.lookup_key(); spin_telemetry::metrics::monotonic_counter!( spin.request_count = 1, trigger_type = "http", - app_id = app_id, + app_id = self.app_id.as_str(), component_id = lookup_key.to_string() ); From 193b2ef48f6b2853a1f33f0da3be5d5fea00bd97 Mon Sep 17 00:00:00 2001 From: Zhiwei Liang Date: Sat, 18 Jul 2026 13:12:19 -0400 Subject: [PATCH 3/5] Check key existence in the SQLite key-value store with a lightweight SELECT ... LIMIT 1 instead of fetching the whole value. Signed-off-by: Zhiwei Liang --- crates/key-value-spin/src/store.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/key-value-spin/src/store.rs b/crates/key-value-spin/src/store.rs index ddba18bb39..fcf9c04014 100644 --- a/crates/key-value-spin/src/store.rs +++ b/crates/key-value-spin/src/store.rs @@ -159,7 +159,15 @@ impl Store for SqliteStore { } async fn exists(&self, key: &str) -> Result { - Ok(self.get(key, usize::MAX).await?.is_some()) + task::block_in_place(|| { + self.connection + .lock() + .unwrap() + .prepare_cached("SELECT 1 FROM spin_key_value WHERE store=$1 AND key=$2 LIMIT 1") + .map_err(log_error)? + .exists([&self.name, key]) + .map_err(log_error) + }) } async fn get_keys(&self, max_result_bytes: usize) -> Result, Error> { From 4815de8cf0f18ec7fecba3f8bcbe91e063505610 Mon Sep 17 00:00:00 2001 From: Zhiwei Liang Date: Sat, 18 Jul 2026 13:12:19 -0400 Subject: [PATCH 4/5] Move embedding vectors out of the response instead of cloning them when building the embeddings result. Signed-off-by: Zhiwei Liang --- crates/llm-remote-http/src/open_ai/schemas.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/crates/llm-remote-http/src/open_ai/schemas.rs b/crates/llm-remote-http/src/open_ai/schemas.rs index fb2c2dd2ff..8ce877d38e 100644 --- a/crates/llm-remote-http/src/open_ai/schemas.rs +++ b/crates/llm-remote-http/src/open_ai/schemas.rs @@ -63,15 +63,6 @@ pub struct CreateEmbeddingResponse { usage: EmbeddingUsage, } -impl CreateEmbeddingResponse { - fn embeddings(&self) -> Vec> { - self.data - .iter() - .map(|embedding| embedding.embedding.clone()) - .collect() - } -} - #[derive(Deserialize)] struct EmbeddingUsage { prompt_tokens: u32, @@ -95,7 +86,7 @@ impl From for wasi_llm::InferencingResult { impl From for wasi_llm::EmbeddingsResult { fn from(value: CreateEmbeddingResponse) -> Self { Self { - embeddings: value.embeddings(), + embeddings: value.data.into_iter().map(|e| e.embedding).collect(), usage: wasi_llm::EmbeddingsUsage { prompt_token_count: value.usage.prompt_tokens, }, From 07b919d82027e445c3b64c9aefa4752a9eb12033 Mon Sep 17 00:00:00 2001 From: Zhiwei Liang Date: Sat, 18 Jul 2026 13:12:20 -0400 Subject: [PATCH 5/5] Clone only the eos_token_id field instead of the entire llama Config when resolving the EOS token. Signed-off-by: Zhiwei Liang --- crates/llm-local/src/llama.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/llm-local/src/llama.rs b/crates/llm-local/src/llama.rs index e4a7193a41..d88a565a31 100644 --- a/crates/llm-local/src/llama.rs +++ b/crates/llm-local/src/llama.rs @@ -89,7 +89,7 @@ impl InferencingModel for LlamaModels { let mut cache = self.cache.clone(); // Try to retrieve the End of Sentence (EOS) token ID from config or // default to a single EOS token. EOS token is used to determine when to stop. - let eos_token_id = config.clone().eos_token_id.or_else(|| { + let eos_token_id = config.eos_token_id.clone().or_else(|| { tokenizer .token_to_id(EOS_TOKEN) .map(llama::LlamaEosToks::Single)