Rethinking Static Reference Tables in GHC
simonmar.github.io
simonmar.github.io
The top-level `Map` example resonated with me, since I recently needed to speed up some scripts which look up data from some statically-known JSON files, which match some user-provided properties. I was using `jq`, but ended up doing an O(N^2) nested loop which was too slow. I wrote a Haskell version, which was easy enough with the Aeson library, but then I was able to speed it up massively by using Template Haskell to read the files, parse the JSON and build a `Map` from properties to data at compile time. This is encoded in the resulting program as a top-level definition, just like the example shown in this article. The resulting binary only needs to do an O(log N) lookup at runtime, which is more than acceptable :)
We had a ridiculous space-leak at DFINITY just last month where the workaround I found involved turning off full-laziness [1] as well as using a variant of `Control.Monad.forever` defined in terms of `(>>=)` rather than `(* >)` - which is how `Control.Monad` does it, which interacted badly with how Conduit implements `(>>=)` and `(* >)`. We never got to the bottom of exactly why it leaked but I'll be sure to try it out again with GHC 8.6. However it's not clear that long-lived CAF data would have been the problem in our case.
[1] https://www.well-typed.com/blog/2016/09/sharing-conduit/
The canonical haskell compiler.
> Simon Marlow is a British computer programmer, author, and co-developer of the Glasgow Haskell Compiler. He and Simon Peyton Jones won the SIGPLAN Programming Languages Software Award in 2011 for their work on GHC.