We’ve spent the last months occasionally rewriting, bit by bit, the hot paths of dns_erlang, the DNS parser library behind erldns and our authoritative name servers. Our name servers now use 12% less CPU per query and handles 14% more queries per second before saturating, from just encoding and decoding changes alone.
The post walks through the patterns that made the difference:
- one accumulator appended all the way
- staying in the match context
- matching in big chunks, checked against the JIT’s assembly output
- SWAR, which ended up in OTP’s json and string modules (#10938, #10948)
- picking map keys the VM can compare with a single memcmp
It also covers what didn’t work. There’s a small confession too: the OTP team had already fixed one of these patterns in my own binary:encode_hex/1 code, three years before I found it again in dns_erlang ![]()
Some ideas from optimising this also got into the OTP’s json and string modules, and even into Elixir’s Plug and Mint. Hopefully you can learn about or see in action some cool optimisation tricks ![]()