
Rethinking Static Reference Tables in GHC - tuukkah
https://simonmar.github.io/posts/2018-06-22-New-SRTs.html
======
chriswarbo
Looks like this "pays for itself" (as in
[https://prog21.dadgum.com/136.html](https://prog21.dadgum.com/136.html) ),
which is always nice to see for a simplification :)

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 :)

------
infinity0
Would this also benefit non-top-level thunks?

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/](https://www.well-typed.com/blog/2016/09/sharing-conduit/)

------
tuukkah
Primary takeaway, for (Haskell) programs compiled with GHC: _" Code size:
overall binary sizes are reduced by ~5% for large programs, ~3% for smaller
programs."_

------
wafflesraccoon
Does he define GHC anywhere in the article? Any idea what that might be?

~~~
chowells
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?

~~~
fake-name
I dunno, maybe because people link to stuff without context?

~~~
kornish
Googling "Simon Marlow" gives the following:

> 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.

