Skip to content

Spawn runtime threads without blocking the main thread #1013

Description

@yorickpeterse

Description

When a program starts, we spawn a bunch of extra threads before running the main thread in Scheduler::run: one process monitor thread, an epoch thread, N process threads and N * 4 backup threads. The time it takes to spawn these threads varies, but based on some measuring it can take around 500 microseconds per thread on average. That's quite high compared to the minimum of 20 microseconds I have measured in the past, but there's not much we can do about that.

A simple way to work around this is to spawn one "spawner" thread which then takes care of spawning all the above threads. This way the main thread can start running (without waiting for the spawner thread to finish) while the background threads are set up. Most notably this means the startup time remains largely constant as the number of threads increases, instead of the startup time also increasing.

Related work

No response

Activity

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

    accepting contributionsIssues that are suitable to be worked on by anybody, not just maintainersperformanceChanges related to improving performanceruntimeChanges related to the Rust-based runtime library

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions