Thanks for the responses everyone, I&#39;ll try them out and see what happens :)<br>Andrew<br><br><div class="gmail_quote">On Fri, Jun 8, 2012 at 4:40 PM, Johan Tibell <span dir="ltr">&lt;<a href="mailto:johan.tibell@gmail.com" target="_blank">johan.tibell@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Andrew,<br>
<div class="im"><br>
On Thu, Jun 7, 2012 at 5:39 PM, Andrew Myers &lt;<a href="mailto:asm198@gmail.com">asm198@gmail.com</a>&gt; wrote:<br>
&gt; Hi Cafe,<br>
&gt; I&#39;m working on inspecting some data that I&#39;m trying to represent as records<br>
&gt; in Haskell and seeing about twice the memory footprint than I was<br>
&gt; expecting.  I&#39;ve got roughly 1.4 million records in a CSV file (400M on<br>
&gt; disk) that I parse in using bytestring-csv.  bytestring-csv returns a<br>
&gt; [[ByteString]] (wrapped in `type`s) which I then convert into a list of<br>
&gt; records that have the following structure:<br>
&gt;<br>
&gt;&gt; 3  Int<br>
&gt;&gt; 1 Text Length 3<br>
&gt;&gt; 1 Text Length 11<br>
&gt;&gt; 12 Float<br>
&gt;&gt; 1 UTCTime<br>
&gt;<br>
&gt; All fields are marked strict and have {-# UNPACK #-} pragmas (I&#39;m guessing<br>
&gt; that doesn&#39;t do anything for non primitives).  (Side note, is there a way to<br>
&gt; check if things are actually being unpacked?)<br>
<br>
</div>GHC used to complain when you use UNPACK with something that can&#39;t be<br>
unpacked, but that warning seems to have been (accidentally) removed<br>
in 7.4.1.<br>
<br>
The rule for unpacking is:<br>
<br>
* all product types (i.e. types with only one constructor) can be<br>
unpacked. This includes Int, Char, Double, etc and tuples or records<br>
their-of.<br>
* sum types (i.e. data types with more than one constructor) and<br>
polymorphic fields can&#39;t be unpacked.<br>
<div class="im"><br>
&gt; My back of the napkin memory estimates based on the assumption that nothing<br>
&gt; is being unpacked (and my very spotty understanding of Haskell data<br>
&gt; structures):<br>
&gt;<br>
&gt; Platform: 64 Bit Linux<br>
&gt; #  Type (Sizeof type (occasionally a guess))<br>
&gt;<br>
&gt; 3 * Int (8)<br>
&gt; 14 * Char (4) -- Text is some kind of bytestring but I&#39;m guessing it can&#39;t<br>
&gt; be worse than the same number of Char?<br>
&gt; 12  * Float (4)<br>
&gt; 18 * sizeOf (ptr) (8)<br>
&gt; UTC:  -- From what I can gather through :info in ghci<br>
&gt; 4 * (ptr) (8)<br>
&gt; 2 * Integer (16) -- Shouldn&#39;t be overly large, times are within 2012<br>
<br>
</div>All fields in a constructor are word aligned. This means that all<br>
primitive types take 8 bytes on a 64-bit platform, including Char and<br>
Float. You might find the following blog posts by me useful in<br>
computing the size of data structures:<br>
<br>
<a href="http://blog.johantibell.com/2011/06/memory-footprints-of-some-common-data.html" target="_blank">http://blog.johantibell.com/2011/06/memory-footprints-of-some-common-data.html</a><br>
<a href="http://blog.johantibell.com/2011/06/computing-size-of-hashmap.html" target="_blank">http://blog.johantibell.com/2011/06/computing-size-of-hashmap.html</a><br>
<a href="http://blog.johantibell.com/2011/11/slides-from-my-guest-lecture-at.html" target="_blank">http://blog.johantibell.com/2011/11/slides-from-my-guest-lecture-at.html</a><br>
<br>
Here&#39;s some more on the topic:<br>
<br>
<a href="http://stackoverflow.com/questions/3254758/memory-footprint-of-haskell-data-types" target="_blank">http://stackoverflow.com/questions/3254758/memory-footprint-of-haskell-data-types</a><br>
<a href="http://stackoverflow.com/questions/6574444/how-to-find-out-ghcs-memory-representations-of-data-types" target="_blank">http://stackoverflow.com/questions/6574444/how-to-find-out-ghcs-memory-representations-of-data-types</a><br>

<div class="im"><br>
&gt; I&#39;ve written a small driver test program that just parses the CSV, finds the<br>
&gt; minimum value for a couple of the Float fields, and exits.  In the process<br>
&gt; monitor the memory usage is 6.9G before the program exits.  I&#39;ve tried<br>
&gt; profiling with +RTS -hc but it ran for &gt;3 hours without finishing, it<br>
&gt; normally finishes within 4 minutes.  Anyone have any ideas for me?  Things<br>
&gt; to try?<br>
&gt; Thanks,<br>
&gt; Andrew<br>
<br>
</div>You could try to use a 32-bit GHC, which would use about half the<br>
memory. You&#39;re at the limit of the size of data that you can<br>
comfortably fit in memory on a normal desktop machine, so it might be<br>
time to consider a streaming approach.<br>
<span class="HOEnZb"><font color="#888888"><br>
-- Johan<br>
</font></span></blockquote></div><br>