What really stood out to me is how fast routing is in phoenix! I have done similar things on apis built for jobs I have done in the passed. For example a nodejs(hapijs) health check doing the same thing takes around 20 times longer at 75ms.
Is there any reason why phoenix routing is so fast? I remember reading something a while back but am having issues finding it.
Yes! The Phoenix router compiles all your routes down to a single function performing a pattern-match on a single binary: The route that is passed in. There have been more than 30 years of compiler/runtime optimizations in Erlang that make these kinds of pattern matches extremely fast.
A quick answer: The router might feel like a DSL — like you might see in Rails, but it’s a Macro! Because it’s a macro, most of the work is handled at compile time. So because this a compiled macro, it’s all pretty much just pattern matching, which is pretty snappy.