[#12] Free internal encoder buffer

```
goos: linux
goarch: amd64
pkg: git.frostfs.info/TrueCloudLab/zapjournald
cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
                                     │     old     │                  1                  │
                                     │   sec/op    │   sec/op     vs base                │
Logger/standard/no_fields-8            435.9n ± 4%   450.3n ± 2%   +3.30% (p=0.041 n=10)
Logger/standard/application_fields-8   629.0n ± 8%   610.4n ± 1%   -2.96% (p=0.002 n=10)
Logger/standard/journald_fields-8      626.8n ± 5%   595.8n ± 5%   -4.95% (p=0.029 n=10)
Logger/journald/no_fields-8            2.097µ ± 3%   1.809µ ± 4%  -13.73% (p=0.000 n=10)
Logger/journald/application_fields-8   2.348µ ± 5%   2.037µ ± 5%  -13.27% (p=0.000 n=10)
Logger/journald/journald_fields-8      2.396µ ± 4%   2.054µ ± 4%  -14.26% (p=0.000 n=10)
geomean                                1.125µ        1.036µ        -7.88%

                                     │      old       │                   1                    │
                                     │      B/op      │     B/op      vs base                  │
Logger/standard/no_fields-8              0.000 ± 0%       0.000 ± 0%        ~ (p=1.000 n=10) ¹
Logger/standard/application_fields-8     128.0 ± 0%       128.0 ± 0%        ~ (p=1.000 n=10) ¹
Logger/standard/journald_fields-8        64.00 ± 0%       64.00 ± 0%        ~ (p=1.000 n=10) ¹
Logger/journald/no_fields-8            2.210Ki ± 0%     1.178Ki ± 0%  -46.71% (p=0.000 n=10)
Logger/journald/application_fields-8   2.491Ki ± 0%     1.459Ki ± 0%  -41.43% (p=0.000 n=10)
Logger/journald/journald_fields-8      2.476Ki ± 0%     1.443Ki ± 0%  -41.70% (p=0.000 n=10)
geomean                                             ²                 -24.72%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

                                     │     old      │                  1                  │
                                     │  allocs/op   │ allocs/op   vs base                 │
Logger/standard/no_fields-8            0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
Logger/standard/application_fields-8   1.000 ± 0%     1.000 ± 0%       ~ (p=1.000 n=10) ¹
Logger/standard/journald_fields-8      1.000 ± 0%     1.000 ± 0%       ~ (p=1.000 n=10) ¹
Logger/journald/no_fields-8            31.00 ± 0%     29.00 ± 0%  -6.45% (p=0.000 n=10)
Logger/journald/application_fields-8   32.00 ± 0%     30.00 ± 0%  -6.25% (p=0.000 n=10)
Logger/journald/journald_fields-8      33.00 ± 0%     31.00 ± 0%  -6.06% (p=0.000 n=10)
geomean                                           ²               -3.18%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean
```

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-10-18 11:29:55 +03:00
parent 49c42ba807
commit 8c4cf38d6a

View file

@ -75,6 +75,7 @@ func (core *Core) Write(entry zapcore.Entry, fields []zapcore.Field) error {
if err != nil { if err != nil {
return fmt.Errorf("failed to encode log entry: %w", err) return fmt.Errorf("failed to encode log entry: %w", err)
} }
defer buffer.Free()
message := buffer.String() message := buffer.String()