Commit 2d56bda
authored
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.1 parent 8ab0c82 commit 2d56bda
2 files changed
+27
-34
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
665 | 665 | | |
666 | 666 | | |
667 | 667 | | |
668 | | - | |
669 | | - | |
670 | | - | |
671 | | - | |
672 | | - | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
673 | 672 | | |
674 | 673 | | |
675 | 674 | | |
| |||
701 | 700 | | |
702 | 701 | | |
703 | 702 | | |
704 | | - | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
709 | 707 | | |
710 | 708 | | |
711 | 709 | | |
| |||
948 | 946 | | |
949 | 947 | | |
950 | 948 | | |
951 | | - | |
| 949 | + | |
952 | 950 | | |
953 | 951 | | |
954 | 952 | | |
955 | | - | |
| 953 | + | |
956 | 954 | | |
957 | 955 | | |
958 | 956 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
| 120 | + | |
121 | 121 | | |
122 | | - | |
| 122 | + | |
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
146 | 135 | | |
147 | 136 | | |
148 | 137 | | |
149 | 138 | | |
150 | 139 | | |
151 | 140 | | |
152 | | - | |
| 141 | + | |
| 142 | + | |
153 | 143 | | |
154 | 144 | | |
155 | 145 | | |
156 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
157 | 149 | | |
158 | 150 | | |
159 | 151 | | |
160 | 152 | | |
161 | 153 | | |
162 | 154 | | |
163 | 155 | | |
164 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
165 | 159 | | |
166 | 160 | | |
167 | 161 | | |
168 | 162 | | |
169 | 163 | | |
170 | 164 | | |
171 | | - | |
| 165 | + | |
172 | 166 | | |
173 | 167 | | |
174 | 168 | | |
| |||
179 | 173 | | |
180 | 174 | | |
181 | 175 | | |
182 | | - | |
| 176 | + | |
183 | 177 | | |
184 | 178 | | |
185 | 179 | | |
| |||
202 | 196 | | |
203 | 197 | | |
204 | 198 | | |
205 | | - | |
| 199 | + | |
| 200 | + | |
206 | 201 | | |
207 | 202 | | |
208 | 203 | | |
| |||
0 commit comments