-
Notifications
You must be signed in to change notification settings - Fork 965
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature-gate all protocols in the libp2p meta crate #1364
Comments
Before doing that, I'd like to have at least some basic measurements that show that removing code does actually speeds up compilation substantially and/or decreases binary size, and that this is not just an urban myth. |
That makes total sense :) I've created a little "benchmark" where I feature-flagged the meta crate in a basic way. I've also left Here is the benchmark repository: https://github.com/thomaseizinger/rust-libp2p-compile-benchmark.
On my machine the results are: For the debug build, that is an improvement of ~20% and in the release build we have ~25%. (If I've got the math right 😁) |
For reference, it is possible to write this: #[cfg_attr(docsrs, doc(cfg(feature = "foo")))]
use ...; Tokio does that, and here's how it renders: https://docs.rs/tokio/0.2.9/tokio/#modules |
I've played with an alternative to this approach, which is to depend on the individual crates and compose everything together manually. Unfortunately, I've hit a wall with the |
I'm aware of this, but I don't think it's fixable. |
I don't think it needs fixing, it is a fine assumption that people are expected to only depend on What is the long-term plan in regards to the crate structure of libp2p? It would also help with issues like #1365 :) |
That's what I would do if it was a personal project. In terms of library user experience, having one single crate beats everything else. But in the case of libp2p, it's always been a major goal to be extensible and that everybody should be able to add their own, and merging everything into one library kind of sends the wrong message. |
Interesting, can you elaborate, what would be so wrong about that? Which extensions to you see possible at the moment that would they go away if libp2p were a single, heavily feature-flagged crate? |
I guess I could ping @mgoelzer or @raulk if they have an opinion about this? |
@tomaka No strong feelings here. Doing this does make the cargo.toml a bit more complicated for the beginner (it's a bit reminiscent of the syn crate's features split), but since one of the goals of the libp2p project is modularity, making this change would certainly not be inconsistent with the philosophy of the project. |
As long as the library is modular in terms of API (e.g. it’s possible to mount custom protocols, secure channels, multiplexers, discoverers, etc. easily), and users can depend only on the modules they actually require, I could be ok taking the path of least resistance that also simplifies life for developers, and feels natural in the target language. Questions/comments:
|
If I'm understanding the question correctly, then no. The
the compiler would not pull in the Right now the meta crate pulls in a bunch of sub crates:
If all you wanted to do is write a new protocol, your project would start by including the meta crate like this:
which will then pull into your build that long list of crates above. llvm doesn't do dead code elimination in debug builds, only release builds (I think - @tomaka would know better), so it's a compile time[*] and binary size tradeoff versus the simplicity of just being able to write
The current way ( [*] Compile time should only be a factor if you're starting from a |
The reason I did the benchmark was because @tomaka was asking for data :) It still quite a tax upon complete rebuilds though which also happen from time to time. However, it is not just compile-times. It is not super harmful but it would be nice to be able to get rid of them :)
Depends. If we keep the meta-crate approach, the release workflow should remain unchanged. |
I'd be in favour of that, as it makes the general user experience of the library way better.
You could still depend on |
Depending on the meta-crate is nice because it is a one-stop shop for all imports.
Unfortunately, depending on the meta-crate
libp2p
brings in all possible protocols (kad, tcp, etc).It would be nice to have a feature per protocol that one could activate from the meta crate, something like:
An orthogonal aspect to this is what the
default
features should be. The minimum you'd want to bring is probablylibp2p-core
(should that even be a feature?), so the default features might as-well be empty. That would mean even protocol-authors only have to depend onlibp2p
instead of pulling inlibp2p_swarm
etc to keep the dependency foot-print low.The text was updated successfully, but these errors were encountered: