-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
WrappingHStack causes high CPU usage #34
Comments
Ill try to inspect it when I can, but I didn't have much luck improving performance so far, since the View generics are very limiting |
This is what happens:
However, there is a problem where Also, in your specific case lazy loading might help, since the really bad performance you are seeing is related to the fact that you load everything at once:
I also would appreciate some help from the community ;) |
Hi Daniel! Thanks for your explanation! I tried the "LazyVStack" approach, and it actually reduces the number of calls a bit (344 initial calls compared to 597 calls without LazyVStack). This ~50% reduction also seems to be the case when interacting with the list. However, I am still hesitant to use it in production for longer lists. Would be great if someone has an idea how to optimize this further. 🙂🤞 |
Hi Daniel!
First of all: Thanks for your awesome work! :)
I noticed that using WrappingHStack in longer lists is quite CPU intensive (not sure if #4 already addresses my point - if so, feel free to close this issue).
Here is an example:
I checked what is causing the high CPU usage and found that the InternalWrappingHStack.init method is being called hundreds of times. Launching the app without further interaction already results in 597 calls. I made a small video that shows how a very small interaction skyrockets the number of calls:
initCalls.mp4
I have no clue what's going on. I believe that GeometryReader in WrappingHStack.swift triggers these calls. However, as the video shows, the width does not change at all. Is there a possibility to react only to relevant changes to reduce the number of InternalWrappingHStack.init calls significantly?
(I had some success by moving the GeometryReader out of WrappingHStack.swift into the view that uses WrappingHStack and passing the width to WrappingHStack, but my knowledge of SwiftUI is too limited to understand what's going on with the height in WrappingHStack.swift)
Again, thanks a lot! :)
The text was updated successfully, but these errors were encountered: