grpc / grpc/grpc-dotnet

Improve memory usage when compression is enabled

Open
#2,329 1 comment 3 reactions 0 assignees View on GitHub
enhancement
Dominant language
C#
Stars
4.5k
Forks
836
Avg merge
6d 3h
Merged PRs (30d)
7

Description

Compression creates a stream on the server because compression APIs are stream based. e.g. https://github.com/grpc/grpc-dotnet/blob/1625f8942791c82d700802fc7278c543025f0fd3/src/Grpc.AspNetCore.Server/Internal/HttpContextSerializationContext.cs#L239-L248

Right now, a memory stream is created which can allocate a large buffer. We could improve memory usage by reusing buffer with something like https://github.com/microsoft/Microsoft.IO.RecyclableMemoryStream

Using https://github.com/microsoft/Microsoft.IO.RecyclableMemoryStream would add a dependency. It might be possible to build a simpler implementation to avoid the dependency.

Contributor guide

Open the contributing guide

Research direction

Start with src/Grpc.AspNetCore.Server/Internal/HttpContextSerializationContext.cs at the referenced lines to understand how compression creates and uses the memory stream. Compare a recyclable-stream approach with a simpler implementation, then verify that compression behavior is unchanged while large buffer allocations and peak memory usage are reduced.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend, performance
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.