Skip to content

Commit

Permalink
consoleEncoder: put cloned jsonEncoder back to pool (uber-go#851)
Browse files Browse the repository at this point in the history
consoleEncoder clone a jsonEncoder in `writeContext`, but never put back to pool after use.
This make zap do more memory allocations, and may increase gc time.
  • Loading branch information
wuyuxiang committed Jul 28, 2020
1 parent 53a3870 commit bb9aed3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion zapcore/console_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ func (c consoleEncoder) EncodeEntry(ent Entry, fields []Field) (*buffer.Buffer,

func (c consoleEncoder) writeContext(line *buffer.Buffer, extra []Field) {
context := c.jsonEncoder.Clone().(*jsonEncoder)
defer context.buf.Free()
defer func() {
context.buf.Free()
putJSONEncoder(context)
}()

addFields(context, extra)
context.closeOpenNamespaces()
Expand Down

0 comments on commit bb9aed3

Please sign in to comment.