-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
optimize: initial render, ladder effect when loading data #57
Comments
Is this new? I don't think I remember seeing behavior like that before... I'm going to try to devote a day this weekend to optimizing so I'll take a look, unless you get there before me 😅 |
@jmeistrich No, this is old issue, it was moderately annoyed by it for few weeks now. Also please note that this video is slowed down four times, so usually it's barely visible(and mostly on android). Also home tab of example app just became long enough, so issue is visible now. I suspect it was introduced by 28ef4f7#diff-2ced1af601733dfe729a60b7ff933e704c1740861e5bbe43066fb909bd51b483
We even request animation frame to make each container visible :) |
Oh yeah, I think you're right that that's the cause, and that it's just not super visible unless in slow motion 😅. So we probably should be queuing multiple updates into one batch instead of multiple animation frames. Should be easy to fix :) |
@jmeistrich Interesting fact @shopify/flashlist contains two native components, AutoLayoutView and CellContainer, which pretty much can be used by the LegendList. Using those we can avoid displaying containers in the invalid positions all together. |
I am hoping to solve layout purely in JS. I think it would be ideal for reducing installation complexity and supporting out of tree platforms. I think we should get as far as we possibly can with JS, and identify what things if any could be significantly improved with native code. It is definitely likely that a native auto layout view would fix that one frame delay from the position changing after being measured. But I think it might also be possible with use of Animated values or other JS-only tricks. So I think for now we should focus on making sure all the behavior is correct and get to a stable 1.0 soon, and then we can experiment with further optimizations? |
Do those native components from flashlist just drop straight in and work with no changes? |
I have this fixed. I'm just testing it more and doing other optimizations. I'll release an update shortly. |
@jmeistrich I've made lot's of experimenting with Animated and Reanimated, so far didn't found any performance benefit over just using just changing state. Thing that also wasn't yet explored is using sync measurement of the containers yet(in the new architecture):
I've checked that, and heights of all containers are actually already known before the first render, but modifying it is a bit of the problem, that's why I've took a look how Flashlist does it, and they solved it with a native module in a very similar manner. FlashList components are not readily available to be used by the LegendList because of slight differences in how recycled containers are handled, plus it's not compatible with maintainVisibleContentPosition. Things that would be hard to do with pure JS and may require native module:
My idea now is to create separate npm package with FlashLists AutoLayout components completely separated, and experiment a little bit more with it. If there is any good results with it, maybe we can create peerDependency to this module and optional prop for LegendList like unstableUseFlashListContainers which allow to enable feature for people who really need it. For now including any native code in the LegendList does not make sense to me too. |
@mbilenko-florio Very interesting! I wasn't aware that useLayoutEffect fires so much earlier than onLayout... But it seems like it won't really help because updating the positions needs another render anyway? I think you're right that it could solve the blank first frame, but I don't think that's a major issue for most apps. Of course there are certainly some where it could be a huge improvement, like in the movies example where it's rendering lots of horizontal lists. I still think there's a lot of room for optimizations before we reach for native as the way to improve performance. I just spent today optimizing and #58 seems to have a pretty big impact! It has a lot of small changes, but the last one significantly reduces how often As we talked about before, when switching between your "Implement advanced maintainVisibleContentPosition algorithm" commit and the one before it, I see it caused a drop in performance. But I was looking into it today and I can't figure out what specifically caused it. Especially since the reduction in number of calls to Do you have any ideas on how to optimize further? I think the current level of performance is shippable, so even though I want to keep optimizing, I think we should focus on stabilizing and making sure all features work as they should. So please let me know if you find any more release-blocking issues! I believe that #58 should fix the original problem in this post so please close this issue if it looks good to you? But these performance discussions are super interesting and we should continue them in a new issue? |
Issues seems to be fixed, moved discussion here #59 |
Initial render has little bit unpleasant effect of displaying element one by one.
Slowed down 4x video https://github.com/user-attachments/assets/373d6c93-5b98-44fe-b9b2-daac09f5b1f9
More desired would be to display all items at once, when elements was measured.
The text was updated successfully, but these errors were encountered: