[erlang-questions] '--' BIF to be used with caution?
Bjorn Gustavsson
bgustavsson@REDACTED
Wed Feb 4 11:48:38 CET 2009
2009/1/13 Malcolm Dowse <malcolm@REDACTED>:
> Hello,
>
> I ran into an issue with Erlang the other day. I'm not sure if it's a bug,
> but I thought I should warn others.
>
> I was using '--' to get the difference between two large lists. As expected
> it was very slow, but, to my surprise, ERTS became completely unresponsive
> for a long time. (Only one CPU was maxed out, and there was still plenty of
> memory available.)
>
> To reproduce (on Ubuntu 7.x, R12B-x), open an Erlang shell and type:
>
> spawn(fun() -> lists:seq(1,1000000) -- lists:seq(1,1000000,2) end).
>
> The unresponsiveness seems to be caused by '--' being a BIF. Is there a good
> reason for making it a BIF if it's not always an improvement?
I suppose it is a BIF because it is an operator (although that is not
strictly necessary).
Nowadays we always make new BIFs non-blocking ("trapping" as we call it) if they
can run for a long time, but we usually only fix old BIFs if there is
a real problem in a real
application.
I have added a warning note to the reference manual and to the documentation
for lists:subtract/2. (Will appear in R13A.)
/Bjorn
--
Björn Gustavsson, Erlang/OTP, Ericsson AB
More information about the erlang-questions
mailing list