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.
Primary takeaway, for (Haskell) programs compiled with GHC: "Code size: overall binary sizes are reduced by ~5% for large programs, ~3% for smaller programs."
As for why he doesn't define it: he's been one of two primary authors of GHC for over 20 years. He assumed anyone reading his blog would already be aware of that, because why else would they be reading his blog?
> 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.
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 :)