66//! Timed: do `batches` more merkleize + apply iterations on top of the pre-built chain, with a
77//! single random update per batch so each overlay covers a tiny fraction of chunks.
88
9- use crate :: common:: { dispatch_arm , make_fixed_value, Digest } ;
9+ use crate :: common:: { make_fixed_value, Digest , WRITE_BUFFER_SIZE } ;
1010use commonware_cryptography:: { Hasher , Sha256 } ;
1111use commonware_runtime:: {
1212 benchmarks:: { context, tokio} ,
13+ buffer:: paged:: CacheRef ,
1314 tokio:: { Config , Context } ,
15+ BufferPooler , ThreadPooler ,
1416} ;
1517use commonware_storage:: {
16- merkle:: { self , mmb:: Family as Mmb } ,
18+ journal:: contiguous:: fixed:: Config as FConfig ,
19+ merkle:: { self , journaled, mmb:: Family as Mmb } ,
1720 qmdb:: {
1821 any:: traits:: { DbAny , MerkleizedBatch as _, UnmerkleizedBatch as _} ,
1922 current:: { ordered:: fixed:: Db as OCFixed , unordered:: fixed:: Db as UCFixed } ,
2023 } ,
2124 translator:: EightCap ,
2225} ;
26+ use commonware_utils:: { NZUsize , NZU16 , NZU64 } ;
2327use criterion:: { criterion_group, Criterion } ;
2428use rand:: { rngs:: StdRng , RngCore , SeedableRng } ;
2529use std:: {
2630 hint:: black_box,
31+ num:: { NonZeroU16 , NonZeroU64 , NonZeroUsize } ,
2732 time:: { Duration , Instant } ,
2833} ;
2934
35+ // -- Config (mirrors merkleize bench) --
36+
37+ const ITEMS_PER_BLOB : NonZeroU64 = NZU64 ! ( 10_000_000 ) ;
38+ const THREADS : NonZeroUsize = NZUsize ! ( 8 ) ;
39+ const PAGE_SIZE : NonZeroU16 = NZU16 ! ( 4096 ) ;
40+ const LARGE_PAGE_CACHE_SIZE : NonZeroUsize = NZUsize ! ( 131_072 ) ;
41+ const PARTITION : & str = "bench-chained-growth" ;
42+
3043const SMALL_CHUNK_SIZE : usize = 32 ;
3144const LARGE_CHUNK_SIZE : usize = 256 ;
3245
@@ -35,6 +48,42 @@ type CurOFix32Mmb = OCFixed<Mmb, Context, Digest, Digest, Sha256, EightCap, SMAL
3548type CurUFix256Mmb = UCFixed < Mmb , Context , Digest , Digest , Sha256 , EightCap , LARGE_CHUNK_SIZE > ;
3649type CurOFix256Mmb = OCFixed < Mmb , Context , Digest , Digest , Sha256 , EightCap , LARGE_CHUNK_SIZE > ;
3750
51+ fn merkle_cfg ( ctx : & ( impl BufferPooler + ThreadPooler ) , pc : CacheRef ) -> journaled:: Config {
52+ journaled:: Config {
53+ journal_partition : format ! ( "journal-{PARTITION}" ) ,
54+ metadata_partition : format ! ( "metadata-{PARTITION}" ) ,
55+ items_per_blob : ITEMS_PER_BLOB ,
56+ write_buffer : WRITE_BUFFER_SIZE ,
57+ thread_pool : Some ( ctx. create_thread_pool ( THREADS ) . unwrap ( ) ) ,
58+ page_cache : pc,
59+ }
60+ }
61+
62+ fn fix_log_cfg ( pc : CacheRef ) -> FConfig {
63+ FConfig {
64+ partition : format ! ( "log-journal-{PARTITION}" ) ,
65+ items_per_blob : ITEMS_PER_BLOB ,
66+ page_cache : pc,
67+ write_buffer : WRITE_BUFFER_SIZE ,
68+ }
69+ }
70+
71+ fn pc ( ctx : & impl BufferPooler ) -> CacheRef {
72+ CacheRef :: from_pooler ( ctx, PAGE_SIZE , LARGE_PAGE_CACHE_SIZE )
73+ }
74+
75+ fn cur_fix_cfg (
76+ ctx : & ( impl BufferPooler + ThreadPooler ) ,
77+ ) -> commonware_storage:: qmdb:: current:: FixedConfig < EightCap > {
78+ let pc = pc ( ctx) ;
79+ commonware_storage:: qmdb:: current:: FixedConfig {
80+ merkle_config : merkle_cfg ( ctx, pc. clone ( ) ) ,
81+ journal_config : fix_log_cfg ( pc) ,
82+ grafted_metadata_partition : format ! ( "grafted-metadata-{PARTITION}" ) ,
83+ translator : EightCap ,
84+ }
85+ }
86+
3887/// Number of pre-populated keys in the seeded database.
3988const NUM_KEYS : u64 = 1_000_000 ;
4089
@@ -78,19 +127,20 @@ const CURRENT_VARIANTS: [CurrentVariant; 4] = [
78127/// Construct a Current database for `$variant`, bind it as `$db`, and execute `$body`.
79128macro_rules! with_current_db {
80129 ( $ctx: expr, $variant: expr, |mut $db: ident| $body: expr) => { {
130+ macro_rules! init_db {
131+ ( $DbType: ty) => { {
132+ #[ allow( unused_mut) ]
133+ let mut $db = <$DbType>:: init( $ctx. clone( ) , cur_fix_cfg( & $ctx) )
134+ . await
135+ . unwrap( ) ;
136+ $body
137+ } } ;
138+ }
81139 match $variant {
82- CurrentVariant :: UnorderedFixed32 => {
83- dispatch_arm!( $ctx, $db, $body, CurUFix32Mmb , cur_fix_cfg)
84- }
85- CurrentVariant :: OrderedFixed32 => {
86- dispatch_arm!( $ctx, $db, $body, CurOFix32Mmb , cur_fix_cfg)
87- }
88- CurrentVariant :: UnorderedFixed256 => {
89- dispatch_arm!( $ctx, $db, $body, CurUFix256Mmb , cur_fix_cfg)
90- }
91- CurrentVariant :: OrderedFixed256 => {
92- dispatch_arm!( $ctx, $db, $body, CurOFix256Mmb , cur_fix_cfg)
93- }
140+ CurrentVariant :: UnorderedFixed32 => init_db!( CurUFix32Mmb ) ,
141+ CurrentVariant :: OrderedFixed32 => init_db!( CurOFix32Mmb ) ,
142+ CurrentVariant :: UnorderedFixed256 => init_db!( CurUFix256Mmb ) ,
143+ CurrentVariant :: OrderedFixed256 => init_db!( CurOFix256Mmb ) ,
94144 }
95145 } } ;
96146}
0 commit comments