[erlang-questions] overhead of lists:dropwhile/2
Sun Apr 26 11:21:26 CEST 2015
On Sat, Apr 25, 2015 at 3:10 PM, Tuncer Ayaz <> wrote:
> While reviewing BjornG's compiler optimization in master, I've
> noticed one pattern of optimization which at least to me isn't
> as evident.
I admit that the optimizations are tiny and that I have
set a bad example by doing micro-optimizations.
Don't try this at home! :-) lists:dropwhile/2 is a fine
function and very rarely will you gain something by
> I've reviewed the implementation of lists:dropwhile/2, and the
> only difference I can see is that a call to the predicate fun is
> avoided. Is that the - now removed - speed bump, or am I missing
> something? If so, does it have to be a speed bump?
You have missed the cost of building the fun
that is passed to lists:dropwhile/2. If lists:dropwhile/2
drops many items from the list, that cost will not be
noticeable. But it will be noticeable if no or few elements
are dropped from the list. For example, in beam_utils,
there is almost never any label to drop (i.e. the
fun would only be called once for each call to
lists:dropwhile/2). Similarly, in beam_jump it is
also fairly common that nothing is dropped.
Björn Gustavsson, Erlang/OTP, Ericsson AB
More information about the erlang-questions