]> git.feebdaed.xyz Git - 0xmirror/grpc-go.git/commit
mem: Remove Reader interface and export the concrete struct (#8669)
authorArjan Singh Bal <46515553+arjan-bal@users.noreply.github.com>
Tue, 28 Oct 2025 06:40:03 +0000 (12:10 +0530)
committerGitHub <noreply@github.com>
Tue, 28 Oct 2025 06:40:03 +0000 (12:10 +0530)
commit2d56bdadb11058f67c48e3c837fcf4a487e15346
tree0ebd4e6c6ab0f6b14b978d7508ec29ec37c5d432
parent8ab0c8214a28222821a1a761996b76f9bfa6aca7
mem: Remove Reader interface and export the concrete struct (#8669)

This PR changes the exported slice reader from an interface to a
concrete struct.

This approach follows the precedent set by standard library packages,
such as [`bufio`'s `bufio.Reader`](https://pkg.go.dev/bufio#Reader).
This interface was not intended for users to implement, and gRPC does
not plan to provide alternative implementations. Users who require an
interface for abstraction or testing can define one in their own
packages.

This change provides two main advantages:

* Performance: It avoids a couple of heap allocations per stream that
were previously required to hold the interface value.
* Maintainability: Adding new methods to the concrete struct is a
backward-compatible change, whereas adding methods to an interface is a
breaking change.

## Benchmarks
```sh
# test command
$ go run benchmark/benchmain/main.go -benchtime=60s -workloads=unary \
   -compression=off -maxConcurrentCalls=200 -trace=off \
   -reqSizeBytes=100 -respSizeBytes=100 -networkMode=Local -resultFile="${RUN_NAME}"

$ go run benchmark/benchresult/main.go unary-before unary-after
               Title       Before        After Percentage
            TotalOps      7801951      7883976     1.05%
             SendOps            0            0      NaN%
             RecvOps            0            0      NaN%
            Bytes/op     10005.90      9951.01    -0.54%
           Allocs/op       146.91       144.90    -1.36%
             ReqT/op 104026013.33 105119680.00     1.05%
            RespT/op 104026013.33 105119680.00     1.05%
            50th-Lat   1.375183ms   1.359194ms    -1.16%
            90th-Lat   2.293816ms   2.258941ms    -1.52%
            99th-Lat   3.162307ms   3.157381ms    -0.16%
             Avg-Lat   1.536462ms   1.520149ms    -1.06%
           GoVersion     go1.24.8     go1.24.8
         GrpcVersion   1.77.0-dev   1.77.0-dev
```

RELEASE NOTES:
* mem: Replace the `Reader` interface with a struct.
internal/transport/controlbuf.go
mem/buffer_slice.go