[Repo Assist] perf(rust-guard): hoist invariant label calls and dedup PR number extraction#6201
Open
github-actions[bot] wants to merge 2 commits into
Conversation
…raction response_paths.rs: - list_notifications: hoist private_user_label() before loop; was allocated N+1 times per response, now N Arc::clones (free) - list_gists: hoist reader_integrity(scope_names::USER, ctx) before loop; was called N+1 times, now N Arc::clones tool_rules.rs: - pull_request arm: extract pull_number once at the top; eliminates a redundant JSON field scan on every get_pull_request/pull_request_read call Closes #6193 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR targets small performance improvements in the Rust guard labeling layer by reducing per-item allocations in response labeling and deduplicating pull request number extraction in tool labeling.
Changes:
- Hoists loop-invariant label computations in
label_response_pathsforlist_notificationsandlist_giststo avoid repeated allocations. - Deduplicates PR number extraction in
apply_tool_labelsfor PR-related tool names to avoid scanning tool args twice.
Show a summary per file
| File | Description |
|---|---|
guards/github-guard/rust-guard/src/labels/response_paths.rs |
Hoists invariant SharedLabels computations out of per-item loops for notifications and gists. |
guards/github-guard/rust-guard/src/labels/tool_rules.rs |
Extracts pull_number once per PR tool arm and reuses it for description/back-end lookup. |
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
216
to
220
| // | ||
| // Extract once; reused for desc and backend lookup to avoid a second JSON field scan. | ||
| let pull_number = extract_number_as_string(tool_args, field_names::PULL_NUMBER) | ||
| .or_else(|| extract_number_as_string(tool_args, "pullNumber")); | ||
| if !owner.is_empty() && !repo.is_empty() { |
Comment on lines
518
to
522
| labels: crate::ResourceLabels { | ||
| description: format!("notification:{}", id), | ||
| secrecy: private_user_label().into(), | ||
| secrecy: notif_secrecy.clone(), | ||
| integrity: vec![].into(), | ||
| }, |
Comment on lines
563
to
567
| labels: crate::ResourceLabels { | ||
| description: format!("gist:{}", id), | ||
| secrecy: secrecy.into(), | ||
| integrity: reader_integrity(scope_names::USER, ctx).into(), | ||
| integrity: gist_integrity.clone(), | ||
| }, |
Collaborator
|
@copilot address review feedback |
… gist secrecy, lazy PR number extraction
Contributor
All three review points addressed in the latest commit:
413 tests pass. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Closes #6193
Root Cause
Two
response_paths.rscollection branches recomputed constant labels on every loop iteration (and again indefault_labels), and theget_pull_request/pull_request_readarm intool_rules.rsscanned JSON args twice for the same PR number.Changes
response_paths.rslist_notifications: hoistprivate_user_label()before the loop. It always returns the sameVec<String>, was allocated N+1 times per response. Now computed once andArc::cloned (free) per item.list_gists: hoistreader_integrity(scope_names::USER, ctx)before the loop. The function may traverse scope-policy lookups before allocating label strings; was called N+1 times, now NArc::clones.tool_rules.rsget_pull_request/pull_request_read/list_pull_requestsarm: extractpull_numberonce at the top. Eliminates a redundant JSON field scan on every single-PR read call. Also creates a single source of truth for how the PR number is extracted.Why This Matters
SharedLabelswrapsArc<Vec<String>>, so.clone()is a single atomic ref-count increment — essentially free. The hoisted calls eliminate N redundantVecallocations perlist_notificationsandlist_gistsresponse. For a typical page of 30–50 items this removes ~30–50 heap allocations per request.This mirrors the same improvement already applied to
response_items.rson 2026-05-19.Test Status
cargo test— 413 tests passedmake build/make test-unitblocked by Go toolchain network download (go1.25.0proxy.golang.orgForbidden) — infrastructure constraint, not caused by this change. The Rust-only files changed have no Go counterpart.Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
proxy.golang.orgSee Network Configuration for more information.