Re: Performance of mnesia:select/2
Vance Shipley <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.general |
|---|---|
| Message-ID | <CAMoa0N+1Eont_Z1MgBWXwywLS=r37-iiGMfcPEKSsf=Bt3UhyQ@mail.gmail.com> |
On Fri, Feb 26, 2021 at 10:12 PM Jacob <[email protected]> wrote: > assuming that the match spec compiler does clever things with patterns, > I'd use select with the following > > MatchExpression = [ {{'_', K, '_'}, [], ['$_']} || K <- Keys ] Sure, that's better, my example is simplified from my real use case which has a more complicated fun(). > If did some quick measurements with plain ETS, timer:tc and 500 keys out > of 1000000 table entries and got: Thanks a bunch for doing what I should have. I understand that empirical test on your own environment is the last word but also interested in the 'why?' question. My intuition was that select could benefit from a lower level (C) implementation while interactive reads may involve more context switching. > * using pattern, [ordered_set]: 4532605 us > * using pattern, [set] : 4645525 us > * using pattern, [ordered_set, {keypos, 2}]: 3826 us (!!!) > * using pattern, [set, {keypos, 2}]: 5714 us (!!!) Yes, the point was to use the actual keys of the table. As I understand it {ets,mnesia}:select/? will optimize when keys or indexes are involved. -- -Vance