<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 17, 2015 at 8:26 PM, Dr. Olaf Klinke <span dir="ltr"><<a href="mailto:o.klinke@dkfz-heidelberg.de" target="_blank">o.klinke@dkfz-heidelberg.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb adM"><div class="h5">On Tue, 17 Feb 2015, Kim-Ee Yeoh wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
On Tue, Feb 17, 2015 at 5:05 PM, Dr. Olaf Klinke <<a href="mailto:o.klinke@dkfz-heidelberg.de" target="_blank">o.klinke@dkfz-heidelberg.de</a>> wrote:<br>
      I'd like to separate serialization (IO) from traversal of the stucture (pure), but how can one avoid the entire heap object from being built? Can lazyness be exploited?<br>
<br>
<br>
Something I didn't quite understand from your email is whether<br>
<br>
1. the data structure is being constructed and you'd like it simultaneously serialized to disk<br>
<br>
or<br>
<br>
2. it's already serialized and you'd like to perform pure traversals on it.<br>
<br>
Problem 1 is one of compute then write, problem 2 is one of read then compute.<br>
<br>
Lazy I/O, as in unsafeInterleaveIO, excels at 2.<br>
<br>
-- Kim-Ee<br>
<br>
<br>
</blockquote>
<br></div></div>
Both.<br>
<br>
The data structure is a search tree, which is intended to be used multiple times, so 1. applies. I guess that the only way to circumvent the memory bottleneck would be to serialize the part of the structure already constructed and use the already serialized part for constructing the rest, somehow without de-serializing it again.<br></blockquote><div><br></div><div>To an extent, the virtual memory of a modern operating system solves the memory bottleneck.<br><br></div><div>I'm curious what you were hoping for when thinking of exploiting laziness. If the search tree is truly huge, you'd probably resort to fancy (or fuzzy or both) algorithms to break up the work.<br></div><div><br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
2. also applies. Queries to the search tree traverse different paths of it, but one can not rule out that multiple queries will eventually have traversed the entire tree. Thus lazily de-serializing it may not be enough unless the garbage collector disposes of parts of the tree after each query. Which it won't, if we say something like this:<br>
<br>
search :: FilePath -> IO (Query -> Result)<br>
search treeOnDisk = do<br>
        searchtree <- decodeFile treeOnDisk<br>
        return (\query -> searchFor query searchtree)<br></blockquote><div> </div></div></div><div class="gmail_extra">No, gc _will_ reclaim memory if decodeFile uses unsafeInterleaveIO. Take a look at the lazy bytestrings package.<br><br></div><div class="gmail_extra">p.s. Your search function looks odd. Surely you mean something with the type signature: FilePath -> Query -> IO Result ?<br></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature">-- Kim-Ee</div></div>
</div></div>