<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 20, 2016, at 10:47 AM, Jens Alfke via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On May 20, 2016, at 1:16 AM, Quinn The Eskimo! via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Alegreya-Regular; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">One of the nice things about the file system is that it has reasonable performance and error characteristics such that you /can/ deal with it synchronously. &nbsp;Revel in that fact!</span><br style="font-family: Alegreya-Regular; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote></div><br class=""><div class="">That’s only really true at small scales, for local filesystems, under light I/O loads. This happens to be true most of the time* for typical Mac/iOS app needs, but it’s not universal.</div><div class=""><br class=""></div><div class="">I believe most people in the Swift community today come from a Mac/iOS background, but as Linux support matures, and with IBM’s backing, that’s going to be less and less true in the future. Me, I’m one of the oddball “mobile guys” at a database company [Couchbase] whose customers [eBay, PayPal, Citi, etc.] very commonly have multi-terabyte data sets.</div></div></div></blockquote><div><br class=""></div><div>Couchbase looks like a great product. &nbsp;Cool to see someone from Couchbase is participating in Swift evolution!</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><span style="font-family: Alegreya-Regular;" class="">Consider the NSXMLDocument example again. &nbsp;This high-level one-shot API is layered on top of a low-level one-shot API.</span></blockquote><br class=""></div><div class="">The trouble with this is that those one-shot APIs tend to suck when working with data coming from the network, because you have to buffer the entire data set in memory, and you can’t start parsing it until the entire response is finished. If it does finish — there are protocols like XMPP/Jabber that use indefinitely-long streams of structured data like XML and can’t be parsed at all with one-shot APIs. I’ve recently had to replace NSJSONSerialization with a 3rd-party streaming JSON parser library, because the latency of reading large JSON documents over HTTP was getting in the way of performance and memory requirements.</div><div class=""><br class=""></div><div class="">Sorry if this is off-topic! What’s relevant is that I’d hate to see Apple’s historical bias toward one-shot I/O get in the way of Swift’s Foundation framework having a kick-ass stream API.</div></div></div></blockquote><div><br class=""></div><div>+1. &nbsp;There are many reasons to prefer streaming implementations. &nbsp;It is also possible to write high-level APIs with relatively simple interfaces that use streaming behind the scenes. &nbsp;The fact that this is not always done is not a good argument against providing robust streaming APIs. &nbsp;In fact, it should be considered a challenge to improve the state of the art.</div><div><br class=""></div><div>For example, I shared an example of a Ruby DSL I wrote that generated streaming XML parsers (in an Objective-C API and some C in the implementation) from the DSL which defined the structure of the document and how it maps to model objects. &nbsp;This was much <b class="">easier</b> to use than any DOM-based API (whether XML, JSON, or whatever) and was more efficient. &nbsp;It did not require the entire document to be in memory at once and did not construct all kinds of intermediate objects not needed by the model (dictionaries and arrays, etc). &nbsp;</div><div><br class=""></div><div>If / when Swift gets macros we should be able to implement something very similar directly in Swift without needing an intermediate code generation step. &nbsp;It may also be possible to do this a <i class="">better</i>&nbsp;way in Swift. &nbsp;</div><div><br class=""></div><div>The main point I am making here is that taking advantage of the benefits of streaming APIs does not need to be difficult at the application level.&nbsp;</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">—Jens</div><div class=""><br class=""></div><div class="">* But not always. I can attest that during OS startup, when dozens of processes are contending for the disk, reading a 10MB file can take an achingly long time by normal standards. This caused lots of “fun” during performance tuning of the PubSub framework. Also, remember the days when devs at Apple still had NFS-based home directories?</div></div>_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></body></html>