Skip to content

improve work queue pipeline to start working on more components in parallel #9188

Closed

Description

@andrewrk

Currently, the only parallelization the main pipeline does is AstGen jobs and C compilation jobs:

zig/src/Compilation.zig

Lines 1913 to 1945 in 8a6de78

// Here we queue up all the AstGen tasks first, followed by C object compilation.
// We wait until the AstGen tasks are all completed before proceeding to the
// (at least for now) single-threaded main work queue. However, C object compilation
// only needs to be finished by the end of this function.
var zir_prog_node = main_progress_node.start("AstGen", self.astgen_work_queue.count);
defer zir_prog_node.end();
var c_obj_prog_node = main_progress_node.start("Compile C Objects", self.c_source_files.len);
defer c_obj_prog_node.end();
self.work_queue_wait_group.reset();
defer self.work_queue_wait_group.wait();
{
self.astgen_wait_group.reset();
defer self.astgen_wait_group.wait();
while (self.astgen_work_queue.readItem()) |file| {
self.astgen_wait_group.start();
try self.thread_pool.spawn(workerAstGenFile, .{
self, file, &zir_prog_node, &self.astgen_wait_group,
});
}
while (self.c_object_work_queue.readItem()) |c_object| {
assert(@ptrToInt(c_object) != 0xaaaa_aaaa_aaaa_aaaa);
self.work_queue_wait_group.start();
try self.thread_pool.spawn(workerUpdateCObject, .{
self, c_object, &c_obj_prog_node, &self.work_queue_wait_group,
});
}
}

If you scroll down and look at the rest of the queue handling, you can see that, among others, the following tasks are done serially:

C/C++ library compilation tasks

  • glibc_crt_file
  • glibc_shared_objects
  • musl_crt_file
  • mingw_crt_file
  • windows_import_lib
  • libunwind
  • libcxx
  • libcxxabi
  • libtsan
  • wasi_libc_crt_file
  • libssp

zig code compilation tasks:

  • compiler_rt_lib
  • compiler_rt_obj
  • zig_libc
  • libfuzzer

At the very least, the C/C++ library compilation tasks should be kicked off in parallel, in the same wait group as C object compilation tasks. The zig compilation tasks can also happen in parallel, but they should wait until after the AstGen tasks are all complete.

Activity

  1. added
    enhancement
    frontend
    on Jun 21, 2021
  2. added this to the 0.9.0 milestone on Jun 21, 2021
  3. modified the milestones: 0.9.0, 0.10.0 on Nov 24, 2021
  4. modified the milestones: 0.10.0, 0.11.0 on Aug 23, 2022
  5. modified the milestones: 0.11.0, 0.12.0 on Jun 19, 2023
  6. andrewrk commented on Feb 10, 2025

    @andrewrk
    MemberAuthor

    done in #22541

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementfrontendoptimization

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions