Skip to content

perf(rust-guard): eliminate wasted allocations in apply_tool_labels and project-item loop#6680

Merged
lpcox merged 1 commit into
mainfrom
perf/rust-guard-eliminate-allocations
May 29, 2026
Merged

perf(rust-guard): eliminate wasted allocations in apply_tool_labels and project-item loop#6680
lpcox merged 1 commit into
mainfrom
perf/rust-guard-eliminate-allocations

Conversation

@lpcox
Copy link
Copy Markdown
Collaborator

@lpcox lpcox commented May 29, 2026

  • Replace extract_repo_info(tool_args) with direct get_string_field calls in apply_tool_labels, avoiding a format!(\"{}/{}\") allocation that was immediately discarded on every tool invocation.

  • Replace unconditional to_lowercase() with a static match for known project item types (ISSUE, PULL_REQUEST, DRAFT_ISSUE), avoiding a heap allocation per item in the common case.

Closes #6674

…nd project-item loop

- Replace extract_repo_info(tool_args) with direct get_string_field
  calls in apply_tool_labels, avoiding a format!("{}/{}") allocation
  that was immediately discarded on every tool invocation.

- Replace unconditional to_lowercase() with a static match for known
  project item types (ISSUE, PULL_REQUEST, DRAFT_ISSUE), avoiding a
  heap allocation per item in the common case.

Closes #6674

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 29, 2026 12:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Performance micro-optimizations in the Rust guard's hot labeling paths to avoid unnecessary heap allocations.

Changes:

  • In apply_tool_labels, replace extract_repo_info (which allocates a discarded repo_id via format!) with direct get_string_field calls for owner and repo.
  • In the list_project_items/projects_list path labeler, replace item_type.to_lowercase() with a Cow-based static match on known types (ISSUE, PULL_REQUEST, DRAFT_ISSUE), falling back to owned lowercase only for unknown types.
Show a summary per file
File Description
guards/github-guard/rust-guard/src/labels/tool_rules.rs Drops discarded format! allocation by extracting owner/repo directly.
guards/github-guard/rust-guard/src/labels/response_paths.rs Uses Cow<'_, str> static-match to skip allocation for known project item types.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 0

@lpcox lpcox merged commit dc56367 into main May 29, 2026
23 checks passed
@lpcox lpcox deleted the perf/rust-guard-eliminate-allocations branch May 29, 2026 12:32
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.

[rust-guard] Rust Guard: Eliminate wasted format! allocation in apply_tool_labels + to_lowercase in project-item loop

2 participants