<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<style id="EHTipGlobalStyle">.EHTipToolTip * {background: inherit;font-family: inherit;font-size: inherit;font-size-adjust: none;font-stretch: normal;line-height: inherit;font-variant: normal;border: 0px;text-transform: inherit;color: inherit;font-style: inherit;text-decoration: inherit;margin: 0px 0px 0px 0px;padding: 0px 0px 0px 0px;float: none;display: inline;cursor: default;}
.EHTipReplacer, .EHTipKey, .EHTipAudio {cursor: pointer;}
.EHTipToolTip hr {margin: 0.4em 0;display: block;border: 1px inset;}
.EHTipTranslation {font-style: normal;}
.EHTipTranslation a {color: #000099;font-style: normal;text-decoration: none;}
.EHTipTranslation a:hover {background: inherit;color: #000000;text-decoration: underline;}
</style>
</head>
<body style="background-color: rgb(255, 255, 255); color: rgb(0, 0,
0);" text="#000000" bgcolor="#FFFFFF">
<p>Hello,</p>
<p>I've come to some strange results using Weigh package. <br>
</p>
<p>It shows that HashMap inside 'data' is using much, much more
memory. <br>
</p>
<p>The strange thing is that I'm seeing too large mem usage in my
app as well (several "MapData" like in records), and trying to
figure out with 'weigh' what's keeping the mem. <br>
</p>
<p>Noticed that when I change the code to use HashMap directly (not
inside 'data', that's the only change), the mem usage observed
with top drops down for ~60M, from 850M to 790M.<br>
</p>
<br>
<p>These are the test results for 10K, 5K and 3.3K items for "data
MapData k v = MapData (HashMap k v)" (at the end is the full
runnable example.)<br>
</p>
<p><font size="-1"><tt>Case Allocated GCs</tt><tt><br>
</tt><tt>HashMap 262,824 0</tt><tt><br>
</tt><tt>HashMap half 58,536 0</tt><tt><br>
</tt><tt>HashMap third 17,064 0</tt><tt><br>
</tt><tt>MapData 4,242,208 4</tt></font></p>
<p>I tested by changing the order, disabling all but one etc., and
the results were the same. Same 'weigh' behaviour with IntMap and
Map.<br>
</p>
<p><br>
</p>
<p>So, if anyone knows and has some experience with such issues, my
questions are:</p>
<p>1. Is 'weigh' package reliable/usable, at least to some extent?
(the results do show diff between full, half and third)</p>
<p>2. How do you measure mem consumptions of your large
data/records?</p>
<p>3. If the results are even approximately valid, what could cause
such large discrepancies with 'data'?</p>
<p>4. Is there a way to see if some record has been freed from
memory, GCed?<br>
</p>
<br>
<p><br>
</p>
<p><font size="-1"><tt>module Main where</tt><tt><br>
</tt><tt><br>
</tt><tt>import Prelude</tt><tt><br>
</tt><tt><br>
</tt><tt>import Control.DeepSeq (NFData)</tt><tt><br>
</tt><tt>import Data.HashMap.Strict (HashMap, fromList)</tt><tt><br>
</tt><tt>import GHC.Generics (Generic)</tt><tt><br>
</tt><tt>import Weigh (mainWith, value)</tt><tt><br>
</tt><tt><br>
</tt><tt><br>
</tt><tt>data MapData k v = MapData (HashMap k v) deriving
Generic</tt><tt><br>
</tt><tt>instance (NFData k, NFData v) => NFData (MapData k
v)</tt><tt><br>
</tt><tt><br>
</tt><tt>full, half, third :: Int</tt><tt><br>
</tt><tt>full = 10000</tt><tt><br>
</tt><tt>half = 5000</tt><tt><br>
</tt><tt>third = 3333</tt><tt><br>
</tt><tt><br>
</tt><tt>main :: IO ()</tt><tt><br>
</tt><tt>main = mainWith $ do</tt><tt><br>
</tt><tt> value "HashMap" ( mkHMList full)</tt><tt><br>
</tt><tt> value "HashMap half" ( mkHMList half)</tt><tt><br>
</tt><tt> value "HashMap third" ( mkHMList third)</tt><tt><br>
</tt><tt> value "MapData" (MapData $ mkHMList full)</tt><tt><br>
</tt><tt><br>
</tt><tt>mkHMList :: Int -> HashMap Int String</tt><tt><br>
</tt><tt>mkHMList n = fromList . zip [1..n] $ replicate n "some
text"</tt><tt><br>
</tt><tt><br>
</tt><tt><br>
</tt></font><br>
</p>
</body>
</html>