Add performance and allocation review learnings from PR #327#354
Add performance and allocation review learnings from PR #327#354
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the repository’s reviewer guidance and Copilot instructions to incorporate performance/allocation learnings from PR #327, aiming to reduce allocation-heavy suggestions and align reviews with established repo patterns.
Changes:
- Expanded
review-rules.mdwith new performance/allocation rules (ArrayPool usage, reusable buffers, avoiding string intermediates, async/stackalloc constraints, thread-safety documentation). - Updated
SKILL.mdworkflow guidance to grep for existing repo patterns before proposing new infrastructure. - Enhanced
.github/copilot-instructions.mdwith buffer-management and thread-safety guidance, plus netstandard2.0 notes.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| .github/skills/android-tools-reviewer/references/review-rules.md | Adds new performance/allocation and thread-safety review rules, plus updated netstandard2.0 guidance. |
| .github/skills/android-tools-reviewer/SKILL.md | Adds workflow guidance to prefer existing repo patterns (ArrayPool/ObjectPool/ProcessUtils) before suggesting alternatives. |
| .github/copilot-instructions.md | Updates Copilot guidance for netstandard2.0, buffer reuse/ArrayPool, and thread-safety documentation expectations. |
New rules and guidance based on review feedback from @jonathanpeppers on the AdbDeviceTracker/AdbClient PR: Review rules (review-rules.md): - ArrayPool for repeated allocations (frequency, not just size threshold) - Reusable instance buffers for fixed-size protocol reads - Avoid string intermediates in binary protocol encode/decode - stackalloc cannot cross await boundaries (prevent false positive suggestions) - Single-instance reuse pattern over per-iteration new - Document thread-safety invariants on types with buffer reuse - UTF-8 literal (u8) limitation on netstandard2.0 Skill workflow (SKILL.md): - Check existing repo patterns before suggesting alternatives (grep for ArrayPool, ObjectPool, ProcessUtils first) Copilot instructions: - ArrayPool<byte> pattern reference (DownloadUtils.cs as canonical example) - stackalloc async limitation - u8 literal netstandard2.0 incompatibility - Thread-safety documentation convention Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
d361fce to
fc4c108
Compare
There was a problem hiding this comment.
Pull request overview
Updates the repository’s reviewer skill guidance and Copilot instructions to incorporate performance/allocation review learnings (from PR #327), with emphasis on hot-path buffer reuse and avoiding avoidable allocations in protocol code.
Changes:
- Expanded reviewer rules to include new performance/allocation guidance (ArrayPool, reusable buffers, avoiding string intermediates, async
stackalloccaveat, loop helper reuse, thread-safety remarks). - Updated the reviewer workflow to explicitly prefer existing repo patterns before proposing new infrastructure.
- Enhanced Copilot instructions with buffer reuse guidance and additional netstandard2.0 considerations.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| .github/skills/android-tools-reviewer/references/review-rules.md | Adds performance/allocation-focused review checks and thread-safety documentation guidance. |
| .github/skills/android-tools-reviewer/SKILL.md | Adds workflow guidance to grep for existing repo patterns before suggesting new ones. |
| .github/copilot-instructions.md | Adds Copilot guidance on buffer reuse and netstandard2.0 compatibility pitfalls. |
| |-------|-----------------| | ||
| | **netstandard2.0 API surface** | Methods/overloads that only exist on net5+. Common traps: `HttpContent.ReadAsStringAsync(CancellationToken)`, `ProcessStartInfo.ArgumentList`, `Environment.IsPrivilegedProcess`, `ArrayPool<T>` (needs `System.Buffers` package on ns2.0). When unsure, check MS Learn docs. | | ||
| | **C# language features** | `init` accessors, `required` keyword, file-scoped types, raw string literals — may need polyfills or `#if` guards. | | ||
| | **C# language features** | `init`, `required`, file-scoped types, raw string literals may need polyfills or `#if` guards. `"text"u8` is not `netstandard2.0`-compatible — use `static readonly byte[]`. | |
| - **Use `FileUtil`**: file operations like extraction, downloads, checksum verification, and path checks belong in `FileUtil.cs`. Don't duplicate file helpers in domain classes. | ||
| - **Concise XML docs**: omit `<summary>` tags for self-explanatory methods. Only add doc comments when the behavior is non-obvious. Avoid restating the method name. | ||
| - **`netstandard2.0` awareness**: many modern .NET APIs are unavailable or have fewer overloads on `netstandard2.0`. When unsure about API availability, search mslearn to check documentation for the target framework. | ||
| - **`netstandard2.0` awareness**: many modern .NET APIs are unavailable or have fewer overloads on `netstandard2.0`. When unsure about API availability, search mslearn to check documentation for the target framework. UTF-8 literals (`"text"u8`) unavailable on `netstandard2.0` — use `static readonly byte[]` with `Encoding.ASCII.GetBytes()`. |
| |-------|-----------------| | ||
| | **Reuse hot-path buffers** | Pool repeated `byte[]` allocations with `ArrayPool<byte>.Shared` (see `DownloadUtils.cs`). For fixed-size repeated reads, use a `readonly byte[]` instance field. Document non-thread-safety in `<remarks>`. | | ||
| | **No string intermediates in protocols** | Avoid `int.ToString("x4")`/`int.TryParse()` for hex. Use direct `byte[]` bitwise helpers. | | ||
| | **No `stackalloc` in async I/O** | `stackalloc` prohibited across `await`. Use ArrayPool or instance buffers. | |
| - **Use `FileUtil`**: file operations like extraction, downloads, checksum verification, and path checks belong in `FileUtil.cs`. Don't duplicate file helpers in domain classes. | ||
| - **Concise XML docs**: omit `<summary>` tags for self-explanatory methods. Only add doc comments when the behavior is non-obvious. Avoid restating the method name. | ||
| - **`netstandard2.0` awareness**: many modern .NET APIs are unavailable or have fewer overloads on `netstandard2.0`. When unsure about API availability, search mslearn to check documentation for the target framework. | ||
| - **`netstandard2.0` awareness**: many modern .NET APIs are unavailable or have fewer overloads on `netstandard2.0`. When unsure about API availability, search mslearn to check documentation for the target framework. UTF-8 literals (`"text"u8`) unavailable on `netstandard2.0` — use `static readonly byte[]` with `Encoding.ASCII.GetBytes()`. |
There was a problem hiding this comment.
Is there a place we need "text"u8? It might be possible to make it work on netstandard2.0.
Summary
Adds new review rules, skill guidance, and copilot instructions distilled from the allocation optimization feedback on PR #327 (AdbDeviceTracker/AdbClient).
What's new
Review rules (
review-rules.md)readonly byte[] headerBuffer = new byte[4]pattern for fixed-size readsint.ToString("x4")allocates; bitwise helpers don'tReconnect()pattern overnew TcpClient()per iterationu8) on netstandard2.0ReadOnlySpan<byte>doesn't exist — usestatic readonly byte[]Skill workflow (
SKILL.md)ArrayPool,ObjectPool,ProcessUtils) before suggesting alternativesCopilot instructions
ArrayPool<byte>pattern reference pointing toDownloadUtils.csContext
These learnings came from:
dotnet/runtime,dotnet/android, anddotnet/aspnetcorefor best-in-class patterns