Very slow JSON parsing using EVReflection depending on iOS device


Very slow JSON parsing using EVReflection depending on iOS device



I am obtaining a json object containing an array of objects. I am willing to parse this json using the lib EVReflection.


EVReflection



The operation takes a while, so I decided to monitorize the steps I'm taking, and realized the parsing of the json can take up to 20 seconds depending on the device.



Using iPhone SE / iOS 11.4 it takes 4 seconds aprox.
Using iPhone 5 / iOS 10.3 it takes 20 seconds aprox.



I am wondering if such variation is normal just depending on devices/OS.



Should I just use another lib or is there anything I can do to speed up the operation?



This is the code I'm using:


func getParkings(update: Bool) -> Observable<[ParkingEvo]> {
if let x = parkings, !update {
return Observable.just(x)
} else {
print("STEP 1: Calling API for parkings (NSDate())")
return RxAlamofire.string(.get, PARKINGS_URL, parameters: getParameters(), headers: nil)
.map { self.parseParkings(json: $0) }
.do(onNext: { self.storeParkings($0) })
}
}

private func parseParkings(json: String) -> [ParkingEvo]{
print("STEP 2: Proceed to parse json (NSDate())")
let parkingsDTO = ParkingsDTO(json: json)
print("STEP 3: ParkingsDTO created (NSDate())")

return parkingsDTO.items
}



Between STEP2 and STEP3 there is the mentioned delay. Any idea on how to optimize this?



Thank you in advance.





I think that for better performance you should not use library based on reflection.
– Roman Podymov
Jun 28 at 16:08






I do not have any experience with EVReflection, but code written using the Codable protocol produces fully compiled code and works even nicer than typical reflection code I have seen (as you end up with nicely typed objects very quickly). In order to judge your timings you should post an example record of your JSON and the number of records you typically get.
– Patru
Jun 28 at 17:53


EVReflection


Codable




2 Answers
2



Try SwiftyJSON for parsing instead it is fast an easy check Hacking with swift



It is project 7 which you need to check



For the record I ended up using ObjectMapper instead of EVReflection and spared 80% of the parsing time.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Rothschild family

Cinema of Italy