mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 07:32:44 +00:00
Sema: fix performance regression
LLVM fails to notice that in release builds, `logFn` ignores its arguments, so their computation can be elided. So, LLVM fails to elide this hashmap lookup. Its cost isn't too significant, but doing it in the hottest loop in Sema adds up! Technically, we could do the lookup a single time, before the loop, but it was cleanest (and a little faster) to just disable this log call at comptime when debug logging is disabled.
This commit is contained in:
parent
6a8cf25a8a
commit
2b677d1660
@ -992,11 +992,16 @@ fn analyzeBodyInner(
|
||||
while (true) {
|
||||
crash_info.setBodyIndex(i);
|
||||
const inst = body[i];
|
||||
|
||||
// The hashmap lookup in here is a little expensive, and LLVM fails to optimize it away.
|
||||
if (build_options.enable_logging) {
|
||||
std.log.scoped(.sema_zir).debug("sema ZIR {s} %{d}", .{ sub_file_path: {
|
||||
const path_digest = block.src_base_inst.resolveFull(&mod.intern_pool).path_digest;
|
||||
const index = mod.path_digest_map.getIndex(path_digest).?;
|
||||
break :sub_file_path mod.import_table.values()[index].sub_file_path;
|
||||
}, inst });
|
||||
}
|
||||
|
||||
const air_inst: Air.Inst.Ref = switch (tags[@intFromEnum(inst)]) {
|
||||
// zig fmt: off
|
||||
.alloc => try sema.zirAlloc(block, inst),
|
||||
|
Loading…
Reference in New Issue
Block a user