Comments (12)
ZippyJSON is actually slower, usually 2.5x or more, when I test it. Running Swift 5.7, Xcode 14 beta 3, macOS 12.5.1, on a 2019 iMac (Intel i9 8-core, 3.6 GHz). Usually takes ~23ms for JSONDecoder and ~67ms for ZippyJSON.
full code
private func decode() async throws {
let url:String = "https://api.weather.gov/alerts/active?status=actual"
let data:Data = try await X // get server response
for _ in 0..<10 {
async let zippy:Void = testZippy(data)
async let apple:Void = testApple(data)
let _:(Void, Void) = await (zippy, apple)
}
}
private func testApple(_ data: Data) async {
let started:Int64 = getCurrentTimeMilliseconds()
let response1:WeatherJSONResponse = try! JSONDecoder().decode(WeatherJSONResponse.self, from: data)
print("configure;testApple;took " + getElapsedTime(started: started))
}
private func testZippy(_ data: Data) async {
let started:Int64 = getCurrentTimeMilliseconds()
let response2:WeatherJSONResponse = try! ZippyJSONDecoder().decode(WeatherJSONResponse.self, from: data)
print("configure;testZippy;took " + getElapsedTime(started: started))
}
private func getCurrentTimeMilliseconds() -> Int64 {
return Int64( (Date().timeIntervalSince1970 * 1000.0).rounded() )
}
private func getElapsedTime(started: Int64) -> String {
return getElapsedTimeFromMilliseconds(elapsedMilliseconds: getCurrentTimeMilliseconds()-started)
}
private func getElapsedTimeFromMilliseconds(elapsedMilliseconds: Int64) -> String {
var elapsedMilliseconds:Int64 = elapsedMilliseconds
var elapsedSeconds:Int64 = elapsedMilliseconds / 1000
elapsedMilliseconds -= elapsedSeconds * 1000
let elapsedMinutes:Int64 = elapsedSeconds / 60
elapsedSeconds -= elapsedMinutes * 60
return (elapsedMinutes > 0 ? elapsedMinutes.description + "m" : "") + (elapsedSeconds > 0 ? elapsedSeconds.description + "s" : "") + Int(elapsedMilliseconds).description + "ms"
}
struct WeatherJSONResponse : Codable {
let features:[WeatherJSONResponseFeature]
}
struct WeatherJSONResponseFeature : Codable {
let id:String, properties:WeatherJSONResponseFeatureProperties?
}
struct WeatherJSONResponseFeatureProperties : Codable {
let id:String, event:String, description:String
let severity:String
let headline:String?, instruction:String?
let sent:String?, ends:String?, effective:String?, expires:String?
let affectedZones:[String]?
}
from zippyjson.
Are you compiling in release mode?
from zippyjson.
Production/release mode gives slightly better performance to both; ~20ms for JSONDecoder and ~57ms for ZippyJSON.
from zippyjson.
Similar case for me, though my JSON file is massive, ~2.6MB and it takes JSONDecoder 0.55s while it took ZippyJSON 3.3s, both debug mode.
from zippyjson.
@addy239 please do all measurements with release mode
@RandomHashTags on my arm mac I am seeing ~4ms for ZippyJSON and ~19ms for Apple, are you sure that you're on release? If so, can you make sure that you're on the latest version, 1.2.5? And try it on an actual phone if it's an iOS app? Note that switching to release generally makes a big difference for ZippyJSON, and doesn't speed up JSONDecoder (any "speed up" you see for JSONDecoder in release is actually just due to noise, beca
active.json.zip
use debug/release doesn't affect JSONDecoder, since it is already compiled). Also, in the attached .zip is the exact copy from that endpoint that I am using.
from zippyjson.
Results with release mode (iPhone 14 Pro, previously I used an iPhone Xs in Debug):
~0.24s with JSONDecoder
~0.36s with ZippyJSONDecoder
Same file as before.
from zippyjson.
Can you provide everything necessary for me to reproduce? I.e. the source code for the benchmarking, JSON models, and the JSON file itself.
from zippyjson.
I'm sorry I don't have the models in a form I can share as they are actively used in production and I'm not sure if only sharing the JSON file would be useful to you.
from zippyjson.
@addy239 please do all measurements with release mode
@RandomHashTags on my arm mac I am seeing ~4ms for ZippyJSON and ~19ms for Apple, are you sure that you're on release? If so, can you make sure that you're on the latest version, 1.2.5? And try it on an actual phone if it's an iOS app? Note that switching to release generally makes a big difference for ZippyJSON, and doesn't speed up JSONDecoder (any "speed up" you see for JSONDecoder in release is actually just due to noise, beca active.json.zip use debug/release doesn't affect JSONDecoder, since it is already compiled). Also, in the attached .zip is the exact copy from that endpoint that I am using.
Upon further investigation, I am getting 4-6ms using ZippyJSON and 19-20ms using JSONDecoder on my same machine, same code, release mode, running Xcode 14.1 beta 3 with toolchain Swift 5.7 Release 2022-09-12. The previously poor performance probably was my configuration some where, and not this library.
from zippyjson.
@addy239 without the code, it's hard for me to reproduce, and as with @RandomHashTags there may be some configuration issue. Closing...
from zippyjson.
@RandomHashTags do you mind to share what configuration affected performance ?
from zippyjson.
@RandomHashTags do you mind to share what configuration affected performance ?
Not sure exactly, but I'm pretty sure it was something with Xcode's build caching. After cleaning the build folder, closing Xcode and simulators completely, and reopening the project, the issue was resolved.
It is important to note that this was 9 months ago (and on an Xcode beta), so I am unconfidently guessing on how I fixed my issue at the time.
Another important note would be: the benchmark methodology is flawed, which can now be measured natively using the <Clock>.measure
function.
from zippyjson.
Related Issues (20)
- Xcode warnings HOT 4
- `michaeleisel/ZippyJSONCFamily` is missing commit for v1.2.4 HOT 2
- Are there dependencies blocking this library working on Linux? HOT 3
- Not enough bits to represent the passed value HOT 4
- ISO8601 with fractional seconds? HOT 2
- Warning: load of misaligned address HOT 1
- Failed to decode Decimal value HOT 1
- not able to parse an Int value that came as nil HOT 2
- First time of ZippyDecoding seems no improvement of CPU time cost HOT 6
- Fix SwiftUI Previews (support arm64 on simulators) HOT 5
- ZippyJSON 1.2.5 depends on JJLISO8601DateFormatter 0.1.4 which does not exist HOT 2
- [ZippyJSONDecoder] Warning: fell back to using Apple's JSONDecoder. HOT 4
- Cannot compile with Xcode 14.1 and 14.2 due to missing JNTErrorInfo and JNTGetErrorInfo HOT 3
- Update release notes with Release Optimisations HOT 2
- Xcode Warning HOT 2
- Reduce size impact of ZippyJSON
- occurs crash on iOS 13.x HOT 11
- Adding Benchmark HOT 3
- Crash during allocation on iOS 13 when app is built with Xcode 15 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zippyjson.