Coder Social home page Coder Social logo

Comments (38)

zabolotiny avatar zabolotiny commented on June 9, 2024

@michaeleisel Can you please give me a hint how to fix this?

from zippyjson.

zabolotiny avatar zabolotiny commented on June 9, 2024

@michaeleisel The issue happens here:
func decode<T>(_ type: T.Type) throws -> T where T : Decodable { try ensureArrayIsNotAtEnd() let decoded = try decoder.unbox(currentValue, as: T.self) advanceArray() return decoded }
image

it is called from extension for decoding a heterogeneous list of objects for a given family in Lottie library

func decode<T : Decodable, U : ClassFamily>(_ heterogeneousType: [T].Type, ofFamily family: U.Type, forKey key: K) throws -> [T] { var container = try self.nestedUnkeyedContainer(forKey: key) var list = [T]() var tmpContainer = container while !container.isAtEnd { let typeContainer = try container.nestedContainer(keyedBy: Discriminator.self) let family: U = try typeContainer.decode(U.self, forKey: U.discriminator) if let type = family.getType() as? T.Type { list.append(try tmpContainer.decode(type)) } } return list }

image

Maybe you can give some hint here?

from zippyjson.

michaeleisel avatar michaeleisel commented on June 9, 2024

I'll take a look soon

from zippyjson.

michaeleisel avatar michaeleisel commented on June 9, 2024

Could you send me a main.swift that reproduces the issue?

from zippyjson.

zabolotiny avatar zabolotiny commented on June 9, 2024

@michaeleisel Hi, can you please check the fork of lottie https://github.com/sheff1422/lottie-ios.git . Please use branch ZippyJSON . Just run example on the simulator and you will see the issue.
I will be checking this thread during today so let me know if i can help u somehow.

from zippyjson.

michaeleisel avatar michaeleisel commented on June 9, 2024

The issue is with having multiple simultaneous references to an unkeyed container, and how mutations to one affect the other with ZippyJSON. Swift makes things difficult without a copy constructor

from zippyjson.

zabolotiny avatar zabolotiny commented on June 9, 2024

@michaeleisel I also came up to this yesterday. But not sure what solution i can apply safely without breaking anything.... Any ideas?

from zippyjson.

michaeleisel avatar michaeleisel commented on June 9, 2024

Let me think about how to solve it, it may require some architectural changes

from zippyjson.

zabolotiny avatar zabolotiny commented on June 9, 2024

@michaeleisel I am ready to participate. Maybe you can share your ideas?

from zippyjson.

michaeleisel avatar michaeleisel commented on June 9, 2024

it may involve memcpy to replicate C++ objects, which is technically undefined behavior. it will need some experimentation, and i don't want to have you do changes only to reject them. i'll take care of this in the next couple weeks

from zippyjson.

zabolotiny avatar zabolotiny commented on June 9, 2024

@michaeleisel Sorry for bothering u. How it is going? I am looking for some alternative ways to fix performance at our project rn but your library looks very promising.

from zippyjson.

michaeleisel avatar michaeleisel commented on June 9, 2024

Hi, it may take a bit for me to do this. Youโ€™re free to fork either lottie or my project to do what you want

from zippyjson.

michaeleisel avatar michaeleisel commented on June 9, 2024

I haven't forgotten about this, a fix is incoming. Just a lot of yak shaving to do for it

from zippyjson.

michaeleisel avatar michaeleisel commented on June 9, 2024

if you have time, please give latest master a shot and see if it fixes it, i.e. as part of release testing before i cut a release

from zippyjson.

michaeleisel avatar michaeleisel commented on June 9, 2024

(also, make sure you fix ZippyJSONCFamily, its dependency, at that one's latest master), e.g. using dev cocoapds

from zippyjson.

zabolotiny avatar zabolotiny commented on June 9, 2024

@michaeleisel I will check that during nearest 2 days

from zippyjson.

zabolotiny avatar zabolotiny commented on June 9, 2024

@michaeleisel Unfortunately the problem is still there :(
valueNotFound(Any, Swift.DecodingError.Context(codingPath: [JSONKey(stringValue: "layers", intValue: nil), JSONKey(stringValue: "Index 9", intValue: 9)], debugDescription: "Cannot get next value -- unkeyed container is at end.", underlyingError: nil))
To reproduce you can check this repo:
https://github.com/sheff1422/lottie-ios.git
branch: Zippy-Json-experiments

from zippyjson.

zabolotiny avatar zabolotiny commented on June 9, 2024

@michaeleisel ๐Ÿ‘†

from zippyjson.

michaeleisel avatar michaeleisel commented on June 9, 2024

yeah i see it

from zippyjson.

michaeleisel avatar michaeleisel commented on June 9, 2024

new fix is in latest master, i've tested your case and it goes from broken to fixed

from zippyjson.

zabolotiny avatar zabolotiny commented on June 9, 2024

@michaeleisel thank you, i will test tomorrow in the morning and get back to this ticket with the feedback

from zippyjson.

zabolotiny avatar zabolotiny commented on June 9, 2024

@michaeleisel Another update is required to make it work
image
After this change all looks correct.
I will measure performance tonight to understand the difference

from zippyjson.

zabolotiny avatar zabolotiny commented on June 9, 2024

@michaeleisel After that change it works but has a huge performance issues.
Decode times:

  1. try ZippyJSONDecoder().decode
    Time to decode animation 153.78289997577667 sec

  2. try JSONDecoder().decode
    Time to decode animation 1.1195780038833618

Tested on iPhone 7.
Maybe you can recommend something?

from zippyjson.

zabolotiny avatar zabolotiny commented on June 9, 2024

@michaeleisel Latest ver is available here https://github.com/zabolotiny/lottie-ios branch: Zippy-Json-experiments

from zippyjson.

michaeleisel avatar michaeleisel commented on June 9, 2024

what's your code to test for equality? JSONEncoder sadly produces non-deterministic output

from zippyjson.

michaeleisel avatar michaeleisel commented on June 9, 2024

by the way, if you'd like to add a some lottie decoding tests to the test suite, it'd help a lot. i can provide any support if you're interested

from zippyjson.

michaeleisel avatar michaeleisel commented on June 9, 2024

investigating further, i see what you mean about the bug. i will fix that. as for the performance, it's tricky because the slowdown comes from all the exceptions being thrown during json parsing, where it computes the codingPath. zippy json is optimized to only compute this in exceptional circumstances, and so here it's slower than apple

from zippyjson.

michaeleisel avatar michaeleisel commented on June 9, 2024

please try 1.2.1 and see if it works better for you - it looks good for me

from zippyjson.

zabolotiny avatar zabolotiny commented on June 9, 2024

@michaeleisel Sorry for late reply. I will check that. We are launching on the new market so i had no chance to check notifications. I will try get back to you with some info during this week.
Just some feedback from 1.1 -> when i was trying to change the build config and use production one. Time comparison was:
JSONDecoder().decode -> 1sec
ZippyJSONDecoder().decode -> 5sec

from zippyjson.

michaeleisel avatar michaeleisel commented on June 9, 2024

Yes, there was a clear bottleneck that has now been fixed

from zippyjson.

zabolotiny avatar zabolotiny commented on June 9, 2024

@michaeleisel Sorry for late response, I was testing it and with my complicated animation pack again:
ZippyJSON 1.2.1
iPad Air 1
Lottie (JSONDecoder) -> 3.3701289892196655s
Lottie (ZippyJSON) -> 3.8821139335632324s

from zippyjson.

zabolotiny avatar zabolotiny commented on June 9, 2024

@michaeleisel One more thing. When I say 1.2.1 -> I mean latest master.
If you think there is a chance to significantly improve performance I would love to help with some Lottie decoding tests.

from zippyjson.

michaeleisel avatar michaeleisel commented on June 9, 2024

Hi, can you explain exactly how to run this benchmark and reproduce these results? Also, have you ensured that you're testing with Release mode and not Debug?

from zippyjson.

michaeleisel avatar michaeleisel commented on June 9, 2024

Also, I noticed in Zippy-Json-experiments that it's not on 1.2.1, it's on 1.2.0

from zippyjson.

zabolotiny avatar zabolotiny commented on June 9, 2024

@michaeleisel Just noticed your message, I will try to find some time on weekends to setup easy project for you.
P.S. the version with 1.2.1 was not pushed. And I used debug mode, I will test in release also and let you know.
P.P.S.: It's pre Christmas rush here because of Appstore review team holidays. We want to ship a lot of stuff. So I am sorry for late replies.

from zippyjson.

michaeleisel avatar michaeleisel commented on June 9, 2024

Sounds good. And what do you mean "not pushed"? I see it in https://github.com/michaeleisel/ZippyJSON/tags and https://cocoapods.org/pods/ZippyJSON (but sometimes Cocoapods is bad at updating these things)

from zippyjson.

zabolotiny avatar zabolotiny commented on June 9, 2024

@michaeleisel Finally I am back again after releasing a big feature on my main project.
Fresh experiment is showing a great boost.
ZippyJSON 1.2.1
iPhone 7
Lottie (JSONDecoder) -> 0.326s
Lottie (ZippyJSON) -> 0.08 - 0.176s
Values significantly change when you test in release mode.
I want to add this to my project so I will make a PR to Lottie branch also in the nearest time.

from zippyjson.

michaeleisel avatar michaeleisel commented on June 9, 2024

Nice!

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.