Only build cdylib when the FFI cfg is active #2763
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
as part of the initiative to improve compile times we've been looking at rustc benchmarks over a number of crates in the ecosystem.
We've noticed
hyper
was preventing pipelining opportunities, both for:tokio
orh2
, depending on the chosen features.hyper
also wait for codegen instead of its metadata, as we can see e.g. here inwarp-0.3.2
.In this cargo timing example,
hyper
could start building 6.6s earlier withh2
's metadata, andwarp
could start building as soon ashyper
's metadata is available, around 6s earlier (from different measurements,hyper
's metadata is not visible in the link above).Adding both of these together, there could be a sizable opportunity to improve compile times in the whole
hyper
ecosystem, in addition tohyper
contributors working on the crate itself.I've discussed this with @nox and they've directed me at #2685 as the cause, with this cargo issue as a blocker. Until that is fixed however, I wanted to discuss this hack as an alternative, to re-enable pipelining (without creating a whole different FFI-binding crate) and improve compile times in the meantime.
The idea is to use
#![crate_type]
to build the cdylib only when the FFI cfg is active, in the source rather than via cargo. This works, I believe, on stable and on your MSRV of 1.46 (but I'm not sure I was able to fully test this, and hope CI will help). It has however been recently deprecated, and that deprecation will land on stable in the 1.59 release tomorrow. I don't think it'll go away before the cargo issue is fixed though, so it still seems pretty safe. (Also: I've had to allow the lint to build with deny warnings, and unknown lints to support 1.46+ which don't yet know about that new lint. Another note: maybe theffi
feature should be checked in addition to thehyper_unstable_ffi
cfg ?).I believe there's another cargo feature which could maybe help, to specify dependency crate types in the cargo manifest; all in all, it seems issues in cargo will be fixed and this is mostly a temporary measure to help things until those principled fixes are available.
Just to give you an idea of the impact this has, I've benchmarked building
hyper
(with theclient,http1,http2
features) from-j2
to-j12
: debug builds improve by 7-8%, and release builds by 18-29% (26% mean). This does translate to downstream crates.I can provide precise numbers and cargo timing graphs if needed.
(Opening as draft for discussion whether something like this could work for you ? and to test it out on CI)