Skip to content

[Repo Assist] perf(rust-guard): hoist invariant integrity/secrecy calls outside per-item loops#6005

Merged
lpcox merged 3 commits into
mainfrom
repo-assist/fix-issue-5997-hoist-invariant-loop-allocs-280bab3dda94e923
May 19, 2026
Merged

[Repo Assist] perf(rust-guard): hoist invariant integrity/secrecy calls outside per-item loops#6005
lpcox merged 3 commits into
mainfrom
repo-assist/fix-issue-5997-hoist-invariant-loop-allocs-280bab3dda94e923

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 Repo Assist — automated AI assistant.

Summary

Eliminates redundant Vec allocations in three label_response_items branches by hoisting constant integrity/secrecy calls outside their loops.

Problem

Three item-labeling loops were recomputing identical Vec values on every iteration:

Branch Repeated call(s)
list_gists / get_gist reader_integrity(scope_names::USER, ctx) × N
list_notifications / get_notification_details private_user_label() × N and none_integrity("", ctx) × N
list_releases / get_latest_release / get_release_by_tag merged_integrity(&repo_full_name, ctx) × N

For a 30-item batch (the default limit) this was ~90 redundant heap allocations per call. In WASM, every allocation is expensive since the linear memory allocator scans free lists on each call.

Fix

Hoist each invariant call before its loop; clone the pre-built Vec per item. Also extracts a DEFAULT_BRANCH_NAMES constant in helpers.rs, consistent with WRITE_OPERATIONS, BLOCKED_TOOLS, and similar named arrays.

The get_file_contents branch already uses this pattern correctly — this change makes the rest of the code consistent.

Closes #5997

Test Status

  • cargo check
  • cargo test ✅ — 411 tests passed, 0 failed

Generated by Repo Assist · ● 2.6M ·

To install this agentic workflow, run

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

…-item loops

Eliminates redundant Vec allocations in three label_response_items branches:
- list_gists: hoist reader_integrity() outside loop (1 alloc instead of N)
- list_notifications: hoist private_user_label() + none_integrity() (2 allocs instead of 2N)
- list_releases: hoist merged_integrity() outside loop (1 alloc instead of N)

For a default 30-item batch this removes ~90 redundant heap allocations,
matching the pattern already used correctly in the get_file_contents branch.

Also extracts DEFAULT_BRANCH_NAMES constant in helpers.rs, consistent with
WRITE_OPERATIONS, BLOCKED_TOOLS and similar named arrays in the codebase.

Closes #5997

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox marked this pull request as ready for review May 19, 2026 14:33
Copilot AI review requested due to automatic review settings May 19, 2026 14:33
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

This PR targets performance in the Rust guard labeling pipeline by reducing repeated work inside per-item response labeling loops, and slightly improves maintainability in branch-ref handling.

Changes:

  • Hoists invariant integrity/secrecy label construction out of several per-item loops in label_response_items.
  • Clones the pre-built label vectors per item instead of recomputing them each iteration.
  • Extracts a DEFAULT_BRANCH_NAMES constant used by is_default_branch_ref.
Show a summary per file
File Description
guards/github-guard/rust-guard/src/labels/response_items.rs Hoists invariant label construction out of loops for gists, notifications, and releases.
guards/github-guard/rust-guard/src/labels/helpers.rs Introduces DEFAULT_BRANCH_NAMES and uses it in is_default_branch_ref for easier updates.

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: 3

Comment on lines 388 to 392
labels: ResourceLabels {
description: format!("gist:{}", id),
secrecy,
integrity: reader_integrity(scope_names::USER, ctx),
integrity: gist_integrity.clone(),
},
Comment on lines +402 to 412
let notif_secrecy = private_user_label();
let notif_integrity = none_integrity("", ctx);
for item in items.iter() {
let id = get_str_or(item, "id", "unknown");
labeled_items.push(LabeledItem {
data: item.clone(),
labels: ResourceLabels {
description: format!("notification:{}", id),
secrecy: private_user_label(),
integrity: none_integrity("", ctx),
secrecy: notif_secrecy.clone(),
integrity: notif_integrity.clone(),
},
Comment on lines 428 to 439
@@ -431,7 +435,7 @@ pub fn label_response_items(
labels: ResourceLabels {
description: format!("release:{}@{}", repo_full_name, tag),
secrecy: secrecy.clone(),
integrity: merged_integrity(&repo_full_name, ctx),
integrity: release_integrity.clone(),
},
@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented May 19, 2026

@copilot address review feedback

Copy link
Copy Markdown
Contributor

Copilot AI commented May 19, 2026

@copilot address review feedback

Addressed in commits 547a710 and 36ff56c.

ResourceLabels now uses shared Arc-backed label storage, and the affected response labeling loops precompute shared secrecy/integrity labels outside per-item loops so each item clones only the shared handle instead of deep-cloning vectors.

Copilot AI requested a review from lpcox May 19, 2026 15:00
@lpcox lpcox merged commit dad2a0a into main May 19, 2026
14 checks passed
@lpcox lpcox deleted the repo-assist/fix-issue-5997-hoist-invariant-loop-allocs-280bab3dda94e923 branch May 19, 2026 15:16
Copilot finished work on behalf of lpcox May 19, 2026 15:30
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.

[rust-guard] Hoist invariant integrity/secrecy calls outside per-item loops in response_items.rs

3 participants