Skip to content

Commit

Permalink
Fix Build: Use default() to init custom hash based datastructures (#1871
Browse files Browse the repository at this point in the history
)

Signed-off-by: Shubham Mishra <shubham@clockworklabs.io>
Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
  • Loading branch information
Shubham8287 and Centril authored Oct 17, 2024
1 parent a4d097c commit 0a86b46
Show file tree
Hide file tree
Showing 13 changed files with 227 additions and 264 deletions.
420 changes: 190 additions & 230 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions crates/client-api/src/routes/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{log_and_500, ControlStateReadAccess};
use axum::extract::State;
use axum::response::IntoResponse;
use serde::{Deserialize, Serialize};
use spacetimedb_data_structures::map::{HashCollectionExt, HashMap};
use spacetimedb_data_structures::map::HashMap;

#[derive(Serialize, Deserialize)]
struct SDConfig {
Expand All @@ -17,7 +17,7 @@ pub async fn get_sd_config<S: ControlStateReadAccess>(
let nodes = ctx.get_nodes().map_err(log_and_500)?;

let mut targets = Vec::new();
let labels = HashMap::new();
let labels = HashMap::default();

for node in nodes {
if let Some(addr) = node.advertise_addr {
Expand Down
14 changes: 7 additions & 7 deletions crates/core/src/db/relational_operators.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use core::marker::PhantomData;
use spacetimedb_data_structures::map::{HashCollectionExt, HashSet};
use spacetimedb_data_structures::map::HashSet;
use spacetimedb_sats::ProductValue;

// NOTE
Expand Down Expand Up @@ -143,8 +143,8 @@ impl<'a, S: Relation, U: Relation> IntoIterator for Union<'a, S, U> {
type IntoIter = std::vec::IntoIter<ProductValue>;

fn into_iter(self) -> Self::IntoIter {
let mut set_s: HashSet<ProductValue> = HashSet::new();
let mut set_u: HashSet<ProductValue> = HashSet::new();
let mut set_s: HashSet<ProductValue> = HashSet::default();
let mut set_u: HashSet<ProductValue> = HashSet::default();
for next in self.s {
set_s.insert(next);
}
Expand All @@ -166,8 +166,8 @@ impl<'a, S: Relation, U: Relation> IntoIterator for Intersection<'a, S, U> {
type IntoIter = std::vec::IntoIter<ProductValue>;

fn into_iter(self) -> Self::IntoIter {
let mut set_s: HashSet<ProductValue> = HashSet::new();
let mut set_u: HashSet<ProductValue> = HashSet::new();
let mut set_s: HashSet<ProductValue> = HashSet::default();
let mut set_u: HashSet<ProductValue> = HashSet::default();
for next in self.s {
set_s.insert(next);
}
Expand All @@ -192,8 +192,8 @@ impl<'a, S: Relation, U: Relation> IntoIterator for Difference<'a, S, U> {
type IntoIter = std::vec::IntoIter<ProductValue>;

fn into_iter(self) -> Self::IntoIter {
let mut set_s: HashSet<ProductValue> = HashSet::new();
let mut set_u: HashSet<ProductValue> = HashSet::new();
let mut set_s: HashSet<ProductValue> = HashSet::default();
let mut set_u: HashSet<ProductValue> = HashSet::default();
for next in self.s {
set_s.insert(next);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl SubscriptionManager {
// Collect the delta tables for each query.
// For selects this is just a single table.
// For joins it's two tables.
let mut units: HashMap<_, ArrayVec<_, 2>> = HashMap::new();
let mut units: HashMap<_, ArrayVec<_, 2>> = HashMap::default();
for table @ DatabaseTableUpdate { table_id, .. } in tables {
if let Some(hashes) = self.tables.get(table_id) {
for hash in hashes {
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/subscription/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use anyhow::Context;
use itertools::Either;
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use spacetimedb_client_api_messages::websocket::{Compression, WebsocketFormat};
use spacetimedb_data_structures::map::{HashCollectionExt, HashSet};
use spacetimedb_data_structures::map::HashSet;
use spacetimedb_lib::db::auth::{StAccess, StTableType};
use spacetimedb_lib::db::error::AuthError;
use spacetimedb_lib::identity::AuthCtx;
Expand Down Expand Up @@ -403,7 +403,7 @@ impl IncrementalJoin {
if produce_if {
producer().collect()
} else {
HashSet::new()
HashSet::default()
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/lib/src/relation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::db::error::{RelationError, TypeError};
use core::fmt;
use core::hash::Hash;
use derive_more::From;
use spacetimedb_data_structures::map::{HashCollectionExt, HashSet};
use spacetimedb_data_structures::map::HashSet;
use spacetimedb_primitives::{ColId, ColList, ColSet, Constraints, TableId};
use spacetimedb_sats::algebraic_value::AlgebraicValue;
use spacetimedb_sats::satn::Satn;
Expand Down Expand Up @@ -237,7 +237,7 @@ pub fn combine_constraints(
*slot = slot.push(constraint);
}

let mut uniques: HashSet<ColSet> = HashSet::new();
let mut uniques: HashSet<ColSet> = HashSet::default();
for (col_list, constraint) in &constraints {
if constraint.has_unique() {
uniques.insert(col_list.into());
Expand Down
14 changes: 8 additions & 6 deletions crates/schema/src/type_for_generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use petgraph::{
use smallvec::SmallVec;
use spacetimedb_data_structures::{
error_stream::{CollectAllErrors, CombineErrors, ErrorStream},
map::{HashCollectionExt, HashMap, HashSet},
map::{HashMap, HashSet},
};
use spacetimedb_lib::{AlgebraicType, ProductTypeElement};
use spacetimedb_sats::{typespace::TypeRefError, AlgebraicTypeRef, ArrayType, SumTypeVariant, Typespace};
Expand Down Expand Up @@ -110,11 +110,13 @@ impl TypespaceForGenerate {
) -> TypespaceForGenerateBuilder<'_> {
TypespaceForGenerateBuilder {
typespace,
result: TypespaceForGenerate { defs: HashMap::new() },
result: TypespaceForGenerate {
defs: HashMap::default(),
},
is_def: is_def.into_iter().collect(),
uses: HashSet::new(),
known_uses: HashMap::new(),
currently_touching: HashSet::new(),
uses: HashSet::default(),
known_uses: HashMap::default(),
currently_touching: HashSet::default(),
}
}

Expand Down Expand Up @@ -157,7 +159,7 @@ pub enum AlgebraicTypeDef {

thread_local! {
/// Used to efficiently extract refs from a def.
static EXTRACT_REFS_BUF: RefCell<HashSet<AlgebraicTypeRef>> = RefCell::new(HashSet::new());
static EXTRACT_REFS_BUF: RefCell<HashSet<AlgebraicTypeRef>> = RefCell::new(HashSet::default());
}

impl AlgebraicTypeDef {
Expand Down
5 changes: 3 additions & 2 deletions crates/sdk/src/spacetime_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
};
use anyhow::Context;
use bytes::Bytes;
use spacetimedb_data_structures::map::{HashCollectionExt, HashMap};
use spacetimedb_data_structures::map::{DefaultHashBuilder, HashCollectionExt, HashMap};
use spacetimedb_lib::{bsatn, de::DeserializeOwned};
use std::{any::Any, fmt::Debug, hash::Hash};

Expand Down Expand Up @@ -196,7 +196,8 @@ impl<Row: DeserializeOwned + Debug> TableUpdate<Row> {
};

// Pre-allocate plenty of space to minimize hash collisions.
let mut diff: HashMap<Pk, DiffEntry<Row>> = HashMap::with_capacity(raw_updates.num_rows() * 2);
let mut diff: HashMap<Pk, DiffEntry<Row>> =
HashMap::<_, _, DefaultHashBuilder>::with_capacity(raw_updates.num_rows() * 2);

// Traverse the `table_update` to construct a diff, merging duplicated `Insert`
// and `Delete` into `Update`.
Expand Down
4 changes: 2 additions & 2 deletions crates/table/src/btree_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ mod test {
use core::ops::Bound::*;
use proptest::prelude::*;
use proptest::{collection::vec, test_runner::TestCaseResult};
use spacetimedb_data_structures::map::{HashCollectionExt, HashMap};
use spacetimedb_data_structures::map::HashMap;
use spacetimedb_primitives::ColId;
use spacetimedb_sats::{
product,
Expand Down Expand Up @@ -589,7 +589,7 @@ mod test {
let next = needle + 1;
let range = prev..=next;

let mut val_to_ptr = HashMap::new();
let mut val_to_ptr = HashMap::default();

// Insert `prev`, `needle`, and `next`.
for x in range.clone() {
Expand Down
4 changes: 2 additions & 2 deletions crates/table/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use core::hash::{Hash, Hasher};
use core::ops::RangeBounds;
use core::{fmt, ptr};
use derive_more::{Add, AddAssign, From, Sub};
use spacetimedb_data_structures::map::{HashCollectionExt, HashMap};
use spacetimedb_data_structures::map::{DefaultHashBuilder, HashCollectionExt, HashMap};
use spacetimedb_lib::{bsatn::DecodeError, de::DeserializeOwned};
use spacetimedb_primitives::{ColId, ColList, IndexId};
use spacetimedb_sats::{
Expand Down Expand Up @@ -1102,7 +1102,7 @@ impl Table {
pages: Pages::default(),
},
schema,
indexes: HashMap::with_capacity(indexes_capacity),
indexes: HashMap::<_, _, DefaultHashBuilder>::with_capacity(indexes_capacity),
pointer_map: PointerMap::default(),
squashed_offset,
row_count: 0,
Expand Down
4 changes: 2 additions & 2 deletions crates/testing/src/sdk.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use duct::cmd;
use lazy_static::lazy_static;
use rand::distributions::{Alphanumeric, DistString};
use spacetimedb_data_structures::map::{HashCollectionExt, HashMap};
use spacetimedb_data_structures::map::HashMap;
use std::fs::create_dir_all;
use std::sync::Mutex;
use std::thread::JoinHandle;
Expand Down Expand Up @@ -119,7 +119,7 @@ macro_rules! memoized {
MEMOIZED
.lock()
.unwrap()
.get_or_insert_with(HashMap::new)
.get_or_insert_with(HashMap::default)
.entry($key)
.or_insert_with_key(|$key| -> $value_ty { $body })
.clone()
Expand Down
6 changes: 3 additions & 3 deletions crates/vm/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use core::slice::from_ref;
use derive_more::From;
use itertools::Itertools;
use smallvec::SmallVec;
use spacetimedb_data_structures::map::{HashCollectionExt, HashSet, IntMap};
use spacetimedb_data_structures::map::{HashSet, IntMap};
use spacetimedb_lib::db::auth::{StAccess, StTableType};
use spacetimedb_lib::db::error::{AuthError, RelationError};
use spacetimedb_lib::relation::{ColExpr, DbTable, FieldName, Header};
Expand Down Expand Up @@ -1058,7 +1058,7 @@ fn select_best_index<'a>(
.collect::<SmallVec<[_; 1]>>();
indices.sort_unstable_by_key(|cl| Reverse(cl.len()));

let mut found: IndexColumnOpSink = IndexColumnOpSink::new();
let mut found: IndexColumnOpSink = IndexColumnOpSink::default();

// Collect fields into a multi-map `(col_id, cmp) -> [col value]`.
// This gives us `log(N)` seek + deletion.
Expand Down Expand Up @@ -1868,7 +1868,7 @@ impl QueryExpr {
fn optimize_select(mut q: QueryExpr, op: ColumnOp, tables: &[SourceExpr]) -> QueryExpr {
// Go through each table schema referenced in the query.
// Find the first sargable condition and short-circuit.
let mut fields_found = HashSet::new();
let mut fields_found = HashSet::default();
for schema in tables {
for op in select_best_index(&mut fields_found, schema.head(), &op) {
if let IndexColumnOp::Scan(op) = &op {
Expand Down
6 changes: 3 additions & 3 deletions crates/vm/src/rel_ops.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::iter;

use crate::relation::RelValue;
use spacetimedb_data_structures::map::{HashCollectionExt, HashMap};
use spacetimedb_data_structures::map::HashMap;
use spacetimedb_lib::relation::ColExpr;
use spacetimedb_sats::AlgebraicValue;

Expand Down Expand Up @@ -181,7 +181,7 @@ pub struct JoinInner<'a, Lhs, Rhs, KeyLhs, KeyRhs, Pred, Proj> {
impl<'a, Lhs, Rhs, KeyLhs, KeyRhs, Pred, Proj> JoinInner<'a, Lhs, Rhs, KeyLhs, KeyRhs, Pred, Proj> {
pub fn new(lhs: Lhs, rhs: Rhs, key_lhs: KeyLhs, key_rhs: KeyRhs, predicate: Pred, projection: Proj) -> Self {
Self {
map: HashMap::new(),
map: HashMap::default(),
lhs,
rhs,
key_lhs,
Expand All @@ -206,7 +206,7 @@ where
fn next(&mut self) -> Option<RelValue<'a>> {
// Consume `Rhs`, building a map `KeyRhs => Rhs`.
if !self.filled_rhs {
self.map = HashMap::new();
self.map = HashMap::default();
while let Some(row_rhs) = self.rhs.next() {
let key_rhs = (self.key_rhs)(&row_rhs);
self.map.entry(key_rhs).or_default().push(row_rhs);
Expand Down

2 comments on commit 0a86b46

@github-actions
Copy link

@github-actions github-actions bot commented on 0a86b46 Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Criterion benchmark results

Criterion benchmark report

YOU SHOULD PROBABLY IGNORE THESE RESULTS.

Criterion is a wall time based benchmarking system that is extremely noisy when run on CI. We collect these results for longitudinal analysis, but they are not reliable for comparing individual PRs.

Go look at the callgrind report instead.

empty

db on disk new latency old latency new throughput old throughput
sqlite 💿 420.6±4.59ns 413.6±1.87ns - -
sqlite 🧠 410.6±2.05ns 405.7±2.30ns - -
stdb_raw 💿 625.8±3.62ns 627.2±1.12ns - -
stdb_raw 🧠 626.2±3.26ns 627.2±1.00ns - -

insert_1

db on disk schema indices preload new latency old latency new throughput old throughput

insert_bulk

db on disk schema indices preload count new latency old latency new throughput old throughput
sqlite 💿 u32_u64_str btree_each_column 2048 256 583.9±0.97µs 585.9±0.72µs 1712 tx/sec 1706 tx/sec
sqlite 💿 u32_u64_str unique_0 2048 256 150.2±0.52µs 149.4±0.66µs 6.5 Ktx/sec 6.5 Ktx/sec
sqlite 💿 u32_u64_u64 btree_each_column 2048 256 467.0±0.71µs 467.3±0.54µs 2.1 Ktx/sec 2.1 Ktx/sec
sqlite 💿 u32_u64_u64 unique_0 2048 256 137.2±0.28µs 139.4±0.44µs 7.1 Ktx/sec 7.0 Ktx/sec
sqlite 🧠 u32_u64_str btree_each_column 2048 256 447.7±0.73µs 447.8±1.20µs 2.2 Ktx/sec 2.2 Ktx/sec
sqlite 🧠 u32_u64_str unique_0 2048 256 123.9±0.71µs 122.2±0.66µs 7.9 Ktx/sec 8.0 Ktx/sec
sqlite 🧠 u32_u64_u64 btree_each_column 2048 256 367.5±0.59µs 364.8±0.74µs 2.7 Ktx/sec 2.7 Ktx/sec
sqlite 🧠 u32_u64_u64 unique_0 2048 256 108.9±0.92µs 105.5±1.03µs 9.0 Ktx/sec 9.3 Ktx/sec
stdb_raw 💿 u32_u64_str btree_each_column 2048 256 627.6±24.88µs 627.7±16.66µs 1593 tx/sec 1593 tx/sec
stdb_raw 💿 u32_u64_str unique_0 2048 256 420.1±19.50µs 499.5±23.29µs 2.3 Ktx/sec 2002 tx/sec
stdb_raw 💿 u32_u64_u64 btree_each_column 2048 256 393.0±7.65µs 376.7±11.30µs 2.5 Ktx/sec 2.6 Ktx/sec
stdb_raw 💿 u32_u64_u64 unique_0 2048 256 362.8±6.32µs 364.7±7.36µs 2.7 Ktx/sec 2.7 Ktx/sec
stdb_raw 🧠 u32_u64_str btree_each_column 2048 256 316.8±0.45µs 306.0±0.18µs 3.1 Ktx/sec 3.2 Ktx/sec
stdb_raw 🧠 u32_u64_str unique_0 2048 256 244.7±0.67µs 239.4±0.18µs 4.0 Ktx/sec 4.1 Ktx/sec
stdb_raw 🧠 u32_u64_u64 btree_each_column 2048 256 260.0±0.10µs 248.5±0.16µs 3.8 Ktx/sec 3.9 Ktx/sec
stdb_raw 🧠 u32_u64_u64 unique_0 2048 256 228.9±0.24µs 221.6±0.42µs 4.3 Ktx/sec 4.4 Ktx/sec

iterate

db on disk schema indices new latency old latency new throughput old throughput
sqlite 💿 u32_u64_str unique_0 23.9±0.24µs 23.2±0.14µs 40.9 Ktx/sec 42.1 Ktx/sec
sqlite 💿 u32_u64_u64 unique_0 22.3±0.19µs 21.9±0.08µs 43.8 Ktx/sec 44.5 Ktx/sec
sqlite 🧠 u32_u64_str unique_0 20.7±0.22µs 20.5±0.14µs 47.2 Ktx/sec 47.5 Ktx/sec
sqlite 🧠 u32_u64_u64 unique_0 20.0±0.17µs 19.4±0.08µs 48.9 Ktx/sec 50.4 Ktx/sec
stdb_raw 💿 u32_u64_str unique_0 3.8±0.00µs 4.7±0.00µs 256.6 Ktx/sec 206.3 Ktx/sec
stdb_raw 💿 u32_u64_u64 unique_0 3.7±0.00µs 4.6±0.00µs 263.5 Ktx/sec 211.2 Ktx/sec
stdb_raw 🧠 u32_u64_str unique_0 3.8±0.00µs 4.7±0.00µs 257.3 Ktx/sec 206.4 Ktx/sec
stdb_raw 🧠 u32_u64_u64 unique_0 3.7±0.00µs 4.6±0.00µs 263.4 Ktx/sec 211.2 Ktx/sec

find_unique

db on disk key type preload new latency old latency new throughput old throughput

filter

db on disk key type index strategy load count new latency old latency new throughput old throughput
sqlite 💿 string index 2048 256 67.7±0.22µs 68.9±0.32µs 14.4 Ktx/sec 14.2 Ktx/sec
sqlite 💿 u64 index 2048 256 66.1±0.14µs 65.4±0.22µs 14.8 Ktx/sec 14.9 Ktx/sec
sqlite 🧠 string index 2048 256 65.1±0.11µs 65.1±0.09µs 15.0 Ktx/sec 15.0 Ktx/sec
sqlite 🧠 u64 index 2048 256 60.8±0.14µs 59.5±0.17µs 16.1 Ktx/sec 16.4 Ktx/sec
stdb_raw 💿 string index 2048 256 4.8±0.00µs 4.8±0.00µs 203.7 Ktx/sec 201.8 Ktx/sec
stdb_raw 💿 u64 index 2048 256 4.9±0.00µs 4.8±0.00µs 201.1 Ktx/sec 201.5 Ktx/sec
stdb_raw 🧠 string index 2048 256 4.8±0.00µs 4.8±0.00µs 203.6 Ktx/sec 202.0 Ktx/sec
stdb_raw 🧠 u64 index 2048 256 4.9±0.00µs 4.8±0.00µs 201.3 Ktx/sec 201.5 Ktx/sec

serialize

schema format count new latency old latency new throughput old throughput
u32_u64_str bflatn_to_bsatn_fast_path 100 3.3±0.01µs 3.3±0.01µs 29.2 Mtx/sec 29.2 Mtx/sec
u32_u64_str bflatn_to_bsatn_slow_path 100 3.4±0.00µs 3.4±0.00µs 28.2 Mtx/sec 28.1 Mtx/sec
u32_u64_str bsatn 100 2.3±0.02µs 2.2±0.00µs 41.3 Mtx/sec 42.8 Mtx/sec
u32_u64_str bsatn 100 40.5±0.04ns 40.5±0.06ns 2.3 Gtx/sec 2.3 Gtx/sec
u32_u64_str json 100 5.5±0.03µs 5.1±0.03µs 17.3 Mtx/sec 18.7 Mtx/sec
u32_u64_str json 100 7.7±0.01µs 7.4±0.11µs 12.4 Mtx/sec 12.9 Mtx/sec
u32_u64_str product_value 100 1022.3±0.52ns 1015.7±10.39ns 93.3 Mtx/sec 93.9 Mtx/sec
u32_u64_u64 bflatn_to_bsatn_fast_path 100 1127.7±1.29ns 1169.8±1.34ns 84.6 Mtx/sec 81.5 Mtx/sec
u32_u64_u64 bflatn_to_bsatn_slow_path 100 2.8±0.01µs 2.8±0.01µs 34.2 Mtx/sec 34.5 Mtx/sec
u32_u64_u64 bsatn 100 1597.5±24.73ns 1539.1±11.60ns 59.7 Mtx/sec 62.0 Mtx/sec
u32_u64_u64 bsatn 100 39.4±0.04ns 39.4±0.06ns 2.4 Gtx/sec 2.4 Gtx/sec
u32_u64_u64 json 100 3.4±0.04µs 3.4±0.03µs 28.1 Mtx/sec 27.8 Mtx/sec
u32_u64_u64 json 100 4.9±0.02µs 5.0±0.04µs 19.4 Mtx/sec 19.2 Mtx/sec
u32_u64_u64 product_value 100 1013.9±1.50ns 1013.5±1.42ns 94.1 Mtx/sec 94.1 Mtx/sec
u64_u64_u32 bflatn_to_bsatn_fast_path 100 926.0±10.57ns 965.7±1.84ns 103.0 Mtx/sec 98.8 Mtx/sec
u64_u64_u32 bflatn_to_bsatn_slow_path 100 2.8±0.00µs 2.8±0.01µs 34.2 Mtx/sec 34.4 Mtx/sec
u64_u64_u32 bsatn 100 1588.9±41.22ns 1539.3±10.87ns 60.0 Mtx/sec 62.0 Mtx/sec
u64_u64_u32 bsatn 100 942.8±1.38ns 946.4±3.56ns 101.2 Mtx/sec 100.8 Mtx/sec
u64_u64_u32 json 100 3.9±0.01µs 3.4±0.02µs 24.8 Mtx/sec 28.0 Mtx/sec
u64_u64_u32 json 100 4.8±0.04µs 5.1±0.05µs 19.7 Mtx/sec 18.8 Mtx/sec
u64_u64_u32 product_value 100 1015.8±0.87ns 1015.1±1.19ns 93.9 Mtx/sec 94.0 Mtx/sec

stdb_module_large_arguments

arg size new latency old latency new throughput old throughput
64KiB 108.3±7.83µs 112.4±7.95µs - -

stdb_module_print_bulk

line count new latency old latency new throughput old throughput
1 45.2±7.53µs 56.5±6.72µs - -
100 591.0±3.94µs 592.8±8.58µs - -
1000 3.7±0.57ms 5.0±0.76ms - -

remaining

name new latency old latency new throughput old throughput
special/db_game/circles/load=10 285.4±4.11µs 286.0±2.35µs - -
special/db_game/circles/load=100 288.0±2.17µs 285.3±3.48µs - -
special/db_game/ia_loop/load=10 0.0±0.00ns 0.0±0.00ns - -
special/db_game/ia_loop/load=100 0.0±0.00ns 0.0±0.00ns - -
sqlite/💿/update_bulk/u32_u64_str/unique_0/load=2048/count=256 57.0±0.09µs 53.8±0.12µs 17.1 Ktx/sec 18.2 Ktx/sec
sqlite/💿/update_bulk/u32_u64_u64/unique_0/load=2048/count=256 47.5±0.26µs 46.4±0.31µs 20.6 Ktx/sec 21.0 Ktx/sec
sqlite/🧠/update_bulk/u32_u64_str/unique_0/load=2048/count=256 41.7±0.23µs 38.8±0.09µs 23.4 Ktx/sec 25.2 Ktx/sec
sqlite/🧠/update_bulk/u32_u64_u64/unique_0/load=2048/count=256 36.8±0.16µs 35.5±0.09µs 26.5 Ktx/sec 27.5 Ktx/sec
stdb_module/💿/update_bulk/u32_u64_str/unique_0/load=2048/count=256 1305.0±14.94µs 1266.4±5.92µs 766 tx/sec 789 tx/sec
stdb_module/💿/update_bulk/u32_u64_u64/unique_0/load=2048/count=256 1017.6±13.12µs 997.4±15.97µs 982 tx/sec 1002 tx/sec
stdb_raw/💿/update_bulk/u32_u64_str/unique_0/load=2048/count=256 663.9±23.34µs 651.6±20.09µs 1506 tx/sec 1534 tx/sec
stdb_raw/💿/update_bulk/u32_u64_u64/unique_0/load=2048/count=256 495.3±6.78µs 487.3±8.05µs 2019 tx/sec 2.0 Ktx/sec
stdb_raw/🧠/update_bulk/u32_u64_str/unique_0/load=2048/count=256 372.5±0.20µs 372.5±0.82µs 2.6 Ktx/sec 2.6 Ktx/sec
stdb_raw/🧠/update_bulk/u32_u64_u64/unique_0/load=2048/count=256 342.3±0.15µs 338.1±0.15µs 2.9 Ktx/sec 2.9 Ktx/sec

@github-actions
Copy link

@github-actions github-actions bot commented on 0a86b46 Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Callgrind benchmark results

Callgrind Benchmark Report

These benchmarks were run using callgrind,
an instruction-level profiler. They allow comparisons between sqlite (sqlite), SpacetimeDB running through a module (stdb_module), and the underlying SpacetimeDB data storage engine (stdb_raw). Callgrind emulates a CPU to collect the below estimates.

Measurement changes larger than five percent are in bold.

In-memory benchmarks

callgrind: empty transaction

db total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw 5385 5386 -0.02% 5463 5432 0.57%
sqlite 5575 5575 0.00% 6019 6013 0.10%

callgrind: filter

db schema indices count preload _column data_type total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str no_index 64 128 1 u64 75578 75579 -0.00% 76078 75997 0.11%
stdb_raw u32_u64_str no_index 64 128 2 string 118075 118076 -0.00% 118633 118624 0.01%
stdb_raw u32_u64_str btree_each_column 64 128 2 string 24070 24095 -0.10% 24572 24515 0.23%
stdb_raw u32_u64_str btree_each_column 64 128 1 u64 23037 23063 -0.11% 23457 23429 0.12%
sqlite u32_u64_str no_index 64 128 2 string 144663 144663 0.00% 146263 146213 0.03%
sqlite u32_u64_str no_index 64 128 1 u64 124013 124013 0.00% 125355 125233 0.10%
sqlite u32_u64_str btree_each_column 64 128 1 u64 131340 131340 0.00% 132910 132752 0.12%
sqlite u32_u64_str btree_each_column 64 128 2 string 134462 134462 0.00% 136182 136140 0.03%

callgrind: insert bulk

db schema indices count preload total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str unique_0 64 128 900431 900922 -0.05% 926355 950658 -2.56%
stdb_raw u32_u64_str btree_each_column 64 128 1048656 1048423 0.02% 1108490 1108717 -0.02%
sqlite u32_u64_str unique_0 64 128 398284 398284 0.00% 420380 416866 0.84%
sqlite u32_u64_str btree_each_column 64 128 983611 983611 0.00% 1024907 1027953 -0.30%

callgrind: iterate

db schema indices count total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str unique_0 1024 152705 152706 -0.00% 152823 152792 0.02%
stdb_raw u32_u64_str unique_0 64 15730 15731 -0.01% 15848 15813 0.22%
sqlite u32_u64_str unique_0 1024 1067233 1067233 0.00% 1070553 1070601 -0.00%
sqlite u32_u64_str unique_0 64 76179 76179 0.00% 77209 77261 -0.07%

callgrind: serialize_product_value

count format total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
64 json 47182 47182 0.00% 49834 49736 0.20%
64 bsatn 25716 25716 0.00% 27858 27892 -0.12%
16 bsatn 8117 8117 0.00% 9375 9375 0.00%
16 json 12078 12078 0.00% 13982 13880 0.73%

callgrind: update bulk

db schema indices count preload total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str unique_0 1024 1024 20658732 20962130 -1.45% 21390706 21600060 -0.97%
stdb_raw u32_u64_str unique_0 64 128 1307968 1309319 -0.10% 1388952 1383749 0.38%
sqlite u32_u64_str unique_0 1024 1024 1802083 1802083 0.00% 1811233 1811319 -0.00%
sqlite u32_u64_str unique_0 64 128 128429 128429 0.00% 131249 131179 0.05%
On-disk benchmarks

callgrind: empty transaction

db total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw 5395 5396 -0.02% 5469 5442 0.50%
sqlite 5617 5617 0.00% 6129 6131 -0.03%

callgrind: filter

db schema indices count preload _column data_type total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str no_index 64 128 1 u64 75588 75589 -0.00% 76084 76003 0.11%
stdb_raw u32_u64_str no_index 64 128 2 string 118085 118107 -0.02% 118663 118719 -0.05%
stdb_raw u32_u64_str btree_each_column 64 128 2 string 24080 24106 -0.11% 24574 24554 0.08%
stdb_raw u32_u64_str btree_each_column 64 128 1 u64 23047 23073 -0.11% 23459 23435 0.10%
sqlite u32_u64_str no_index 64 128 1 u64 125934 125934 0.00% 127584 127414 0.13%
sqlite u32_u64_str no_index 64 128 2 string 146584 146584 0.00% 148432 148354 0.05%
sqlite u32_u64_str btree_each_column 64 128 2 string 136584 136584 0.00% 138714 138680 0.02%
sqlite u32_u64_str btree_each_column 64 128 1 u64 133426 133426 0.00% 135354 135328 0.02%

callgrind: insert bulk

db schema indices count preload total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str unique_0 64 128 849350 849785 -0.05% 905146 898349 0.76%
stdb_raw u32_u64_str btree_each_column 64 128 997901 998350 -0.04% 1057393 1059554 -0.20%
sqlite u32_u64_str unique_0 64 128 415821 415821 0.00% 437247 433693 0.82%
sqlite u32_u64_str btree_each_column 64 128 1021862 1021862 0.00% 1062378 1065348 -0.28%

callgrind: iterate

db schema indices count total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str unique_0 1024 152715 152716 -0.00% 152825 152790 0.02%
stdb_raw u32_u64_str unique_0 64 15740 15741 -0.01% 15850 15815 0.22%
sqlite u32_u64_str unique_0 1024 1070301 1070301 0.00% 1074035 1074107 -0.01%
sqlite u32_u64_str unique_0 64 77951 77951 0.00% 79201 79293 -0.12%

callgrind: serialize_product_value

count format total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
64 json 47182 47182 0.00% 49834 49736 0.20%
64 bsatn 25716 25716 0.00% 27858 27892 -0.12%
16 bsatn 8117 8117 0.00% 9375 9375 0.00%
16 json 12078 12078 0.00% 13982 13880 0.73%

callgrind: update bulk

db schema indices count preload total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str unique_0 1024 1024 19401537 19450642 -0.25% 20210525 20145870 0.32%
stdb_raw u32_u64_str unique_0 64 128 1258623 1263160 -0.36% 1338217 1338712 -0.04%
sqlite u32_u64_str unique_0 1024 1024 1809644 1809644 0.00% 1818258 1818128 0.01%
sqlite u32_u64_str unique_0 64 128 132555 132555 0.00% 135447 135445 0.00%

Please sign in to comment.