From 4d25940030733aad917e7750e705dd8273ab7707 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Fri, 18 Nov 2022 13:39:23 +0100 Subject: [PATCH] funcr: optimize WithValues/WithName/WithCallDepth All of these functions indirectly copied the entire Options struct because it gets stored by value in the Formatter and thus fnlogger. The struct is read-only, therefore sharing a single copy by pointer via different logger instances is possible. Performance for the context value benchmark got better. --- funcr/funcr.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/funcr/funcr.go b/funcr/funcr.go index 0baf003..e52f0cd 100644 --- a/funcr/funcr.go +++ b/funcr/funcr.go @@ -218,7 +218,7 @@ func newFormatter(opts Options, outfmt outputFormat) Formatter { prefix: "", values: nil, depth: 0, - opts: opts, + opts: &opts, } return f } @@ -232,7 +232,7 @@ type Formatter struct { values []interface{} valuesStr string depth int - opts Options + opts *Options } // outputFormat indicates which outputFormat to use.