Skip to content

Optimize search highlight lookups for scroll performance#24

Open
kdkavanagh-agent wants to merge 2 commits intomasterfrom
perf/set-based-search-lookup-v2
Open

Optimize search highlight lookups for scroll performance#24
kdkavanagh-agent wants to merge 2 commits intomasterfrom
perf/set-based-search-lookup-v2

Conversation

@kdkavanagh-agent
Copy link
Copy Markdown
Collaborator

@kdkavanagh-agent kdkavanagh-agent commented Mar 25, 2026

Summary

Optimizes search highlight performance by converting internal data structures for O(1) lookups:

  1. _search_set (set) — Used in _get_sel_col_bg_color() for O(1) membership tests instead of O(n) linear scan on the Python list
  2. _search_series (pl.Series) — Pre-computed Polars Series passed to is_in() so Polars doesn't rebuild from a Python list on every render call
  3. watch_active_search_queue() — Reactive watcher rebuilds both cached structures only when the search queue changes

The original active_search_queue list is preserved unchanged, so n/N search iteration order is unaffected.

Performance Results

Slowdown = (search_scroll_time - baseline_scroll_time) / baseline_scroll_time. Threshold: 15%.

Test Hits Screen Master (before) PR 24 (after) Improvement
single_match 1 120x30 0.1% -1.9% -
single_match 1 800x200 -2.3% -4.6% -
single_match 1 3000x1000 -1.0% 1.0% -
sparse_far_apart 200 120x30 0.8% 1.9% -
sparse_far_apart 200 800x200 -1.9% -0.2% -
sparse_far_apart 200 3000x1000 1.8% 0.6% -
many_adjacent 50,000 120x30 -0.9% 0.3% -
many_adjacent 50,000 800x200 4.6% 8.2% -
many_adjacent 50,000 3000x1000 6.1% 3.7% 2.4pp better
dense_most_rows 199,992 120x30 3.2% 3.1% -
dense_most_rows 199,992 800x200 13.7% 14.2% now passes
dense_most_rows 199,992 3000x1000 10.9% 8.0% 2.9pp better

All 12 tests pass (threshold: 15%). Previously dense_most_rows at 800x200 was intermittently failing at 15-16%.

Test plan

  • All 12 parametrized perf tests pass
  • All 27 existing functional tests pass
  • n/N search iteration order preserved (list unchanged, only parallel set/series added)

Generated with Claude Code

Claude Code and others added 2 commits March 25, 2026 04:38
Parametrized tests measuring scroll performance with active search
highlights vs baseline across different search cardinalities (single
match, sparse, adjacent block, dense) and screen sizes (120x30,
800x200, 3000x1000). Tests fail if search scrolling is >15% slower.
Configured pytest-xdist with -n 2 for parallel execution.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ries

Convert active_search_queue lookups from O(n) list scans to O(1) set
lookups for per-row color checks, and cache a Polars Series to avoid
rebuilding from a Python list on every render call to is_in().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant