You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf: avoid per-byte allocations in random access stream - #5389
RandomAccessStream inherits Stream.ReadByte, which allocates a temporary one-byte array on each call. GitPackReader uses this path for variable-length packed-object offsets. Override ReadByte using a stack span and the existing span read so file bounds, positions and EOF behavior remain consistent on net10 and net11.
Adds regression coverage for unsigned byte values, mixed reads, bounded/physical EOF, seek and independent stream positions, shared-handle ownership, and per-call allocations. The allocation test fails without the override (32,768 bytes for 1,024 reads) and passes with it.
Validation: all 182 managed-backend tests passed on each framework on macOS ARM64; formatting/whitespace checks passed; CodeRabbit reviewed both files with zero findings. An isolated probe saved 32 bytes per call on both runtimes. Reading 1,000 real commits saved 6,496 allocated bytes (~0.16%); this does not establish an application speedup or general memory reduction. Cross-platform CI remains to validate the PR.
Follow-up to #5210. No .NET 11-specific API or benchmark infrastructure is added.
Summary by CodeRabbit
New Features
Added support for reading individual bytes from managed random-access streams.
Returns an end-of-stream indicator when no more data is available.
Tests
Added coverage for byte reads, stream positions, end-of-stream behavior, shared handles, disposal, and repeated reads without allocations.
Documentation
Updated version-calculation documentation review metadata while preserving existing behavior and accuracy.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
📝 Walkthrough
RandomAccessStream adds ReadByte, which returns a byte value or -1 at end of stream. Tests cover read positions, shared-handle behavior, and zero allocations across repeated calls. Version-calculation documentation metadata is updated.
Changes: RandomAccessStream byte reads
Layer / File(s)
Summary
Add and verify single-byte reads src/GitVersion.Git.Managed/RandomAccessStream.cs, src/GitVersion.Git.Managed.Tests/RandomAccessStreamTests.cs, docs/version-calculation-map.json
ReadByte uses the existing Read method. Tests cover unsigned values, position advancement, end-of-stream behavior, independent positions over a shared handle, and zero allocations. The documentation metadata records the reviewed change.
This change avoids a small per-call allocation in single-byte reads while preserving existing stream behavior. No concrete merge-blocking risk was identified.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 2 files. (1 skipped: 1…
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 4 passed
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title clearly and concisely identifies the main change: preventing per-byte allocations in RandomAccessStream.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage
Explanation
Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 2 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
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
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.
RandomAccessStream inherits Stream.ReadByte, which allocates a temporary one-byte array on each call. GitPackReader uses this path for variable-length packed-object offsets. Override ReadByte using a stack span and the existing span read so file bounds, positions and EOF behavior remain consistent on net10 and net11.
Adds regression coverage for unsigned byte values, mixed reads, bounded/physical EOF, seek and independent stream positions, shared-handle ownership, and per-call allocations. The allocation test fails without the override (32,768 bytes for 1,024 reads) and passes with it.
Validation: all 182 managed-backend tests passed on each framework on macOS ARM64; formatting/whitespace checks passed; CodeRabbit reviewed both files with zero findings. An isolated probe saved 32 bytes per call on both runtimes. Reading 1,000 real commits saved 6,496 allocated bytes (~0.16%); this does not establish an application speedup or general memory reduction. Cross-platform CI remains to validate the PR.
Follow-up to #5210. No .NET 11-specific API or benchmark infrastructure is added.
Summary by CodeRabbit
New Features
Tests
Documentation