opencode icon indicating copy to clipboard operation
opencode copied to clipboard

perf: optimize model picker dialog for instant response

Open noah79 opened this issue 2 weeks ago • 0 comments

Summary

  • Split options memo into baseOptions (stable computation) and options (filtering only)
  • Add 50ms debounce to search input to reduce fuzzy search frequency
  • Extract shared selectModel handler to avoid creating new closures per option

Problem

The model picker dialog (ctrl+x m) was sluggish to open and search. Every keystroke triggered:

  1. Full recomputation of ALL option objects (favorites, recents, providers)
  2. Creation of new onSelect closure functions for every single model
  3. 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.

noah79 avatar Dec 31 '25 06:12 noah79