mesonbuild / mesonbuild/vscode-meson

[Feature] Configuring the number of parallel jobs

Open
#152 6 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
138
Forks
53
PR merge metrics
No merged PRs in 30d

Description

## Issue

Ninja, the build system used by Meson, currently uses all available hardware threads + 2 (i.e. logical CPU count + 2) to run compilation jobs in parallel.

This is unsafe on hardware with a high logical CPU count and relatively low available memory. (e.g. on a system with 32 hardware threads but only 32 GiB of memory). As it can cause the following problem

- Reduce system responsiveness
- A large number of parallel compilation jobs will quickly consume all available memory, leading to havey swapping, OOM kill and, in the worst case, a system freeze or crash.
- High usage of all CPU cores can lead to high core temperatures, especially on laptops where the cooling system may not be able to effectively lower the excessive temperature, resulting in potential hardware damage if the compilation takes a long time.

As stated in ninja-build/ninja#1441, there is no mechanism in Ninja where an environment variable can be used to control the number of parallel jobs. So `tasks.options.env` cannot be used to work around this problem.

Based on my limited and possibly inaccurate observations, the Ninja project won't be adding support for configuring the number of parallel jobs or passing flags via environment variables in the foreseeable future.

- https://github.com/ninja-build/ninja/pull/1399#issuecomment-379016530
- https://github.com/ninja-build/ninja/issues/1441#issuecomment-439275459 prematurely closed

My apologies if there are any inaccuracies in the above statements.

## Conclusion

In light of the above, it may be considered reasonable and to introduce an option in this extension to conveniently limit the number of parallel jobs in Ninja.

## Possible workarounds

- start vscode with taskset
```bash
taskset -c 0-3 code
```
- create a shell script wrapper for ninja that passes the `-j` flag
- use an [alternative implementation](https://github.com/michaelforney/samurai) of ninja
- locally patch the ninja source to support ninja flags in environment variables.

## Notes

- `tasks.runOptions.instanceLimit` is unrelated to limiting parallel Ninja jobs

---

Thank you very much for generously volunteering your time and skills to contribute to this important project.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing how the extension handles tasks.options.env and compare that path with tasks.runOptions.instanceLimit. Define the configuration and Ninja invocation behavior needed to cap parallel jobs, then verify the limit through the extension's task execution tests or manual task runs.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.