11use core:: ops:: Deref ;
22use std:: borrow:: Cow ;
3- use std:: collections:: BTreeMap ;
43use std:: { ops:: RangeBounds , sync:: Arc } ;
54
65use super :: locking_tx_datastore:: datastore:: TxMetrics ;
@@ -9,6 +8,7 @@ use super::Result;
98use crate :: execution_context:: Workload ;
109use crate :: system_tables:: ST_TABLE_ID ;
1110use spacetimedb_data_structures:: map:: IntSet ;
11+ use spacetimedb_data_structures:: small_map:: SmallHashMap ;
1212use spacetimedb_durability:: TxOffset ;
1313use spacetimedb_lib:: { hash_bytes, Identity } ;
1414use spacetimedb_primitives:: * ;
@@ -171,6 +171,12 @@ pub enum IsolationLevel {
171171
172172pub type EphemeralTables = IntSet < TableId > ;
173173
174+ /// The [`TxData`] entry for one table.
175+ ///
176+ /// All information about a table is stored in one place
177+ /// as the access pattern is to write as fast as possible
178+ /// and because it all fits within a single cache line
179+ /// and so that we can use `SmallVec`.
174180#[ derive( Debug , Clone , PartialEq , Eq ) ]
175181pub struct TxDataTableEntry {
176182 /// The name of the table for which there were deletions and/or insertions.
@@ -222,7 +228,7 @@ impl TxDataTableEntry {
222228/// so that the recording of execution metrics can be done without holding the tx lock.
223229#[ derive( Default ) ]
224230pub struct TxData {
225- entries : BTreeMap < TableId , TxDataTableEntry > ,
231+ entries : SmallHashMap < TableId , TxDataTableEntry , 1 , 8 > ,
226232
227233 /// Tx offset of the transaction which performed these operations.
228234 ///
@@ -250,8 +256,7 @@ impl TxData {
250256 /// or initializes it with `table_name`.
251257 fn init_entry ( & mut self , table_id : TableId , table_name : & TableName ) -> & mut TxDataTableEntry {
252258 self . entries
253- . entry ( table_id)
254- . or_insert_with ( || TxDataTableEntry :: new ( table_name. clone ( ) ) )
259+ . get_or_insert ( table_id, || TxDataTableEntry :: new ( table_name. clone ( ) ) )
255260 }
256261
257262 /// Set `rows` as the inserted rows for `(table_id, table_name)`.
0 commit comments