grpc-go icon indicating copy to clipboard operation
grpc-go copied to clipboard

Reuse compression buffer

Open ash2k opened this issue 1 year ago • 1 comments

Use case(s) - what problem will this feature solve?

gRPC's compression code allocates a bytes.Buffer for each sent message. This code is responsible for 25% of RAM allocations in my program.

https://github.com/grpc/grpc-go/blob/d41b01db97ca2e3627b2c9949fffe8f152a4255d/rpc_util.go#L658

Screenshot 2024-02-08 at 11 09 27 am

Proposed Solution

Reuse bytes.Buffer using a sync.Pool.

Alternatives Considered

Additional Context

ash2k avatar Feb 08 '24 00:02 ash2k

To the folks interested in this behavior that are open to using third-party dependencies, I suggest https://github.com/mostynb/go-grpc-compression

It's got a lot of more efficient algorithms, too.

jzelinskie avatar Aug 22 '24 18:08 jzelinskie

We've made some recent changes to introduce a new encoding API which addresses this issue. See: https://github.com/grpc/grpc-go/pull/7356

Would appreciate your feedback on how the new changes work for you.

Also, I'm closing this, and if you still have issues, please use https://github.com/grpc/grpc-go/issues/6619 or file a new issue. Thanks.

easwars avatar Aug 30 '24 18:08 easwars