Skip to content

Commit

Permalink
internal: Improve documentation around buffer.Unbounded (grpc#3241)
Browse files Browse the repository at this point in the history
  • Loading branch information
easwars authored Dec 10, 2019
1 parent 3a4f66e commit 81a07a9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 7 additions & 0 deletions internal/buffer/unbounded.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ import "sync"
//
// All methods on this type are thread-safe and don't block on anything except
// the underlying mutex used for synchronization.
//
// Unbounded supports values of any type to be stored in it by using a channel
// of `interface{}`. This means that a call to Put() incurs an extra memory
// allocation, and also that users need a type assertion while reading. For
// performance critical code paths, using Unbounded is strongly discouraged and
// defining a new type specific implementation of this buffer is preferred. See
// internal/transport/transport.go for an example of this.
type Unbounded struct {
c chan interface{}
mu sync.Mutex
Expand Down
9 changes: 5 additions & 4 deletions internal/transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ type recvMsg struct {
}

// recvBuffer is an unbounded channel of recvMsg structs.
// Note recvBuffer differs from controlBuffer only in that recvBuffer
// holds a channel of only recvMsg structs instead of objects implementing "item" interface.
// recvBuffer is written to much more often than
// controlBuffer and using strict recvMsg structs helps avoid allocation in "recvBuffer.put"
//
// Note: recvBuffer differs from buffer.Unbounded only in the fact that it
// holds a channel of recvMsg structs instead of objects implementing "item"
// interface. recvBuffer is written to much more often and using strict recvMsg
// structs helps avoid allocation in "recvBuffer.put"
type recvBuffer struct {
c chan recvMsg
mu sync.Mutex
Expand Down

0 comments on commit 81a07a9

Please sign in to comment.