[erlang-questions] Erlang APIs and JSON

Erik Søe Sørensen <>
Sat Aug 31 01:38:27 CEST 2013


2013/8/30 Garrett Smith <>

> 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).

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)

/Erik [like pushing a button]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130831/420774e3/attachment.html>


More information about the erlang-questions mailing list