Skip to content

Consider replacing Foundation JSON encoder #153

Closed
@pokryfka

Description

@pokryfka

Given that:

  • Foundation JSON encoder/decoder has terrible performance on Linux (~10 times slower than PureJSONSwift and IkigaJSON
  • swift-aws-lambda-runtime runs on Linux
  • AWS Lambda handler does a lot of JSON decoding/encoding, including:
    • AWS Lambda Runtime API
    • JSON payloads delivered as String (APIGateway, DynamoDB, SNS, SQS, ...)
  • most people dont change the default implementation assuming libraries are well tuned
  • swift-aws-lambda-runtime performance is compared against other runtimes: https://www.twitch.tv/videos/661855412?t=04h53m04s
  • as far as AWS Lambda is concerned, time literally costs money

Consider:

  • replacing Foundation JSON encoder/decoder with PureJSONSwift or IkigaJSON
  • recommend not to use it describing how to change it
  • improve performance of Foundation JSON on Linux

Performance comparison:

From PureJSONSwift

Encoding

macOS Swift 5.1 macOS Swift 5.2 Linux Swift 5.1 Linux Swift 5.2
Foundation 2.61s 2.62s 13.03s 12.52s
PureSwiftJSON 1.23s 1.25s 1.13s 1.05s
Speedup ~2x ~2x ~10x ~10x

Decoding

macOS Swift 5.1 macOS Swift 5.2 Linux Swift 5.1 Linux Swift 5.2
Foundation 2.72s 3.04s 10.27s 10.65s
PureSwiftJSON 1.70s 1.72s 1.39s 1.16s
Speedup ~1.5x ~1.5x ~7x ~8x

From aws-xray-sdk-swift

(Average) results in seconds of EncodingTests from run 191224345

Test test-macos (5.2.4) test-linux (swift:5.2) test-linux (swiftlang/swift:nightly-5.3-bionic)
testEncodingUsingFoundationJSON 0.884 2.258 2.293
testEncodingUsingIkigaJSON 0.518 0.262 0.248
testEncodingUsingPureSwiftJSON 0.497 0.347 0.328

Metadata

Metadata

Labels

area/documentationImprovements or additions to documentation.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions