bignerdranch / Freddy

A reusable framework for parsing JSON in Swift.
MIT License
1.09k stars 120 forks source link

JSONParser in swift 4 is extremely slow for big data #264

Closed rafaelnobrepd closed 6 years ago

rafaelnobrepd commented 6 years ago

Large JSON responses ( > 1MB ) become extremely slow with 100% cpu for several minutes using the custom JSONParser in Swift 4. Instruments points to Array.append operations. Switching back to JSONSerialization improves the issue.

davidahouse commented 6 years ago

@rafaelnobrepd Do you have a snippet of the JSON you are testing with? I'm curious to see if it is due to the size of the JSON in general, or perhaps just a product of how the JSON is structured. In particular I'm wondering if the JSON represents many instances of a particular JSON object in an array?

Once I have some further details I'll create some measurement tests and do some investigation.

dabeku commented 6 years ago

Same issue here. My test case is a simple JSON with one field that contains around 2.5 MB of data. Deserialization - tested with breakpoint before and after

let jsonObject = try JSON(data: responseData!);

takes around 10 minutes.

zwaldowski commented 6 years ago

Like all Swift code, Freddy is not designed for performance in debug mode. Compile the framework with optimizations on to get the best performance.