Skip to content

Replace strconv.Quote with strconv.AppendQuote everywhere to reduce allocations#426

Open
asergunov wants to merge 4 commits intokubernetes:mainfrom
asergunov:reduce-allocations
Open

Replace strconv.Quote with strconv.AppendQuote everywhere to reduce allocations#426
asergunov wants to merge 4 commits intokubernetes:mainfrom
asergunov:reduce-allocations

Conversation

@asergunov
Copy link

What this PR does / why we need it:

Spotted calls to strconv.Quote which allocates the new string. Replaced with strconv.AppendQuote.

In most of the places I'm using the pattern:

b.Write(strconv.AppendQuote(b.AvailableBuffer(), str))

So we reusing the already allocated buffer if it's available.

The only exception is stack-allocated fixed size buffers we have introduced in #413. As you can see from the benchmark_out_reduce-allocations-fix-alloc.txt column it's faster in benchmarks as it is. The benchmark_out_reduce-allocations.txt is a results with these places also replaced and you can see it performs worse in some cases. So I kept that code untouched.

goos: linux
goarch: amd64
pkg: k8s.io/klog/v2/textlogger
cpu: 13th Gen Intel(R) Core(TM) i5-1345U
                                                                               │ benchmark_out_main.txt │ benchmark_out_reduce-allocations-fix-alloc.txt │ benchmark_out_reduce-allocations.txt  │
                                                                               │         sec/op         │         sec/op           vs base               │    sec/op      vs base                │
TextloggerOutput/handle_odd-numbers_of_KVs_in_both_log_values_and_Info_args-12             4.363µ ± 19%             1.429µ ±   4%  -67.25% (p=0.001 n=7)    1.981µ ± 35%   -54.60% (p=0.001 n=7)
TextloggerOutput/KObjs-12                                                                  2.855µ ± 47%             1.285µ ±  12%  -54.99% (p=0.001 n=7)    3.992µ ±  7%   +39.82% (p=0.017 n=7)
TextloggerOutput/KObjSlice_int_arg-12                                                      3.095µ ± 36%             1.157µ ±   8%  -62.62% (p=0.001 n=7)    1.519µ ± 13%   -50.92% (p=0.001 n=7)
TextloggerOutput/String()_that_panics-12                                                   3.339µ ± 19%             1.686µ ±  28%  -49.51% (p=0.001 n=7)    4.261µ ± 13%   +27.61% (p=0.002 n=7)
TextloggerOutput/mixed_duplicates-12                                                      19.123µ ±  8%             7.769µ ±   3%  -59.37% (p=0.001 n=7)   23.587µ ± 30%         ~ (p=0.165 n=7)
TextloggerOutput/vmodule-12                                                                3.586µ ± 21%             2.029µ ±  13%  -43.42% (p=0.001 n=7)    3.397µ ± 25%         ~ (p=0.318 n=7)
TextloggerOutput/call_depth-12                                                             3.193µ ± 21%             1.108µ ±   6%  -65.30% (p=0.001 n=7)    1.630µ ± 54%   -48.95% (p=0.001 n=7)
TextloggerOutput/Error()_for_nil-12                                                       13.133µ ± 14%             4.342µ ±  75%  -66.94% (p=0.001 n=7)   13.181µ ±  9%         ~ (p=0.902 n=7)
TextloggerOutput/Error()_that_panics-12                                                    4.799µ ± 16%             1.784µ ±  19%  -62.83% (p=0.001 n=7)    4.000µ ± 18%   -16.65% (p=0.004 n=7)
TextloggerOutput/MarshalLog()_that_panics-12                                               4.676µ ±  7%             1.645µ ±  14%  -64.82% (p=0.001 n=7)    3.293µ ± 33%   -29.58% (p=0.001 n=7)
TextloggerOutput/other_vmodule-12                                                          839.6n ± 10%             305.7n ±   6%  -63.59% (p=0.001 n=7)    689.1n ± 34%   -17.93% (p=0.026 n=7)
TextloggerOutput/KObjSlice_nil_entry-12                                                    2.959µ ±  5%             1.097µ ±  16%  -62.93% (p=0.001 n=7)    2.809µ ± 15%    -5.07% (p=0.011 n=7)
TextloggerOutput/ignore_MarshalJSON-12                                                     3.054µ ±  7%             1.037µ ±  52%  -66.04% (p=0.001 n=7)    2.669µ ± 19%         ~ (p=0.259 n=7)
TextloggerOutput/struct_values-12                                                          3.424µ ±  9%             1.306µ ±   6%  -61.86% (p=0.001 n=7)    2.957µ ± 21%   -13.64% (p=0.004 n=7)
TextloggerOutput/log_with_name_and_values-12                                               3.426µ ± 16%             1.243µ ±  28%  -63.72% (p=0.001 n=7)    3.177µ ± 21%         ~ (p=0.318 n=7)
TextloggerOutput/handle_odd-numbers_of_KVs-12                                              3.065µ ±  5%             1.167µ ±  14%  -61.92% (p=0.001 n=7)    3.471µ ± 14%   +13.25% (p=0.001 n=7)
TextloggerOutput/regular_error_types_as_value-12                                           2.539µ ± 18%             1.005µ ± 122%  -60.42% (p=0.001 n=7)    2.679µ ± 15%         ~ (p=0.383 n=7)
TextloggerOutput/KObjSlice_nil_arg-12                                                     2213.0n ± 16%             977.2n ±  29%  -55.84% (p=0.001 n=7)   1318.0n ± 15%   -40.44% (p=0.001 n=7)
TextloggerOutput/odd_WithValues-12                                                         9.966µ ± 22%             3.563µ ±  14%  -64.25% (p=0.001 n=7)   10.910µ ± 27%         ~ (p=0.710 n=7)
TextloggerOutput/multiple_WithValues-12                                                   10.511µ ±  7%             5.030µ ±  11%  -52.15% (p=0.001 n=7)   13.295µ ±  8%   +26.49% (p=0.001 n=7)
TextloggerOutput/quotation-12                                                              2.925µ ± 19%             1.025µ ±   7%  -64.96% (p=0.001 n=7)    2.426µ ± 46%         ~ (p=0.053 n=7)
TextloggerOutput/preserve_order_of_key/value_pairs-12                                      4.650µ ± 15%             1.359µ ±  24%  -70.77% (p=0.001 n=7)    3.970µ ± 17%   -14.62% (p=0.017 n=7)
TextloggerOutput/KObjSlice_okay-12                                                         2.732µ ± 20%             1.175µ ±  12%  -56.99% (p=0.001 n=7)    1.724µ ± 32%   -36.90% (p=0.001 n=7)
TextloggerOutput/KObjSlice_ints-12                                                         3.198µ ± 23%             1.052µ ±  14%  -67.10% (p=0.001 n=7)    1.810µ ± 29%   -43.40% (p=0.001 n=7)
TextloggerOutput/String()_for_nil-12                                                      13.027µ ± 15%             4.376µ ±   8%  -66.41% (p=0.001 n=7)   12.669µ ± 14%         ~ (p=0.805 n=7)
TextloggerOutput/MarshalLog()_that_returns_itself-12                                       3.234µ ± 22%             1.144µ ±  54%  -64.63% (p=0.001 n=7)    1.881µ ± 36%   -41.84% (p=0.001 n=7)
TextloggerOutput/log_with_values-12                                                        2.682µ ± 19%             1.003µ ±  12%  -62.60% (p=0.001 n=7)    1.358µ ± 35%   -49.37% (p=0.001 n=7)
TextloggerOutput/override_single_value-12                                                  3.411µ ± 20%             1.258µ ±  51%  -63.12% (p=0.001 n=7)    3.768µ ± 24%         ~ (p=0.128 n=7)
TextloggerOutput/override_WithValues-12                                                    4.605µ ± 19%             1.479µ ±  14%  -67.88% (p=0.001 n=7)    2.610µ ± 26%   -43.32% (p=0.001 n=7)
TextloggerOutput/handle_integer_keys-12                                                    4.969µ ± 23%             1.637µ ±  12%  -67.06% (p=0.001 n=7)    4.724µ ± 43%         ~ (p=0.259 n=7)
TextloggerOutput/duplicates-12                                                            20.498µ ± 15%             7.045µ ±  13%  -65.63% (p=0.001 n=7)   21.466µ ± 24%         ~ (p=0.805 n=7)
TextloggerOutput/struct_keys-12                                                            4.376µ ± 23%             1.360µ ±  10%  -68.92% (p=0.001 n=7)    4.143µ ± 10%         ~ (p=0.383 n=7)
TextloggerOutput/slice_values-12                                                           3.882µ ± 13%             1.374µ ±  48%  -64.61% (p=0.001 n=7)    3.665µ ±  7%         ~ (p=0.259 n=7)
TextloggerOutput/verbosity_disabled-12                                                    166.40n ± 26%             76.25n ±  11%  -54.18% (p=0.001 n=7)   175.60n ± 14%         ~ (p=0.805 n=7)
TextloggerOutput/log_with_multiple_names_and_values-12                                     4.339µ ± 20%             1.337µ ±   9%  -69.19% (p=0.001 n=7)    3.575µ ± 38%         ~ (p=0.209 n=7)
TextloggerOutput/empty_WithValues-12                                                      2580.0n ± 15%             968.0n ±  30%  -62.48% (p=0.001 n=7)   2478.0n ± 14%         ~ (p=0.318 n=7)
TextloggerOutput/MarshalLog()_for_nil-12                                                   4.626µ ± 25%             1.817µ ±  18%  -60.72% (p=0.001 n=7)    4.765µ ±  6%         ~ (p=0.128 n=7)
TextloggerOutput/klog.Format-12                                                            6.059µ ± 25%             2.130µ ±   8%  -64.85% (p=0.001 n=7)    4.186µ ± 31%   -30.91% (p=0.004 n=7)
TextloggerOutput/verbosity_enabled-12                                                     2263.0n ± 59%             814.8n ±  11%  -63.99% (p=0.001 n=7)   2482.0n ± 22%         ~ (p=0.165 n=7)
TextloggerOutput/KObj-12                                                                   978.3n ±  8%             993.6n ±   9%        ~ (p=0.805 n=7)   1439.0n ± 16%   +47.09% (p=0.001 n=7)
TextloggerOutput/regular_error_types_when_using_logr.Error-12                              1.064µ ± 11%             1.065µ ±  12%        ~ (p=1.000 n=7)    2.894µ ±  8%  +171.99% (p=0.001 n=7)
TextloggerOutput/map_values-12                                                             2.217µ ± 20%             2.443µ ±  17%        ~ (p=0.805 n=7)    3.204µ ± 37%   +44.52% (p=0.001 n=7)
TextloggerOutput/cyclic_list-12                                                            189.2µ ± 44%             147.6µ ±  28%        ~ (p=0.053 n=7)    218.1µ ± 35%   +15.28% (p=0.026 n=7)
TextloggerOutput/print_duplicate_keys_in_arguments-12                                      1.517µ ± 26%             1.253µ ±  28%  -17.40% (p=0.024 n=7)    3.463µ ± 21%  +128.28% (p=0.001 n=7)
TextloggerOutput/html_characters-12                                                        1.089µ ± 80%             1.020µ ±  13%        ~ (p=0.128 n=7)    1.235µ ± 20%         ~ (p=0.209 n=7)
TextloggerOutput/map_keys-12                                                               1.796µ ± 26%             1.739µ ±  16%        ~ (p=0.209 n=7)    2.616µ ± 24%   +45.66% (p=0.007 n=7)
geomean                                                                                    3.651µ                   1.563µ         -57.18%                  3.420µ          -6.32%

                                                                               │ benchmark_out_main.txt │ benchmark_out_reduce-allocations-fix-alloc.txt │ benchmark_out_reduce-allocations.txt  │
                                                                               │          B/op          │         B/op           vs base                 │     B/op      vs base                 │
TextloggerOutput/handle_odd-numbers_of_KVs_in_both_log_values_and_Info_args-12               424.0 ± 0%              360.0 ± 0%  -15.09% (p=0.001 n=7)       360.0 ± 0%  -15.09% (p=0.001 n=7)
TextloggerOutput/KObjs-12                                                                    296.0 ± 0%              296.0 ± 0%        ~ (p=1.000 n=7) ¹     296.0 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/KObjSlice_int_arg-12                                                        296.0 ± 0%              296.0 ± 0%        ~ (p=1.000 n=7) ¹     296.0 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/String()_that_panics-12                                                     376.0 ± 0%              328.0 ± 0%  -12.77% (p=0.001 n=7)       328.0 ± 0%  -12.77% (p=0.001 n=7)
TextloggerOutput/mixed_duplicates-12                                                       3.081Ki ± 0%            2.377Ki ± 0%  -22.85% (p=0.001 n=7)     2.378Ki ± 0%  -22.82% (p=0.001 n=7)
TextloggerOutput/vmodule-12                                                                  296.0 ± 0%              296.0 ± 0%        ~ (p=1.000 n=7) ¹     296.0 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/call_depth-12                                                               376.0 ± 0%              360.0 ± 0%   -4.26% (p=0.001 n=7)       360.0 ± 0%   -4.26% (p=0.001 n=7)
TextloggerOutput/Error()_for_nil-12                                                          712.0 ± 0%              520.0 ± 0%  -26.97% (p=0.001 n=7)       520.0 ± 0%  -26.97% (p=0.001 n=7)
TextloggerOutput/Error()_that_panics-12                                                      376.0 ± 0%              328.0 ± 0%  -12.77% (p=0.001 n=7)       328.0 ± 0%  -12.77% (p=0.001 n=7)
TextloggerOutput/MarshalLog()_that_panics-12                                                 392.0 ± 0%              344.0 ± 0%  -12.24% (p=0.001 n=7)       344.0 ± 0%  -12.24% (p=0.001 n=7)
TextloggerOutput/other_vmodule-12                                                            64.00 ± 0%              64.00 ± 0%        ~ (p=1.000 n=7) ¹     64.00 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/KObjSlice_nil_entry-12                                                      296.0 ± 0%              296.0 ± 0%        ~ (p=1.000 n=7) ¹     296.0 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/ignore_MarshalJSON-12                                                       312.0 ± 0%              296.0 ± 0%   -5.13% (p=0.001 n=7)       296.0 ± 0%   -5.13% (p=0.001 n=7)
TextloggerOutput/struct_values-12                                                            296.0 ± 0%              296.0 ± 0%        ~ (p=1.000 n=7) ¹     296.0 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/log_with_name_and_values-12                                                 440.0 ± 0%              408.0 ± 0%   -7.27% (p=0.001 n=7)       408.0 ± 0%   -7.27% (p=0.001 n=7)
TextloggerOutput/handle_odd-numbers_of_KVs-12                                                328.0 ± 0%              296.0 ± 0%   -9.76% (p=0.001 n=7)       296.0 ± 0%   -9.76% (p=0.001 n=7)
TextloggerOutput/regular_error_types_as_value-12                                             312.0 ± 0%              296.0 ± 0%   -5.13% (p=0.001 n=7)       296.0 ± 0%   -5.13% (p=0.001 n=7)
TextloggerOutput/KObjSlice_nil_arg-12                                                        296.0 ± 0%              296.0 ± 0%        ~ (p=1.000 n=7) ¹     296.0 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/odd_WithValues-12                                                          1064.0 ± 0%             1000.0 ± 0%   -6.02% (p=0.001 n=7)      1000.0 ± 0%   -6.02% (p=0.001 n=7)
TextloggerOutput/multiple_WithValues-12                                                    1.470Ki ± 0%            1.470Ki ± 0%        ~ (p=1.000 n=7) ¹   1.470Ki ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/quotation-12                                                                320.0 ± 0%              296.0 ± 0%   -7.50% (p=0.001 n=7)       296.0 ± 0%   -7.50% (p=0.001 n=7)
TextloggerOutput/preserve_order_of_key/value_pairs-12                                        472.0 ± 0%              392.0 ± 0%  -16.95% (p=0.001 n=7)       392.0 ± 0%  -16.95% (p=0.001 n=7)
TextloggerOutput/KObjSlice_okay-12                                                           296.0 ± 0%              296.0 ± 0%        ~ (p=1.000 n=7) ¹     296.0 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/KObjSlice_ints-12                                                           304.0 ± 0%              304.0 ± 0%        ~ (p=1.000 n=7) ¹     304.0 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/String()_for_nil-12                                                         712.0 ± 0%              520.0 ± 0%  -26.97% (p=0.001 n=7)       520.0 ± 0%  -26.97% (p=0.001 n=7)
TextloggerOutput/MarshalLog()_that_returns_itself-12                                         296.0 ± 0%              296.0 ± 0%        ~ (p=1.000 n=7) ¹     296.0 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/log_with_values-12                                                          312.0 ± 0%              296.0 ± 0%   -5.13% (p=0.001 n=7)       296.0 ± 0%   -5.13% (p=0.001 n=7)
TextloggerOutput/override_single_value-12                                                    360.0 ± 0%              328.0 ± 0%   -8.89% (p=0.001 n=7)       328.0 ± 0%   -8.89% (p=0.001 n=7)
TextloggerOutput/override_WithValues-12                                                      416.0 ± 0%              376.0 ± 0%   -9.62% (p=0.001 n=7)       376.0 ± 0%   -9.62% (p=0.001 n=7)
TextloggerOutput/handle_integer_keys-12                                                      448.0 ± 0%              392.0 ± 0%  -12.50% (p=0.001 n=7)       392.0 ± 0%  -12.50% (p=0.001 n=7)
TextloggerOutput/duplicates-12                                                             2.892Ki ± 0%            2.188Ki ± 0%  -24.32% (p=0.001 n=7)     2.188Ki ± 0%  -24.32% (p=0.001 n=7)
TextloggerOutput/struct_keys-12                                                              408.0 ± 0%              368.0 ± 0%   -9.80% (p=0.001 n=7)       368.0 ± 0%   -9.80% (p=0.001 n=7)
TextloggerOutput/slice_values-12                                                             296.0 ± 0%              296.0 ± 0%        ~ (p=1.000 n=7) ¹     296.0 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/verbosity_disabled-12                                                       64.00 ± 0%              64.00 ± 0%        ~ (p=1.000 n=7) ¹     64.00 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/log_with_multiple_names_and_values-12                                       568.0 ± 0%              536.0 ± 0%   -5.63% (p=0.001 n=7)       536.0 ± 0%   -5.63% (p=0.001 n=7)
TextloggerOutput/empty_WithValues-12                                                         296.0 ± 0%              296.0 ± 0%        ~ (p=1.000 n=7) ¹     296.0 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/MarshalLog()_for_nil-12                                                     408.0 ± 0%              408.0 ± 0%        ~ (p=1.000 n=7) ¹     408.0 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/klog.Format-12                                                              560.0 ± 0%              560.0 ± 0%        ~ (p=1.000 n=7) ¹     560.0 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/verbosity_enabled-12                                                        296.0 ± 0%              296.0 ± 0%        ~ (p=1.000 n=7) ¹     296.0 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/KObj-12                                                                     296.0 ± 0%              296.0 ± 0%        ~ (p=1.000 n=7) ¹     296.0 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/regular_error_types_when_using_logr.Error-12                                312.0 ± 0%              296.0 ± 0%   -5.13% (p=0.001 n=7)       296.0 ± 0%   -5.13% (p=0.001 n=7)
TextloggerOutput/map_values-12                                                               488.0 ± 0%              488.0 ± 0%        ~ (p=1.000 n=7) ¹     488.0 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/cyclic_list-12                                                              580.0 ± 1%              577.0 ± 1%   -0.52% (p=0.038 n=7)       581.0 ± 1%        ~ (p=0.346 n=7)
TextloggerOutput/print_duplicate_keys_in_arguments-12                                        328.0 ± 0%              296.0 ± 0%   -9.76% (p=0.001 n=7)       296.0 ± 0%   -9.76% (p=0.001 n=7)
TextloggerOutput/html_characters-12                                                          312.0 ± 0%              296.0 ± 0%   -5.13% (p=0.001 n=7)       296.0 ± 0%   -5.13% (p=0.001 n=7)
TextloggerOutput/map_keys-12                                                                 440.0 ± 0%              440.0 ± 0%        ~ (p=1.000 n=7) ¹     440.0 ± 0%        ~ (p=1.000 n=7) ¹
geomean                                                                                      397.1                   370.9        -6.60%                     370.9        -6.59%
¹ all samples are equal

                                                                               │ benchmark_out_main.txt │ benchmark_out_reduce-allocations-fix-alloc.txt │ benchmark_out_reduce-allocations.txt │
                                                                               │       allocs/op        │       allocs/op        vs base                 │  allocs/op   vs base                 │
