Skip to content

perf: pre-compute column indices once per table; avoid Vec<char> in detect_columns#61

Merged
shanselman merged 3 commits intomainfrom
copilot/perf-precompute-column-indices
Mar 28, 2026
Merged

perf: pre-compute column indices once per table; avoid Vec<char> in detect_columns#61
shanselman merged 3 commits intomainfrom
copilot/perf-precompute-column-indices

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 26, 2026

Two hot-path allocations in the winget output parser eliminated — one per-row (repeated to_lowercase column lookups), one per-table (collecting header chars into a Vec<char>).

Changes

  • detect_columns: replaced Vec<char> collect + index loop with char_indices().peekable(), giving (byte_offset, char) pairs directly with no heap allocation.

  • PackageCols / SourceCols structs (#[derive(Copy, Clone)]): hold pre-computed Option<usize> column indices. Factory methods package_column_map() / source_column_map() run all find_column_ci calls and positional-fallback logic once per table instead of once per row.

// Before: find_column_ci called for every row (O(rows × cols) to_lowercase allocs)
fn parse_table_row(&self, line: &str, cols: &[(&str, usize)]) -> Option<Package> {
    let mut name_idx = Self::find_column_ci(cols, &["name", "nom", "nombre", "nome"]);
    let mut id_idx   = Self::find_column_ci(cols, &["id", "id."]);
    // ...
}

// After: indices computed once, passed as Copy struct
let col_map = Self::package_column_map(&col_positions);          // once per table
.filter_map(|line| self.parse_table_row(line, &col_positions, col_map))

No behaviour change — purely mechanical refactor of the parsing hot path.


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Copilot AI and others added 2 commits March 26, 2026 07:19
Copilot AI changed the title [WIP] Improve performance by pre-computing column indices in output parser perf: pre-compute column indices once per table; avoid Vec<char> in detect_columns Mar 26, 2026
Copilot AI requested a review from shanselman March 26, 2026 07:25
@shanselman shanselman marked this pull request as ready for review March 28, 2026 00:11
@shanselman shanselman merged commit 056e7f7 into main Mar 28, 2026
17 of 18 checks passed
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.

[Repo Assist] perf: pre-compute column indices once per table; avoid Vec(char) in detect_columns

2 participants