<div dir="ltr"><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important">Hello Haskellers,</p>
<p style="margin:0px 0px 1.2em!important">I have been working through the <a href="http://book.realworldhaskell.org/read/profiling-and-optimization.html">Real World Haskell chapter on Profiling and Optimisation</a>, and got to the section <em>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">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">uvector</code>.</p>
<p style="margin:0px 0px 1.2em!important">Does anyone know how to rewrite this to not use deprecated libraries?</p>
<p style="margin:0px 0px 1.2em!important">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">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">vector</code>, but my version consumes a lot of memory.</p>
<p style="margin:0px 0px 1.2em!important">The code I have is here:</p>
<p style="margin:0px 0px 1.2em!important"><a href="https://github.com/haskell-works/hw-tutorial-performance/blob/master/hw-tutorial-performance-rwhe/Main.hs">https://github.com/haskell-works/hw-tutorial-performance/blob/master/hw-tutorial-performance-rwhe/Main.hs</a></p>
<p style="margin:0px 0px 1.2em!important">With that code, I get “1831 MB total memory in use”, which is terrible</p>
<p style="margin:0px 0px 1.2em!important">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"><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;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important">stack build --executable-profiling --library-profiling --ghc-options="-fprof-auto -rtsopts -auto-all -caf-all -fforce-recomp"

time /Users/jky/wrk/haskell-works/hw-tutorial-performance/.stack-work/install/x86_64-osx/lts-7.10/8.0.1/bin/hw-tutorial-performance-rwhe +RTS -sstderr -p -hy -RTS 1e7
</code></pre><p style="margin:0px 0px 1.2em!important">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">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">Double</code>.</p>
<p style="margin:0px 0px 1.2em!important">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">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">Data.Vector</code></p>
<p style="margin:0px 0px 1.2em!important">Any help appreciated.</p>
<p style="margin:0px 0px 1.2em!important">Cheers,</p>
<p style="margin:0px 0px 1.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