3 ms·
The world's fastest Objective-C JSON serializer/deserializer
This weekend, I finished writing the world's fastest Objective-C implementation of a JSON serializer/deserializer.
It has a simple API, compile clean (even with pedantic warnings), has 90% test coverage, and supports compiling with or without ARC.
Code is here: https://github.com/kstenerud/KSJSON
Benchmark is here: https://github.com/kstenerud/JSONCompare
- LinaLauneBaer 15y agoCan you explain what optimizations you made and what impact they had on the performance? Would be great to hear. Also: You are using a lot of "low level" API calls to Core Foundation. Have you tried using the Foundation classes instead? Did this have a huge impact on the performance? Thank you!
- kstenerud 15y agoI wrote a blog post showing some of the bigger optimizations: http://codeinhindsight.blogspot.com/2011/10/down-rabbit-hole-of-optimization.html http://codeinhindsight.blogspot.com/2011/10/down-rabbit-hole... Aside from the pokey NumberFormatter and "replaceOccurrencesOfString" calls, the biggest source of slowdown was the Objective-C calling mechanism itself. After that, it came down to minimizing even the CF API calls. They work fine, but they are generic routines, and you can get better speed by rolling your own specialized code for buffer management and such. In the end, the only thing I left to CF (aside from constructing the final objects) was unicode conversion.