Skip to content

feat: memoize filteringOptions scan and add precomputed override#135

Draft
mxschll wants to merge 3 commits intomainfrom
dev-v3-schomax-performance
Draft

feat: memoize filteringOptions scan and add precomputed override#135
mxschll wants to merge 3 commits intomainfrom
dev-v3-schomax-performance

Conversation

@mxschll
Copy link
Copy Markdown
Member

@mxschll mxschll commented Mar 11, 2026

Description of changes:

  1. Move computeFilteringOptions out of createSyncProps and into useCollection 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.

Issue #, if available: AWSUI-61773

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

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.
@mxschll mxschll requested a review from a team as a code owner March 11, 2026 10:33
@mxschll mxschll requested review from amanabiy and removed request for a team March 11, 2026 10:33
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (eb52b37) to head (3db409c).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mxschll mxschll changed the title perf: memoize filteringOptions scan and add precomputed override feat: memoize filteringOptions scan and add precomputed override Mar 11, 2026
@mxschll mxschll removed the request for review from amanabiy March 11, 2026 10:40
@mxschll mxschll marked this pull request as draft March 11, 2026 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant