[erlang-questions] Best Practice in Map keys: Atoms or Binaries (or Strings)?
Richard A. O'Keefe
Mon Oct 3 02:24:47 CEST 2016
On 1/10/16 11:37 PM, Pagayon, Ruel wrote:
> 1. What is the most optimal key type for maps?
I'm not sure that question has an answer.
So much depends on your usage patterns.
Even a little benchmark comparing lookup/update
speeds for maps could be misleading because it
wouldn't take into account the work done by your
program in *getting* the keys to use.
> 2. If there is little to no effect in performance (or resources in
> general), as a convention, which is the best to use?
Whatever is most appropriate for your immediate needs.
If the frames proposal had been adopted, the answer would
have been "only atoms work, so what's the question". But
the frames proposal *wasn't* adopted, and one *point* of
using maps is to be able to use as keys whatever you need
to use as keys, without worrying too much about converting
them to something else.
This really is the most helpful response I can give.
Today's machines are literally thousands of times faster
than the machines I used as an undergraduate. The era
of micro-optimisation is long gone. For a long time now
the advice has been "make your program RIGHT before
making it FAST." Optimise the human time it takes to get
to a working program, then benchmark that, and when you
know (a) that you HAVE a performance problem and (b) WHERE
the performance is suffering, that's the time to try
OK, there's no point in premature pessimisation either.
More information about the erlang-questions