<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>I started on the pretty printing side of it last night. There are going to be issues when Swift types are used within object hierarchy as the AnyObject bridging makes the original type unknown, especially true for the Swift.Bool type.&nbsp;</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">I'm not sure why we'd want to use C though. That seems to defeat the point.&nbsp;<br><br>Sent from my iPhone</div><div><br>On Dec 5, 2015, at 9:17 AM, Geordie Jay &lt;<a href="mailto:geojay@gmail.com">geojay@gmail.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><span id="mailbox-conversation"><div>Sorry to spam, but I’ve just run some tests re: memory usage and found that running NSJSONSerialization.JSONObjectWithData() repeatedly results in huge memory usage (unbounded into the gigabytes). The pure Swift version I’ve been working on remains at a constant and minimal ~2 MB memory usage.</div>
<div><br></div>
<div>I’m not sure what the reason for this is huge discrepancy is. I assume the current Foundation version is using as much memory as it can for efficiency, but this may be another reason not to trust NSJSONSerialization is the best possible outcome, especially for embedded systems, servers, and the like. Considering the minimal CPU time difference, I would again vote for a pure Swift version, and focus on improving the standard library decoding speeds if possible.</div></span><br><br><div class="gmail_quote"><p></p>On Sat, Dec 5, 2015 at 5:58 PM, Geordie Jay <span dir="ltr">&lt;<a href="mailto:geojay@gmail.com" target="_blank">geojay@gmail.com</a>&gt;</span> wrote:<br><p></p><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div>
<span id="mailbox-conversation"><div>What I’m not so sure about is the most efficient way of working with NSData in this context, considering we are very much assuming the data to have come from a String of some kind (correct me if I’m wrong). So it seems to me like taking NSData insead of just a String is a regression into Objective-C land.</div>
<div><br></div>
<div>Can anyone explain why we might want to do this rather than working in an idiomatic Swift way (obviously backwards compatibility is a big one – is it the only one?). The only other thing I can think of is that NSData can be streamed. That is going into territory that I haven’t dealt with in Swift yet though. Would love to hear some input from others on this.</div></span><br><br><div class="gmail_quote">
<p></p>On Sat, Dec 5, 2015 at 5:29 PM, Geordie Jay <span dir="ltr">&lt;<a href="mailto:geojay@gmail.com">geojay@gmail.com</a>&gt;</span> wrote:<br><p></p>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div>
<span id="mailbox-conversation"><div>
<p class="p1" style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; color: rgb(73, 79, 80);">I’m not sure about performance hit of calling C from Swift either (it should be statically linked, so I suspect there is none), but the performance is only marginally slower than NSJSONSerialization as is, in the pure Swift version I am making. My test character set is about 2000 characters long, running serialize on it 5000 times, my current Swift-only version takes 1 second for each test run, and the existing (C-backed) NSJSONSerialization takes about 0.75 seconds.</p>
<p class="p2" style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; min-height: 17px; color: rgb(73, 79, 80);"><br></p>
<p class="p1" style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; color: rgb(73, 79, 80);">The difference isn’t huge and I suspect with more optimisation of the Swift code and of the standard library (in particular comparing UTF16 strings) this gap would disappear. I for one would be in favour of a pure Swift solution for readability, and also as a challenge to improve the standard library’s performance.</p>
<p class="p2" style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; min-height: 17px; color: rgb(73, 79, 80);"><br></p>
<p class="p1" style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; color: rgb(73, 79, 80);">Another thing to note is that Swift is supposed to be future-proofed in terms of UTF String handling (I’m not sure about JSON though, to be honest – is it supposed to support CharSets beyond UTF8?), maybe having the strings decode in UTF16 by default is not such a bad idea, even if it has a minor performance hit for now.</p>
</div></span><br><br><div class="gmail_quote">
<p></p>On Sat, Dec 5, 2015 at 5:17 PM, Tom Leavy <span dir="ltr">&lt;<a href="mailto:tom@wickr.com">tom@wickr.com</a>&gt;</span> wrote:<br><p></p>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div dir="auto">
<div>I would rather go right to the end game here and just work on coding up an implementation of JSON encoding / decoding and making it conform to the NSJSONSerialization spec. I can set up a repo for us to work on it.&nbsp;</div>
<div><br></div>
<div>The main decision here, is do we code a small lib in C and then call it from the Swift side, or do we just write the entire implementation in Swift? From a performance standpoint C is usually my go to, but if we use swift with only structs and we really
 focus on minimizing use of functions that would be costly / do a lot of profiling and optimization we can get very close to equivalent performance? At least to the level of the current objective c / c version? I'm also not sure of potential performance penalties
 of calling C functions from swift. Someone with more knowledge will have to weigh in on that one.&nbsp;<br><br><div><span style="background-color: rgba(255, 255, 255, 0);">Thomas Leavy | Wickr Inc.<br class="">
VP Mobile Applications &amp; Architecture |&nbsp;<a dir="ltr" href="x-apple-data-detectors://0/1">Newark, NJ</a><br></span></div>
</div>
<div>
<br>
On Dec 4, 2015, at 6:24 PM, swizzlr &lt;<a href="mailto:me@swizzlr.co">me@swizzlr.co</a>&gt; wrote:<br><br></div>
<blockquote type="cite">Re: Rules on adding dependencies</blockquote>

This e-mail message is intended only for the named recipient(s) above and is covered by the Electronic Communications Privacy Act 18 U.S.C. Section 2510-2521. This e-mail is confidential and may contain information that is privileged or exempt from disclosure under applicable law. If you have received this message in error please immediately notify the sender by return e-mail and delete this e-mail message from your computer, mobile devices and any cloud storage backup systems as well as destroy any printed copy you might have made.

<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=gzeF687jF1KGxasikbmBm7cdEtERkoUWGCyj6DDeJrrc4HssABhdc-2B4hWxLmURIT0hv9-2BvntSu5RPBaI8-2F3uGdEIzCVD3EGZJxQHbghjFuhXesuIBprXSBw8FhcSP-2FuJRC-2BUDFLMfjym9j5Wc1y7Oh-2FA1yIiKky24PsNseI6zVOpzT88HjHpnKuOCvL6F49JUdR5UWEV6Uyk9ZsHFu1MbcB013zshrhMBwxUxQ5QoRA-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;"></div></blockquote>
</div>
<br></div></blockquote>
</div>
<br></div></blockquote></div><br><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=nE9rxSXA5G4kxsTVkgv43pXkLx-2B36P-2BPNJufHeY0dgcBtIdZ0LOQp0TyJ70hiBOgeDilqTR0SwxdZxNSYbRVqhtLoRXm-2B0p8OenGhZaPXnie4BK8GNDAIW6POLnlCAiaGY64OKKMhM9xt0X82FcHeT-2FrrwB4EjEVAMngwDrggduRrTrhRbsgfZL83V6J1AKN-2FiOWpaHDAh9mIFKKxV0EEW2vQnPCr0zmamO3KSz9Eck-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;">
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-corelibs-dev mailing list</span><br><span><a href="mailto:swift-corelibs-dev@swift.org">swift-corelibs-dev@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-corelibs-dev">https://lists.swift.org/mailman/listinfo/swift-corelibs-dev</a></span><br></div></blockquote></body></html>