[erlang-questions] ets:lookup() versus mnesia:ets()

Paulo Sérgio Almeida psa@REDACTED
Thu May 10 16:59:04 CEST 2007

Hi all,

I know this is a sacrilege, breaking all rules of abstraction, assuming 
some internals of the implementation, bla, bla, bla, ... ;)

But ... suppose that it is important to squeeze the last bit of 
performance and, in a scenario where I wanted to do reads on a 
non-replicated disc_copies mnesia table, of records that are only 
updated by the same process (even though other processes update other 
records), and where I use:

mnesia:ets(fun()-> mnesia:read({Table, Key}) end)

and therefore have the lowest access context / isolation level available 
and I am happy with it. Is there anything that could go wrong if I 
instead used:

ets:lookup(Table, Key)

This would save building the closure, and the tests that read must make 
to figure out the access context, and it can be twice as fast in a set 
table (I measured 2 microseconds instead of 4 on my notebook; 
mnesia:dirty_read is slower, taking 5 microseconds).

So, is there any problem switching from mnesia:ets to ets:lookup in this 
scenario? Has such a thing crossed anyone's mind?

Paulo Almeida

More information about the erlang-questions mailing list