# A Late Answer Is a Wrong Answer: Heaps, Continuations and ETS on the BEAM

**URL:** <https://erlangforums.com/t/a-late-answer-is-a-wrong-answer-heaps-continuations-and-ets-on-the-beam/6105>\
**Category:** Blog Posts\
**Tags:** performance, ets, blogs-by-nelsonvides\
**Created:** [November 4, 2026, 2:23pm UTC](https://erlangforums.com/t/a-late-answer-is-a-wrong-answer-heaps-continuations-and-ets-on-the-beam/6105 "2026-11-04T14:23:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NelsonVides](https://erlangforums.com/user_avatar/erlangforums.com/nelsonvides/32/1205_2.png) [@NelsonVides](https://erlangforums.com/u/NelsonVides)\
**Post date:** [November 4, 2026, 2:23pm UTC](https://erlangforums.com/t/a-late-answer-is-a-wrong-answer-heaps-continuations-and-ets-on-the-beam/6105/1 "2026-11-04T14:23:37Z")

</div>

Following up on [Making `dns_erlang` fast: binary tricks for the BEAM](https://erlangforums.com/t/making-dns-erlang-fast-binary-tricks-for-the-beam/6059) , there’s our second post in our series on making erldns, an authoritative DNS server, faster: it’s techniques for hot paths that work in any Erlang or Elixir codebase, I really hope you’ll learn a trick or two.

- Find, don’t count. `ets:select_count/2 =/= 0` is the ETS version of `length(L) =/= 0` when matching `[_ | _]` would do. Stopping at the first match cut our name servers’ CPU by a third.
- One `ets:next/2` instead of a match spec got many kinds of answers 1.8x faster. On an ordered\_set, one step from a key that sorts just before the name tells you both whether the name exists and whether anything is below it.
- Give short-lived processes the heap they need. Spawning a process with a well-chosen `min_heap_size` made a query take less than half the time as it ran to completion without a single GC cycle.

In production, p90 dropped by about 25%, and by about 33% if the query requests DNSSEC.

Questions and feedback welcome!

> **[A Late Answer Is a Wrong Answer: Heaps, Continuations and ETS on the BEAM](https://blog.dnsimple.com/2026/11/a-late-answer-is-a-wrong-answer/)**
>
> How smarter ETS lookups, heap sizing and continuations made erldns answer sooner, and cut a third of our name servers' CPU in one deploy.
