unsafeLocalState = unsafeDupablePerformIO?

Simon Marlow marlowsd at gmail.com
Fri Jul 8 12:43:03 CEST 2011

On 08/07/2011 09:46, Paterson, Ross wrote:
> Simon Marlow writes:
>> We currently have
>>     Foreign.Marshal.Unsafe.unsafeLocalState :: IO a ->  a
>>     unsafeLocalState = unsafePerformIO
>> however, unsafePerformIO in GHC is rather expensive, because it tries to
>> avoid the IO being executed more than once when there are multiple
>> processors.  However, for the cases that we claim unsafeLocalState is to
>> be used for, it would be safe to use the cheaper unsafeDupablePerformIO
>> instead.
> So code using unsafeLocalState as documented will go faster?  Sounds
> like a clear win.  That's part of the reason for documenting interfaces.
> (That code misusing it will get broken is a bonus.)


> It might make sense to also export unsafeDupablePerformIO from
> System.IO.Unsafe, for single-threaded uses that don't conform to the
> unsafeLocalState contract.



More information about the Libraries mailing list