crclark / foundationdb-haskell

Haskell FFI bindings to the FoundationDB C API
https://crclark.github.io/foundationdb-haskell/
BSD 3-Clause "New" or "Revised" License
36 stars 5 forks source link

Speed up decoding of bytes/string tuple elements. #33

Closed Dretch closed 4 years ago

Dretch commented 4 years ago

I thought that larger text elements in tuples were taking a long time to decode, so I tried making it faster.

Before this change (using the new benchmark I added in this pull request):

benchmarked decodeTupleElems/Text long
time                 107.3 ms   (103.4 ms .. 111.8 ms)
                     0.998 R²   (0.995 R² .. 1.000 R²)
mean                 103.7 ms   (102.6 ms .. 105.7 ms)
std dev              2.425 ms   (1.025 ms .. 3.537 ms)

and afterwards:

benchmarked decodeTupleElems/Text long
time                 16.89 ms   (16.46 ms .. 17.30 ms)
                     0.997 R²   (0.995 R² .. 0.998 R²)
mean                 18.14 ms   (17.77 ms .. 18.68 ms)
std dev              1.086 ms   (798.6 μs .. 1.428 ms)
variance introduced by outliers: 25% (moderately inflated)

I am no kind of Haskell optimisation expert, so I suppose it can be sped up even more, but this is a start.