Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extensive trace logging is expensive even when disabled #28064

Closed
thaarok opened this issue Sep 5, 2023 · 3 comments · Fixed by #28069
Closed

Extensive trace logging is expensive even when disabled #28064

thaarok opened this issue Sep 5, 2023 · 3 comments · Fixed by #28069
Labels

Comments

@thaarok
Copy link

thaarok commented Sep 5, 2023

While running performance benchmarks of ethereum code, I have discovered a significant amount of time is consumed by trace logging, even when the trace logging is not enabled.

By cpuprofile, 2% of my runtime is consumed by:

log.Trace
log.write
stack.Caller

In the source:
https://github.com/ethereum/go-ethereum/blob/v1.12.2/log/logger.go#L185

Actual behaviour

The ethereum logging generates expensive stacktraces on every log.Trace() call, even when the trace logging is disabled.

Expected behaviour

The stacktrace should be generated only when the log is not going to be dropped.

System information

Commit hash : 25733a4

@holiman
Copy link
Contributor

holiman commented Sep 5, 2023 via email

@Deacon77

This comment was marked as spam.

@holiman
Copy link
Contributor

holiman commented Sep 6, 2023

A benchmark:

func BenchmarkTraceLogging(b *testing.B) {
	Root().SetHandler(LvlFilterHandler(LvlInfo, StreamHandler(os.Stderr, TerminalFormat(true))))
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		Trace("a message", "v", i)
	}
}

Results, for commenting out the line Call: stack.Caller(skip),:

[user@work go-ethereum]$ benchstat before.txt after.txt 
name            old time/op    new time/op    delta
TraceLogging-8    2.84µs ± 8%    0.97µs ±11%  -65.80%  (p=0.008 n=5+5)

name            old alloc/op   new alloc/op   delta
TraceLogging-8      511B ± 0%      263B ± 0%  -48.53%  (p=0.000 n=5+4)

name            old allocs/op  new allocs/op  delta
TraceLogging-8      4.00 ± 0%      2.00 ± 0%  -50.00%  (p=0.008 n=5+5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants