Skip to content

Commit

Permalink
perf(bigtable): Use RecvMsg instead of Recv (#10674)
Browse files Browse the repository at this point in the history
* perf(bigtable): reuse existing memory for all stream responses

* feat(bigtable): Reset data before receiving message
  • Loading branch information
bhshkh authored Aug 28, 2024
1 parent dfe3af4 commit 7e4fbc5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions bigtable/bigtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,10 @@ func (t *Table) readRows(ctx context.Context, arg RowSet, f func(Row) bool, mt *
// Ignore error since header is only being used to record builtin metrics
// Failure to record metrics should not fail the operation
*headerMD, _ = stream.Header()
res := new(btpb.ReadRowsResponse)
for {
res, err := stream.Recv()
proto.Reset(res)
err := stream.RecvMsg(res)
if err == io.EOF {
*trailerMD = stream.Trailer()
break
Expand Down Expand Up @@ -438,7 +440,8 @@ func (t *Table) readRows(ctx context.Context, arg RowSet, f func(Row) bool, mt *
// Cancel and drain stream.
cancel()
for {
if _, err := stream.Recv(); err != nil {
proto.Reset(res)
if err := stream.RecvMsg(res); err != nil {
*trailerMD = stream.Trailer()
// The stream has ended. We don't return an error
// because the caller has intentionally interrupted the scan.
Expand Down

0 comments on commit 7e4fbc5

Please sign in to comment.