-
Notifications
You must be signed in to change notification settings - Fork 4.6k
transport: Reduce pointer usage in Stream structs #8624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #8624 +/- ##
==========================================
+ Coverage 82.12% 82.15% +0.03%
==========================================
Files 415 415
Lines 40701 40711 +10
==========================================
+ Hits 33425 33447 +22
+ Misses 5895 5884 -11
+ Partials 1381 1380 -1
🚀 New features to boost your workflow:
|
a44546b
to
4ebd663
Compare
4ebd663
to
42b1067
Compare
func newWriteQuota(sz int32, done <-chan struct{}) *writeQuota { | ||
w := &writeQuota{ | ||
func initWriteQuota(wq *writeQuota, sz int32, done <-chan struct{}) { | ||
*wq = writeQuota{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This syntax does feel a little weird to me. Did you try some of these options to see if they read better (and don't perform worse)?
- directly set fields of
wq
in here instead of settingwq
to a completely new instance ofwriteQuota
- Can this
initWriteQuota
be a method onStream
? - Can we make the zero value of
writeQouta
something that can actually work?
This comment applies to other types as well like recvBuffer
.
Thanks.
The pprof profiles for unary RPC benchmarks indicate significant time spent in
runtime.mallocgc
andruntime.gcBgMarkWorker
. This indicates gRPC is spending significant CPU cycles allocating or garbage collecting.This change reduces the number of pointer fields in the structs that represent client and server stream. This will reduce number of memory allocations (faster) and also reduce pressure on garbage collector (faster garbage collections) since the GC doesn't need to scan non-pointer fields. For structs which were stored as pointers to ensure values are not copied, a
noCopy
struct is embedded that will causego vet
to fail if copies are performed. Non-pointer fields are also moved to the end of the struct to improve allocation speed.Results
There are improvements in QPS, latency and allocs/op for unary RPCs.
Resources
RELEASE NOTES: