sandlock icon indicating copy to clipboard operation
sandlock copied to clipboard

Suggestion: narrow three of sandlock-core's dependency features

Open ljedrz opened this issue 1 month ago • 1 comments

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:

  1. tokio-util: drop features = ["rt"]. Core only uses sync::CancellationToken, which needs no feature. rt pulls in futures-util (with its futures-macro proc macro), futures-task and slab, about 29k lines in all.
  2. goblin: only the ELF parser. vdso.rs only parses ELF, but the default features also build the Mach-O, PE and archive parsers. With default-features = false, features = ["std", "elf32", "elf64", "endian_fd"], the compiled library is 2.1 MB instead of 6.9 MB. The parser vdso.rs uses is unchanged.
  3. nix: only user. The only call is User::from_uid in expand.rs. With features = ["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 --lib gives the same results before and after.
  • clippy reports no new warnings.
  • Core builds with and without default features.

ljedrz avatar Oct 26 '26 12:10 ljedrz

Thanks for your suggestion, @ljedrz . I created https://github.com/multikernel/sandlock/pull/329 , please take a look if I still miss anything.

congwang-mk avatar Oct 27 '26 04:10 congwang-mk