Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bindings/napi/root.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ fn init(old_ref_count: u32) !void {

var cpu_count: u64 = options.thread_count;
if (options.thread_count == 0) {
std.debug.print("Note: no -Dthread-count set, will use runtime CPU count minus 1: {}\n", .{cpu_count});
cpu_count = @max((try std.Thread.getCpuCount()) - 1, 1);
std.debug.print("Note: no -Dthread-count set, will use runtime CPU count minus 1: {}\n", .{cpu_count});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For library and binding code, it is best practice to use std.log.info instead of std.debug.print. std.debug.print unconditionally outputs to stderr and cannot be easily configured or disabled by the consuming application. Note that std.log functions automatically append a newline, so the trailing \n should be omitted.

Additionally, to adhere to the repository style guide's requirement of maintaining an assertion density of at least two assertions per function (see Repository Style Guide, lines 51-55), we should assert the invariant that cpu_count > 0.

            std.log.info("Note: no -Dthread-count set, will use runtime CPU count minus 1: {}", .{cpu_count});
            std.debug.assert(cpu_count > 0);
References
  1. Assert all function arguments and return values, pre/postconditions and invariants. The assertion density of the code must average a minimum of two assertions per function. (link)

}

const n_workers = @min(cpu_count, @import("bls").ThreadPool.MAX_WORKERS);
Expand Down
Loading