Skip to content

Add optimize(size) to some particularly large functions #705

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

Merged
merged 2 commits into from
May 7, 2025

Conversation

clubby789
Copy link
Contributor

When built as part of libstd, this saves a few kb in hello world binaries.

The comments are formatted like they are so that if this feature is stabilized they can be identified and used unconditionally.

@clubby789
Copy link
Contributor Author

Hm. Is there a way to check that we're actually built as part of libstd, without enabling for as-if-std 🤔

@workingjubilee
Copy link
Member

I mean, I think that's kind of the point, no?

@workingjubilee
Copy link
Member

workingjubilee commented Apr 28, 2025

It does seem more than slightly annoying though that we aren't really testing building this in std under actually-as-if-std conditions (e.g. nightly features), to be clear.

@clubby789 clubby789 force-pushed the opt-size branch 7 times, most recently from 081b94e to a748d77 Compare April 28, 2025 21:33
@clubby789
Copy link
Contributor Author

Changed the as-if-std jobs to only run when using a nightly toolchain. The binary size job failure seems unrelated

@workingjubilee
Copy link
Member

It is indeed. I am of half a mind to give that CI job the knife, but it certainly won't block this. It is supposed to help answering questions like "is this exact kind of PR an improvement?" but I can manually validate things.

Small questions first before I go looking: Did you evaluate these functions for size based on their source size or the actual compiled code size? Did the reduction happen only in those functions or was the entire compiled libstd smaller? I'm mostly wondering to make sure we didn't just hit some weird inlining thresholds or anti-thresholds.

@workingjubilee
Copy link
Member

workingjubilee commented Apr 28, 2025

I'm mostly wondering to make sure we didn't just hit some weird inlining thresholds or anti-thresholds.

I think those "anti-thresholds" are called "limits", Jubilee.

@clubby789
Copy link
Contributor Author

I identified these functions with cargo bloat iirc, then recompiled stage1 rustc with these changes, then a hello world binary with that compiler, and compared the size of those binaries

@workingjubilee
Copy link
Member

Neat!

Copy link
Member

@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reproduces!

@workingjubilee workingjubilee merged commit 6c882eb into rust-lang:master May 7, 2025
40 of 41 checks passed
@clubby789
Copy link
Contributor Author

rust-lang/rust#140735 (comment) (includes backtrace update with these changes)
Some small but nice binary size wins 🙂

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.

2 participants