-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
VirtualScroll does a complete reset when ANY item has changed. #11294
Comments
@masimplo yes, adding items at the tail is a cheap operation, I added this fast path not a long time ago.
I don't think that's true. let's say you remove the second item, and we are rendering from 50 to 100, we have to re update everything, since now we should be rendering from 49 to 99. It can be done, but feels like a very complicated problem. Each item can have a different size. But please, feel free to try improve the needsClean algorithm, I will be happy to assist you. |
mmmm maybe we can add another fast path if the change is not an addition or a removal? is that what you meant? |
I see. But if you are rendering the first 20 items and have a list of 1000 items though and a change happens at item say 500, I believe it is wasteful to recalculate everything, since nothing really changes for the VS. For Add/Delete to items before our current position, I will have to give it some thought, but I believe a more "surgical" approach might be in order (like finding the offending cell and adding/removing its height to top offsets or something similar, again I need to think about this before coming with a concrete solution). Side story on how I got into this |
I do agree, I am working in a PR |
But I think it does affect adding/removing before our current position... |
Can you play with #11297 ? |
Yeap, will keep you posted. |
I have added some comments to your PR. SummarisingCurrent state is:
With replacing the if statement inside the forEachOperation with the two proposed if statements 1 and 2 still stand, but 4 and 5 also take fast path if after lastRecord. I am now thinking about what should happen when an update happens in any position and not just after lastRecord. Do you think that a cleanup could be avoided, or is it that even an update could change the height of a record? And if so, could there be an optimisation where the user could specify that elements will have a fixed height and improve performance throughout operations? Take a look and let me know. |
@manucorporat I Just created pull request #11491 with what was discussed above. I also have figured out why VirtualTrackBy is not working and have a solution using a setter and re-initializing |
This has been greatly improved by merging #11297 |
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out. |
Ionic version: (check one with "x")
[ ] 1.x
[ ] 2.x
[x] 3.x
I'm submitting a ... (check one with "x")
[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/
Current behavior:
I have a list with 1000 items that is bound to a virtual scroll component. If I replace any of 1000 items with a new reference (i.e. items[500] = new Item();) then all components rendered inside the virtual scroll are destroyed and recreated.
Expected behavior:
The items should not be re-created especially if the affected item is not in the list of rendered items.
Steps to reproduce:
http://plnkr.co/edit/WljhJIp8ZDqAMshpCQPr?p=preview Please look at the console and notice that after 5 secs timeout all nodes are destroyed and re-created although a single item has changed.
Related code:
After some debugging I found that the decision of whether rendered items will be re-created is taken around line 423. If I understand correctly the only occasion when the rendered items will not be re-created, if any changes are present, is when you add an item at the end of the list, which does not make much sense.
I believe a better, but still not over-engineered implementation would be to set needClean only if an item matching a rendered item has changed.
@manucorporat I would love to hear you point of view here, in case I have understood something completely wrong.
Ionic info: (run
ionic info
from a terminal/cmd prompt and paste output below):The text was updated successfully, but these errors were encountered: