TIL `JSONDecoder`, `JJLISO8601DateFormatter`; Read Caching in Swift
TIL ZippyJSON:
When should you use this library?
At first, default to using
JSONDecoder
. It’s very battle-tested, and for plenty of use cases is just fine. Then, once you start looking for new things to optimize, take a look at how long your JSON parsing is taking. After all, JSON parsing can be a bottleneck for getting data to the user. As a rule of thumb, divide its current time taken by 4 to approximate the time taken withZippyJSON
. If that difference is significant to you (and even milliseconds can impact a user experience!), then consider usingZippyJSON
.
TIL JJLISO8601DateFormatter - a 10x+ faster drop-in replacement for NSISO8601DateFormatter:
Why is it so much faster?
There’s nothing special about the library. It is written in straight-forward C and tries to avoid unnecessary allocations, locking, etc. It uses versions of mktime and localtime from tzdb. A better question is, why is Apple’s so much slower? Apple’s date formatting classes are built on top of ICU, which although reliable, is a fairly slow library. It’s hard from a glance to say exactly why, but it seems to have a lot of extra abstraction, needless copying, etc., and in general doesn’t prioritize performance as much.
May be useful Caching in Swift.
Interesting case The Curious Case of the Core Data Crash how not proper finishing background execution could crash app.