unsafeLocalState = unsafeDupablePerformIO?

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. The only way to get at unsafeDupablePerformIO currently is from GHC.IO, this would give users a legitimate way to get at a cheaper unsafePerformIO. Or perhaps we should just export unsafeDupablePerformIO from System.IO.Unsafe? Thoughts? Cheers, Simon

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.

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.)
Yes.
It might make sense to also export unsafeDupablePerformIO from System.IO.Unsafe, for single-threaded uses that don't conform to the unsafeLocalState contract.
Ok. Cheers, Simon
participants (2)
-
Paterson, Ross
-
Simon Marlow