Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

Commit 128ad0d

Browse files
committed
Use SmpAllocator when not in Debug
In our case (lots of C headers), codegen went from ~90s to less than 1s.
1 parent a22b208 commit 128ad0d

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎src/main.zig‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const builtin = @import("builtin");
12
const std = @import("std");
23
const assert = std.debug.assert;
34
const mem = std.mem;
@@ -7,11 +8,14 @@ const Translator = @import("Translator.zig");
78

89
const fast_exit = @import("builtin").mode != .Debug;
910

10-
var general_purpose_allocator: std.heap.GeneralPurposeAllocator(.{}) = .init;
11+
var debug_allocator: std.heap.DebugAllocator(.{}) = .init;
1112

1213
pub fn main() u8 {
13-
const gpa = general_purpose_allocator.allocator();
14-
defer _ = general_purpose_allocator.deinit();
14+
const gpa = if (builtin.mode == .Debug)
15+
debug_allocator.allocator()
16+
else
17+
std.heap.smp_allocator;
18+
defer if (builtin.mode == .Debug) std.debug.assert(debug_allocator.deinit() == .ok);
1519

1620
var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
1721
defer arena_instance.deinit();

0 commit comments

Comments
 (0)