Closed Bug 1646936 Opened 4 years ago Closed 4 years ago

Multiple RunCbindgen running in parallel are blocking each other

Categories

(Firefox Build System :: General, task)

task

Tracking

(firefox79 fixed)

RESOLVED FIXED
mozilla79
Tracking Status
firefox79 --- fixed

People

(Reporter: glandium, Assigned: glandium)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

When running the export tier at default parallelism, and tracking the time taken by each python script, one can see that the slowest RunCbindgen takes about 15s.

However, when running at -j1, the slowest is 1.94s.

What's happening is that each cbindgen is invoking cargo metadata, each of which doesn't allow another instance of cargo to run at the same time, delaying any other one that starts.
(per https://github.com/eqrion/cbindgen/blob/c83137f3662e90d312b4b69abd84f5a08d4a00e9/src/bindgen/cargo/cargo_metadata.rs#L184)

Ironically, they all invoke the same cargo metadata command, and that command, when run alone, takes 1.4s, so is the longest part of cbindgen.

Note: In the hypothetical future where we leave it to Make to handle the dependencies between code and the headers cbindgen generates, we need to account for the fact that cbindgen is going to take jobserver slots forever if cargo build is running at the same time for the normal rust code compilation.

Blocks: 1646939

(In reply to Mike Hommey [:glandium] from comment #1)

There's another cargo invocation that probably holds the lock too:
https://github.com/eqrion/cbindgen/blob/c83137f3662e90d312b4b69abd84f5a08d4a00e9/src/bindgen/cargo/cargo_expand.rs#L70

That one we shouldn't be using, because cargo expand is a nightly-only feature to expand macros.

This needs https://github.com/eqrion/cbindgen/pull/538, and obviously a
cbindgen update, but I think it should address this issue.

I get similar times as before with ./mach build pre-export export, but
this is on a very-parallel machine, to the point where it may not
matter... It'd be worth profiling this before landing to ensure that
this is worth it.

I'd rather avoid requiring a cbindgen upgrade. The way I was going for was to set CARGO to a wrapper script that returns the metadata that would be created first. The main problem (which also applies to your approach), is to properly refresh the cached metadata when changes happen. I'm not quite sure whether Cargo.toml + Cargo.lock cut it.

FWIW, I don't think requiring a cbindgen upgrade is a big deal. We've been deferring them for a long while, see bug 1631929... So I wouldn't avoid one just for the sake of doing so.

(In reply to Mike Hommey [:glandium] from comment #4)

I'd rather avoid requiring a cbindgen upgrade. The way I was going for was to set CARGO to a wrapper script that returns the metadata that would be created first. The main problem (which also applies to your approach), is to properly refresh the cached metadata when changes happen. I'm not quite sure whether Cargo.toml + Cargo.lock cut it.

Updating any crate version updates the version and checksum in cargo.lock, so I think it does. I could be wrong of course. cbindgen doesn't care about much more than dependency versions..

FWIW, I don't think requiring a cbindgen upgrade is a big deal

I think it is a significant deal: it requires every contributors to update (Either with "cargo install" or with "mach bootstrap" and none of them are quick) and interrupting them in their tasks.

(In reply to Sylvestre Ledru [:Sylvestre] from comment #7)

FWIW, I don't think requiring a cbindgen upgrade is a big deal

I think it is a significant deal.

Sure, but nobody has got to update it in more than three months, and we have other reasons to want to do it other than this.

Attachment #9157932 - Attachment description: Bug 1646936 - Generate a single build/cargo-metadata.json in the objdir, and feed it to cbindgen. → Bug 1646936 - Generate a single build/cargo-metadata.json in the objdir, and feed it to cbindgen. r=glandium!
Attachment #9157932 - Attachment description: Bug 1646936 - Generate a single build/cargo-metadata.json in the objdir, and feed it to cbindgen. r=glandium! → Bug 1646936 - Generate a single metadata file in the objdir, and feed it to cbindgen. r=glandium!
Pushed by ealvarez@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/8f948dd74aba Generate a single metadata file in the objdir, and feed it to cbindgen. r=glandium
Flags: needinfo?(emilio)
Pushed by ealvarez@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/564eedd27f0a Generate a single metadata file in the objdir, and feed it to cbindgen. r=glandium
Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla79
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: