diff --git a/clients/rust/crates/mxgw-cli/src/main.rs b/clients/rust/crates/mxgw-cli/src/main.rs index 21e153b..edcca89 100644 --- a/clients/rust/crates/mxgw-cli/src/main.rs +++ b/clients/rust/crates/mxgw-cli/src/main.rs @@ -568,7 +568,7 @@ async fn run(cli: Cli) -> Result<(), Error> { json, } => { let session = session_for(connection, session_id).await?; - let results = session.read_bulk(server_handle, items, timeout_ms).await?; + let results = session.read_bulk(server_handle, &items, timeout_ms).await?; print_read_bulk_results("read-bulk", &results, json); } Command::WriteBulk { @@ -1038,7 +1038,7 @@ async fn run_bench_read_bulk( + std::time::Duration::from_secs(warmup_seconds); while std::time::Instant::now() < warmup_deadline { let _ = session - .read_bulk(server_handle, tags.clone(), timeout_ms) + .read_bulk(server_handle, &tags, timeout_ms) .await; } @@ -1052,7 +1052,7 @@ async fn run_bench_read_bulk( while std::time::Instant::now() < steady_deadline { let call_start = std::time::Instant::now(); - let outcome = session.read_bulk(server_handle, tags.clone(), timeout_ms).await; + let outcome = session.read_bulk(server_handle, &tags, timeout_ms).await; let elapsed_ms = call_start.elapsed().as_secs_f64() * 1000.0; latencies_ms.push(elapsed_ms); match outcome { diff --git a/clients/rust/src/session.rs b/clients/rust/src/session.rs index dddae21..e7e8930 100644 --- a/clients/rust/src/session.rs +++ b/clients/rust/src/session.rs @@ -477,16 +477,28 @@ impl Session { /// Per-tag failures appear as `BulkReadResult` entries with /// `was_successful = false`; the call never errors on per-tag failure. /// + /// `tag_addresses` is taken by borrowed slice so callers can re-issue the + /// same call repeatedly (typical for the bench loop and for any caller + /// polling a fixed snapshot set) without owning or cloning the list at the + /// call site. The method still has to materialise an owned `Vec` + /// internally because prost's `ReadBulkCommand` field requires it, so this + /// is a clarity-of-ownership change rather than an allocation-reducing + /// one: total heap traffic per call is unchanged. + /// /// # Errors /// /// Same conditions as [`Session::add_item_bulk`]. - pub async fn read_bulk( + pub async fn read_bulk>( &self, server_handle: i32, - tag_addresses: Vec, + tag_addresses: &[S], timeout_ms: u32, ) -> Result, Error> { ensure_bulk_size("tag_addresses", tag_addresses.len())?; + let tag_addresses: Vec = tag_addresses + .iter() + .map(|s| s.as_ref().to_owned()) + .collect(); let reply = self .invoke( MxCommandKind::ReadBulk, diff --git a/clients/rust/tests/client_behavior.rs b/clients/rust/tests/client_behavior.rs index c156b91..0a50969 100644 --- a/clients/rust/tests/client_behavior.rs +++ b/clients/rust/tests/client_behavior.rs @@ -154,7 +154,7 @@ async fn read_bulk_forwards_timeout_and_unpacks_cached_flag() { let session = client.session("session-fixture"); let results = session - .read_bulk(12, vec!["Area001.Pump001.Speed".to_owned()], 750) + .read_bulk(12, &["Area001.Pump001.Speed"], 750) .await .unwrap();