Skip to content

[Repo Assist] perf: avoid heap allocations in local-filter search for ASCII names/IDs - #511

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/perf-ascii-local-filter-22968439603ff16d
Draft

github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/perf-ascii-local-filter-22968439603ff16d

Conversation

@github-actions

@github-actions github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

🤖 This is an automated contribution from Repo Assist, an AI assistant for this repository.

What

App::apply_filter()'s local-package-filter path (used for the Installed/Upgrades local filter and the Search-view narrowing) called to_lowercase() on every package's name and id inside the retain() closure, on every single call — which fires on every keystroke while typing a filter. Each call allocates two new heap Strings per package, even though package names and IDs are almost always pure ASCII.

Fix

Added a contains_ignore_case(haystack, query, query_lower) helper in src/app.rs:

  • Takes a zero-allocation ASCII fast path (byte-slice windows() scan with eq_ignore_ascii_case) when both the haystack and query are ASCII — the overwhelmingly common case for winget package metadata.
  • Falls back to the original to_lowercase().contains() behavior for non-ASCII input, so Unicode package names/ids still match correctly.
  • The query is now lowercased once per apply_filter() call (outside the loop) instead of allocating fresh strings per package.

This mirrors the existing ASCII-fast-path convention already used in cli_backend.rs::normalize_show_key().

Trade-offs

None expected — this is a pure performance optimization with identical observable behavior (same case-insensitive substring matching semantics), verified by new and existing tests.

Test Status

  • cargo check --all-targets — ✅ pass
  • cargo fmt -- --check — ✅ pass
  • cargo clippy --all-targets -- -D warnings — ✅ pass, no warnings
  • cargo test — ✅ 450 passed, 0 failed (up from 445; added 5 new unit tests for contains_ignore_case covering ASCII match/no-match, empty query, query-longer-than-haystack, and non-ASCII fallback)

Closes no specific issue — this was identified during a routine performance-improvement pass (Task 8) of the Repo Assist workflow.

Generated by Repo Assist · copilot · sonnet50 · ~165 AIC · ⌖ ~16 AIC · ⊞ 7.1K · ◷
Comment /repo-assist to run again

Add this agentic workflow to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@cbb46ab386962aa371045839fc9998ee4e97ca64

App::apply_filter() calls to_lowercase() on every package name and id
on every keystroke in the local filter/search box. This allocates two
new Strings per package per call, even though package names/ids are
almost always pure ASCII.

Add a contains_ignore_case() helper that takes a zero-allocation
ASCII-only fast path (byte-slice windows() scan with
eq_ignore_ascii_case) when both haystack and query are ASCII, falling
back to the existing to_lowercase().contains() behavior for non-ASCII
input. The query is lowercased once per apply_filter() call instead of
once per package.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants