unsafeLocalState = unsafeDupablePerformIO?

Paterson, Ross R.Paterson at city.ac.uk
Fri Jul 8 10:46:00 CEST 2011


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