Created
February 2, 2018 10:28
-
-
Save m0ar/6feb721b545c2be9954efbd079a9d7ef to your computer and use it in GitHub Desktop.
Weird memory issue depending on type annotation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE StandaloneDeriving #-} | |
{-# LANGUAGE TypeFamilies #-} | |
module HaxlLab (mainHaxl) where | |
import Data.Hashable (Hashable (..)) | |
import Data.List (foldl') | |
import Haxl.Core | |
data Heavy a where | |
Mock :: Heavy Integer | |
instance DataSource () Heavy where | |
fetch _ _ _ reqs = SyncFetch $ | |
mapM_ (\(BlockedFetch req var) -> runHeavy req var) | |
reqs | |
runHeavy :: Heavy a -> ResultVar a -> IO () | |
runHeavy Mock var = do | |
-- This runs as expected: | |
let !n = foldl' (+) 0 [1..100000000] :: Integer | |
-- Without the type annotation it eats RAM like crazy | |
-- let !n = foldl' (+) 0 [1..100000000] | |
putSuccess var n | |
mainHaxl :: IO () | |
mainHaxl = do | |
env <- initEnv initialState () | |
summed <- runHaxl env $ dataFetch Mock | |
putStrLn $ "Result = " ++ show summed | |
initialState :: StateStore | |
initialState = stateSet NoState stateEmpty | |
deriving instance Show (Heavy a) | |
deriving instance Eq (Heavy a) | |
instance StateKey Heavy where | |
data State Heavy = NoState | |
instance Hashable (Heavy a) where | |
hashWithSalt salt _ = hashWithSalt salt () | |
instance DataSourceName Heavy where | |
dataSourceName _ = "Heavy" | |
instance ShowP Heavy where | |
showp _ = "Heavy" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment