@@ -21,6 +21,7 @@ import Database.LSMTree.Extras.Random (frequency, randomByteStringR,
2121import Database.LSMTree.Extras.UTxO
2222import Database.LSMTree.Internal.Arena (ArenaManager , closeArena ,
2323 newArena , newArenaManager , withArena )
24+ import qualified Database.LSMTree.Internal.BloomFilter as Bloom
2425import Database.LSMTree.Internal.Entry (Entry (.. ), NumEntries (.. ))
2526import Database.LSMTree.Internal.Index as Index
2627import Database.LSMTree.Internal.Lookup (bloomQueries , indexSearches ,
@@ -84,6 +85,9 @@ benchmarks = bgroup "Bench.Database.LSMTree.Internal.Lookup" [
8485 }
8586 ]
8687
88+ benchSalt :: Bloom. Salt
89+ benchSalt = 4
90+
8791benchLookups :: Config -> Benchmark
8892benchLookups conf@ Config {name} =
8993 withEnv $ \ ~ (_dir, arenaManager, _hasFS, hasBlockIO, wbblobs, rs, ks) ->
@@ -96,23 +100,23 @@ benchLookups conf@Config{name} =
96100 -- The bloomfilter is queried for all lookup keys. The result is an
97101 -- unboxed vector, so only use @whnf@.
98102 bench " Bloomfilter query" $
99- whnf (\ ks' -> bloomQueries blooms ks') ks
103+ whnf (\ ks' -> bloomQueries benchSalt blooms ks') ks
100104 -- The compact index is only searched for (true and false) positive
101105 -- lookup keys. We use whnf here because the result is
102- , env (pure $ bloomQueries blooms ks) $ \ rkixs ->
106+ , env (pure $ bloomQueries benchSalt blooms ks) $ \ rkixs ->
103107 bench " Compact index search" $
104108 whnfAppIO (\ ks' -> withArena arenaManager $ \ arena -> stToIO $ indexSearches arena indexes kopsFiles ks' rkixs) ks
105109 -- prepLookups combines bloom filter querying and index searching.
106110 -- The implementation forces the results to WHNF, so we use
107111 -- whnfAppIO here instead of nfAppIO.
108112 , bench " Lookup preparation in memory" $
109- whnfAppIO (\ ks' -> withArena arenaManager $ \ arena -> stToIO $ prepLookups arena blooms indexes kopsFiles ks') ks
113+ whnfAppIO (\ ks' -> withArena arenaManager $ \ arena -> stToIO $ prepLookups arena benchSalt blooms indexes kopsFiles ks') ks
110114 -- Submit the IOOps we get from prepLookups to HasBlockIO. We use
111115 -- perRunEnv because IOOps contain mutable buffers, so we want fresh
112116 -- ones for each run of the benchmark. We manually evaluate the
113117 -- result to WHNF since it is unboxed vector.
114118 , bench " Submit IOOps" $
115- perRunEnv (withArena arenaManager $ \ arena -> stToIO $ prepLookups arena blooms indexes kopsFiles ks) $ \ ~ (_rkixs, ioops) -> do
119+ perRunEnv (withArena arenaManager $ \ arena -> stToIO $ prepLookups arena benchSalt blooms indexes kopsFiles ks) $ \ ~ (_rkixs, ioops) -> do
116120 ! _ioress <- FS. submitIO hasBlockIO ioops
117121 pure ()
118122 -- When IO result have been collected, intra-page lookups searches
@@ -125,7 +129,7 @@ benchLookups conf@Config{name} =
125129 , bench " Perform intra-page lookups" $
126130 perRunEnvWithCleanup
127131 ( do arena <- newArena arenaManager
128- (rkixs, ioops) <- stToIO (prepLookups arena blooms indexes kopsFiles ks)
132+ (rkixs, ioops) <- stToIO (prepLookups arena benchSalt blooms indexes kopsFiles ks)
129133 ioress <- FS. submitIO hasBlockIO ioops
130134 pure (rkixs, ioops, ioress, arena)
131135 )
@@ -141,7 +145,7 @@ benchLookups conf@Config{name} =
141145 , bench " Lookups in IO" $
142146 whnfAppIO (\ ks' -> lookupsIOWithWriteBuffer
143147 hasBlockIO arenaManager resolveV
144- WB. empty wbblobs
148+ benchSalt WB. empty wbblobs
145149 rs blooms indexes kopsFiles ks') ks
146150 ]
147151 -- TODO: consider adding benchmarks that also use the write buffer
@@ -192,7 +196,7 @@ lookupsInBatchesEnv Config {..} = do
192196 wbblobs <- WBB. new hasFS (FS. mkFsPath [" 0.wbblobs" ])
193197 wb <- WB. fromMap <$> traverse (traverse (WBB. addBlob hasFS wbblobs)) storedKeys
194198 let fsps = RunFsPaths (FS. mkFsPath [] ) (RunNumber 0 )
195- r <- Run. fromWriteBuffer hasFS hasBlockIO runParams fsps wb wbblobs
199+ r <- Run. fromWriteBuffer hasFS hasBlockIO benchSalt runParams fsps wb wbblobs
196200 let NumEntries nentriesReal = Run. size r
197201 assertEqual nentriesReal nentries $ pure ()
198202 -- 42 to 43 entries per page
0 commit comments