[erlang-questions] Re: ets traversal time

Ulf Wiger ulf.wiger@REDACTED
Thu Jul 16 17:01:08 CEST 2009

Jim Morris wrote:
> Have you tried ets:foldl which is tail recursive (presumably as it
> does not specify in the docs, but it is in lists:foldl) or is there a
> reason to use foldr?
> If foldr is not tail recursive then I suspect that with 20K entries
> the stack will get used up and or eat a lot of memory which needs to
> be allocated and released, maybe even causing swapping to the disk.

The only difference between ets:foldl and ets:foldr is that foldl
uses first/next and foldr uses last/prev. Apart from that, they
are exactly the same. See ets.erl

If the ets table is a 'set', last() -> first() and prev() -> next(),
since there is no defined ordering in hash tables. See erl_db_hash.c.

If there is a difference in the timings, I would first try to
rule out measurement error or see if it falls within the margin
of error for the measurement.

Ulf W
Ulf Wiger
CTO, Erlang Training & Consulting Ltd

More information about the erlang-questions mailing list