bennofs / th-lift-instances

Lift instances for common haskell data types
http://hackage.haskell.org/package/th-lift-instances
Other
12 stars 11 forks source link

Instances for ByteString lead to long compile times and lots of memory usage #4

Closed mgsloan closed 5 years ago

mgsloan commented 8 years ago
{-# LANGUAGE TemplateHaskell #-}
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BSC
import System.IO.Unsafe (unsafePerformIO)
import Data.ByteString.Unsafe (unsafePackAddressLen)
import Language.Haskell.TH
import Language.Haskell.TH.Syntax
import Data.Word (Word8)

With code similar to what th-lift-instances uses:

main :: IO ()
main = BSC.putStrLn
    $([|BS.pack $(lift (replicate 65536 42 :: [Word8]))|])

time stack ghc -- --make th-lift-instances-test1.hs in th-utilities yields

[1 of 1] Compiling Main             ( th-lift-instances-test1.hs, th-lift-instances-test1.o )
^C^C

real    1m11.212s
user    0m56.148s
sys 0m1.824s

I had to cancel it because I was running out of memory and my computer was getting sluggish.

Instead, something like the following should be used:

main :: IO ()
main = BSC.putStrLn
    $([|unsafePerformIO (unsafePackAddressLen 65536 $(litE (stringPrimL (replicate 65536 42))))|])

yields

[1 of 1] Compiling Main             ( th-lift-instances-test2.hs, th-lift-instances-test2.o )
Linking th-lift-instances-test2 ...

real    0m1.324s
user    0m0.980s
sys 0m0.152s
mgsloan commented 8 years ago

I'm working on a PR for this

mgsloan commented 7 years ago

BTW, I have not forgotten about this. Plan is to put the requisite utilities into store-core and make it a dep of th-lift-instances.

phadej commented 5 years ago

Does store-core works with GHCJS, related to #9 ?

mgsloan commented 5 years ago

Last time I checked most of store works with ghcjs: https://github.com/fpco/store/issues/43 . Main exception is the instance for integer, but that should be straightforward to fix if it's needed.

On Wed, Jan 30, 2019, 08:31 Oleg Grenrus <notifications@github.com wrote:

Does store-core works with GHCJS, related to #9 https://github.com/bennofs/th-lift-instances/issues/9 ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bennofs/th-lift-instances/issues/4#issuecomment-459011547, or mute the thread https://github.com/notifications/unsubscribe-auth/AABYKtq2OQilwmY8dOwmsKmwYWGoG3vtks5vIcjtgaJpZM4IzuLu .