TextloggerOutput/handle_odd-numbers_of_KVs_in_both_log_values_and_Info_args-12               8.000 ± 0%              4.000 ± 0%  -50.00% (p=0.001 n=7)      4.000 ± 0%  -50.00% (p=0.001 n=7)
TextloggerOutput/KObjs-12                                                                    3.000 ± 0%              3.000 ± 0%        ~ (p=1.000 n=7) ¹    3.000 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/KObjSlice_int_arg-12                                                        3.000 ± 0%              3.000 ± 0%        ~ (p=1.000 n=7) ¹    3.000 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/String()_that_panics-12                                                     5.000 ± 0%              4.000 ± 0%  -20.00% (p=0.001 n=7)      4.000 ± 0%  -20.00% (p=0.001 n=7)
TextloggerOutput/mixed_duplicates-12                                                         58.00 ± 0%              40.00 ± 0%  -31.03% (p=0.001 n=7)      40.00 ± 0%  -31.03% (p=0.001 n=7)
TextloggerOutput/vmodule-12                                                                  3.000 ± 0%              3.000 ± 0%        ~ (p=1.000 n=7) ¹    3.000 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/call_depth-12                                                               5.000 ± 0%              4.000 ± 0%  -20.00% (p=0.001 n=7)      4.000 ± 0%  -20.00% (p=0.001 n=7)
TextloggerOutput/Error()_for_nil-12                                                          8.000 ± 0%              6.000 ± 0%  -25.00% (p=0.001 n=7)      6.000 ± 0%  -25.00% (p=0.001 n=7)
TextloggerOutput/Error()_that_panics-12                                                      5.000 ± 0%              4.000 ± 0%  -20.00% (p=0.001 n=7)      4.000 ± 0%  -20.00% (p=0.001 n=7)
TextloggerOutput/MarshalLog()_that_panics-12                                                 6.000 ± 0%              5.000 ± 0%  -16.67% (p=0.001 n=7)      5.000 ± 0%  -16.67% (p=0.001 n=7)
TextloggerOutput/other_vmodule-12                                                            1.000 ± 0%              1.000 ± 0%        ~ (p=1.000 n=7) ¹    1.000 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/KObjSlice_nil_entry-12                                                      3.000 ± 0%              3.000 ± 0%        ~ (p=1.000 n=7) ¹    3.000 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/ignore_MarshalJSON-12                                                       4.000 ± 0%              3.000 ± 0%  -25.00% (p=0.001 n=7)      3.000 ± 0%  -25.00% (p=0.001 n=7)
TextloggerOutput/struct_values-12                                                            3.000 ± 0%              3.000 ± 0%        ~ (p=1.000 n=7) ¹    3.000 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/log_with_name_and_values-12                                                 9.000 ± 0%              6.000 ± 0%  -33.33% (p=0.001 n=7)      6.000 ± 0%  -33.33% (p=0.001 n=7)
TextloggerOutput/handle_odd-numbers_of_KVs-12                                                5.000 ± 0%              3.000 ± 0%  -40.00% (p=0.001 n=7)      3.000 ± 0%  -40.00% (p=0.001 n=7)
TextloggerOutput/regular_error_types_as_value-12                                             4.000 ± 0%              3.000 ± 0%  -25.00% (p=0.001 n=7)      3.000 ± 0%  -25.00% (p=0.001 n=7)
TextloggerOutput/KObjSlice_nil_arg-12                                                        3.000 ± 0%              3.000 ± 0%        ~ (p=1.000 n=7) ¹    3.000 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/odd_WithValues-12                                                           15.00 ± 0%              11.00 ± 0%  -26.67% (p=0.001 n=7)      11.00 ± 0%  -26.67% (p=0.001 n=7)
TextloggerOutput/multiple_WithValues-12                                                      16.00 ± 0%              16.00 ± 0%        ~ (p=1.000 n=7) ¹    16.00 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/quotation-12                                                                4.000 ± 0%              3.000 ± 0%  -25.00% (p=0.001 n=7)      3.000 ± 0%  -25.00% (p=0.001 n=7)
TextloggerOutput/preserve_order_of_key/value_pairs-12                                        9.000 ± 0%              4.000 ± 0%  -55.56% (p=0.001 n=7)      4.000 ± 0%  -55.56% (p=0.001 n=7)
TextloggerOutput/KObjSlice_okay-12                                                           3.000 ± 0%              3.000 ± 0%        ~ (p=1.000 n=7) ¹    3.000 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/KObjSlice_ints-12                                                           4.000 ± 0%              4.000 ± 0%        ~ (p=1.000 n=7) ¹    4.000 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/String()_for_nil-12                                                         8.000 ± 0%              6.000 ± 0%  -25.00% (p=0.001 n=7)      6.000 ± 0%  -25.00% (p=0.001 n=7)
TextloggerOutput/MarshalLog()_that_returns_itself-12                                         3.000 ± 0%              3.000 ± 0%        ~ (p=1.000 n=7) ¹    3.000 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/log_with_values-12                                                          4.000 ± 0%              3.000 ± 0%  -25.00% (p=0.001 n=7)      3.000 ± 0%  -25.00% (p=0.001 n=7)
TextloggerOutput/override_single_value-12                                                    6.000 ± 0%              4.000 ± 0%  -33.33% (p=0.001 n=7)      4.000 ± 0%  -33.33% (p=0.001 n=7)
TextloggerOutput/override_WithValues-12                                                     12.000 ± 0%              6.000 ± 0%  -50.00% (p=0.001 n=7)      6.000 ± 0%  -50.00% (p=0.001 n=7)
TextloggerOutput/handle_integer_keys-12                                                     10.000 ± 0%              6.000 ± 0%  -40.00% (p=0.001 n=7)      6.000 ± 0%  -40.00% (p=0.001 n=7)
TextloggerOutput/duplicates-12                                                               58.00 ± 0%              40.00 ± 0%  -31.03% (p=0.001 n=7)      40.00 ± 0%  -31.03% (p=0.001 n=7)
TextloggerOutput/struct_keys-12                                                              9.000 ± 0%              5.000 ± 0%  -44.44% (p=0.001 n=7)      5.000 ± 0%  -44.44% (p=0.001 n=7)
TextloggerOutput/slice_values-12                                                             3.000 ± 0%              3.000 ± 0%        ~ (p=1.000 n=7) ¹    3.000 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/verbosity_disabled-12                                                       1.000 ± 0%              1.000 ± 0%        ~ (p=1.000 n=7) ¹    1.000 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/log_with_multiple_names_and_values-12                                       12.00 ± 0%              10.00 ± 0%  -16.67% (p=0.001 n=7)      10.00 ± 0%  -16.67% (p=0.001 n=7)
TextloggerOutput/empty_WithValues-12                                                         3.000 ± 0%              3.000 ± 0%        ~ (p=1.000 n=7) ¹    3.000 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/MarshalLog()_for_nil-12                                                     5.000 ± 0%              5.000 ± 0%        ~ (p=1.000 n=7) ¹    5.000 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/klog.Format-12                                                              11.00 ± 0%              11.00 ± 0%        ~ (p=1.000 n=7) ¹    11.00 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/verbosity_enabled-12                                                        3.000 ± 0%              3.000 ± 0%        ~ (p=1.000 n=7) ¹    3.000 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/KObj-12                                                                     3.000 ± 0%              3.000 ± 0%        ~ (p=1.000 n=7) ¹    3.000 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/regular_error_types_when_using_logr.Error-12                                4.000 ± 0%              3.000 ± 0%  -25.00% (p=0.001 n=7)      3.000 ± 0%  -25.00% (p=0.001 n=7)
TextloggerOutput/map_values-12                                                               11.00 ± 0%              11.00 ± 0%        ~ (p=1.000 n=7) ¹    11.00 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/cyclic_list-12                                                              8.000 ± 0%              8.000 ± 0%        ~ (p=1.000 n=7) ¹    8.000 ± 0%        ~ (p=1.000 n=7) ¹
TextloggerOutput/print_duplicate_keys_in_arguments-12                                        5.000 ± 0%              3.000 ± 0%  -40.00% (p=0.001 n=7)      3.000 ± 0%  -40.00% (p=0.001 n=7)
TextloggerOutput/html_characters-12                                                          5.000 ± 0%              3.000 ± 0%  -40.00% (p=0.001 n=7)      3.000 ± 0%  -40.00% (p=0.001 n=7)
TextloggerOutput/map_keys-12                                                                10.000 ± 0%              9.000 ± 0%  -10.00% (p=0.001 n=7)      9.000 ± 0%  -10.00% (p=0.001 n=7)
geomean                                                                                      5.598                   4.520       -19.27%                    4.520       -19.27%
¹ all samples are equal

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:

Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.

