Optimize encoder #12
No reviewers
Labels
No labels
Infrastructure
blocked
bug
config
discussion
documentation
duplicate
enhancement
go
help wanted
internal
invalid
kludge
observability
perfomance
question
refactoring
wontfix
No milestone
No project
No assignees
6 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: TrueCloudLab/zapjournald#12
Loading…
Reference in a new issue
No description provided.
Delete branch "fyrchik/zapjournald:optimize-encoder"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Reduce time overhead for encoding log from ~300% to ~30%
Reduce allocations by infinity.
Also, fix a bug where
SYSLOG_
fields were duplicated both in user message and in journald fields.Here we try a bit different approach by providing encoder and sink, but using standard core.
Most of the optimizations are possible even with the current approach, let's discuss.
We are using zap, so I believe having 0 allocations is worth the effort.
@ -0,0 +45,4 @@
}
func (e *journaldEncoder) Clone() zapcore.Encoder {
return &journaldEncoder{Encoder: e.Encoder.Clone()}
Please explain why only the encoder is cloned? Why aren't the other fields (fields and buf) cloned?
Because I wrote this like before adding buffers, will fix
removed this
That's awesome stuff!
@ -0,0 +32,4 @@
var pool = buffer.NewPool()
func newEncoder(cfg zapcore.EncoderConfig, fields ...field) *journaldEncoder {
// FIXME (@fyrchik): We would like to accept any encoder here, but to prevent acidentally passing journald encoder.
acidentally -> accidentally
removed this
@ -0,0 +73,4 @@
}
}
func writeFieldBytes(w *buffer.Buffer, name string, value []byte) {
Let's probably stick with
buf
for buffer parameter name (as on line 68).@ -0,0 +98,4 @@
w.Write([]byte{'\n'})
// 1 allocation here.
// binary.Write(w, binary.LittleEndian, uint64(len(value)))
Let's remove commented code.
I wanted to keep the code from
journal
library for easier verification.ca8f766274
to2821b2e8f9
2821b2e8f9
toad30ad03a0
ad30ad03a0
to7db0bb250b
Skip
fields allow to optimize, but it looks hacky: we could always haveInterface
, but it is +1 allocation. Another option is to haveObjectMarshaler
field set, should try this too.Actual benchmark results:
7db0bb250b
to028c873de4
028c873de4
to1eb6e99148
1eb6e99148
to8c785a966e
8c785a966e
toa9e1aa74f7
With my scheme we cannot currently support all requirements. So let's make this PR do the first 80% of the optimizations and have some correctness fixes. Let's discuss the other 20% in #14
a9e1aa74f7
to2b6d84de9a