Skip to content

GHC.Event.Thread.eventManager has a lot of indirections

Current eventManager:

eventManager :: IORef (IOArray Int (Maybe (ThreadId, EventManager)))
eventManager = unsafePerformIO $ do
...

That's a lot of indirections just to grab your thread's event manager.

Consider the following, which I believe would improve the performance of this:

data UnliftedIORef :: TYPE 'UnliftedRep -> Type where
  UnliftedIORef :: MutVar# RealWorld a -> UnliftedIORef a

eventManager :: UnliftedIORef (MutableArray# RealWorld Things)

data Things = Things !ThreadId !EventManager

I think the Maybe can be eliminated. I'm unsure. What makes me think it can be is the following snippet:

getSystemEventManager :: IO (Maybe EventManager)
getSystemEventManager = do
  t <- myThreadId
  (cap, _) <- threadCapability t
  eventManagerArray <- readIORef eventManager
  mmgr <- readIOArray eventManagerArray cap
  return $ fmap snd mmgr

getSystemEventManager_ :: IO EventManager
getSystemEventManager_ = do
  Just mgr <- getSystemEventManager
  return mgr
{-# INLINE getSystemEventManager_ #-}
Trac metadata
Trac field Value
Version 8.6.2
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component libraries/base
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information