From b5ea2f7154472b1a1890538b0e0366d5060dd4ac Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Wed, 24 Jun 2026 17:40:59 -0500 Subject: [PATCH] Avoid `String` allocation --- rust/src/storage/store.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/rust/src/storage/store.rs b/rust/src/storage/store.rs index 4e8f63549c..36cb775c1b 100644 --- a/rust/src/storage/store.rs +++ b/rust/src/storage/store.rs @@ -13,6 +13,8 @@ * */ +use std::sync::Arc; + use futures::FutureExt; use serde::Serialize; @@ -61,10 +63,12 @@ impl Store { ) -> Result, anyhow::Error> { // It's not enabled globally, so check whether it's enabled per-user. // - // Owned copies so the callback can be `'static` (it may be moved to - // another thread and called multiple times under retries). - let user_id = user_id.to_owned(); - let feature = feature.to_string(); + // We need owned copies to move into the callback because it is `'static` (it + // may be moved to another thread). We use `Arc` rather than `String` so + // the per-call clone is just a cheap refcount bump rather than a fresh + // allocation. + let user_id: Arc = user_id.into(); + let feature: Arc = feature.to_string().into(); let is_feature_enabled_for_user = self .db_pool @@ -80,7 +84,7 @@ impl Store { "SELECT enabled \ FROM per_user_experimental_features \ WHERE user_id = ? AND feature = ?", - &[user_id.as_str(), feature.as_str()], + &[user_id.as_ref(), feature.as_ref()], ) .await?;