Skip to content

src: do not format the values of the fields for the logs without the logger - #53

Merged
Insei merged 1 commit into
mainfrom
noop-log-fast-path
Oct 19, 2026
Merged

Insei merged 1 commit into
mainfrom
noop-log-fast-path

Conversation

@Insei

@Insei Insei commented Oct 19, 2026

Copy link
Copy Markdown
Owner

The CPU and memory profiles of Parse showed that without the logger a quarter of the allocations and ~6% of CPU were spent on the log records that nobody writes: With per field and driver, the fields of initial, skip, override, the values formatted by fmt.Sprintf, the texts of the errors. Now Parse and the reloads skip it if the logger is the noop one (no WithLogger). The behaviour with the logger, including the deferred one, is not changed.

                   │   old    │   new                    │
Parse-32             8.021µ     3.075µ  -61.67%
Parse_SubConfig-32   2.727µ     1.286µ  -52.83%
Parse_Drivers-32     65.34µ     52.04µ  -20.35%   (tag + yaml + env)

allocs/op
Parse-32             139        18      -87.05%
Parse_SubConfig-32   44         10      -77.27%
Parse_Drivers-32     648        411     -36.57%

Also checked, no changes needed:

  • goroutines: 20 000 cycles of Subscribe and cancel, and 9 000 reloads of a file with the subscriber, leave the same number of goroutines after the cancel;
  • heap: it grows during the warm-up and stays flat, ~1.8 MB after 20 000 subscriptions and after 9 000 reloads, no leaks;
  • locks: the network loads of the drivers are outside of the locks of Manager, Current is atomic.

…logger

Signed-off-by: Dmitriy Aleksandrov <goodmobiledevices@gmail.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7e2b443) to head (9f5060f).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #53   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           32        32           
  Lines         2630      2638    +8     
=========================================
+ Hits          2630      2638    +8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Insei
Insei merged commit 5f9bf99 into main Oct 19, 2026
4 checks passed
@Insei
Insei deleted the noop-log-fast-path branch October 19, 2026 02:42
@github-actions

Copy link
Copy Markdown
Contributor

Benchmark diff: 7e2b443 → 9b6e5e1 (10 runs)

goos: linux
goarch: amd64
pkg: github.com/insei/tinyconf/v2
cpu: AMD EPYC 9V45 96-Core Processor                
                    │   base.txt   │              head.txt               │
                    │    sec/op    │   sec/op     vs base                │
Parse-4                4.403µ ± 2%   1.945µ ± 2%  -55.83% (p=0.000 n=10)
Parse_SubConfig-4     1593.0n ± 5%   850.3n ± 0%  -46.62% (p=0.000 n=10)
Current-4              45.99n ± 0%   47.04n ± 0%   +2.28% (p=0.001 n=10)
Current_SubConfig-4    66.36n ± 1%   67.49n ± 1%   +1.70% (p=0.000 n=10)
geomean                382.5n        269.2n       -29.63%

                    │    base.txt    │                head.txt                │
                    │      B/op      │     B/op      vs base                  │
Parse-4               4.899Ki ± 0%     1.344Ki ± 0%  -72.57% (p=0.000 n=10)
Parse_SubConfig-4      1400.0 ± 0%       392.0 ± 0%  -72.00% (p=0.000 n=10)
Current-4               0.000 ± 0%       0.000 ± 0%        ~ (p=1.000 n=10) ¹
Current_SubConfig-4     0.000 ± 0%       0.000 ± 0%        ~ (p=1.000 n=10) ¹
geomean                            ²                 -47.36%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

                    │   base.txt    │               head.txt               │
                    │   allocs/op   │ allocs/op   vs base                  │
Parse-4               139.00 ± 0%     18.00 ± 0%  -87.05% (p=0.000 n=10)
Parse_SubConfig-4      44.00 ± 0%     10.00 ± 0%  -77.27% (p=0.000 n=10)
Current-4              0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) ¹
Current_SubConfig-4    0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) ¹
geomean                           ²               -58.58%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

pkg: github.com/insei/tinyconf/v2/drivers
                │  base.txt   │              head.txt               │
                │   sec/op    │   sec/op     vs base                │
Parse_Drivers-4   36.32µ ± 3%   30.58µ ± 7%  -15.81% (p=0.000 n=10)

                │   base.txt   │               head.txt               │
                │     B/op     │     B/op      vs base                │
Parse_Drivers-4   32.04Ki ± 0%   25.14Ki ± 0%  -21.54% (p=0.000 n=10)

                │  base.txt  │              head.txt              │
                │ allocs/op  │ allocs/op   vs base                │
Parse_Drivers-4   645.0 ± 0%   408.0 ± 0%  -36.74% (p=0.000 n=10)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants