Skip to content

perf(property-search): memoize derived search computations - #1295

Merged
nanaf6203-bit merged 2 commits into
MettaChain:mainfrom
1Psalm:feat/issue-1218-memoize-property-search-computations
Oct 15, 2026
Merged

nanaf6203-bit merged 2 commits into
MettaChain:mainfrom
1Psalm:feat/issue-1218-memoize-property-search-computations

Conversation

@1Psalm

@1Psalm 1Psalm commented Oct 15, 2026

Copy link
Copy Markdown

Summary

Memoizes the derived values computed on every render of the PropertySearch component and removes a per-render array allocation from the autocomplete default, so the search box does less work on each pass.

Problem

PropertySearch recomputed showDropdown - a boolean derived from focus state, the presence of suggestions, loading state and the history flag - and rebuilt the �ctiveOptionId string on every render, including renders triggered by unrelated parent state. In addition, the autocomplete hook was destructured with a [] default, which allocated a brand new array instance on every render while the query had no data yet, invalidating any memoisation that keyed off suggestions.

Changes Made

  • Imported useMemo in src/components/PropertySearch.tsx.
  • Replaced the inline showDropdown and �ctiveOptionId expressions with useMemo calls keyed on [isFocused, suggestions.length, isLoading, showHistory] and [listboxId, selectedIndex] respectively.
  • Added a module-level EMPTY_SUGGESTIONS constant and used it as the destructuring default for the autocomplete query.

Implementation Details

Dependencies track exactly what each derived value reads - suggestions.length rather than the array itself, since only its length affects the dropdown visibility - so the memos remain correct while avoiding recomputation on unrelated renders. The shared empty array keeps a stable identity when there are no suggestions, which is what allows consumers of suggestions to skip work. Rendered markup and autocomplete behaviour are unchanged.

Closes #1218

Closes #1217

Closes #1216

Closes #1215

@drips-wave

drips-wave Bot commented Oct 15, 2026

Copy link
Copy Markdown

@1Psalm Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@nanaf6203-bit nanaf6203-bit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nanaf6203-bit
nanaf6203-bit merged commit aac049e into MettaChain:main Oct 15, 2026
0 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants