Skip to content

Commit 6e61261

Browse files
committed
delete_by_col_eq: optimize with smallvec for 1 row case
1 parent fa96dc2 commit 6e61261

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ rayon-core.workspace = true
6060
regex.workspace = true
6161
rustc-demangle.workspace = true
6262
rustc-hash.workspace = true
63+
smallvec.workspace = true
6364
scopeguard.workspace = true
6465
sendgrid.workspace = true
6566
serde.workspace = true

crates/core/src/host/instance_env.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use parking_lot::{Mutex, MutexGuard};
33
use spacetimedb_lib::{bsatn, ProductValue};
44
use std::ops::DerefMut;
55
use std::sync::Arc;
6+
use smallvec::SmallVec;
67

78
use crate::database_instance_context::DatabaseInstanceContext;
89
use crate::database_logger::{BacktraceProvider, LogLevel, Record};
@@ -162,7 +163,9 @@ impl InstanceEnv {
162163
let rows_to_delete = stdb
163164
.iter_by_col_eq(ctx, tx, table_id, col_id, eq_value)?
164165
.map(|x| RowId(*x.id()))
165-
.collect::<Vec<_>>();
166+
// `delete_by_field` only cares about 1 element,
167+
// so optimize for that.
168+
.collect::<SmallVec<[_; 1]>>();
166169

167170
// Delete them and count how many we deleted.
168171
Ok(stdb.delete(tx, table_id, rows_to_delete))

0 commit comments

Comments
 (0)