Skip to content

Add MpscGrowableBuffer - #836

Open
bitfaster wants to merge 2 commits into
mainfrom
feat/mpsc-growable-array-queue
Open

bitfaster wants to merge 2 commits into
mainfrom
feat/mpsc-growable-array-queue

Conversation

@bitfaster

@bitfaster bitfaster commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Summary

Add MpscGrowableBuffer<T> to BitFaster.Caching.Buffers, adapting Caffeine's growable MPSC queue (derived from JCTools 2.0).

  • Grow by linking progressively larger arrays without copying queued items. Enforce a power-of-two maximum capacity and reuse the final array as a ring buffer.
  • Reuse PaddedLong for the producer index, consumer index, and cached producer limit, with Interlocked/Volatile publication.
  • Provide the BitFaster-style TryAdd/TryTake API returning BufferStatus, plus Count, Capacity, Clear, and DrainTo. Contention is reported rather than spinning inside the try methods; consumer operations require a single consumer.
  • Restore the producer index if resize allocation fails. An internal allocation seam supports deterministic failure and in-progress resize tests without changing the public API.
  • Cover growth, wraparound, FIFO ordering, capacity bounds, reference release, concurrent producers, resize contention, and allocation failure in one test class.
  • Retain upstream attribution and include the Apache 2.0 license in THIRD-PARTY-NOTICES.txt, including the NuGet package.

This is a standalone addition against main; existing buffers and cache implementations are unchanged.

Validation

  • dotnet format on the library and unit-test projects, scoped to the changed C# files.
  • Renamed buffer unit tests: 119 passed across .NET Framework 4.8, .NET Core 3.1, .NET 6, and .NET 10.
  • Release package generation and package/API compatibility validation passed. Verified that the packaged third-party notice exactly matches the source file.
  • git diff --cached --check passed.

The .NET 10 build emitted an AD0001 warning from DoNotPassDisposablesIntoUnawaitedTasksAnalyzer; compilation and tests completed successfully.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 154d216f-cb02-4eb0-b7af-f0fb50f4e328
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 154d216f-cb02-4eb0-b7af-f0fb50f4e328
@bitfaster bitfaster changed the title Add MpscGrowableArrayQueue Add MpscGrowableBuffer Nov 29, 2026
}

var expected = new Queue<string>();
var random = new Random(42);
@coveralls

coveralls commented Nov 29, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 99.252%. first build — feat/mpsc-growable-array-queue into main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants