[erlang-questions] Performance of matches

Bengt Kleberg <>
Tue Jun 3 07:01:55 CEST 2008


Reasons to avoid the process dictionary:

1 It is using side effects which makes your code harder to
understand/reason about.
2 It is per process which makes your code harder to test.


On Mon, 2008-06-02 at 14:15 -0700, Darren New wrote:
> Darren New wrote:
> > David Lloyd wrote:
> >  >> Is either of those O(1) lookup time?
> >  > It strikes me that this is something that is eminently easy to profile...
> > 
> > Good point. 
> Actually, I was asking a slightly more complex question. It's only easy 
> to profile if the compiler doesn't have special cases that make some 
> things faster. For example, Haskell has enough smarts to notice some 
> operations never look at the unmodified value after you modify it, and 
> use that to avoid copying the whole collection (for example) when you 
> modify one element. Much the same way I've read Erlang avoids copying 
> binaries when you append to them in certain circumstances.
> So, basically, I was trying to ask the question "is there any O(1) data 
> structure in Erlang, such as a hashtable or an array equivalent?" Maybe 
> it just hasn't clicked for me, is all.
> Good to know the process dictionary is actually a hashtable, but there's 
> only one per process and they don't nest, so that's pretty limited. Plus 
> there are recommendations to avoid it, for some reason that isn't 
> explained.

More information about the erlang-questions mailing list