shootout - nsieve-bits benchmark

Mikael Pettersson <>
Tue May 2 14:28:08 CEST 2006


Matthias Lang writes:
 > Kostis Sagonas writes:
 > 
 >  > I've kept quiet till now, because I did not want to reveal the HiPE
 >  > magic to the world, 
 > 
 > So, finally, zero-copy message passing is possible in Erlang. I offer
 > the first example of abuse.
 > 
 > Matthias
 > 
 > ----------------------------------------------------------------------
 > 
 > -module(kostis).
 > -export([go/0]).
 > 
 > go() ->
 >   Bin = hipe_bifs:bytearray(100, 0),
 >   spawn(fun() -> wait(Bin) end),
 >   timer:sleep(5000),
 >   hipe_bifs:bytearray_update(Bin, 0, 9).
 > 
 > wait(<<9, _/binary>>) -> io:fwrite("got the message\n");
 > wait(Bin) -> wait(Bin).

Neat :-)

Be advised that
1. Whether HiPE's bytearrays are copied or remain shared on message
   sends is unspecified, and currently depends on the heap model of
   the runtime system (private, shared, hybrid), and on the size of
   the array. IOW, you shouldn't rely on that aspect.
2. There are plans to change HiPE's bytearrays to improve performance.
   I'm not making any guarantees that this will preserve their
   behaviour wrt sharing/copying on message sends.

They are used to good measure in the HiPE compiler, and they are clearly
useful for fixing slow microbenchmarks, but programmers in general should
NOT rely on them in any way.

Now, if Erlang had general arrays with O(1) indexing and update operations
I would be a happy programmer. But there are sound reasons, both language-
philosophical ones and implementation-technical ones, why this is not the case.

/Mikael



More information about the erlang-questions mailing list