# One Billion Row challenge in Hs

**URL:** <https://discourse.haskell.org/t/one-billion-row-challenge-in-hs/8946>\
**Category:** Links\
**Created:** [March 3, 2024, 8:24am UTC](https://discourse.haskell.org/t/one-billion-row-challenge-in-hs/8946 "2024-03-03T08:24:38Z")\
**Posts on this page:** 1\
**Showing post:** 66

<div class="post-metadata">

**Author:** ![jaror](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jaror/32/3271_2.png) [@jaror](https://discourse.haskell.org/u/jaror)\
**Post date:** [March 9, 2024, 10:30pm UTC](https://discourse.haskell.org/t/one-billion-row-challenge-in-hs/8946/66 "2024-03-09T22:30:01Z")

</div>

> [@tomjaguarpaw](#):
>
> I appreciate the `return $!`/`pure $!`!

Yeah, I think it would be great if flatparse would provide a [“value strict”](http://discourse.haskell.org/t/why-shouldnt-i-make-my-monads-value-strict/8609) `Parser`.

* * *

I have now also implemented a little adapter to make flatparse work with lazy bytestrings:

```haskell
-- needs to be top-level now
f :: T -> T -> T
f (T a b c d) (T a' b' c' d') = T (min a a') (max b b') (c+c') (d+d')

runParserLazy :: (a -> a -> a) -> a -> Parser e a -> B.ByteString -> Result e a
runParserLazy k z p = B.foldlChunks step (OK z mempty) where
  step (OK x bs) bs' = k x <$> runParser p (bs <> bs')
  step x _ = x

main :: IO ()
main = do
  str <- B.readFile "measurements.txt"
  OK x _ <- pure $ runParserLazy (M.unionWith f) M.empty parseMeasurements str
  M.foldrWithKey (\k (T a b c d) go -> print (k, a, b, c/d) *> go) (pure ()) x

```

That doesn’t decrease the time on my machine by much, it is still 1.15 seconds. And it reduces the maximum residency from 138,019,888 to 207,456.

---

_[View the full topic](https://discourse.haskell.org/t/one-billion-row-challenge-in-hs/8946)._
