NethermindEth / Paprika

A custom storage engine of Nethermind, benefiting from the alignment of the underlying data structure with the layout of State & Storage trees of Ethereum.
GNU Lesser General Public License v3.0
89 stars 11 forks source link

BitMapFilter altered to use ref int #358

Closed Scooletz closed 2 months ago

Scooletz commented 2 months ago

This PR changes the BitMapFilter to use ref int. This simplifies the code a bit and allows to make it less unsafe. Also, by basing all calls on ref int, should allow to use Interlocked.Or and make the filter concurrency/atomic friendly. An addiitonal side effect is faster MayContainAny

Benchmarks

Before

Method Mean Error StdDev Code Size Allocated
Or_BitMapFilter_Of1 38.9126 ns 0.3472 ns 0.3247 ns 235 B -
Or_BitMapFilter_Of2 82.1053 ns 1.6279 ns 1.5228 ns 459 B -
Or_BitMapFilter_OfN_128 9,127.0372 ns 116.5773 ns 103.3428 ns 332 B -
MayContainAny_BitMapFilter_OfN_128 0.9688 ns 0.0146 ns 0.0137 ns 435 B -

After

Method Mean Error StdDev Code Size Allocated
Or_BitMapFilter_Of1 38.5533 ns 0.4279 ns 0.4003 ns 235 B -
Or_BitMapFilter_Of2 80.3172 ns 1.3885 ns 1.2309 ns 459 B -
Or_BitMapFilter_OfN_128 9,032.1915 ns 153.9109 ns 143.9684 ns 332 B -
MayContainAny_BitMapFilter_OfN_128 0.6839 ns 0.0129 ns 0.0121 ns 332 B -

Diff for MayContainAny

image

github-actions[bot] commented 2 months ago

Code Coverage

Package Line Rate Branch Rate Health
Paprika 85% 79%
Summary 85% (4066 / 4800) 79% (1299 / 1646)

Minimum allowed line rate is 75%