There's a nice Ruby trick btw where you put significant precalculations in constants, since the value of a constant gets computed during program startup it still allow you to do work "up front" instead of during a web request.
(edit to reply since I can't reply to a reply to a reply)
Yep, it is very common in lisp/smalltalk environments to dump the state of the world to disk and re-load it later. This is one of those tricks that gets relearned every generation. :)
For bonus credit apply this analogy to docker images. :)
* Some early step in the init process. May things are still interpreted at init.
* Some early step in the init process. Many things are still interpreted at init.
https://news.ycombinator.com/item?id=21394916
https://lwn.net/Articles/707615/ "The Emacs dumper dispute"
https://lwn.net/Articles/673724/ "Removing support for Emacs unexec from Glibc"
Anyway, I coded it up in my local dev environment. Unfortunately, it turned out that I'd been mislead and the actual deployment environment didn't have a database server available.
In desperation and facing a deadline, I dumped all the lookup values into an array in a PHP file. As you said, it was really quite performant. The first request after starting the server was a bit slow (but not too bad... still < 10 seconds I think) and after that things were golden.
I felt a bit dirty, but things worked and we got paid.
Imagine describing globals in C, Python, or JavaScript, or static fields in Java or C# as a "neat trick"...