Skip to content
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

boulder/moss: Reduce binary size by reducing dependency features #283

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ReillyBrogan
Copy link
Contributor

I used cargo-bloat to find out what some of the biggest offenders with regards to binary size were and found that reqwest and regex could both be trimmed a bit by disabling some features that we don't need.

For regex I switched it to only have the std feature enabled. This disables some of the performance features and unicode support but as far as I can tell we don't use the unicode support and the existing regexes are in non-performance-critical sections. This reduces boulder binary size with the release profile from 16.9MiB -> 15.2MiB.

For reqwest I switched to using native-tls over rustls. Since this links against the system openssl the binary size is further reduced from 15.2MiB -> 13.1MiB.

Final binary sizes when this patch is applied to the experimental Solus package (which already links against system libzstd and sqlite3) are:

  • Boulder: 11.8MiB -> 9.2MiB (-22%)
  • Moss: 10.7MiB -> 8.1MiB (-24%)

@ikeycode
Copy link
Member

I'd whole heartedly understand why this is desirable. However...

I'd sooner not rely on openssl at all, and even our curl package in serpent uses it. The other dependencies would introduce issues in volatile whereby we could dep-break the repo or images, rather than controlled isolated binaries.

Yes, it's an annoying approach but having an almost entirely static build eliminates a plethora of LD issues and makes iteration less problematic (consider the solbuild + libgit2 issues we've known to love and cherish)

Ideally we should trim fat where feasible and nuke lardy deps like petgraph and Co, and use the "packaging" moss target which already yields a similar binary size to the one you've provided.

I used cargo-bloat to find out what some of the biggest offenders with regards to binary size were and found that reqwest and regex could both be trimmed a bit by disabling some features that we don't need.

For regex I switched it to only have the `std` feature enabled. This disables some of the performance features and unicode support but as far as I can tell we don't use the unicode support and the existing regexes are in non-performance-critical sections. This reduces boulder binary size with the `release` profile from `16.9MiB` -> `15.2MiB`.

For reqwest I switched to using `native-tls` over `rustls`. Since this links against the system openssl the binary size is further reduced from `15.2MiB` -> `13.1MiB`.

Final binary sizes when this patch is applied to the experimental Solus package (which already links against system libzstd and sqlite3) are:
- Boulder: 11.8MiB -> 9.2MiB (-22%)
- Moss: 10.7MiB -> 8.1MiB (-24%)
@tarkah
Copy link
Collaborator

tarkah commented Aug 23, 2024

@ReillyBrogan can we remove the rustls change so we can get the regex change in? It's still very material on it's own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants