[Haskell-cafe] [Haskell-Cafe] Different memory profile in cabal project.

Thomas Vanhelden thomas.vanhelden at gmail.com
Fri Feb 24 11:11:06 UTC 2017

I have a (dummy) program that reads the contents of a file into a ByteString and then converts the ByteString to a Vector of Floats. To test the laziness of this program,  I’ve taken a slice of the the Vector and printed it to the standard output.

The program looks like this:

	import qualified Data.Vector.Unboxed as V
	import qualified Data.ByteString as BS
	import Data.Word
	import System.Environment
	import GHC.Int

	main = do
    		[file] <- getArgs
    		samples <- getSamplesFromFile file
    		let slice = V.slice 0 50000 samples
    		print slice
	getSamplesFromFile = fmap toVector . BS.readFile 

	toVector :: BS.ByteString -> V.Vector Float
	toVector bs =  vgenerate (fromIntegral (BS.length bs `div` 3)) $ \i ->
	     	myToFloat [BS.index bs (3*i), BS.index bs (3*i+1), BS.index bs (3*i+2)]
 	  	 myToFloat :: [Word8] -> Float
  	  	 myToFloat = sum . map fromIntegral 

	vgenerate n f = V.generate n (f . fromIntegral)

So I compile this program and generate a memory profile via:
ghc Main.hs -O2 -rtsopts -prof 
./Main debug48.wav +RTS -hy
hp2ps -e8in -c Main.hp
ps2pdf Main.ps
The file debug48.wav  is a 12.9MB file.
This is the result:

If I now create a cabal project and add the exact same program as the main file by:
mkdir testing
cd testing
cabal init
add the program’s code to src/Main.hs
add bytestring and vector to the build dependencies (in testing.cabal)
add -O2 -rtsopts -prof to the ghc-options (in testing.cabal)
cabal install
testing debug48.wav +RTS -hy
hp2ps -e8in -c testing.hp
ps2pdf testing.ps
This is the result:

How can there be such a big difference in memory usage, just by the code being part of a cabal project?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170224/4223466b/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2017-02-24 at 11.49.18.png
Type: image/png
Size: 101778 bytes
Desc: not available
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170224/4223466b/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2017-02-24 at 12.01.25.png
Type: image/png
Size: 90815 bytes
Desc: not available
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170224/4223466b/attachment-0003.png>

More information about the Haskell-Cafe mailing list