Coder Social home page Coder Social logo

Comments (12)

RandomHashTags avatar RandomHashTags commented on June 26, 2024

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.

michaeleisel avatar michaeleisel commented on June 26, 2024

Are you compiling in release mode?

from zippyjson.

RandomHashTags avatar RandomHashTags commented on June 26, 2024

Production/release mode gives slightly better performance to both; ~20ms for JSONDecoder and ~57ms for ZippyJSON.

from zippyjson.

addy239 avatar addy239 commented on June 26, 2024

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.

michaeleisel avatar michaeleisel commented on June 26, 2024

@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.

addy239 avatar addy239 commented on June 26, 2024

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.

michaeleisel avatar michaeleisel commented on June 26, 2024

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.

addy239 avatar addy239 commented on June 26, 2024

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.

RandomHashTags avatar RandomHashTags commented on June 26, 2024

@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.

michaeleisel avatar michaeleisel commented on June 26, 2024

@addy239 without the code, it's hard for me to reproduce, and as with @RandomHashTags there may be some configuration issue. Closing...

from zippyjson.

robsontenorio avatar robsontenorio commented on June 26, 2024

@RandomHashTags do you mind to share what configuration affected performance ?

from zippyjson.

RandomHashTags avatar RandomHashTags commented on June 26, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.