Skip to content

perf: avoid re-preparing searchable list items on every keystroke - #946

Open
Shawnsuun wants to merge 1 commit into
flyteorg:masterfrom
Shawnsuun:perf-searchable-list-state
Open

Shawnsuun wants to merge 1 commit into
flyteorg:masterfrom
Shawnsuun:perf-searchable-list-state

Conversation

@Shawnsuun

Copy link
Copy Markdown

Summary

useSearchableListState rebuilt its unfiltered results and called fuzzysort.prepare on every item on every keystroke, because both happened inside the useMemo keyed on searchString. On installs with many projects, workflows or launch plans, this makes search inputs (e.g. Select Project, which #941 paginated) lag while typing.

Changes

  • Memoize unfilteredResults and the prepared fuzzysort items on [items, propertyGetter], so they are computed once per item list instead of once per keystroke.
  • Filter against useDeferredValue(searchString) so the input stays responsive while results update.
  • loading is now true while the deferred search value catches up; it used to be always false. No current caller reads loading.
  • Add common/test/useSearchableListState.test.tsx, covering empty search, filtering, and that fuzzysort.prepare runs once per item and not again on each keystroke.

All current callers (SelectProject, FilterableNamedEntityList, ResponsiveLaunchPlanList) pass string property getters, so the memo stays stable across renders.

Testing

  • NODE_ENV=test yarn jest packages/oss-console/src/components/common packages/oss-console/src/components/SelectProject packages/oss-console/src/components/LaunchPlan → 8 suites / 21 tests passed
  • With the hook change reverted, the new "prepares each item only once" test fails (1 failed, 2 passed).
  • npx eslint on the changed files → no issues

All commits are signed off (DCO).

useSearchableListState rebuilt the unfiltered results and re-ran
fuzzysort.prepare for every item on each search change. Memoize those on the
item list and filter against a deferred search string so typing stays
responsive with large lists (e.g. Select Project on large installs).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Shawn Sun <shasun@linkedin.com>
@Shawnsuun

Copy link
Copy Markdown
Author

Friendly ping @Sovietaced @pingsutw, could you take a look when you have a moment? CI is green and it merges cleanly. Thanks!

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