Release note:

Reduce memory allocations by replacing `strconv.Quote` with `strconv.AppendQuote` 

Updated the logging functions to utilize cached buffers more effectively by replacing the creation of new byte slices with calls to `AvailableBuffer()`. This change reduces memory allocations and enhances performance across multiple logging components, including `klog`, `klogr_slog`, and `textlogger`.

Additionally, modified the JSON serialization in `keyvalues_slog.go` and `keyvalues.go` to leverage the same buffer optimization for quoting string values. This refactor aims to streamline logging operations and improve overall efficiency.

Signed-off-by: Anton Sergunov <anton.sergunov@flant.com>
Signed-off-by: Anton Sergunov <anton.sergunov@flant.com>
Signed-off-by: Anton Sergunov <anton.sergunov@flant.com>
Signed-off-by: Anton Sergunov <anton.sergunov@flant.com>
@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: asergunov
Once this PR has been reviewed and has the lgtm label, please assign thockin for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 14, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Nov 14, 2025
@k8s-ci-robot
Copy link

Welcome @asergunov!

It looks like this is your first PR to kubernetes/klog 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/klog has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Nov 14, 2025
@asergunov
Copy link
Author

Don't take in account the reported speed improvements. It could be just Laptop heating. It has less allocations for sure.

Copy link

@pohly pohly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I double-checked performance on an Arrow Lake desktop with pinning to one P-core (to avoid variance). I see moderate improvements:

pkg: k8s.io/klog/v2
...
geomean                                                                  61.43n         61.20n       -0.37%

pkg: k8s.io/klog/v2/textlogger
...
geomean                                                                        586.6n        578.7n       -1.35%

But any improvement which doesn't unduly increase complexity is welcome, so thanks for the PR!

@asergunov: can you squash into one commit?

/assign @dims

Tests passed locally, workflows still need to be triggered (don't have permissions for that).

@dims
Copy link
Member

dims commented Nov 21, 2025

i've approved workflows to run @pohly

@asergunov
Copy link
Author

@pohly could you please give a performance test on this commit 0f1b22b313560f992029a5ae447d332eef67cfb9

There is the one replacing also the 1024 bytes buffer allocation on the stack. I mean writing to the bufer itself directly should be a bit faster than writing to stack and then copying to the buffer.

@pohly
Copy link

pohly commented Nov 27, 2025

@asergunov: here's a comparison before and with 0f1b22b

goos: linux
goarch: amd64
pkg: k8s.io/klog/v2
cpu: Intel(R) Core(TM) Ultra 9 285
                                                                      │ /tmp/0f1b22.before │         /tmp/0f1b22.after          │
                                                                      │       sec/op       │    sec/op     vs base              │
Header                                                                         240.4n ± 0%    240.7n ± 0%       ~ (p=0.262 n=6)
HeaderWithDir                                                                  361.9n ± 0%    361.7n ± 0%       ~ (p=0.171 n=6)
V                                                                             0.9357n ± 1%   0.9345n ± 1%       ~ (p=0.814 n=6)
KRef                                                                          0.1802n ± 0%   0.1801n ± 0%       ~ (p=0.844 n=6)
KObj                                                                           1.924n ± 0%    1.934n ± 0%  +0.52% (p=0.002 n=6)
KObjs/0/simple                                                                 36.63n ± 0%    36.76n ± 0%  +0.35% (p=0.002 n=6)
KObjs/0/conditional                                                            1.095n ± 1%    1.097n ± 1%       ~ (p=0.223 n=6)
KObjs/10/simple                                                                140.7n ± 0%    141.0n ± 1%  +0.25% (p=0.015 n=6)
KObjs/10/conditional                                                           1.093n ± 1%    1.094n ± 0%       ~ (p=0.991 n=6)
KObjs/20/simple                                                                229.8n ± 0%    230.2n ± 1%  +0.17% (p=0.032 n=6)
KObjs/20/conditional                                                           1.093n ± 1%    1.096n ± 0%       ~ (p=0.665 n=6)
KObjs/30/simple                                                                309.7n ± 0%    309.9n ± 0%       ~ (p=0.236 n=6)
KObjs/30/conditional                                                           1.097n ± 1%    1.093n ± 1%       ~ (p=0.513 n=6)
KObjs/40/simple                                                                385.7n ± 0%    385.6n ± 0%       ~ (p=0.459 n=6)
KObjs/40/conditional                                                           1.092n ± 0%    1.096n ± 0%  +0.37% (p=0.006 n=6)
KObjs/50/simple                                                                466.9n ± 1%    467.4n ± 1%       ~ (p=0.188 n=6)
KObjs/50/conditional                                                           1.095n ± 1%    1.097n ± 0%       ~ (p=0.403 n=6)
KObjs/60/simple                                                                578.2n ± 0%    579.8n ± 1%  +0.27% (p=0.002 n=6)
KObjs/60/conditional                                                           1.093n ± 0%    1.092n ± 1%       ~ (p=0.498 n=6)
KObjs/70/simple                                                                629.0n ± 0%    631.7n ± 1%  +0.43% (p=0.002 n=6)
KObjs/70/conditional                                                           1.093n ± 0%    1.094n ± 1%       ~ (p=0.225 n=6)
KObjs/80/simple                                                                749.5n ± 0%    751.4n ± 0%  +0.27% (p=0.009 n=6)
KObjs/80/conditional                                                           1.095n ± 1%    1.095n ± 0%       ~ (p=0.851 n=6)
KObjs/90/simple                                                                779.2n ± 0%    779.5n ± 1%       ~ (p=0.310 n=6)
KObjs/90/conditional                                                           1.093n ± 0%    1.096n ± 1%       ~ (p=0.208 n=6)
KObjs/100/simple                                                               860.1n ± 0%    862.2n ± 1%  +0.25% (p=0.026 n=6)
KObjs/100/conditional                                                          1.095n ± 0%    1.097n ± 1%       ~ (p=0.333 n=6)
KObjSlice/0/simple                                                             35.87n ± 0%    35.94n ± 0%  +0.20% (p=0.037 n=6)
KObjSlice/0/conditional                                                        1.090n ± 0%    1.091n ± 0%       ~ (p=0.552 n=6)
KObjSlice/10/simple                                                            35.95n ± 0%    36.09n ± 0%       ~ (p=0.058 n=6)
KObjSlice/10/conditional                                                       1.092n ± 1%    1.091n ± 0%       ~ (p=0.807 n=6)
KObjSlice/20/simple                                                            36.03n ± 1%    36.17n ± 1%  +0.37% (p=0.024 n=6)
KObjSlice/20/conditional                                                       1.090n ± 0%    1.091n ± 0%       ~ (p=0.323 n=6)
KObjSlice/30/simple                                                            36.05n ± 1%    36.15n ± 0%       ~ (p=0.074 n=6)
KObjSlice/30/conditional                                                       1.092n ± 0%    1.091n ± 0%       ~ (p=0.561 n=6)
KObjSlice/40/simple                                                            36.02n ± 0%    36.26n ± 0%  +0.68% (p=0.004 n=6)
KObjSlice/40/conditional                                                       1.090n ± 0%    1.094n ± 0%  +0.37% (p=0.032 n=6)
KObjSlice/50/simple                                                            36.08n ± 0%    36.23n ± 0%  +0.40% (p=0.037 n=6)
KObjSlice/50/conditional                                                       1.092n ± 1%    1.089n ± 0%       ~ (p=0.069 n=6)
KObjSlice/60/simple                                                            35.98n ± 1%    36.06n ± 0%       ~ (p=0.052 n=6)
KObjSlice/60/conditional                                                       1.092n ± 0%    1.091n ± 0%       ~ (p=0.903 n=6)
KObjSlice/70/simple                                                            36.01n ± 0%    36.05n ± 0%       ~ (p=0.409 n=6)
KObjSlice/70/conditional                                                       1.089n ± 1%    1.091n ± 0%       ~ (p=0.857 n=6)
KObjSlice/80/simple                                                            36.08n ± 0%    36.25n ± 0%  +0.47% (p=0.002 n=6)
KObjSlice/80/conditional                                                       1.089n ± 0%    1.095n ± 1%  +0.46% (p=0.045 n=6)
KObjSlice/90/simple                                                            36.13n ± 0%    36.13n ± 0%       ~ (p=1.000 n=6)
KObjSlice/90/conditional                                                       1.090n ± 0%    1.092n ± 1%       ~ (p=0.171 n=6)
KObjSlice/100/simple                                                           36.23n ± 0%    36.22n ± 0%       ~ (p=0.920 n=6)
KObjSlice/100/conditional                                                      1.089n ± 0%    1.089n ± 0%       ~ (p=0.784 n=6)
Scalars/simple                                                                 15.38n ± 0%    15.39n ± 0%       ~ (p=0.158 n=6)
Scalars/conditional                                                            1.097n ± 1%    1.093n ± 1%  -0.27% (p=0.032 n=6)
ScalarsWithLogger/simple                                                       17.64n ± 0%    17.59n ± 0%  -0.31% (p=0.002 n=6)
ScalarsWithLogger/conditional                                                  1.473n ± 0%    1.474n ± 0%       ~ (p=0.080 n=6)
KObjSliceWithLogger/simple                                                     37.25n ± 0%    37.41n ± 0%  +0.42% (p=0.002 n=6)
KObjSliceWithLogger/conditional                                                1.474n ± 0%    1.474n ± 0%       ~ (p=1.000 n=6)
Logs                                                                           1.852µ ± 0%    1.852µ ± 0%       ~ (p=0.688 n=6)
Flush                                                                          109.4n ± 0%    108.9n ± 0%  -0.46% (p=0.002 n=6)
WithoutDeferUnLock                                                             10.30n ± 0%    10.29n ± 0%  -0.10% (p=0.002 n=6)
WithDeferUnLock                                                                10.22n ± 0%    10.22n ± 0%       ~ (p=1.000 n=6)
PassingLogger/with_context                                                    0.3884n ± 5%   0.4007n ± 2%       ~ (p=0.093 n=6)
PassingLogger/without_context                                                 0.4354n ± 0%   0.4360n ± 0%       ~ (p=0.372 n=6)
ExtractLogger/from_context                                                     2.934n ± 0%    2.937n ± 0%  +0.10% (p=0.004 n=6)
KlogOutput/String()_for_nil                                                    1.926µ ± 0%    1.924µ ± 0%  -0.10% (p=0.041 n=6)
KlogOutput/MarshalLog()_that_returns_itself                                    528.9n ± 0%    527.3n ± 0%  -0.30% (p=0.002 n=6)
KlogOutput/map_values                                                          844.4n ± 0%    844.1n ± 0%  -0.04% (p=0.035 n=6)
KlogOutput/slice_values                                                        611.5n ± 0%    610.8n ± 0%  -0.12% (p=0.022 n=6)
KlogOutput/klog.Format                                                         855.4n ± 0%    855.9n ± 0%       ~ (p=0.216 n=6)
KlogOutput/Error()_that_panics                                                 873.9n ± 0%    873.0n ± 0%  -0.11% (p=0.006 n=6)
KlogOutput/handle_integer_keys                                                 846.1n ± 0%    845.7n ± 0%       ~ (p=1.000 n=6)
KlogOutput/handle_odd-numbers_of_KVs_in_both_log_values_and_Info_args          747.8n ± 1%    749.1n ± 0%       ~ (p=0.390 n=6)
KlogOutput/KObjSlice_int_arg                                                   517.0n ± 0%    517.0n ± 0%       ~ (p=1.000 n=6)
KlogOutput/MarshalLog()_that_panics                                            744.6n ± 0%    743.7n ± 0%  -0.12% (p=0.022 n=6)
KlogOutput/struct_values                                                       541.2n ± 0%    540.8n ± 0%       ~ (p=0.084 n=6)
KlogOutput/verbosity_disabled                                                  7.054n ± 0%    7.050n ± 0%  -0.06% (p=0.002 n=6)
KlogOutput/log_with_values                                                     472.2n ± 0%    472.2n ± 0%       ~ (p=0.673 n=6)
KlogOutput/call_depth                                                          752.6n ± 0%    751.8n ± 0%       ~ (p=0.061 n=6)
KlogOutput/empty_WithValues                                                    407.3n ± 0%    406.5n ± 0%  -0.20% (p=0.002 n=6)
KlogOutput/print_duplicate_keys_in_arguments                                   558.3n ± 0%    558.6n ± 0%       ~ (p=0.232 n=6)
KlogOutput/preserve_order_of_key/value_pairs                                   788.5n ± 1%    784.7n ± 0%       ~ (p=1.000 n=6)
KlogOutput/Error()_for_nil                                                     2.150µ ± 0%    2.151µ ± 0%       ~ (p=0.141 n=6)
KlogOutput/duplicates                                                          3.272µ ± 0%    3.267µ ± 0%  -0.17% (p=0.006 n=6)
KlogOutput/handle_odd-numbers_of_KVs                                           547.2n ± 0%    546.8n ± 0%       ~ (p=0.165 n=6)
KlogOutput/ignore_MarshalJSON                                                  475.9n ± 0%    475.4n ± 0%  -0.11% (p=0.004 n=6)
KlogOutput/regular_error_types_when_using_logr.Error                           646.6n ± 0%    646.4n ± 0%       ~ (p=0.613 n=6)
KlogOutput/vmodule                                                             960.2n ± 0%    960.1n ± 0%       ~ (p=0.370 n=6)
KlogOutput/quotation                                                           509.8n ± 0%    510.3n ± 0%       ~ (p=0.266 n=6)
KlogOutput/KObj                                                                464.8n ± 0%    465.2n ± 0%  +0.10% (p=0.032 n=6)
KlogOutput/KObjs                                                               604.7n ± 0%    604.4n ± 0%       ~ (p=0.100 n=6)
KlogOutput/KObjSlice_nil_arg                                                   455.1n ± 0%    454.6n ± 0%  -0.12% (p=0.015 n=6)
KlogOutput/String()_that_panics                                                722.9n ± 0%    721.6n ± 0%  -0.19% (p=0.011 n=6)
KlogOutput/struct_keys                                                         728.6n ± 0%    726.3n ± 0%  -0.32% (p=0.002 n=6)
KlogOutput/cyclic_list                                                         63.91µ ± 1%    63.75µ ± 0%       ~ (p=0.513 n=6)
KlogOutput/other_vmodule                                                       74.71n ± 3%    73.70n ± 2%       ~ (p=0.180 n=6)
KlogOutput/log_with_name_and_values                                            544.5n ± 0%    544.3n ± 0%       ~ (p=0.227 n=6)
KlogOutput/log_with_multiple_names_and_values                                  595.1n ± 0%    595.0n ± 0%       ~ (p=0.485 n=6)
KlogOutput/override_single_value                                               608.6n ± 0%    608.2n ± 0%       ~ (p=0.409 n=6)
KlogOutput/override_WithValues                                                 716.3n ± 1%    717.0n ± 0%       ~ (p=0.420 n=6)
KlogOutput/odd_WithValues                                                      1.718µ ± 0%    1.720µ ± 0%  +0.15% (p=0.009 n=6)
KlogOutput/html_characters                                                     463.5n ± 0%    463.5n ± 0%       ~ (p=0.905 n=6)
KlogOutput/verbosity_enabled                                                   430.2n ± 0%    430.1n ± 0%       ~ (p=0.634 n=6)
KlogOutput/multiple_WithValues                                                 2.232µ ± 0%    2.221µ ± 0%  -0.52% (p=0.002 n=6)
KlogOutput/regular_error_types_as_value                                        475.5n ± 0%    476.0n ± 0%       ~ (p=0.071 n=6)
KlogOutput/MarshalLog()_for_nil                                                756.5n ± 0%    756.8n ± 0%       ~ (p=0.087 n=6)
KlogOutput/map_keys                                                            712.9n ± 0%    713.6n ± 0%  +0.11% (p=0.013 n=6)
KlogOutput/mixed_duplicates                                                    3.970µ ± 0%    3.969µ ± 0%       ~ (p=0.394 n=6)
KlogOutput/KObjSlice_okay                                                      520.4n ± 0%    520.6n ± 0%       ~ (p=0.968 n=6)
KlogOutput/KObjSlice_nil_entry                                                 493.3n ± 0%    493.3n ± 0%       ~ (p=0.643 n=6)
KlogOutput/KObjSlice_ints                                                      557.8n ± 0%    558.6n ± 0%       ~ (p=0.331 n=6)
geomean                                                                        60.90n         60.94n       +0.06%

pkg: k8s.io/klog/v2/textlogger
                                                                            │ /tmp/0f1b22.before │         /tmp/0f1b22.after         │
                                                                            │       sec/op       │   sec/op     vs base              │
TextloggerOutput/html_characters                                                     349.1n ± 0%   344.5n ± 0%  -1.33% (p=0.002 n=6)
TextloggerOutput/handle_odd-numbers_of_KVs_in_both_log_values_and_Info_args          524.6n ± 0%   520.7n ± 0%  -0.75% (p=0.002 n=6)
TextloggerOutput/String()_that_panics                                                604.5n ± 0%   601.2n ± 0%  -0.54% (p=0.002 n=6)
TextloggerOutput/klog.Format                                                         730.9n ± 0%   725.9n ± 0%  -0.67% (p=0.002 n=6)
TextloggerOutput/other_vmodule                                                       110.0n ± 0%   111.8n ± 0%  +1.59% (p=0.002 n=6)
TextloggerOutput/quotation                                                           396.5n ± 0%   391.1n ± 0%  -1.36% (p=0.002 n=6)
TextloggerOutput/KObjs                                                               473.2n ± 0%   471.9n ± 0%  -0.25% (p=0.002 n=6)
TextloggerOutput/KObjSlice_nil_entry                                                 377.2n ± 0%   372.4n ± 0%  -1.27% (p=0.002 n=6)
TextloggerOutput/MarshalLog()_that_panics                                            629.2n ± 0%   625.9n ± 0%  -0.52% (p=0.002 n=6)
TextloggerOutput/handle_integer_keys                                                 653.8n ± 0%   641.4n ± 0%  -1.90% (p=0.002 n=6)
TextloggerOutput/map_keys                                                            595.2n ± 0%   590.6n ± 0%  -0.77% (p=0.002 n=6)
TextloggerOutput/verbosity_enabled                                                   335.0n ± 0%   326.8n ± 0%  -2.45% (p=0.002 n=6)
TextloggerOutput/print_duplicate_keys_in_arguments                                   437.4n ± 1%   432.0n ± 0%  -1.21% (p=0.002 n=6)
TextloggerOutput/KObjSlice_nil_arg                                                   341.0n ± 0%   332.8n ± 0%  -2.40% (p=0.002 n=6)
TextloggerOutput/ignore_MarshalJSON                                                  361.6n ± 0%   358.9n ± 0%  -0.75% (p=0.002 n=6)
TextloggerOutput/Error()_that_panics                                                 594.2n ± 0%   592.9n ± 0%       ~ (p=0.058 n=6)
TextloggerOutput/call_depth                                                          400.6n ± 0%   399.2n ± 0%  -0.35% (p=0.002 n=6)
TextloggerOutput/odd_WithValues                                                      1.286µ ± 0%   1.274µ ± 0%  -0.89% (p=0.002 n=6)
TextloggerOutput/handle_odd-numbers_of_KVs                                           423.7n ± 0%   420.1n ± 0%  -0.84% (p=0.002 n=6)
TextloggerOutput/KObjSlice_ints                                                      431.6n ± 0%   428.5n ± 1%  -0.72% (p=0.002 n=6)
TextloggerOutput/MarshalLog()_that_returns_itself                                    416.0n ± 0%   406.4n ± 0%  -2.32% (p=0.002 n=6)
TextloggerOutput/slice_values                                                        483.8n ± 0%   482.1n ± 0%  -0.35% (p=0.002 n=6)
TextloggerOutput/vmodule                                                             854.9n ± 0%   849.4n ± 0%  -0.64% (p=0.002 n=6)
TextloggerOutput/log_with_multiple_names_and_values                                  530.3n ± 1%   525.8n ± 0%  -0.85% (p=0.002 n=6)
TextloggerOutput/override_WithValues                                                 533.7n ± 0%   525.1n ± 0%  -1.60% (p=0.002 n=6)
TextloggerOutput/multiple_WithValues                                                 1.710µ ± 0%   1.688µ ± 0%  -1.26% (p=0.002 n=6)
TextloggerOutput/regular_error_types_when_using_logr.Error                           358.1n ± 0%   355.1n ± 0%  -0.82% (p=0.002 n=6)
TextloggerOutput/cyclic_list                                                         64.36µ ± 1%   64.20µ ± 0%       ~ (p=0.485 n=6)
TextloggerOutput/preserve_order_of_key/value_pairs                                   536.2n ± 0%   534.7n ± 0%  -0.29% (p=0.015 n=6)
TextloggerOutput/String()_for_nil                                                    1.982µ ± 0%   1.989µ ± 1%  +0.38% (p=0.006 n=6)
TextloggerOutput/struct_values                                                       423.9n ± 0%   420.6n ± 0%  -0.78% (p=0.002 n=6)
TextloggerOutput/duplicates                                                          2.675µ ± 0%   2.641µ ± 0%  -1.25% (p=0.002 n=6)
TextloggerOutput/mixed_duplicates                                                    3.100µ ± 0%   3.062µ ± 0%  -1.23% (p=0.002 n=6)
TextloggerOutput/log_with_values                                                     356.2n ± 0%   353.8n ± 0%  -0.67% (p=0.002 n=6)
TextloggerOutput/override_single_value                                               462.6n ± 0%   457.4n ± 0%  -1.13% (p=0.002 n=6)
TextloggerOutput/KObjSlice_okay                                                      406.5n ± 0%   398.4n ± 0%  -1.97% (p=0.002 n=6)
TextloggerOutput/Error()_for_nil                                                     1.794µ ± 0%   1.804µ ± 0%  +0.56% (p=0.015 n=6)
TextloggerOutput/map_values                                                          714.1n ± 0%   709.4n ± 0%  -0.67% (p=0.002 n=6)
TextloggerOutput/log_with_name_and_values                                            429.5n ± 0%   427.3n ± 0%  -0.51% (p=0.002 n=6)
TextloggerOutput/KObj                                                                350.3n ± 0%   343.9n ± 0%  -1.80% (p=0.002 n=6)
TextloggerOutput/KObjSlice_int_arg                                                   401.1n ± 0%   394.8n ± 0%  -1.57% (p=0.002 n=6)
TextloggerOutput/regular_error_types_as_value                                        360.8n ± 0%   358.8n ± 0%  -0.57% (p=0.002 n=6)
TextloggerOutput/MarshalLog()_for_nil                                                826.8n ± 0%   818.4n ± 0%  -1.01% (p=0.002 n=6)
TextloggerOutput/struct_keys                                                         539.5n ± 0%   536.0n ± 0%  -0.64% (p=0.002 n=6)
TextloggerOutput/verbosity_disabled                                                  21.98n ± 1%   21.89n ± 1%  -0.36% (p=0.032 n=6)
TextloggerOutput/empty_WithValues                                                    316.2n ± 0%   311.9n ± 0%  -1.38% (p=0.002 n=6)
geomean                                                                              571.2n        566.1n       -0.89%

@asergunov
Copy link
Author

asergunov commented Nov 29, 2025

@pohly Thanks a lot! What do you think which one we should merge?

@asergunov
Copy link
Author

I mean I can see a benefit in removing hardcoded magic value and removing extra copy. Are these results acceptable?

@pohly
Copy link

pohly commented Dec 1, 2025

The PR looks reasonable to me and we should merge it. But I don't understand the question about "which one we should merge"?

@asergunov
Copy link
Author

The PR looks reasonable to me and we should merge it. But I don't understand the question about "which one we should merge"?

I mean the latest one or at this commit 0f1b22b

The latest state is not changing the two places when we use 1024 bytes buffer on stack

@asergunov
Copy link
Author

Should we also update the 1024 bytes buffer stack allocations with direct buffer writes?

@pohly
Copy link

pohly commented Dec 1, 2025

So the question is whether these changes are wanted: https://github.com/kubernetes/klog/compare/0f1b22b..5025e083b0c56

5025e08 diff cleanup
6db40fd Get constant allocations back

The 6db40fd commit makes the code more complex again (on-stack 1024 bytes buffer). It claims to reduce the number of allocations (right?) but I don't see that when using -benchmem - there's no difference in allocations at all.

Earlier, I misunderstood what you wanted to be benchmarked. In #426 (comment) I compared 0f1b22b against its predecessor, not the full branch. Here's the 0f1b22b..5025e08 performance comparison. It's actually a bit worse.

goos: linux
goarch: amd64
pkg: k8s.io/klog/v2
cpu: Intel(R) Core(TM) Ultra 9 285
                                                                      │ 0f1b22b.out  │          5025e083b0c56.out           │
                                                                      │    sec/op    │    sec/op     vs base                │
Header                                                                   240.7n ± 0%    240.0n ± 0%  -0.33% (p=0.011 n=6)
HeaderWithDir                                                            361.3n ± 0%    360.9n ± 0%  -0.10% (p=0.015 n=6)
V                                                                       0.9384n ± 2%   0.9276n ± 0%       ~ (p=0.288 n=6)
KRef                                                                    0.1801n ± 0%   0.1801n ± 0%       ~ (p=0.526 n=6)
KObj                                                                     1.935n ± 0%    1.927n ± 0%  -0.41% (p=0.002 n=6)
KObjs/0/simple                                                           36.95n ± 0%    36.70n ± 0%  -0.66% (p=0.002 n=6)
KObjs/0/conditional                                                      1.095n ± 0%    1.090n ± 1%       ~ (p=0.162 n=6)
KObjs/10/simple                                                          141.2n ± 2%    141.1n ± 0%       ~ (p=0.576 n=6)
KObjs/10/conditional                                                     1.098n ± 1%    1.092n ± 0%  -0.59% (p=0.017 n=6)
KObjs/20/simple                                                          230.9n ± 1%    230.8n ± 0%       ~ (p=0.416 n=6)
KObjs/20/conditional                                                     1.093n ± 1%    1.094n ± 0%       ~ (p=0.740 n=6)
KObjs/30/simple                                                          310.2n ± 0%    310.1n ± 0%       ~ (p=0.922 n=6)
KObjs/30/conditional                                                     1.096n ± 1%    1.091n ± 1%       ~ (p=0.069 n=6)
KObjs/40/simple                                                          386.5n ± 2%    387.1n ± 0%       ~ (p=0.119 n=6)
KObjs/40/conditional                                                     1.095n ± 0%    1.094n ± 0%       ~ (p=0.383 n=6)
KObjs/50/simple                                                          469.4n ± 1%    469.6n ± 0%       ~ (p=0.937 n=6)
KObjs/50/conditional                                                     1.097n ± 1%    1.095n ± 0%       ~ (p=0.396 n=6)
KObjs/60/simple                                                          581.3n ± 1%    581.1n ± 1%       ~ (p=0.675 n=6)
KObjs/60/conditional                                                     1.097n ± 1%    1.093n ± 0%       ~ (p=0.080 n=6)
KObjs/70/simple                                                          634.9n ± 1%    634.8n ± 0%       ~ (p=0.422 n=6)
KObjs/70/conditional                                                     1.097n ± 1%    1.094n ± 0%       ~ (p=0.071 n=6)
KObjs/80/simple                                                          753.1n ± 0%    752.9n ± 0%       ~ (p=0.132 n=6)
KObjs/80/conditional                                                     1.098n ± 1%    1.093n ± 0%       ~ (p=0.074 n=6)
KObjs/90/simple                                                          782.5n ± 1%    784.2n ± 0%       ~ (p=0.076 n=6)
KObjs/90/conditional                                                     1.099n ± 1%    1.094n ± 0%       ~ (p=0.084 n=6)
KObjs/100/simple                                                         865.0n ± 1%    866.7n ± 0%       ~ (p=0.076 n=6)
KObjs/100/conditional                                                    1.098n ± 1%    1.092n ± 0%  -0.55% (p=0.032 n=6)
KObjSlice/0/simple                                                       36.02n ± 0%    36.06n ± 0%       ~ (p=0.665 n=6)
KObjSlice/0/conditional                                                  1.093n ± 0%    1.093n ± 1%       ~ (p=0.719 n=6)
KObjSlice/10/simple                                                      36.10n ± 0%    36.05n ± 0%       ~ (p=0.310 n=6)
KObjSlice/10/conditional                                                 1.093n ± 0%    1.093n ± 0%       ~ (p=0.810 n=6)
KObjSlice/20/simple                                                      36.16n ± 0%    36.06n ± 1%       ~ (p=0.167 n=6)
KObjSlice/20/conditional                                                 1.096n ± 0%    1.092n ± 1%       ~ (p=0.130 n=6)
KObjSlice/30/simple                                                      36.05n ± 0%    36.10n ± 0%       ~ (p=0.234 n=6)
KObjSlice/30/conditional                                                 1.093n ± 0%    1.093n ± 1%       ~ (p=0.846 n=6)
KObjSlice/40/simple                                                      36.15n ± 0%    36.08n ± 0%       ~ (p=0.266 n=6)
KObjSlice/40/conditional                                                 1.092n ± 1%    1.093n ± 0%       ~ (p=0.335 n=6)
KObjSlice/50/simple                                                      36.42n ± 1%    36.10n ± 0%  -0.88% (p=0.002 n=6)
KObjSlice/50/conditional                                                 1.094n ± 1%    1.093n ± 0%       ~ (p=0.171 n=6)
KObjSlice/60/simple                                                      36.03n ± 1%    36.10n ± 0%       ~ (p=0.284 n=6)
KObjSlice/60/conditional                                                 1.095n ± 1%    1.092n ± 0%       ~ (p=0.186 n=6)
KObjSlice/70/simple                                                      36.14n ± 0%    36.05n ± 1%       ~ (p=0.329 n=6)
KObjSlice/70/conditional                                                 1.093n ± 1%    1.092n ± 0%       ~ (p=0.260 n=6)
KObjSlice/80/simple                                                      36.34n ± 0%    36.22n ± 1%  -0.33% (p=0.002 n=6)
KObjSlice/80/conditional                                                 1.093n ± 0%    1.091n ± 0%       ~ (p=0.074 n=6)
KObjSlice/90/simple                                                      36.33n ± 0%    36.22n ± 1%  -0.32% (p=0.015 n=6)
KObjSlice/90/conditional                                                 1.095n ± 0%    1.091n ± 0%       ~ (p=0.100 n=6)
KObjSlice/100/simple                                                     36.43n ± 0%    36.15n ± 4%       ~ (p=0.058 n=6)
KObjSlice/100/conditional                                                1.094n ± 0%    1.092n ± 1%       ~ (p=0.550 n=6)
Scalars/simple                                                           15.46n ± 0%    15.41n ± 0%  -0.29% (p=0.009 n=6)
Scalars/conditional                                                      1.100n ± 0%    1.100n ± 0%       ~ (p=0.835 n=6)
ScalarsWithLogger/simple                                                 17.74n ± 0%    17.70n ± 0%  -0.23% (p=0.004 n=6)
ScalarsWithLogger/conditional                                            1.483n ± 0%    1.483n ± 0%       ~ (p=0.182 n=6)
KObjSliceWithLogger/simple                                               37.43n ± 0%    37.31n ± 0%       ~ (p=0.063 n=6)
KObjSliceWithLogger/conditional                                          1.484n ± 0%    1.483n ± 0%  -0.07% (p=0.015 n=6)
Logs                                                                     1.854µ ± 0%    1.854µ ± 0%       ~ (p=0.924 n=6)
Flush                                                                    111.0n ± 0%    111.3n ± 0%       ~ (p=0.080 n=6)
WithoutDeferUnLock                                                       10.29n ± 0%    10.30n ± 0%       ~ (p=0.407 n=6)
WithDeferUnLock                                                          10.22n ± 0%    10.22n ± 0%       ~ (p=1.000 n=6) ¹
PassingLogger/with_context                                              0.3926n ± 3%   0.3911n ± 2%       ~ (p=0.937 n=6)
PassingLogger/without_context                                           0.4362n ± 0%   0.4389n ± 0%  +0.62% (p=0.002 n=6)
ExtractLogger/from_context                                               2.953n ± 0%    2.951n ± 0%       ~ (p=0.061 n=6)
KlogOutput/ignore_MarshalJSON                                            476.4n ± 0%    483.9n ± 0%  +1.57% (p=0.002 n=6)
KlogOutput/MarshalLog()_for_nil                                          758.4n ± 0%    765.1n ± 0%  +0.88% (p=0.002 n=6)
KlogOutput/struct_values                                                 542.0n ± 0%    544.0n ± 0%  +0.38% (p=0.002 n=6)
KlogOutput/map_keys                                                      717.9n ± 0%    718.9n ± 0%  +0.13% (p=0.004 n=6)
KlogOutput/klog.Format                                                   856.9n ± 0%    860.3n ± 0%  +0.39% (p=0.002 n=6)
KlogOutput/cyclic_list                                                   63.91µ ± 1%    64.06µ ± 3%       ~ (p=0.589 n=6)
KlogOutput/vmodule                                                       960.5n ± 0%    965.1n ± 0%  +0.47% (p=0.002 n=6)
KlogOutput/log_with_multiple_names_and_values                            597.3n ± 0%    603.1n ± 0%  +0.96% (p=0.002 n=6)
KlogOutput/preserve_order_of_key/value_pairs                             785.7n ± 0%    790.3n ± 0%  +0.59% (p=0.002 n=6)
KlogOutput/KObjs                                                         607.0n ± 0%    609.3n ± 0%  +0.39% (p=0.002 n=6)
KlogOutput/String()_that_panics                                          724.4n ± 0%    723.2n ± 0%  -0.17% (p=0.002 n=6)
KlogOutput/handle_integer_keys                                           847.0n ± 0%    851.1n ± 0%  +0.48% (p=0.002 n=6)
KlogOutput/mixed_duplicates                                              3.979µ ± 0%    4.015µ ± 0%  +0.89% (p=0.002 n=6)
KlogOutput/KObjSlice_nil_arg                                             455.6n ± 0%    462.3n ± 0%  +1.46% (p=0.002 n=6)
KlogOutput/KObjSlice_nil_entry                                           495.5n ± 0%    499.5n ± 0%  +0.82% (p=0.002 n=6)
KlogOutput/MarshalLog()_that_returns_itself                              529.7n ± 0%    532.6n ± 0%  +0.56% (p=0.002 n=6)
KlogOutput/map_values                                                    847.2n ± 0%    847.4n ± 0%       ~ (p=0.818 n=6)
KlogOutput/slice_values                                                  612.6n ± 0%    613.5n ± 0%  +0.14% (p=0.050 n=6)
KlogOutput/other_vmodule                                                 73.20n ± 2%    73.67n ± 3%       ~ (p=0.180 n=6)
KlogOutput/log_with_values                                               472.9n ± 1%    480.3n ± 0%  +1.56% (p=0.002 n=6)
KlogOutput/override_single_value                                         610.5n ± 0%    618.0n ± 0%  +1.21% (p=0.002 n=6)
KlogOutput/KObjSlice_ints                                                559.1n ± 0%    562.9n ± 0%  +0.68% (p=0.002 n=6)
KlogOutput/regular_error_types_when_using_logr.Error                     648.3n ± 0%    657.6n ± 0%  +1.44% (p=0.002 n=6)
KlogOutput/String()_for_nil                                              1.931µ ± 0%    1.934µ ± 0%       ~ (p=0.071 n=6)
KlogOutput/struct_keys                                                   728.4n ± 0%    732.0n ± 0%  +0.49% (p=0.002 n=6)
KlogOutput/override_WithValues                                           719.1n ± 0%    721.8n ± 0%  +0.38% (p=0.002 n=6)
KlogOutput/KObj                                                          466.3n ± 0%    472.2n ± 0%  +1.25% (p=0.002 n=6)
KlogOutput/Error()_that_panics                                           875.2n ± 0%    875.1n ± 0%       ~ (p=0.452 n=6)
KlogOutput/MarshalLog()_that_panics                                      746.4n ± 0%    744.2n ± 0%  -0.30% (p=0.002 n=6)
KlogOutput/odd_WithValues                                                1.725µ ± 0%    1.742µ ± 0%  +1.01% (p=0.002 n=6)
KlogOutput/multiple_WithValues                                           2.233µ ± 0%    2.264µ ± 0%  +1.37% (p=0.002 n=6)
KlogOutput/html_characters                                               465.1n ± 0%    471.8n ± 0%  +1.44% (p=0.002 n=6)
KlogOutput/KObjSlice_int_arg                                             518.3n ± 0%    523.1n ± 0%  +0.92% (p=0.002 n=6)
KlogOutput/regular_error_types_as_value                                  477.2n ± 1%    484.0n ± 0%  +1.42% (p=0.002 n=6)
KlogOutput/duplicates                                                    3.279µ ± 0%    3.320µ ± 0%  +1.27% (p=0.002 n=6)
KlogOutput/call_depth                                                    754.8n ± 0%    752.7n ± 0%  -0.28% (p=0.015 n=6)
KlogOutput/print_duplicate_keys_in_arguments                             560.0n ± 0%    568.1n ± 0%  +1.45% (p=0.002 n=6)
KlogOutput/quotation                                                     511.2n ± 0%    515.0n ± 0%  +0.73% (p=0.002 n=6)
KlogOutput/handle_odd-numbers_of_KVs_in_both_log_values_and_Info_args    751.7n ± 0%    749.0n ± 0%  -0.35% (p=0.002 n=6)
KlogOutput/KObjSlice_okay                                                522.4n ± 0%    527.1n ± 0%  +0.91% (p=0.002 n=6)
KlogOutput/Error()_for_nil                                               2.162µ ± 0%    2.200µ ± 0%  +1.73% (p=0.002 n=6)
KlogOutput/verbosity_enabled                                             432.0n ± 0%    444.0n ± 0%  +2.79% (p=0.002 n=6)
KlogOutput/verbosity_disabled                                            7.067n ± 0%    7.066n ± 0%  -0.03% (p=0.009 n=6)
KlogOutput/log_with_name_and_values                                      546.2n ± 0%    553.8n ± 0%  +1.38% (p=0.002 n=6)
KlogOutput/empty_WithValues                                              408.2n ± 0%    416.2n ± 0%  +1.97% (p=0.002 n=6)
KlogOutput/handle_odd-numbers_of_KVs                                     548.5n ± 0%    556.0n ± 0%  +1.36% (p=0.002 n=6)
geomean                                                                  61.09n         61.23n       +0.24%
¹ all samples are equal

pkg: k8s.io/klog/v2/textlogger
                                                                            │ 0f1b22b.out │         5025e083b0c56.out         │
                                                                            │   sec/op    │   sec/op     vs base              │
TextloggerOutput/KObjSlice_int_arg                                            394.5n ± 0%   405.8n ± 0%  +2.88% (p=0.002 n=6)
TextloggerOutput/MarshalLog()_that_panics                                     625.9n ± 0%   639.2n ± 0%  +2.13% (p=0.002 n=6)
TextloggerOutput/handle_integer_keys                                          640.6n ± 0%   661.5n ± 0%  +3.25% (p=0.002 n=6)
TextloggerOutput/verbosity_disabled                                           21.89n ± 1%   21.94n ± 0%       ~ (p=0.052 n=6)
TextloggerOutput/preserve_order_of_key/value_pairs                            533.0n ± 0%   541.7n ± 0%  +1.63% (p=0.002 n=6)
TextloggerOutput/KObj                                                         341.8n ± 0%   353.8n ± 0%  +3.51% (p=0.002 n=6)
TextloggerOutput/ignore_MarshalJSON                                           357.6n ± 0%   368.1n ± 0%  +2.96% (p=0.002 n=6)
TextloggerOutput/Error()_for_nil                                              1.807µ ± 0%   1.828µ ± 0%  +1.16% (p=0.002 n=6)
TextloggerOutput/verbosity_enabled                                            325.6n ± 0%   344.1n ± 0%  +5.70% (p=0.002 n=6)
TextloggerOutput/call_depth                                                   396.9n ± 0%   413.2n ± 0%  +4.12% (p=0.002 n=6)
TextloggerOutput/multiple_WithValues                                          1.691µ ± 0%   1.727µ ± 0%  +2.16% (p=0.002 n=6)
TextloggerOutput/print_duplicate_keys_in_arguments                            430.9n ± 0%   445.2n ± 0%  +3.32% (p=0.002 n=6)
TextloggerOutput/KObjSlice_okay                                               397.3n ± 0%   410.6n ± 0%  +3.32% (p=0.002 n=6)
TextloggerOutput/String()_for_nil                                             1.988µ ± 0%   2.010µ ± 0%  +1.13% (p=0.002 n=6)
TextloggerOutput/struct_keys                                                  536.8n ± 1%   545.8n ± 0%  +1.67% (p=0.002 n=6)
TextloggerOutput/html_characters                                              344.6n ± 0%   355.4n ± 0%  +3.13% (p=0.002 n=6)
TextloggerOutput/KObjSlice_nil_arg                                            331.7n ± 0%   345.0n ± 0%  +4.01% (p=0.002 n=6)
TextloggerOutput/regular_error_types_as_value                                 357.4n ± 0%   367.0n ± 0%  +2.71% (p=0.002 n=6)
TextloggerOutput/Error()_that_panics                                          591.1n ± 0%   605.5n ± 0%  +2.42% (p=0.002 n=6)
TextloggerOutput/String()_that_panics                                         600.6n ± 0%   616.0n ± 0%  +2.56% (p=0.002 n=6)
TextloggerOutput/map_keys                                                     590.6n ± 0%   604.0n ± 0%  +2.27% (p=0.002 n=6)
TextloggerOutput/mixed_duplicates                                             3.062µ ± 0%   3.139µ ± 0%  +2.53% (p=0.002 n=6)
TextloggerOutput/log_with_multiple_names_and_values                           525.0n ± 0%   532.9n ± 0%  +1.51% (p=0.002 n=6)
TextloggerOutput/override_WithValues                                          522.8n ± 0%   540.3n ± 0%  +3.36% (p=0.002 n=6)
TextloggerOutput/KObjs                                                        469.7n ± 0%   479.0n ± 0%  +1.98% (p=0.002 n=6)
TextloggerOutput/regular_error_types_when_using_logr.Error                    354.2n ± 0%   364.8n ± 0%  +2.96% (p=0.002 n=6)
TextloggerOutput/map_values                                                   711.6n ± 0%   716.0n ± 0%  +0.61% (p=0.002 n=6)
TextloggerOutput/slice_values                                                 480.7n ± 0%   495.5n ± 0%  +3.08% (p=0.002 n=6)
TextloggerOutput/vmodule                                                      847.1n ± 0%   861.9n ± 0%  +1.74% (p=0.002 n=6)
TextloggerOutput/KObjSlice_ints                                               427.1n ± 0%   437.8n ± 0%  +2.49% (p=0.002 n=6)
TextloggerOutput/MarshalLog()_for_nil                                         818.0n ± 0%   832.2n ± 1%  +1.73% (p=0.002 n=6)
TextloggerOutput/MarshalLog()_that_returns_itself                             405.9n ± 0%   420.5n ± 0%  +3.60% (p=0.002 n=6)
TextloggerOutput/klog.Format                                                  728.9n ± 0%   740.6n ± 0%  +1.61% (p=0.002 n=6)
TextloggerOutput/cyclic_list                                                  64.30µ ± 1%   66.46µ ± 2%  +3.37% (p=0.002 n=6)
TextloggerOutput/log_with_name_and_values                                     426.4n ± 0%   436.3n ± 0%  +2.31% (p=0.002 n=6)
TextloggerOutput/odd_WithValues                                               1.270µ ± 0%   1.321µ ± 0%  +3.98% (p=0.002 n=6)
TextloggerOutput/empty_WithValues                                             310.7n ± 0%   321.7n ± 0%  +3.54% (p=0.002 n=6)
TextloggerOutput/handle_odd-numbers_of_KVs_in_both_log_values_and_Info_args   519.9n ± 0%   536.1n ± 0%  +3.11% (p=0.002 n=6)
TextloggerOutput/KObjSlice_nil_entry                                          371.2n ± 0%   380.8n ± 0%  +2.59% (p=0.002 n=6)
TextloggerOutput/struct_values                                                420.7n ± 0%   431.9n ± 0%  +2.67% (p=0.002 n=6)
TextloggerOutput/log_with_values                                              352.9n ± 0%   363.2n ± 0%  +2.92% (p=0.002 n=6)
TextloggerOutput/override_single_value                                        455.9n ± 0%   472.2n ± 0%  +3.57% (p=0.002 n=6)
TextloggerOutput/handle_odd-numbers_of_KVs                                    419.2n ± 0%   433.6n ± 0%  +3.42% (p=0.002 n=6)
TextloggerOutput/duplicates                                                   2.638µ ± 0%   2.712µ ± 0%  +2.79% (p=0.002 n=6)
TextloggerOutput/other_vmodule                                                110.2n ± 0%   110.2n ± 0%       ~ (p=0.636 n=6)
TextloggerOutput/quotation                                                    389.1n ± 0%   404.5n ± 0%  +3.96% (p=0.002 n=6)
geomean                                                                       564.9n        579.9n       +2.64%

@dgrisonnet
Copy link
Member

/triage accepted
/assign @pohly

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Dec 12, 2025
@pohly
Copy link

pohly commented Jan 5, 2026

The 6db40fd commit makes the code more complex again (on-stack 1024 bytes buffer). It claims to reduce the number of allocations (right?) but I don't see that when using -benchmem - there's no difference in allocations at all.

@asergunov: can you clarify? Should I see less allocations because of that commit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants