Strange performance effects with unsafePerformIO

Simon Marlow marlowsd at gmail.com
Fri Apr 8 10:54:33 CEST 2011


On 07/04/2011 13:51, Björn Peemöller wrote:
> Simon Marlow schrieb:
>
>> Incidentally this will be faster with GHC 7.2, because we implemented
>> chunked stacks, so unsafePerformIO never has to traverse more than 32k
>> of stack (you can tweak the chunk size with an RTS option).  This is
>> still quite a lot of overhead, but at least it is bounded.
>>
>> The example above runs in 1.45s for me with current HEAD, and I gave up
>> waiting with 7.0.
>
> Thank you all for your explanations,
>
> the blackholing indeed seems to be the cause for the slowdown. Is there
> any documentation available about the blackholing process?

Unfortunately no.  But the main point is that unsafePerformIO needs to 
traverse the stack down to the most recent thunk evaluation, so the bad 
case happens when you're in a non-tail-recursive loop with no 
intervening thunk evaluations.

> Maybe we can find a hint on how to change our code to avoid the problem.

If you don't mind your unsafePerformIO being performed multiple times 
when running in parallel, then you can use unsafeDupablePerformIO to 
avoid the overhead.  Apart from that, there's really no way around it.

Cheers,
	Simon



More information about the Glasgow-haskell-users mailing list