Internal data representation of an empty tuple

Hi,
I am trying to figure out why :erts_debug.size({}) returns 0. The function returns the number of words taken up in the heap. For an empty list, it makes sense since the empty list will be represented by the immediate nil term. But does an empty tuple also have a similar representation that does not take up any space in the heap. Shouldn’t the empty tuple still have a boxed term as the container and a header word in the heap?

Thank you.

https://www.erlang.org/doc/efficiency_guide/advanced.html

This documents tuples as 2 words + the size of each element. Interestingly enough :erts_debug.size({}) returns 1 for me. Both your and my returned value don’t align with the docs though.

Hi @LostKobrakai


The same call returns 0 for me.

Your return value does align with the doc. The 2 words include both the boxed term(stack) and the header word(heap). The :erts_debug.size function returns only the number of words taken up in the heap and hence the return value 1 seems correct. I am not sure why it returns 0 for me.

It is an optimization for zero arity tuples: arm jit opt: emit_i_is_tagged_tuple and emit_i_is_tagged_tuple_ff by kjellwinblad · Pull Request #5259 · erlang/otp · GitHub

6 Likes