[erlang-questions] Erlang APIs and JSON

Garrett Smith g@REDACTED
Sat Aug 31 14:44:51 CEST 2013

On Fri, Aug 30, 2013 at 6:38 PM, Erik Søe Sørensen <eriksoe@REDACTED> wrote:
> 2013/8/30 Garrett Smith <g@REDACTED>
>> Alternatively, if your JSON is acting more as a lookup table -- strip
>> off the one-tuple and use proplists:get_value - it's *very* efficient
>> with small lists (based on rough measurements, < 200 items).
> I feel obliged to point out that for {Key,Value} lists, it usually makes
> better sense to use lists:keyfind/3 instead of functions from the proplists
> module. Performance-wise, because it's faster by a factor of 3x for small
> lists and 10-15x for lists of length 30+ (keyfind is implemented in C, and
> so is hard to beat). And arguably semantic-wise as well, because the
> proplists module don't work quite the way many believe (it's not just
> [{_,_}] it handles).

You're absolutely right! I misspoke here -- the benchmarks I was
referred to use the *lists* module.

This silly benchmark shows at least that member tests for small lists
are roughly equivalent to members tests for small sets and dicts. Note
this is more a framework for getting *some* information on
storage/retrieval options and any absolute truth (as has been pointed
out many times in previous threads - benchmark results can change
wildly and unexpectedly under different circumstances).


> Whether that micro-benchmark difference has any impact on your system as a
> whole depends of course on how heavily it's used -- it did on one I worked
> on once --, but my view is that, all other things being equal, there's no
> reason to adopt proplists as a habit if it offers no other advantages over
> more lightweight functions.
> (Assuming that 'dict' is the obvious alternative when dealing with lookup
> tables: My quick meaurements indicate  that proplists:get_value() becomes
> slower than dict:fetch() at 6 elements; for lists:keyfind() vs. dict that
> doesn't happen until ~140 elements. At which point proplists is 16x slower
> than both.)
> Just my 2¢ - no nitpicking at all, it's just that you brought up
> performance...
> (in the same sentence as proplists)

Definitely grateful for the correction and elaboration! This is an
*Erlang* list after all :)


More information about the erlang-questions mailing list