Skip to content

Commit

Permalink
pref: clear filedef's listener fields' pool on Close (#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
muktihari authored Oct 9, 2024
1 parent 5b0e64f commit 6bf188f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions profile/filedef/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ func (l *Listener) Close() {
return
}
close(l.mesgc)

// PERF: In case the Listener might be reused later, this ensure fields' pool does not reference any pointer
// such as proto.FieldBase created for unknown fields or field.Value that reference any pointer to a slice.
for i := uint(0); i < l.options.channelBuffer; i++ {
fields := <-l.poolc
clear(fields[:cap(fields):cap(fields)])
l.poolc <- fields
}

<-l.done
l.active = false
}
Expand Down

0 comments on commit 6bf188f

Please sign in to comment.