@@ -2,6 +2,7 @@ use std::{ops::Deref, sync::Arc};
2
2
3
3
use criterion:: * ;
4
4
use matrix_sdk_crypto:: { EncryptionSettings , OlmMachine } ;
5
+ use matrix_sdk_sled:: SledCryptoStore ;
5
6
use matrix_sdk_sqlite:: SqliteCryptoStore ;
6
7
use matrix_sdk_test:: response_from_file;
7
8
use ruma:: {
@@ -65,11 +66,15 @@ pub fn keys_query(c: &mut Criterion) {
65
66
66
67
let name = format ! ( "{count} device and cross signing keys" ) ;
67
68
69
+ // Benchmark memory store.
70
+
68
71
group. bench_with_input ( BenchmarkId :: new ( "memory store" , & name) , & response, |b, response| {
69
72
b. to_async ( & runtime)
70
73
. iter ( || async { machine. mark_request_as_sent ( & txn_id, response) . await . unwrap ( ) } )
71
74
} ) ;
72
75
76
+ // Benchmark sqlite store.
77
+
73
78
let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
74
79
let store = Arc :: new ( runtime. block_on ( SqliteCryptoStore :: open ( dir. path ( ) , None ) ) . unwrap ( ) ) ;
75
80
let machine =
@@ -85,6 +90,18 @@ pub fn keys_query(c: &mut Criterion) {
85
90
drop ( machine) ;
86
91
}
87
92
93
+ // Benchmark (deprecated) sled store.
94
+
95
+ let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
96
+ let store = Arc :: new ( runtime. block_on ( SledCryptoStore :: open ( dir. path ( ) , None ) ) . unwrap ( ) ) ;
97
+ let machine =
98
+ runtime. block_on ( OlmMachine :: with_store ( alice_id ( ) , alice_device_id ( ) , store) ) . unwrap ( ) ;
99
+
100
+ group. bench_with_input ( BenchmarkId :: new ( "sled store" , & name) , & response, |b, response| {
101
+ b. to_async ( & runtime)
102
+ . iter ( || async { machine. mark_request_as_sent ( & txn_id, response) . await . unwrap ( ) } )
103
+ } ) ;
104
+
88
105
group. finish ( )
89
106
}
90
107
@@ -147,6 +164,28 @@ pub fn keys_claiming(c: &mut Criterion) {
147
164
)
148
165
} ) ;
149
166
167
+ group. bench_with_input ( BenchmarkId :: new ( "sled store" , & name) , & response, |b, response| {
168
+ b. iter_batched (
169
+ || {
170
+ let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
171
+ let store =
172
+ Arc :: new ( runtime. block_on ( SledCryptoStore :: open ( dir. path ( ) , None ) ) . unwrap ( ) ) ;
173
+
174
+ let machine = runtime
175
+ . block_on ( OlmMachine :: with_store ( alice_id ( ) , alice_device_id ( ) , store) )
176
+ . unwrap ( ) ;
177
+ runtime
178
+ . block_on ( machine. mark_request_as_sent ( & txn_id, & keys_query_response) )
179
+ . unwrap ( ) ;
180
+ ( machine, & runtime, & txn_id)
181
+ } ,
182
+ move |( machine, runtime, txn_id) | {
183
+ runtime. block_on ( machine. mark_request_as_sent ( txn_id, response) ) . unwrap ( )
184
+ } ,
185
+ BatchSize :: SmallInput ,
186
+ )
187
+ } ) ;
188
+
150
189
group. finish ( )
151
190
}
152
191
@@ -171,6 +210,8 @@ pub fn room_key_sharing(c: &mut Criterion) {
171
210
group. throughput ( Throughput :: Elements ( count as u64 ) ) ;
172
211
let name = format ! ( "{count} devices" ) ;
173
212
213
+ // Benchmark memory store.
214
+
174
215
group. bench_function ( BenchmarkId :: new ( "memory store" , & name) , |b| {
175
216
b. to_async ( & runtime) . iter ( || async {
176
217
let requests = machine
@@ -192,6 +233,8 @@ pub fn room_key_sharing(c: &mut Criterion) {
192
233
} )
193
234
} ) ;
194
235
236
+ // Benchmark sqlite store.
237
+
195
238
let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
196
239
let store = Arc :: new ( runtime. block_on ( SqliteCryptoStore :: open ( dir. path ( ) , None ) ) . unwrap ( ) ) ;
197
240
@@ -226,6 +269,37 @@ pub fn room_key_sharing(c: &mut Criterion) {
226
269
drop ( machine) ;
227
270
}
228
271
272
+ // Benchmark (deprecated) sled store.
273
+
274
+ let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
275
+ let store = Arc :: new ( runtime. block_on ( SledCryptoStore :: open ( dir. path ( ) , None ) ) . unwrap ( ) ) ;
276
+
277
+ let machine =
278
+ runtime. block_on ( OlmMachine :: with_store ( alice_id ( ) , alice_device_id ( ) , store) ) . unwrap ( ) ;
279
+ runtime. block_on ( machine. mark_request_as_sent ( & txn_id, & keys_query_response) ) . unwrap ( ) ;
280
+ runtime. block_on ( machine. mark_request_as_sent ( & txn_id, & response) ) . unwrap ( ) ;
281
+
282
+ group. bench_function ( BenchmarkId :: new ( "sled store" , & name) , |b| {
283
+ b. to_async ( & runtime) . iter ( || async {
284
+ let requests = machine
285
+ . share_room_key (
286
+ room_id,
287
+ users. iter ( ) . map ( Deref :: deref) ,
288
+ EncryptionSettings :: default ( ) ,
289
+ )
290
+ . await
291
+ . unwrap ( ) ;
292
+
293
+ assert ! ( !requests. is_empty( ) ) ;
294
+
295
+ for request in requests {
296
+ machine. mark_request_as_sent ( & request. txn_id , & to_device_response) . await . unwrap ( ) ;
297
+ }
298
+
299
+ machine. invalidate_group_session ( room_id) . await . unwrap ( ) ;
300
+ } )
301
+ } ) ;
302
+
229
303
group. finish ( )
230
304
}
231
305
@@ -246,12 +320,16 @@ pub fn devices_missing_sessions_collecting(c: &mut Criterion) {
246
320
247
321
runtime. block_on ( machine. mark_request_as_sent ( & txn_id, & response) ) . unwrap ( ) ;
248
322
323
+ // Benchmark memory store.
324
+
249
325
group. bench_function ( BenchmarkId :: new ( "memory store" , & name) , |b| {
250
326
b. to_async ( & runtime) . iter_with_large_drop ( || async {
251
327
machine. get_missing_sessions ( users. iter ( ) . map ( Deref :: deref) ) . await . unwrap ( )
252
328
} )
253
329
} ) ;
254
330
331
+ // Benchmark sqlite store.
332
+
255
333
let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
256
334
let store = Arc :: new ( runtime. block_on ( SqliteCryptoStore :: open ( dir. path ( ) , None ) ) . unwrap ( ) ) ;
257
335
@@ -271,6 +349,22 @@ pub fn devices_missing_sessions_collecting(c: &mut Criterion) {
271
349
drop ( machine) ;
272
350
}
273
351
352
+ // Benchmark (deprecated) sled store.
353
+
354
+ let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
355
+ let store = Arc :: new ( runtime. block_on ( SledCryptoStore :: open ( dir. path ( ) , None ) ) . unwrap ( ) ) ;
356
+
357
+ let machine =
358
+ runtime. block_on ( OlmMachine :: with_store ( alice_id ( ) , alice_device_id ( ) , store) ) . unwrap ( ) ;
359
+
360
+ runtime. block_on ( machine. mark_request_as_sent ( & txn_id, & response) ) . unwrap ( ) ;
361
+
362
+ group. bench_function ( BenchmarkId :: new ( "sled store" , & name) , |b| {
363
+ b. to_async ( & runtime) . iter ( || async {
364
+ machine. get_missing_sessions ( users. iter ( ) . map ( Deref :: deref) ) . await . unwrap ( )
365
+ } )
366
+ } ) ;
367
+
274
368
group. finish ( )
275
369
}
276
370
0 commit comments