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
feat(serialization): add owned Arc buffer codec and copier - #11463
ArcBuffer gains a built-in codec that preserves source ownership and contents across repeated serialization, and a copier that acquires independent pins over the referenced bytes. Reader<TInput>.ReadOwnedBuffer(int) centralizes owned payload reads: nonempty Arc input acquires slice pins from the reader's current backing page, other inputs copy into available pooled-page capacity through the shared reader-to-writer helper, and zero-length reads return owner-free ArcBuffer.Empty without advancing. Cursor-relative slicing preserves sequential traversal across page boundaries, empty pages, and nested fork offsets.
Ownership is explicit. Struct assignment creates a borrowed view whose lifetime is bounded by its owner. Every independent owner acquires a pin before handoff using Slice, Pin, or the copier, keeps its own struct copy, and disposes that handle exactly once. Concurrent owners can release their own handles while the remaining owners keep the immutable bytes alive. Serialization borrows the source; decoded/copied results belong to their caller. Code that acquires a result is responsible for releasing it, including when its subsequent work fails. Temporary writers used during payload copying are disposed when that operation fails, and sender-owned inputs remain available for retry.
Following maintainer direction, this revision uses the existing explicit pin/borrowing contract and coding discipline. It removes the earlier per-handle lease and operation-rollback machinery, including CopyContext.ArcBuffers and SerializerSession.ArcBuffers. General serializer and copy-context implementations match main. The focused tests cover borrowed struct assignments, independent concurrent Slice/Pin/copier owners, custom cleanup on failure, non-consuming serialization and retry, reference identity, and reader cursor/lifetime boundaries.
Public signatures and the length-prefixed wire format are preserved. General buffer bounds/lifetime correctness and raw lifetime tests were split into merged #11474; this branch builds on main fbe240c34e9a1389ca5ab2d52f292ed8749ea530.
Originally extracted from #10693, this layer serves independently owned pooled-byte serialization. Durable Messaging uses GC-owned byte[] envelope payloads and remains independent. Main's page-pool policy is preserved; RPC lifetimes and retention policy remain separate concerns.
Making default/Empty a supported value means First is legitimately null for a valid ArcBuffer (as the new tests assert), but the public First field and constructor parameter still advertise non-nullable ArcBufferPage. Nullable-aware consumers can therefore dereference ArcBuffer.Empty.First without a warning. Please update the public nullability contract (and regenerate the API surface) so owner-free buffers expose ArcBufferPage?.
Empty makes First == null a valid public state, but First and the constructor parameter still expose non-nullable ArcBufferPage. Nullable-aware callers therefore receive no warning before dereferencing ArcBuffer.Empty.First. Change both contracts to ArcBufferPage? and regenerate the API surface.
Consume exact remaining page capacity before allocating
Requesting exactly 4096 bytes causes ArcBufferWriter.GetSpan to allocate whenever the current page has exactly 4096 bytes left (sizeHint >= WriteCapacity). As a result, this copy path leaves one quarter of each 16 KiB pooled page unused and allocates roughly 33% more pages for large payloads. Obtain the current span first and cap the read size afterward so exact remaining capacity is consumed.
The newest successful coverage run tested 880559d, not current main 3f42edf.
Coverage combines every CI test matrix job, including providers, CodeGen, .NET 8/10, Linux, Windows, and macOS, using canonical physical source and branch identities.
The comparison remains report-only while normal line and branch variance is calibrated.
Empty makes a null First part of the valid public contract, but ArcBuffer.First and the constructor's first parameter are still declared non-nullable (and the generated API surface preserves that annotation). Nullable-aware consumers can therefore dereference ArcBuffer.Empty.First without a warning and get a NullReferenceException. Please annotate the page as ArcBufferPage? throughout the public and dependent internal API, then regenerate the API surface.
The disposed-state guard is only effective for methods which call ThrowIfPinnedPages. After Dispose() nulls the page fields, AdvanceReader(0), PeekSlice(0), and ConsumeSlice(0) still bypass this guard and dereference _readPage, producing NullReferenceException instead of the newly established ObjectDisposedException behavior. Add a shared disposed check to these public entry points as well.
The reason will be displayed to describe this comment to others. Learn more.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Create owned slices from the current backing page instead of rescanning consumed prefixes. Reuse the shared reader-to-writer copy helper and cover reference composition, cursor boundaries, and custom-codec local ownership cleanup.
Composite-failure rollback remains a separate ownership-design blocker; no borrowed-copy rollback assumption is introduced.
Track codec-acquired owners within returned-value serializer and copy operations. Transfer ownership at successful outermost return and release failed-operation acquisitions through release state shared with custom cleanup.
Preserve caller ownership for direct low-level calls and in-place partial results, document Reset before failed-context reuse, and regenerate the ArcBuffer reference-layout marker using official GenAPI.
AppendPinned adopts an independently pinned raw slice because the writer releases individual pages directly. Cover disposal, reader advancement, reset and writer survival across enclosing codec and copier failures.
Use relative empty-copy pin assertions, an exact Assert.Throws check for truncated empty input, and CI-compatible test whitespace.
Remove per-handle leases and serializer/copy-context rollback tracking per maintainer direction. Struct assignment borrows; each independent concurrent owner acquires its own pin before handoff and disposes its own copy exactly once.
Keep non-consuming serialization, independently owned decoding/copying, cursor-local reads and temporary-output failure cleanup. Document ownership responsibilities, cover parallel disposal and sender retry, and remove tests of the retired aggregate rollback guarantee.
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.
ArcBuffergains a built-in codec that preserves source ownership and contents across repeated serialization, and a copier that acquires independent pins over the referenced bytes.Reader<TInput>.ReadOwnedBuffer(int)centralizes owned payload reads: nonempty Arc input acquires slice pins from the reader's current backing page, other inputs copy into available pooled-page capacity through the shared reader-to-writer helper, and zero-length reads return owner-freeArcBuffer.Emptywithout advancing. Cursor-relative slicing preserves sequential traversal across page boundaries, empty pages, and nested fork offsets.Ownership is explicit. Struct assignment creates a borrowed view whose lifetime is bounded by its owner. Every independent owner acquires a pin before handoff using
Slice,Pin, or the copier, keeps its own struct copy, and disposes that handle exactly once. Concurrent owners can release their own handles while the remaining owners keep the immutable bytes alive. Serialization borrows the source; decoded/copied results belong to their caller. Code that acquires a result is responsible for releasing it, including when its subsequent work fails. Temporary writers used during payload copying are disposed when that operation fails, and sender-owned inputs remain available for retry.Following maintainer direction, this revision uses the existing explicit pin/borrowing contract and coding discipline. It removes the earlier per-handle lease and operation-rollback machinery, including
CopyContext.ArcBuffersandSerializerSession.ArcBuffers. General serializer and copy-context implementations match main. The focused tests cover borrowed struct assignments, independent concurrentSlice/Pin/copier owners, custom cleanup on failure, non-consuming serialization and retry, reference identity, and reader cursor/lifetime boundaries.Public signatures and the length-prefixed wire format are preserved. General buffer bounds/lifetime correctness and raw lifetime tests were split into merged #11474; this branch builds on main
fbe240c34e9a1389ca5ab2d52f292ed8749ea530.Originally extracted from #10693, this layer serves independently owned pooled-byte serialization. Durable Messaging uses GC-owned
byte[]envelope payloads and remains independent. Main's page-pool policy is preserved; RPC lifetimes and retention policy remain separate concerns.Microsoft Reviewers: Open in CodeFlow