Why does :gen use an improper list internally?

Bit of a random question, but I was reading through the :gen_server/:gen implementation and I noticed that the tag allocated for a call is an improper list of [:alias | reference]. I thought that was pretty weird as I would have expected a tuple {:alias, reference} or similar.

I don’t think I’ve ever seen an improper list used for anything in Elixir, so I was wondering what the reasoning was. After some searching it sounds like that representation saves a byte over the tuple, so I guess that’s probably the reason (that code is a pretty hot path).

Does anyone know any more about this? Does this come up anywhere else in the codebase(s)?

Also, there is an optimization for matching a message with a reference. Does anyone know if this has any interaction with that?

1 Like

The improper list is 5 words in size, the tuple is 6 words. So it‘s likely plain size being the reason.

:erts_debug.size([:alias | make_ref()])
# 5
:erts_debug.size({:alias, make_ref()})
# 6
3 Likes

Also, improper list are awesome.

1 Like