opencode
opencode copied to clipboard
perf: optimize model picker dialog for instant response
Summary
- Split
optionsmemo intobaseOptions(stable computation) andoptions(filtering only) - Add 50ms debounce to search input to reduce fuzzy search frequency
- Extract shared
selectModelhandler to avoid creating new closures per option
Problem
The model picker dialog (ctrl+x m) was sluggish to open and search. Every keystroke triggered:
- Full recomputation of ALL option objects (favorites, recents, providers)
- Creation of new
onSelectclosure functions for every single model - 4x fuzzy search calls across all option arrays
Solution
Now baseOptions memo only recomputes when providers/favorites/recents actually change. The options memo just filters the pre-computed arrays. Combined with debouncing, this makes the dialog feel instant.
Testing
Tested locally - dialog opens instantly and search is responsive even with many providers connected.