@@ -2,24 +2,19 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion};
22use spacetimedb:: client:: consume_each_list:: ConsumeEachBuffer ;
33use spacetimedb:: db:: relational_db:: RelationalDB ;
44use spacetimedb:: error:: DBError ;
5- use spacetimedb:: host:: module_host:: DatabaseTableUpdate ;
65use spacetimedb:: identity:: AuthCtx ;
76use spacetimedb:: sql:: ast:: SchemaViewer ;
8- use spacetimedb:: subscription:: query:: compile_read_only_queryset;
97use spacetimedb:: subscription:: row_list_builder_pool:: BsatnRowListBuilderPool ;
10- use spacetimedb:: subscription:: subscription:: ExecutionSet ;
118use spacetimedb:: subscription:: tx:: DeltaTx ;
129use spacetimedb:: subscription:: { collect_table_update, TableUpdateType } ;
1310use spacetimedb_bench:: database:: BenchDatabase as _;
1411use spacetimedb_bench:: spacetime_raw:: SpacetimeRaw ;
15- use spacetimedb_client_api_messages:: websocket:: v1:: { BsatnFormat , Compression } ;
12+ use spacetimedb_client_api_messages:: websocket:: v1:: BsatnFormat ;
1613use spacetimedb_datastore:: execution_context:: Workload ;
1714use spacetimedb_execution:: pipelined:: PipelinedProject ;
1815use spacetimedb_primitives:: { col_list, TableId } ;
1916use spacetimedb_query:: compile_subscription;
20- use spacetimedb_sats:: { bsatn, product, AlgebraicType , AlgebraicValue , ProductValue } ;
21-
22- use spacetimedb_schema:: table_name:: TableName ;
17+ use spacetimedb_sats:: { bsatn, product, AlgebraicType , AlgebraicValue } ;
2318#[ cfg( not( target_env = "msvc" ) ) ]
2419use tikv_jemallocator:: Jemalloc ;
2520
@@ -52,15 +47,6 @@ fn create_table_footprint(db: &RelationalDB) -> Result<TableId, DBError> {
5247 db. create_table_for_test ( "footprint" , schema, indexes)
5348}
5449
55- fn insert_op ( table_id : TableId , table_name : & str , row : ProductValue ) -> DatabaseTableUpdate {
56- DatabaseTableUpdate {
57- table_id,
58- table_name : TableName :: for_test ( table_name) ,
59- inserts : [ row] . into ( ) ,
60- deletes : [ ] . into ( ) ,
61- }
62- }
63-
6450fn eval ( c : & mut Criterion ) {
6551 let raw = SpacetimeRaw :: build ( false ) . unwrap ( ) ;
6652
@@ -115,16 +101,12 @@ fn eval(c: &mut Criterion) {
115101 let footprint = AlgebraicValue :: sum ( 1 , AlgebraicValue :: unit ( ) ) ;
116102 let owner = 6u64 ;
117103
118- let new_lhs_row = product ! ( entity_id, owner, footprint) ;
119- let new_rhs_row = product ! ( entity_id, chunk_index, x, z, dimension) ;
120-
121- let ins_lhs = insert_op ( lhs, "footprint" , new_lhs_row) ;
122- let ins_rhs = insert_op ( rhs, "location" , new_rhs_row) ;
123- let update = [ & ins_lhs, & ins_rhs] ;
104+ let _new_lhs_row = product ! ( entity_id, owner, footprint) ;
105+ let _new_rhs_row = product ! ( entity_id, chunk_index, x, z, dimension) ;
124106
125107 let bsatn_rlb_pool = black_box ( BsatnRowListBuilderPool :: new ( ) ) ;
126108
127- // A benchmark runner for the new query engine
109+ // A benchmark runner for the subscription engine.
128110 let bench_query = |c : & mut Criterion , name, sql| {
129111 c. bench_function ( name, |b| {
130112 let tx = raw. db . begin_tx ( Workload :: Subscribe ) ;
@@ -154,20 +136,6 @@ fn eval(c: &mut Criterion) {
154136 } ) ;
155137 } ;
156138
157- let bench_eval = |c : & mut Criterion , name, sql| {
158- c. bench_function ( name, |b| {
159- let tx = raw. db . begin_tx ( Workload :: Update ) ;
160- let query = compile_read_only_queryset ( & raw . db, & AuthCtx :: for_testing ( ) , & tx, sql) . unwrap ( ) ;
161- let query: ExecutionSet = query. into ( ) ;
162-
163- b. iter ( || {
164- let updates =
165- black_box ( query. eval :: < BsatnFormat > ( & raw . db, & tx, & bsatn_rlb_pool, None , Compression :: None ) ) ;
166- updates. consume_each_list ( & mut |buffer| bsatn_rlb_pool. try_put ( buffer) ) ;
167- } )
168- } ) ;
169- } ;
170-
171139 // Join 1M rows on the left with 12K rows on the right.
172140 // Note, this should use an index join so as not to read the entire footprint table.
173141 let semijoin = format ! (
@@ -183,66 +151,6 @@ fn eval(c: &mut Criterion) {
183151 bench_query ( c, "footprint-scan" , "select * from footprint" ) ;
184152 bench_query ( c, "footprint-semijoin" , & semijoin) ;
185153 bench_query ( c, "index-scan-multi" , index_scan_multi) ;
186-
187- // To profile this benchmark for 30s
188- // samply record -r 10000000 cargo bench --bench=subscription --profile=profiling -- full-scan --exact --profile-time=30
189- // Iterate 1M rows.
190- bench_eval ( c, "full-scan" , "select * from footprint" ) ;
191-
192- // To profile this benchmark for 30s
193- // samply record -r 10000000 cargo bench --bench=subscription --profile=profiling -- full-join --exact --profile-time=30
194- // Join 1M rows on the left with 12K rows on the right.
195- // Note, this should use an index join so as not to read the entire footprint table.
196- let name = format ! (
197- r#"
198- select footprint.*
199- from footprint join location on footprint.entity_id = location.entity_id
200- where location.chunk_index = {chunk_index}
201- "#
202- ) ;
203- bench_eval ( c, "full-join" , & name) ;
204-
205- // To profile this benchmark for 30s
206- // samply record -r 10000000 cargo bench --bench=subscription --profile=profiling -- incr-select --exact --profile-time=30
207- c. bench_function ( "incr-select" , |b| {
208- // A passthru executed independently of the database.
209- let select_lhs = "select * from footprint" ;
210- let select_rhs = "select * from location" ;
211- let tx = & raw . db. begin_tx ( Workload :: Update ) ;
212- let query_lhs = compile_read_only_queryset ( & raw . db, & AuthCtx :: for_testing ( ) , tx, select_lhs) . unwrap ( ) ;
213- let query_rhs = compile_read_only_queryset ( & raw . db, & AuthCtx :: for_testing ( ) , tx, select_rhs) . unwrap ( ) ;
214- let query = ExecutionSet :: from_iter ( query_lhs. into_iter ( ) . chain ( query_rhs) ) ;
215- let tx = & tx. into ( ) ;
216-
217- b. iter ( || drop ( black_box ( query. eval_incr_for_test ( & raw . db, tx, & update, None ) ) ) )
218- } ) ;
219-
220- // To profile this benchmark for 30s
221- // samply record -r 10000000 cargo bench --bench=subscription --profile=profiling -- incr-join --exact --profile-time=30
222- c. bench_function ( "incr-join" , |b| {
223- // Not a passthru - requires reading of database state.
224- let join = format ! (
225- "\
226- select footprint.* \
227- from footprint join location on footprint.entity_id = location.entity_id \
228- where location.chunk_index = {chunk_index}"
229- ) ;
230- let tx = & raw . db. begin_tx ( Workload :: Update ) ;
231- let query = compile_read_only_queryset ( & raw . db, & AuthCtx :: for_testing ( ) , tx, & join) . unwrap ( ) ;
232- let query: ExecutionSet = query. into ( ) ;
233- let tx = & tx. into ( ) ;
234-
235- b. iter ( || drop ( black_box ( query. eval_incr_for_test ( & raw . db, tx, & update, None ) ) ) ) ;
236- } ) ;
237-
238- // To profile this benchmark for 30s
239- // samply record -r 10000000 cargo bench --bench=subscription --profile=profiling -- query-indexes-multi --exact --profile-time=30
240- // Iterate 1M rows.
241- bench_eval (
242- c,
243- "query-indexes-multi" ,
244- "select * from location WHERE x = 0 AND z = 10000 AND dimension = 0" ,
245- ) ;
246154}
247155
248156criterion_group ! ( benches, eval) ;
0 commit comments