perf(rust-guard): eliminate wasted allocations in apply_tool_labels and project-item loop#6680
Merged
Merged
Conversation
…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>
Contributor
There was a problem hiding this comment.
Pull request overview
Performance micro-optimizations in the Rust guard's hot labeling paths to avoid unnecessary heap allocations.
Changes:
- In
apply_tool_labels, replaceextract_repo_info(which allocates a discardedrepo_idviaformat!) with directget_string_fieldcalls forownerandrepo. - In the
list_project_items/projects_listpath labeler, replaceitem_type.to_lowercase()with aCow-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
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.
Replace
extract_repo_info(tool_args)with directget_string_fieldcalls inapply_tool_labels, avoiding aformat!(\"{}/{}\")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