Optimizing Interpreters with Scala (with Cats!)
Hi!
Just in time for the holiday break, a new chapter of Scala with Cats is ready for you:
https://scalawithcats.github.io/scala-with-cats/dist/scala-with-cats.pdf
This one is all about optimizing interpreters. It looks at algebraic simplification and virtual machines. It has what I think are some really neat case studies: regular expressions via derivatives, and an stack machine for evaluating arithmetic.
The stack machine really took me down the optimization rabbit hole. So much so that I have some overflow content. Firstly, a blog post on virtual machine dispatch that relates different techniques via dualities (which ties in very nicely with one of the main themes of the book). There is also code with implementations and benchmarks. The benchmarks are kinda crazy. I had a 60000 times improvement when I use subroutine threaded dispatch vs switch dispatch. I haven't got to the bottom of this one yet, but I think it's the style of code allowing Hotspot inlining to really show some benefits.
With these three new chapters complete, this finishes one thread of content. In writing up this content I think I need to reorganize the book a bit as I think advanced material is coming too early in the book. So my next steps will be returning to my book plan, and fixing some of the issues in the book build (e.g. the broken cover).
One final thing: if you're in Seattle you might be interested in WeSea FP, which is going through Functional Programming in Scala and Scala with Cats.
Hope you have a great holiday, and I'll catch you in 2024.
Regards,
Noel
P.S. As always, shout out to my sponsors who help me stay motivated and writing content.