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.02%. Comparing base (f448a97) to head (7d18a35).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8669      +/-   ##
==========================================
+ Coverage   81.97%   83.02%   +1.04%     
==========================================
  Files         417      417              
  Lines       40788    32294    -8494     
==========================================
- Hits        33435    26811    -6624     
+ Misses       5991     4099    -1892     
- Partials     1362     1384      +22     
Files with missing lines Coverage Δ
internal/transport/controlbuf.go 90.04% <100.00%> (+0.15%) ⬆️
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.

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.

3 participants