I have been looking at the OTP source a bit, and I was surprised to see how much of Erlang’s map functionality is implemented in C. This has led to me scratching my head a bit about where the line was drawn (between C and Erlang) when implementing maps, and the rationale behind it. As far as I can tell, there are 2 main locations defining map behavior:
So I think I have a few questions:
- Are BIFs essential to the performance characteristics of maps on the BEAM? If you simply wrote them as an Erlang/Elixir module would they be unusable and slow? Are there other benefits to structuring it this way?
- What is the role of shadowing the BIFs in the Erlang module? It seems like the shadowed functions just check types and then throw a
nif_error. I can’t quite figure out the purpose of that.
swizzle32??? Is that a hash function? Is it used anywhere besides the BEAM?