<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="">Hi Geordie,<div class=""><br class=""></div><div class="">The choice of NSData instead of String was very deliberate for NSJSONSerialization. The reason is that JSON is received from disk or the network as a data blob, not a String. Converting it into a String requires figuring out the encoding and doing a conversion. NSJSONSerialization looks at the leading bytes and then parses the data directly instead of converting the entire thing to a String first. This is a major perf boost, since there is usually a huge portion of the data which never needs to be a string (numbers, for example). Only actual result Strings need the conversion.</div><div class=""><br class=""></div><div class="">On a higher-level note, I agree with the approach of implementing the existing API first before considering alternate APIs. There is no doubt that dealing with untyped JSON output in Swift results in a less than ideal experience of casts or other things. I want to think about how to improve it, but first I want to make sure we have our cross-platform story in place. This means that clients of Foundation can simply use the same NSJSONSerialization API that they are used to and get the results that they expect.</div><div class=""><br class=""></div><div class="">- Tony</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 5, 2015, at 8:58 AM, Geordie Jay &lt;<a href="mailto:geojay@gmail.com" class="">geojay@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><span id="mailbox-conversation" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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 class="">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 class=""><br class=""></div><div class="">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 style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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 class="gmail_quote" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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;"><p class="">On Sat, Dec 5, 2015 at 5:29 PM, Geordie Jay<span class="Apple-converted-space">&nbsp;</span><span dir="ltr" class="">&lt;<a href="mailto:geojay@gmail.com" target="_blank" class="">geojay@gmail.com</a>&gt;</span><span class="Apple-converted-space">&nbsp;</span>wrote:<br class=""></p><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div class=""><span id="mailbox-conversation" class=""><div class=""><div style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; color: rgb(73, 79, 80);" class="">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.</div><div style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; min-height: 17px; color: rgb(73, 79, 80);" class=""><br class=""></div><div style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; color: rgb(73, 79, 80);" class="">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.</div><div style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; min-height: 17px; color: rgb(73, 79, 80);" class=""><br class=""></div><div style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; color: rgb(73, 79, 80);" class="">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.</div></div></span><br class=""><br class=""><div class="gmail_quote"><p class="">On Sat, Dec 5, 2015 at 5:17 PM, Tom Leavy<span class="Apple-converted-space">&nbsp;</span><span dir="ltr" class="">&lt;<a href="mailto:tom@wickr.com" class="">tom@wickr.com</a>&gt;</span><span class="Apple-converted-space">&nbsp;</span>wrote:<br class=""></p><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div dir="auto" class=""><div class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">Thomas Leavy | Wickr Inc.<br class="">VP Mobile Applications &amp; Architecture |&nbsp;<a dir="ltr" href="x-apple-data-detectors://0/1" class="">Newark, NJ</a><br class=""></span></div></div><div class=""><br class="">On Dec 4, 2015, at 6:24 PM, swizzlr &lt;<a href="mailto:me@swizzlr.co" class="">me@swizzlr.co</a>&gt; wrote:<br class=""><br class=""></div><blockquote type="cite" class="">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.<span class="Apple-converted-space">&nbsp;</span><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: 0px !important; margin: 0px !important; padding: 0px !important;" class=""></div></blockquote></div><br class=""></div></blockquote></div><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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=""><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=U7z7oSqRMSwdl2rYt9JJ4zIFaeg4R-2FxExg9xndDuCbzACIcYvqnF-2BvzNvI-2B5Xjd9zW7s1LIS4goRQcCPcbmOWgw-2Fd6alwrAp84KdPq66qyzlJoGI1Y1OCvoQzd1W2EVDTN6FeJAGC13kCMhwVmcU9fiCKibi7VHh-2Bd2iGuClewHSHSXNHOxwVLcMWdI1smYOflR-2BSJ3W-2B5tptQPrzNL3R-2FH18ZSFPnnMcc4kLXHJabo-3D" alt="" width="1" height="1" border="0" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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; height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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=""><span class="Apple-converted-space">&nbsp;</span>_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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="">swift-corelibs-dev mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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=""><a href="mailto:swift-corelibs-dev@swift.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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="">swift-corelibs-dev@swift.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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=""><a href="https://lists.swift.org/mailman/listinfo/swift-corelibs-dev" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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="">https://lists.swift.org/mailman/listinfo/swift-corelibs-dev</a></div></blockquote></div><br class=""></div></body></html>