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

[SR-12419] Large performance regression with JSONSerialization.jsonObject on Linux with Swift 5.2 #4393

Closed
swift-ci opened this issue Mar 26, 2020 · 1 comment

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-12419
Radar None
Original Reporter kuwerty (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Both tests conducted on the same Amazon EC2 g4dn.2xlarge instance within seconds of each other.

processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 85
model name  : Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
stepping    : 7
microcode   : 0x5002f00
cpu MHz     : 2499.998
cache size  : 36608 KB
physical id : 0
siblings    : 8
core id     : 0
cpu cores   : 4
apicid      : 0
initial apicid  : 0
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc aperfmperf tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single kaiser fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx avx512f rdseed adx smap clflushopt clwb avx512cd xsaveopt xsavec xgetbv1 ida arat pku
bugs        : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit
bogomips    : 4999.99
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:
Additional Detail from JIRA
Votes 2
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: 548b820a134ee2d1aff019be1e624774

Issue Description:

We're seeing a pretty huge performance regression with Swift 5.2 on Linux and using JSONSerialization.jsonObject.

With Swift 5.1 we decode a 30MB Json file in approx 4s but that takes around 50s with Swift 5.2.

/tmp/json$ /data/swift-5.1-DEVELOPMENT-SNAPSHOT-2020-01-28-a-ubuntu16.04/usr/bin/swiftc -O json.swift
/tmp/json$ time ./json

real    0m4.389s
user    0m4.328s
sys 0m0.060s
/tmp/json$ 
/tmp/json$ 
/tmp/json$ swift --version
Swift version 5.2 (swift-5.2-RELEASE)
Target: x86_64-unknown-linux-gnu
/tmp/json$ swiftc -O json.swift
/tmp/json$ time ./json

real    0m50.944s
user    0m50.868s
sys 0m0.072s

Test code is as follows:

import Foundation

func load() {
  let url = URL(fileURLWithPath: "foo.json")
  let data = try! Data(contentsOf: url)
  let dict = try! JSONSerialization.jsonObject(with: data, options: [])
  _ = dict
}

load()

The test json file is available at https://gist.github.com/kuwerty/56a3ab1427bffe6a346a640b77ef486b

It's been gzipped and then base64 encoded for github, the following should get it back:

cat foo.json.gz.base64 | base64 -d | gunzip >foo.json

It's definitely the JSON decoding, without that line the test completes in a few milliseconds.

While on the subject a 2017 MacBook Pro runs the same test (on Swift 5.2 or 5.1) in 0.4s. I know it's not an apples to apples comparison but the CPUs are in a similar class. The MBP is higher clocked but it's not close to explaining a 10x performance difference.

@swift-ci
Copy link
Contributor Author

Comment by Krister Wombell (JIRA)

Tested and fixed in Swift 5.2.1

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
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

1 participant