[PR #6791] perf: optimize model dialog visibility lookups #12109

Closed
opened 2026-02-16 18:17:02 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/6791

State: closed
Merged: Yes


Summary

  • Fixes model dialog lag that occurs during longer sessions
  • Replaces O(n) array lookups with O(1) Set/Map lookups in the visible() function

Problem

The visible() function in packages/app/src/context/local.tsx was called inside a .filter() loop for each model. Each call performed:

  1. A linear search through store.user array
  2. A linear search through latest() array (which involves expensive date computations)

With many models, this became O(n²) and caused noticeable lag when opening the model selector.

Solution

Added two memoized lookup structures:

  • latestSet: A Set for O(1) lookup of whether a model is "latest"
  • userVisibilityMap: A Map for O(1) lookup of user visibility preferences

The memos are only recomputed when their underlying data changes, not on every visible() call.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6791 **State:** closed **Merged:** Yes --- ## Summary - Fixes model dialog lag that occurs during longer sessions - Replaces O(n) array lookups with O(1) Set/Map lookups in the `visible()` function ## Problem The `visible()` function in `packages/app/src/context/local.tsx` was called inside a `.filter()` loop for each model. Each call performed: 1. A linear search through `store.user` array 2. A linear search through `latest()` array (which involves expensive date computations) With many models, this became O(n²) and caused noticeable lag when opening the model selector. ## Solution Added two memoized lookup structures: - `latestSet`: A `Set` for O(1) lookup of whether a model is "latest" - `userVisibilityMap`: A `Map` for O(1) lookup of user visibility preferences The memos are only recomputed when their underlying data changes, not on every `visible()` call.
yindo added the pull-request label 2026-02-16 18:17:02 -05:00
yindo closed this issue 2026-02-16 18:17:02 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12109