<div dir="ltr">Try using foldl', usually that's the right thing to do for this kind of data structure.</div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Nov 27, 2016 at 2:39 PM, John Ky <span dir="ltr"><<a href="mailto:newhoggy@gmail.com" target="_blank">newhoggy@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">It looks like Haskell stack's profile options are defeating stream fusion.<div><br></div><div>Anyone know a work-around?<br><div><br></div></div></div><div class="HOEnZb"><div class="h5"><br><div class="gmail_quote"><div dir="ltr">On Mon, 28 Nov 2016 at 08:23 John Ky <<a href="mailto:newhoggy@gmail.com" target="_blank">newhoggy@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="m_4782240883915217247gmail_msg"><div class="m_4782240883915217247m_-9148532425262574777markdown-here-wrapper m_4782240883915217247gmail_msg"><p style="margin:0px 0px 1.2em!important" class="m_4782240883915217247gmail_msg">Hello Haskellers,</p>
<p style="margin:0px 0px 1.2em!important" class="m_4782240883915217247gmail_msg">I have been working through the <a href="http://book.realworldhaskell.org/read/profiling-and-optimization.html" class="m_4782240883915217247gmail_msg" target="_blank">Real World Haskell chapter on Profiling and Optimisation</a>, and got to the section <em class="m_4782240883915217247gmail_msg">Advanced techniques: fusion</em>, where I encountered some code using  <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="m_4782240883915217247gmail_msg">Data.Array.Vector</code> from the deprecated library <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="m_4782240883915217247gmail_msg">uvector</code>.</p>
<p style="margin:0px 0px 1.2em!important" class="m_4782240883915217247gmail_msg">Does anyone know how to rewrite this to not use deprecated libraries?</p>
<p style="margin:0px 0px 1.2em!important" class="m_4782240883915217247gmail_msg">I have tried to use <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="m_4782240883915217247gmail_msg">Data.Vector.Unboxed</code> from <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="m_4782240883915217247gmail_msg">vector</code>, but my version consumes a lot of memory.</p>
<p style="margin:0px 0px 1.2em!important" class="m_4782240883915217247gmail_msg">The code I have is here:</p>
<p style="margin:0px 0px 1.2em!important" class="m_4782240883915217247gmail_msg"><a href="https://github.com/haskell-works/hw-tutorial-performance/blob/master/hw-tutorial-performance-rwhe/Main.hs" class="m_4782240883915217247gmail_msg" target="_blank">https://github.com/haskell-<wbr>works/hw-tutorial-performance/<wbr>blob/master/hw-tutorial-<wbr>performance-rwhe/Main.hs</a></p>
<p style="margin:0px 0px 1.2em!important" class="m_4782240883915217247gmail_msg">With that code, I get “1831 MB total memory in use”, which is terrible</p>
<p style="margin:0px 0px 1.2em!important" class="m_4782240883915217247gmail_msg">Build run steps I used were:</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px" class="m_4782240883915217247gmail_msg"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre-wrap;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important" class="m_4782240883915217247gmail_msg">stack build --executable-profiling --library-profiling --ghc-options="-fprof-auto -rtsopts -auto-all -caf-all -fforce-recomp"

time /Users/jky/wrk/haskell-works/<wbr>hw-tutorial-performance/.<wbr>stack-work/install/x86_64-osx/<wbr>lts-7.10/8.0.1/bin/hw-<wbr>tutorial-performance-rwhe +RTS -sstderr -p -hy -RTS 1e7
</code></pre><p style="margin:0px 0px 1.2em!important" class="m_4782240883915217247gmail_msg">I get very large numbers of allocations of <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="m_4782240883915217247gmail_msg">Pair</code> and <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="m_4782240883915217247gmail_msg">Double</code>.</p>
<p style="margin:0px 0px 1.2em!important" class="m_4782240883915217247gmail_msg">There is also a very large upfront allocation <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="m_4782240883915217247gmail_msg">ARR_WORDS</code>, which I feared would happen when using <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="m_4782240883915217247gmail_msg">Data.Vector</code></p>
<p style="margin:0px 0px 1.2em!important" class="m_4782240883915217247gmail_msg">Any help appreciated.</p>
<p style="margin:0px 0px 1.2em!important" class="m_4782240883915217247gmail_msg">Cheers,</p>
<p style="margin:0px 0px 1.2em!important" class="m_4782240883915217247gmail_msg">-John</p>
<div title="MDH:SGVsbG8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FwcGVuIHdoZW4gdXNpbmcgYERhdGEuVmVjdG9yYDwvZGl2PjxkaXY+PGJyPjwvZGl2
PjwvZGl2PjxkaXY+QW55IGhlbHAgYXBwcmVjaWF0ZWQuPC9kaXY+PGRpdj48YnI+PC9kaXY+PGRp
dj5DaGVlcnMsPC9kaXY+PGRpdj48YnI+PC9kaXY+PGRpdj4tSm9objwvZGl2PjxkaXY+PC9kaXY+
PGRpdj48YnI+PC9kaXY+" style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0" class="m_4782240883915217247gmail_msg">​</div></div></div></blockquote></div>
</div></div><br>______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>