Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analysis of JSON performance #1040

Closed
djones6 opened this issue Mar 22, 2017 · 0 comments
Closed

Analysis of JSON performance #1040

djones6 opened this issue Mar 22, 2017 · 0 comments
Assignees
Milestone

Comments

@djones6
Copy link
Collaborator

djones6 commented Mar 22, 2017

Serialization

SwiftyJSON currently uses LclJSONSerialization on Linux, as although JSONSerialization in Foundation is functionally equivalent, there are some remaining performance issues relating to serializing number types that need to be addressed.

Swift 3.1

Swift 3.1 gives us a 25-30% improvement in JSON serialization performance for LclJSONSerialization, compared to 3.0.2.

apple/swift-corelibs-foundation#718 and apple/swift-corelibs-foundation#723 are included in Swift 3.1, and reduce the performance gap. In 3.1, Foundation is on-par for Strings, but still 2x slower for number types (Int, UInt, Float, Double).

The reason: our Lcl implementation uses String(describing:) to convert these values to Strings, whereas Foundation uses a NumberFormatter (which is significantly slower). The Lcl method was not considered an acceptable solution in JSONSerialization, as it essentially delegates control over the output format to String.

A solution for Int / UInt types is being worked on by @ddunn2, who has a prototype which is showing promising results very close to performance of Lcl, but will not make it into 3.1.

We haven't tackled Double / Float yet - assuming David's algorithm is accepted, we may well be able to extend it to cover these types as well.

Benefit of bypassing SwiftyJSON

I saw around 10-20% performance improvement when using the new API introduced in #1025, in other words replacing
response.send(json: JSON([“a": 1, “b": 2, “c": 3]))
with
response.send(json: [“a": 1, “b": 2, “c": 3])

Parsing

I have not analyzed the parsing side. This needs work.

@djones6 djones6 self-assigned this Mar 22, 2017
@djones6 djones6 added this to the 2017.07 milestone Mar 22, 2017
@na-gupta na-gupta modified the milestones: 2017.08, 2017.07 Apr 6, 2017
@na-gupta na-gupta modified the milestones: 2017.09, 2017.08 Apr 19, 2017
@na-gupta na-gupta modified the milestones: 2017.10, 2017.09 May 3, 2017
@na-gupta na-gupta modified the milestones: 2017.11, 2017.10 May 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants