-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
replace @setCold
with @cold
#5177
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
Comments
How does this work with comptime-known coldness? The old approach would have been: fn foo() void {
@setCold(comptime_foo_is_cold);
} But with the new approach: fn foo() void {
if (comptime_foo_is_cold) {
@cold(); // doesn't work, applies to the if body.
}
// function implementation
} |
I guess this might work, since technically there's no scope: fn foo() void {
if (comptime_foo_is_cold) @cold();
// function implementation
} |
That later example would still apply to the then-body of the if statement, communicating that This proposal removes the ability to specify comptime-known coldness. I would be happy to reconsider if there is a convincing enough use case for comptime-known coldness. |
ZeeAlloc has manual size tuning using |
Thanks for the example. OK I'll amend the proposal to have
|
There's a solution over at #5239 -- simple configuration is concise ( |
btw I noticed that LLVM has a way to mark arbitrary code paths as cold: https://llvm.org/docs/LangRef.html#assume-operand-bundles |
As I understand it, Ideally, I'd like to see |
Okay, so as per #6556 and #6596, Overall I'm of the opinion there are two options:
I think these are both solid options and that it may be one of the rare cases where it might actually be worthwhile to do both -- treating |
I think I have another use case for Let's say we're making a loop which we want to iterate, say, a billion times per second, and for at least a few thousand iterations per loop entry. Every single μop matters, and we want the optimizer to prioritize maximum iterations per second over anything else, including exiting the loop. With I suppose an alternative solution would be letting |
Consider having an if (foo) {
std.debug.print("this is probably going to happen", .{});
} else unlikely {
std.debug.print("this would fit so nicely into the language!", .{});
} fn panic() noreturn {
unlikely {
// the indentation here feels a bit gross...
std.debug.print("boo!", .{});
}
} switch (foo) {
42 => "life",
69, 666 => unlikely "funny number",
else => unlikely "anything else",
} The pragmas proposal is pretty interesting too. |
I find the section on assume operator bundles unclear - one interpretation is that putting an operand bundle with the "cold" tag on an assume intrinsic lets the optimizer assume that the location containing the assume intrinsic has the "cold" tag, rather than making particular block cold. If that's the case, another option might be the expect intrinsic or the expect with probability intrinsic. |
…c path" This reverts commit f6678f0. Specifically, `@setCold` only affects full function scopes. The zig language feature for marking specific scopes as "cold" is being tracked in ziglang/zig#5177.
I was just now writing some @setCold zig code, and realized it is very confusing because my brain sees a word cold, but in fact @setCold(false) -> Hot path. So it takes a couple of seconds to comprehend that even though it says cold in reality it is in fact hot. More clear syntax would be highly appreciated even though not necessary as it currently works ok 👍 |
Isn't |
If that's the case then I'm even more confused by the syntax. Thanks for pointing that one out. |
Yes, this is for the case that you want to set coldness via a comptime-known value as noted above in the thread. |
Should there be an equivalent of |
See #489 |
Rejected in favor of #21148. |
Status quo:
Proposal:
Annotates that it is relatively uncommon for control flow to reach this point. Similar to
unreachable
, but only communicates probability. It communicates a willingness to compromise performance of the cold path in order to improve performance of the hot path.This makes #489 unnecessary. Instead of:
With this proposal:
The text was updated successfully, but these errors were encountered: