[erlang-questions] ets vs list

Ulf Wiger ulf.wiger@REDACTED
Mon Sep 13 18:25:49 CEST 2010

On 09/13/2010 06:10 PM, Morten Krogh wrote:
>  Thanks again.
> My question might have been hard to understand because I made an
> assumption that might be wrong, namely that
> an ets table has a corresponding process. I don't mean the owning
> process, but an implicit process that is spawned automatically
> when the table is created, and that all insertions and deletions are
> going through that process. Is that just my imagination?
> Is an ets table only a hash table and nothing more? No corresponding
> process that serializes all access to it? ETS:lookup is just a function
> call, not a hidden
> message pass, receive construct or what?
> Morten.

ETS tables do not have a corresponding process (except for the
temporary pseudo process during select()). Serialization is done
with mutexes, so essentially, it's just a hash table or B-tree.

That said, Erlang purists often hide behind the fact that you
_could_ model ETS tables with processes and message passing
(thus, process spawning and messaging are still the only
means of side-effecting in Erlang ;-)

It's not terribly difficult, but hard to do efficiently. The
main issue is named tables, since you need a table registry,
which implies another set of messages. I did this once (and
as it happened, Robert V was doing the same thing at the same
time - I was doing it for the Erlang Processor, and he was
doing it for his own VM, VEE). As far as I recall, performance
of my ETS emulation was ca 30x slower than regular ETS, at
least on named tables*. :) This was many years ago, so the
numbers may be completely different today.

Ulf W

* But, as it happened, the Erlang Processor used ca 30x fewer
clock cycles than my workstation to execute Erlang code, so
ultimately I thought myself no worse off. :)

More information about the erlang-questions mailing list