feat: memoize filteringOptions scan and add precomputed override#135
Draft
feat: memoize filteringOptions scan and add precomputed override#135
Conversation
The O(items × filteringProperties) scan that builds filteringOptions ran synchronously on every render with no caching. For pages with many tag-based filterable properties this caused the UI to freeze on every pagination, sort, selection, and data-load event. Two changes: 1. Memoize the scan Move computeFilteringOptions out of createSyncProps (a plain function) and into useCollection (a hook) where it can be wrapped in useMemo. The scan now only runs when allItems or filteringProperties change — not on pagination, sorting, or selection state changes. 2. Add propertyFiltering.filteringOptions option When the caller supplies this list, useCollection skips its internal item scan entirely and returns the list as-is. This is an escape hatch for sparse data structures (e.g. tags) where the property-first scan is inherently inefficient: with 10,000 items and 1,000 tag keys the scan does 10M property reads of which ~99% return undefined. Callers who maintain a compact item-first index (item.tags[]) can pre-compute the options in O(items × avg_tags) ≈ 50k ops and bypass the scan completely. The option is strictly additive — existing callers that omit it continue to get the current scan behaviour unchanged.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #135 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 13 13
Lines 423 430 +7
Branches 159 158 -1
=========================================
+ Hits 423 430 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description of changes:
Move
computeFilteringOptionsout ofcreateSyncPropsand intouseCollectionwhere it can be wrapped inuseMemo. The scan now only runs whenallItemsorfilteringPropertieschange (not on pagination, sorting, or selection state changes)Add
propertyFiltering.filteringOptionsoption. When the caller supplies this list,useCollectionskips its internal item scan entirely and returns the list as-is. This is an escape hatch for sparse data structures (e.g. tags) where the property-first scan is inherently inefficient.Issue #, if available:
AWSUI-61773By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.