Commit 8695645
perf: reuse one Utf8TextWriter for custom formatter bodies
Serialization allocated a Utf8TextWriter per event inside the batch loop on
the custom-ITextFormatter path -- 48 bytes each, ~47 KB of garbage per
1000-event batch. SerializationBuffers already caches the equivalent writer
for the message buffer; this adds the symmetric one over the body buffer.
Safe because Utf8TextWriter holds no state beyond its backing buffer (every
Write goes straight through, there is no internal buffering), that buffer is
already cleared per event, and SerializationBuffers is sink-owned and used
serially -- the same guarantee MessageWriter already relies on. Dropping the
`use` costs nothing: Utf8TextWriter does not override Dispose, so a formatter
retaining the reference is exactly as protected as before.
CustomFormatterSinkBenchmarks, Push(EventCount: 1000):
Payload=Simple 116.03 KB -> 69.37 KB (-40.2%)
Payload=Exception 7573.80 KB -> 7519.11 KB (-0.7%, exception rendering dominates)
Covered by the existing batch test, which drives a custom formatter across
four events and would fail if the reused writer carried state between them.
Refs #349
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 9b0afd1 commit 8695645
1 file changed
Lines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
45 | 50 | | |
46 | 51 | | |
47 | 52 | | |
48 | 53 | | |
49 | 54 | | |
| 55 | + | |
50 | 56 | | |
51 | 57 | | |
52 | 58 | | |
| |||
131 | 137 | | |
132 | 138 | | |
133 | 139 | | |
| 140 | + | |
| 141 | + | |
134 | 142 | | |
135 | 143 | | |
136 | 144 | | |
137 | | - | |
138 | | - | |
| 145 | + | |
139 | 146 | | |
140 | 147 | | |
141 | 148 | | |
| |||
0 commit comments