Skip to content

cargo-pgrx: build Postgres in parallel during cargo pgrx init#2291

Open
philippemnoel wants to merge 2 commits into
pgcentralfoundation:developfrom
philippemnoel:parallel-make-build-init
Open

cargo-pgrx: build Postgres in parallel during cargo pgrx init#2291
philippemnoel wants to merge 2 commits into
pgcentralfoundation:developfrom
philippemnoel:parallel-make-build-init

Conversation

@philippemnoel
Copy link
Copy Markdown
Contributor

@philippemnoel philippemnoel commented May 15, 2026

Summary

cargo pgrx init already takes -j / --jobs and uses it to size a jobslot::Client, which exposes the jobserver auth to child make processes via MAKEFLAGS. However, neither make world-bin nor make install-world-bin was given -j on its own argv, so GNU make ignored the jobserver and ran serially. Result: cargo pgrx init built Postgres single-threaded even on big hosts.

This PR:

  • Extracts the existing job-count resolution into Init::resolved_jobs() (--jobs -> available_parallelism() -> 1)
  • Reuses it to seed the jobserver (no behavior change there)
  • Passes -jN to both make invocations so GNU make actually parallelizes

No new flags; the existing --jobs/-j keeps working and now has an observable effect on the Postgres build, not just the jobserver token pool.

Test plan

  • cargo check -p cargo-pgrx passes
  • cargo pgrx init rebuild is measurably faster on a multi-core host (verified locally by author)
  • cargo pgrx init -j 1 produces a serial build (verified locally by author)

`cargo pgrx init` already accepts `-j`/`--jobs` and uses it to size a
`jobslot::Client`, which makes the jobserver auth available to child
`make` processes via `MAKEFLAGS`. However, the `make world-bin` and
`make install-world-bin` invocations were never given `-j` on their
argv, so GNU make ignored the jobserver and ran serially — making
`cargo pgrx init` slower than it needed to be on multi-core hosts.

This pulls the existing job-count resolution into an `Init::resolved_jobs()`
helper, reuses it to seed the jobserver, and passes `-jN` to both `make`
invocations so GNU make actually parallelizes. With no `--jobs` flag,
the default is `std::thread::available_parallelism()`, matching the
previous jobserver-only behavior in spirit but now applied in practice.
@philippemnoel
Copy link
Copy Markdown
Contributor Author

The "verify package can build / ubuntu" run will be fixed once #2292 is merged

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant