New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better unsafe perform io #325
Better unsafe perform io #325
Conversation
e8b3679
to
fab12cf
Compare
The previous code was struggling to create artificial dependencies to prevent `unsafePerformIO` calls from being floated out of their proper context. Push the context into each `unsafePerformIO` call so the dependency is real. Reading a bit of the resulting Core, I don't expect to see many (if any) performance regressions. Performance will hopefully improve a bit if/when [GHC issue 15127](https://gitlab.haskell.org/ghc/ghc/issues/15127) is fixed.
fab12cf
to
9bf7cb5
Compare
I believe it should be safe to use |
unsafeBuildDynamic readV0 v' = Dyn $ unsafeNewIORef x $ UnsafeDyn x | ||
where x = (readV0, v') | ||
unsafeBuildDynamic readV0 v' = | ||
Dyn $ unsafePerformIO $ newIORef $ UnsafeDyn (readV0, v') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this gets called many times, then it might be worth working around GHC 15127 by using runRW#
manually to unbox the IORef
.
unsafeNewIORef :: a -> IORef a
unsafeNewIORef a = IORef $ STRef ( runRW# $ \s ->
case newMutVar# a (noDuplicate# s) of
(# _s', mv #) -> mv )
or
unsafeDupableNewIORef :: a -> IORef a
unsafeDupableNewIORef a = IORef $ STRef ( runRW# $ \s ->
case newMutVar# a s of
(# _s', mv #) -> mv )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it does - because unsafeBuildDynamic is not a very frequently used function. Current benchmarks show no significant difference (for any of these changes)
* 'release/0.6.2.1' of github.com:ryantrinkle/reflex: (30 commits) Loosen monoidal-containers version bounds Update CONTRIBUTING.md Update CONTRIBUTING.md Use unsafePerformIO better (#325) Generalize fan following DMap (#318) Distribute more generally Generalize merge Drop *Tag classes Fix deprecation warnings related to updated Data.Some Bump dependent-sum to latest version fan: Rewrite haddock Replace hackage link with badge Use Some for more existential types (which should be efficient now that it is a newtype) Bump upper bounds Typo DRY conditional compilation Bump 'these' upper bound Typo Update changelog for holdDyn fix Make holdDyn lazy in its Event again ...
This reverts commit dc3ce15.
This reverts commit dc3ce15.
This reverts commit dc3ce15.
The previous code was struggling to create artificial dependencies
to prevent
unsafePerformIO
calls from being floated out of theirproper context. Push the context into each
unsafePerformIO
callso the dependency is real. Reading a bit of the resulting Core,
I don't expect to see many (if any) performance regressions.
Performance will hopefully improve a bit if/when
GHC issue 15127
is fixed.