Skip to content
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

hashMap forces a memory leak #8

Open
doyougnu opened this issue Jan 11, 2021 · 0 comments
Open

hashMap forces a memory leak #8

doyougnu opened this issue Jan 11, 2021 · 0 comments

Comments

@doyougnu
Copy link
Owner

doyougnu commented Jan 11, 2021

For some reason using a hashmap instead of an intmap causes a memory leak that slows down the solver, consider:

type Cache a b = Map.HashMap (StableName a) b
type ACache = Cache IL (V :/\ IL)

instance (Monad m, MonadIO m, MonadLogger m) =>
  Cacheable (SolverT m) IL (V :/\ IL) where
  memo !a go = do acc  <- readCache accCache
                  !i   <- liftIO $ makeStableName a
                  case Map.lookup i acc of
                    Just b -> do logInProducerWith "Acc Cache Hit on " a
                                 succAccCacheHits
                                 return b
                    Nothing -> do !b <- go
                                  logInProducerWith "Acc Cache miss on " a
                                  updateCache accCache $! Map.insert i b
                                  return b

just this causes a memory leak and I cannot find out why or where. Using an IntMap this leak goes away suggesting it is in the keys:

type Cache a = IMap.IntMap a
type ACache = Cache (V :/\ IL)

instance (Monad m, MonadIO m, MonadLogger m) =>
  Cacheable (SolverT m) IL (V :/\ IL) where
  memo !a go = do acc  <- readCache accCache
                  !i   <- liftIO $ hashStableName <$> makeStableName a
                  case IMap.lookup i acc of
                    Just b -> do logInProducerWith "Acc Cache Hit on " a
                                 succAccCacheHits
                                 return b
                    Nothing -> do !b <- go
                                  logInProducerWith "Acc Cache miss on " a
                                  updateCache accCache $! IMap.insert i b
                                  return b

This is especially weird because the hashable instance is essentially the exact same thing! (hashing just calls out the hashStableName:

instance Hashable (StableName a) where
    hash = hashStableName
    hashWithSalt = defaultHashWithSalt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant