Skip to content

Commit

Permalink
consoleEncoder: put cloned jsonEncoder back to pool (#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
wyxloading committed Jul 28, 2020
1 parent 53a3870 commit 6b618ff
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 6b618ff

Please sign in to comment.