Revise @branchHint probabilities

Arguably, my previous use of @setCold() was incorrect in some cases, but
it happened to work out better than not providing any hints.  Let's use
the more granular hints now that Zig 0.14 supports them.
This commit is contained in:
Yorhel 2025-03-05 10:54:23 +01:00
parent 5438312440
commit af7163acf6
3 changed files with 4 additions and 4 deletions

View file

@ -118,7 +118,7 @@ pub const Thread = struct {
} }
fn flush(t: *Thread, expected_len: usize) void { fn flush(t: *Thread, expected_len: usize) void {
@branchHint(.cold); @branchHint(.unlikely);
const block = createBlock(t); const block = createBlock(t);
defer block.deinit(); defer block.deinit();

View file

@ -73,7 +73,7 @@ pub const Writer = struct {
dir_entry_open: bool = false, dir_entry_open: bool = false,
fn flush(ctx: *Writer, bytes: usize) void { fn flush(ctx: *Writer, bytes: usize) void {
@branchHint(.cold); @branchHint(.unlikely);
// This can only really happen when the root path exceeds PATH_MAX, // This can only really happen when the root path exceeds PATH_MAX,
// in which case we would probably have error'ed out earlier anyway. // in which case we would probably have error'ed out earlier anyway.
if (bytes > ctx.buf.len) ui.die("Error writing JSON export: path too long.\n", .{}); if (bytes > ctx.buf.len) ui.die("Error writing JSON export: path too long.\n", .{});

View file

@ -83,7 +83,6 @@ const Parser = struct {
} }
fn fill(p: *Parser) void { fn fill(p: *Parser) void {
@branchHint(.cold);
p.rdoff = 0; p.rdoff = 0;
p.rdsize = (if (p.zstd) |z| z.read(p.rd, &p.buf) else p.rd.read(&p.buf)) catch |e| switch (e) { p.rdsize = (if (p.zstd) |z| z.read(p.rd, &p.buf) else p.rd.read(&p.buf)) catch |e| switch (e) {
error.IsDir => p.die("not a file"), // should be detected at open() time, but no flag for that... error.IsDir => p.die("not a file"), // should be detected at open() time, but no flag for that...
@ -98,6 +97,7 @@ const Parser = struct {
// (Returning a '?u8' here is nicer but kills performance by about +30%) // (Returning a '?u8' here is nicer but kills performance by about +30%)
fn nextByte(p: *Parser) u8 { fn nextByte(p: *Parser) u8 {
if (p.rdoff == p.rdsize) { if (p.rdoff == p.rdsize) {
@branchHint(.unlikely);
p.fill(); p.fill();
if (p.rdsize == 0) return 0; if (p.rdsize == 0) return 0;
} }
@ -133,7 +133,7 @@ const Parser = struct {
} }
fn stringContentSlow(p: *Parser, buf: []u8, head: u8, off: usize) []u8 { fn stringContentSlow(p: *Parser, buf: []u8, head: u8, off: usize) []u8 {
@branchHint(.cold); @branchHint(.unlikely);
var b = head; var b = head;
var n = off; var n = off;
while (true) { while (true) {