Skip to content

Conversation

@arjan-bal
Copy link
Contributor

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. 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

# 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.

@arjan-bal arjan-bal added this to the 1.77 Release milestone Oct 23, 2025
@arjan-bal arjan-bal added Type: API Change Breaking API changes (experimental APIs only!) Area: Transport Includes HTTP/2 client/server and HTTP server handler transports and advanced transport features. labels Oct 23, 2025
@arjan-bal arjan-bal changed the title mem: Remove Reader interface and export the sliceReader struct mem: Remove Reader interface and export the concrete struct Oct 23, 2025
@codecov
Copy link

codecov bot commented Oct 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.01%. Comparing base (f448a97) to head (eae391a).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8669      +/-   ##
==========================================
+ Coverage   81.97%   83.01%   +1.04%     
==========================================
  Files         417      417              
  Lines       40788    32308    -8480     
==========================================
- Hits        33435    26822    -6613     
+ Misses       5991     4097    -1894     
- Partials     1362     1389      +27     
Files with missing lines Coverage Δ
internal/transport/controlbuf.go 91.07% <100.00%> (+1.19%) ⬆️
mem/buffer_slice.go 97.29% <100.00%> (+0.86%) ⬆️

... and 362 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@easwars easwars assigned arjan-bal and unassigned easwars and dfawley Oct 28, 2025
@arjan-bal arjan-bal merged commit 2d56bda into grpc:master Oct 28, 2025
15 checks passed
@arjan-bal arjan-bal deleted the remove-mem-reader-interface branch October 28, 2025 06:40
@nanassito
Copy link

welp we were using this interface :(

@dfawley
Copy link
Member

dfawley commented Oct 30, 2025

welp we were using this interface :(

If you can say more about why and how, maybe we can have a discussion.

In the meantime I can refer you to https://pkg.go.dev/google.golang.org/grpc/mem which says prominently at the top:

Experimental

Notice: All APIs in this package are EXPERIMENTAL and may be changed or removed in a later release.

And https://github.com/grpc/grpc-go/blob/master/Documentation/versioning.md:

The gRPC-Go versioning policy follows the Semantic Versioning 2.0.0 specification, with the following exceptions:

  • An API was marked as EXPERIMENTAL upon its introduction.

@nanassito
Copy link

@dfawley We are wrapping thrift into gRPC as a migration path. Don't worry though, we know this is experimental, the fix is trivial on our end to adapt to this.

@dfawley
Copy link
Member

dfawley commented Oct 30, 2025

@nanassito,

the fix is trivial on our end to adapt to this.

Glad to hear. We aren't trying to break anyone, so if something changes from possible->impossible, or is causing undue burden, even for experimental APIs, we would like to hear about it.

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

Labels

Area: Transport Includes HTTP/2 client/server and HTTP server handler transports and advanced transport features. Type: API Change Breaking API changes (experimental APIs only!)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants