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

Commit 5fde64e

Browse files
authored
Use raw_c_allocator when not in Debug
In our case (lots of C headers), codegen went from ~90s to less than 1s.
1 parent 74da43f commit 5fde64e

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

build.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub fn build(b: *std.Build) void {
77
const skip_run_translated = b.option(bool, "skip-run-translated", "Main test suite skips run-translated tests") orelse false;
88
const test_cross_targets = b.option(bool, "test-cross-targets", "Include cross-translation targets in the test cases") orelse false;
99
const use_llvm = b.option(bool, "llvm", "Use LLVM backend to generate aro executable");
10+
const link_libc = b.option(bool, "link-libc", "Link libc") orelse (optimize != .Debug);
1011

1112
const aro = b.dependency("aro", .{
1213
.target = target,
@@ -40,6 +41,9 @@ pub fn build(b: *std.Build) void {
4041
.use_llvm = use_llvm,
4142
.use_lld = use_llvm,
4243
});
44+
if (link_libc) {
45+
translate_c_exe.linkLibC();
46+
}
4347

4448
b.installDirectory(.{
4549
.source_dir = aro.path("include"),

src/main.zig

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ const Translator = @import("Translator.zig");
77

88
const fast_exit = @import("builtin").mode != .Debug;
99

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

1212
pub fn main() u8 {
13-
const gpa = general_purpose_allocator.allocator();
14-
defer _ = general_purpose_allocator.deinit();
13+
const gpa = if (@import("builtin").link_libc)
14+
std.heap.raw_c_allocator
15+
else
16+
debug_allocator.allocator();
17+
defer if (!@import("builtin").link_libc) {
18+
_ = debug_allocator.deinit();
19+
};
1520

1621
var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
1722
defer arena_instance.deinit();

0 commit comments

Comments
 (0)