Skip to content

fix(tui): keep the model picker responsive with large catalogs - #66370

Merged
neriousy merged 1 commit into
devfrom
tui-model-search
Nov 25, 2026
Merged

neriousy merged 1 commit into
devfrom
tui-model-search

Conversation

@neriousy

Copy link
Copy Markdown
Member

Issue for this PR

Closes #66326

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

the tui model picker got really slow with big catalogs (openrouter, kilo). there were 3 problems:

  • findModel in context/local.tsx was a linear scan, and the picker calls isSpeed (so findModel twice) for every model on every key. that's O(n²): ~190ms per key at 2k models. it's now a map lookup
  • dialog-model.tsx rebuilt every option object on every key. the model options are now a memo that doesn't depend on the query, so search returns the same objects. new designs no longer clones each result to swap the description and footer; they use searchDescription (new, next to the existing searchFooter) and searchFooter
  • DialogSelect rendered <For each={grouped()}>, and every update builds new [category, options] tuples, so every row got mounted again on every key. headers and rows are now one flat list keyed by identity, so rows that stay listed are kept, including when the list switches between grouped and flat

rows that a search removes still mount again when you widen the search, because <For> disposes them. that now costs about as much as opening the picker. no visual changes: frames before and after are identical with new designs on and off

no flag, it's a fix

How did you verify your code works?

timed opening the picker and typing gatewaya model 512 one key at a time (component render, 2 generated providers, the same setup as the repro in the issue):

models open first key whole query (18 keys)
2,000 before 300ms 405ms 5.7s
2,000 after 121ms 94ms 0.21s
6,000 before 2.6s 3.5s 53.7s
6,000 after 278ms 271ms 0.8s
6,000 after, new designs 349ms 185ms 0.73s
  • added keeps rows mounted while the filter changes to test/cli/tui/dialog-select.test.tsx. it fails on dev and passes 10 of 10 reruns here
  • full tui suite passes (1741 pass), bun typecheck clean

Screenshots / recordings

no visual change

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@neriousy
neriousy merged commit ea8aa5b into dev Nov 25, 2026
11 checks passed
@neriousy
neriousy deleted the tui-model-search branch November 25, 2026 13:18

@opencodejr opencodejr Bot 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.

Looks good. I reproduced the lag on the base with the #66326 script (2 providers x 1,000 models, typing gatewaya model 512 one key at a time): each key took 0.9–1.8 s, about 25 s for the query. With this PR each key takes 21–357 ms, 1.9 s in total, and the picker opens in about half the time. The search results look the same before and after. The new test fails on the base and passes here, and the TUI tests (445) and tsc -b pass.

Public API is unchanged: searchDescription is a new optional field on the TUI-internal DialogSelectOption.

I didn't find anything blocking.

Before

After

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.

Huge input lag/performance problems when searching model list in TUI

1 participant