After recent optimizations, the current next biggest offender of more allocations than would be expected revealed by profiling is due to the trace logging closures for the scripting engine execution. Once upon a time, there was no way to check the current logging level with the logging infrastructure at the time and thus a logging closure was used to defer the fairly expensive construction of the trace logging information until it was actually invoked (meaning tracing is enabled). However, those closures come at the cost of allocations, and since script execution is something that happens non-stop during normal operation, those allocations really add up, as the profiling shows. As some point, the logging infrastructure was changed out, and it is now possible to determine the logging level, so this updates the code to take advantage of that and avoid the closures while still only performing the fairly expensive construction of trace logging information when tracing is enabled. In other words, with this change there is zero cost (other than the conditional check, of course) when tracing is not enabled. Finally, this also removes the no longer necessary code related to creating the logging closures.
22 lines
608 B
Go
22 lines
608 B
Go
// Copyright (c) 2013-2015 The btcsuite developers
|
|
// Copyright (c) 2015-2019 The Decred developers
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package txscript
|
|
|
|
import (
|
|
"github.com/decred/slog"
|
|
)
|
|
|
|
// log is a logger that is initialized with no output filters. This
|
|
// means the package will not perform any logging by default until the caller
|
|
// requests it.
|
|
// The default amount of logging is none.
|
|
var log = slog.Disabled
|
|
|
|
// UseLogger uses a specified Logger to output package logging info.
|
|
func UseLogger(logger slog.Logger) {
|
|
log = logger
|
|
}
|