diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2025-06-12 09:56:37 +0100 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2025-06-12 17:51:31 +0100 |
| commit | 5bb5aaf932b8ed30aebfbb0036e1532abfc6af46 (patch) | |
| tree | 059ef1f8ab00e70585895068e5561681d49514f5 /src/Compilation.zig | |
| parent | f9a670d46de3c62be16202f186eacfee6ec096d4 (diff) | |
| download | zig-5bb5aaf932b8ed30aebfbb0036e1532abfc6af46.tar.gz zig-5bb5aaf932b8ed30aebfbb0036e1532abfc6af46.zip | |
compiler: don't queue too much AIR/MIR
Without this cap, unlucky scheduling and/or details of what pipeline
stages perform best on the host machine could cause many gigabytes of
MIR to be stuck in the queue. At a certain point, pause the main thread
until some of the functions in flight have been processed.
Diffstat (limited to 'src/Compilation.zig')
| -rw-r--r-- | src/Compilation.zig | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 9f851cf135..ad184b2bc9 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -4607,12 +4607,17 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void { }; assert(zcu.pending_codegen_jobs.rmw(.Add, 1, .monotonic) > 0); // the "Code Generation" node hasn't been ended zcu.codegen_prog_node.increaseEstimatedTotalItems(1); + // This value is used as a heuristic to avoid queueing too much AIR/MIR at once (hence + // using a lot of memory). If this would cause too many AIR bytes to be in-flight, we + // will block on the `dispatchZcuLinkTask` call below. + const air_bytes: u32 = @intCast(air.instructions.len * 5 + air.extra.items.len * 4); if (comp.separateCodegenThreadOk()) { // `workerZcuCodegen` takes ownership of `air`. comp.thread_pool.spawnWgId(&comp.link_task_wait_group, workerZcuCodegen, .{ comp, func.func, air, shared_mir }); comp.dispatchZcuLinkTask(tid, .{ .link_func = .{ .func = func.func, .mir = shared_mir, + .air_bytes = air_bytes, } }); } else { { @@ -4624,6 +4629,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void { comp.dispatchZcuLinkTask(tid, .{ .link_func = .{ .func = func.func, .mir = shared_mir, + .air_bytes = air_bytes, } }); air.deinit(gpa); } |
