β‘ Bolt: Optimize SliverGrid with findChildIndexCallback #25
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
π‘ What
Added
findChildIndexCallbackto theSliverChildBuilderDelegateinMediaGridSliverand updated the childMediaCardto use aValueKey.π― Why
When a list is rebuilt, Flutter needs to find the new position of existing widgets. Without this callback, it performs a less efficient search. This callback provides a direct lookup on the underlying data model, speeding up the reconciliation of the widget tree.
π Impact
Reduces the cost of rebuilding the media grid, especially for large lists or when items are frequently added, removed, or reordered. This leads to smoother scrolling and faster UI updates. The complexity is reduced from a potentially expensive element tree traversal to a direct
O(N)search on theitemslist, which is a net performance gain.π¬ Measurement
The improvement can be observed by profiling the application with Flutter DevTools. When scrolling or filtering a large media library displayed with
MediaGridSliver, there should be fewer dropped frames and a lower build time for the grid widget.PR created automatically by Jules for task 5421563159739691719 started by @Doezer