Suggestion: narrow three of sandlock-core's dependency features
Thanks for the ongoing changes benefiting embedders. While building with default-features = false, I noticed that three of sandlock-core's dependencies are built with some features that could be disabled. Narrowing them is a three-line change to Cargo.toml, with no code changes. It makes core build faster and compile less third-party code:
tokio-util: dropfeatures = ["rt"]. Core only usessync::CancellationToken, which needs no feature.rtpulls infutures-util(with itsfutures-macroproc macro),futures-taskandslab, about 29k lines in all.goblin: only the ELF parser.vdso.rsonly parses ELF, but the default features also build the Mach-O, PE and archive parsers. Withdefault-features = false, features = ["std", "elf32", "elf64", "endian_fd"], the compiled library is 2.1 MB instead of 6.9 MB. The parservdso.rsuses is unchanged.nix: onlyuser. The only call isUser::from_uidinexpand.rs. Withfeatures = ["user"], the compiled library is 0.8 MB instead of 4.1 MB.
What it gains. Measured at 4d68f08 on x86_64 (16 cores), with clean release builds averaged over 3 runs:
sandlock-core --no-default-features |
now | with the change |
|---|---|---|
| crates | 47 (6 proc macros) | 43 (5) |
| build CPU time | 81 s | 67 s (−17%) |
| build wall time | 12.4 s | 11.6 s (-6.45%) |
Less third-party code compiled into the supervisor also means less code to audit.
The default-feature build and the CLI keep the same crates, because the HTTP stack brings futures-util back. They still compile less of goblin and nix.
Checked on the change:
cargo test -p sandlock-core --libgives the same results before and after.- clippy reports no new warnings.
- Core builds with and without default features.
Thanks for your suggestion, @ljedrz . I created https://github.com/multikernel/sandlock/pull/329 , please take a look if I still miss anything.