|
|
|
|
|
by mnem
4207 days ago
|
|
I hacked together a quick reproduction of this since the author didn't provide any working code. I don't really know Swift and my Objective-C skills are pretty rusty at the moment, but it compiles and show similar performance characteristics: https://github.com/mnem/swift-json-speedtests The initial Swift version the author created uses a third party library for wrapping the JSON decoding and that library appears to create a metric shit ton (technical term) of short lived objects whilst performing its magic. I cobbled together a less memory insane version (likely similar to the one described as Obj-C in Swift - although I disagree with that description) which is an order of magnitude faster. Finally there is an Objective-C version which is an order of magnitude faster again. All tests were running on an iPhone 5s in release mode. Decoding JSON is an annoying task for most languages. That Swift decodes half a megabyte of JSON in a tenth of a second is a reasonable trade off, for me, when comparing it to the verbosity and occasional fiddlyness of working with Obj-C. It was quite nice to see how simple it was to mix Swift and Obj-C as I was creating this, so that suggests little downside to using Swift for the mundane tasks and coding specific bits in Obj-C when that's necessary for speed reasons - although Obj-C is not uniformly faster than Swift as noted in other articles. |
|