Skip to content

Commit

Permalink
perf(bechmarks): use direct print logger instead of channel logger (S…
Browse files Browse the repository at this point in the history
…yndica#425)

When I look at the flamegraphs from running benchmarks, the majority of the time is spent in the logger, busy spinning while waiting for log messages. This makes it harder to understand benchmark results.

I don't see a reason to use something as complex as a channel logger just to print information about the benchmarks. So I switched it to the logger that simply prints in the current thread.

Seeing these flamegraphs makes me concerned about the channel still being overly greedy of system resources. But I'm not trying to address this in the current pr. I have another PR which adds blocking recv methods to the channel to prevent busy spinning.
  • Loading branch information
dnut authored Dec 6, 2024
1 parent 7c23984 commit 535eea1
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/benchmarks.zig
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,10 @@ fn exitWithUsage() noreturn {
/// zig build benchmark -- gossip
pub fn main() !void {
const allocator = std.heap.c_allocator;
var std_logger = try sig.trace.ChannelPrintLogger.init(.{
.allocator = allocator,
.max_level = .info, // NOTE: change to debug to see all logs
.max_buffer = 1 << 15,
});
defer std_logger.deinit();
var std_logger = sig.trace.DirectPrintLogger.init(
allocator,
.info, // NOTE: change to debug to see all logs
);
const logger = std_logger.logger();

if (builtin.mode == .Debug) logger.warn().log("running benchmark in Debug mode");
Expand Down

0 comments on commit 535eea1

Please sign in to comment.