-
Notifications
You must be signed in to change notification settings - Fork 277
[AI Task] [Tizen.NUI.Components] Remove unrealizedItems temp list in Linear/GridLayouter scroll path #7644
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
base: main
Are you sure you want to change the base?
[AI Task] [Tizen.NUI.Components] Remove unrealizedItems temp list in Linear/GridLayouter scroll path #7644
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -419,17 +419,15 @@ public override void RequestLayout(float scrollPosition, bool force = false) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LastVisible = end; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 2. Unrealize invisible items. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<RecyclerViewItem> unrealizedItems = new List<RecyclerViewItem>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| foreach (RecyclerViewItem item in VisibleItems) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| VisibleItems.RemoveAll(item => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (item.Index < FirstVisible || item.Index > LastVisible) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unrealizedItems.Add(item); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| collectionView.UnrealizeItem(item); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| VisibleItems.RemoveAll(unrealizedItems.Contains); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unrealizedItems.Clear(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the change in |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 3. Realize and placing visible items. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (int i = FirstVisible; i <= LastVisible; i++) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1134,22 +1132,20 @@ public override void NotifyItemRangeRemoved(IItemSource source, int startIndex, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else collectionView.ContentContainer.SizeHeight = ScrollContentSize; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 4. Update Visible Items. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<RecyclerViewItem> unrealizedItems = new List<RecyclerViewItem>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| foreach (RecyclerViewItem item in VisibleItems) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| VisibleItems.RemoveAll(item => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ((item.Index >= startIndex) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| && (item.Index < startIndex + count)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unrealizedItems.Add(item); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| collectionView.UnrealizeItem(item); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else if (item.Index >= startIndex + count) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (item.Index >= startIndex + count) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| item.Index -= count; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| VisibleItems.RemoveAll(unrealizedItems.Contains); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unrealizedItems.Clear(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 [AI Review]
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 [AI Review] |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (startIndex <= FirstVisible) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this change significantly improves performance by moving from O(N×M) to O(N), it doesn't strictly achieve "zero per-call allocation" as stated in the PR description. In C#, a lambda that captures local variables or
this(which happens here viaFirstVisible,LastVisible, andcollectionView) results in a heap allocation for a closure object and a delegate instance on every call.Since
RequestLayoutis on the scroll hot path, you could achieve true zero allocation by using a manualforloop to shift elements in-place, followed by aRemoveRangecall. However,RemoveAllis much more idiomatic and readable, so this is only worth changing if absolute zero allocation is required for this performance-critical path.