Skip to content

Replace MemoryStream with RecyclableMemoryStream for stream pooling#4122

Merged
jeremydmiller merged 1 commit intomasterfrom
recyclable-streams
Feb 9, 2026
Merged

Replace MemoryStream with RecyclableMemoryStream for stream pooling#4122
jeremydmiller merged 1 commit intomasterfrom
recyclable-streams

Conversation

@jeremydmiller
Copy link
Member

Summary

  • Adds Microsoft.IO.RecyclableMemoryStream (v3.0.1) to pool MemoryStream instances used across Marten's JSON streaming APIs
  • Replaces all 14 new MemoryStream() allocations in Marten and Marten.AspNetCore with pooled streams via a shared RecyclableMemoryStreamManager
  • Reduces GC pressure from repeated buffer allocations in high-throughput scenarios

Closes #2791

Test plan

  • CoreTests pass (256 passed, 10 pre-existing failures unrelated to this change)
  • DocumentDbTests pass (925 passed, 12 pre-existing failures unrelated to this change)
  • Marten and Marten.AspNetCore build cleanly across net8.0/net9.0/net10.0

🤖 Generated with Claude Code

Introduces Microsoft.IO.RecyclableMemoryStream to pool MemoryStream
instances used in JSON streaming APIs, reducing GC pressure from
repeated buffer allocations. Closes GH-2791

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Pooling of Streams in Marten.AspNetCore.QueryableExtensions

1 participant