Skip to content

"hello world" binary size increase in each release #75804

Closed
@tesuji

Description

@tesuji
Contributor

The binary size of "hello world" program increased in each release:
image
image

Detail table
Rust version debug debug - stripped release release - stripped
1.32.0 2382904 199096 2375720 199016
1.40.0 2595400 215464 2588264 215384
1.41.0 2637336 215464 2629832 215384
1.42.0 2659672 211368 2652488 211288
1.43.0 2729192 223584 2722128 223504
1.44.0 2584120 248160 2579144 248080
1.45.0 2847440 244064 2842464 243984
beta 2848152 244064 2843168 243984
nightly 3210208 293200 3203712 293112
main.rs
fn main() {
    println!("hello world");
}
Script to reproduce
rustup set profile minimal
rustup toolchain install 1.{40..45}.0 beta nightly

RUST_DBG_FLAGS='-C debuginfo=1 -C panic=abort -C opt-level=0'
RUST_REL_FLAGS='-C debuginfo=0 -C panic=abort -C opt-level=3'

mkdir -p build/debug
mkdir -p build/release
for ver in 1.{40..45}.0 beta nightly; do
    bin_dbg=build/debug/main-$ver
    bin_rel=build/release/main-$ver
    rustc +$ver $RUST_DBG_FLAGS main.rs -o $bin_dbg
    echo "-- $ver"
    before=$(stat --printf="%s" $bin_dbg)
    strip $bin_dbg
    after=$(stat --printf="%s" $bin_dbg)
    printf "    dbg: %d, stripped: %d\n" $before $after

    rustc +$ver $RUST_REL_FLAGS main.rs -o $bin_rel
    before=$(stat --printf="%s" $bin_rel)
    strip $bin_rel
    after=$(stat --printf="%s" $bin_rel)
    printf "    release: %d, stripped: %d\n" $before $after
done

# rustup toolchain uninstall 1.{40..45}.0 beta nightly

Meta

beta:

rustc 1.46.0-beta.5 (cfbc6d4cf 2020-08-21)
binary: rustc
commit-hash: cfbc6d4cf1acbac5c025acf8ed68929caa551df3
commit-date: 2020-08-21
host: x86_64-unknown-linux-gnu
release: 1.46.0-beta.5
LLVM version: 10.0

nightly:

rustc 1.47.0-nightly (de521cbb3 2020-08-21)
binary: rustc
commit-hash: de521cbb303c08febd9fa3755caccd4f3e491ea3
commit-date: 2020-08-21
host: x86_64-unknown-linux-gnu
release: 1.47.0-nightly
LLVM version: 10.0

Activity

added
I-heavyIssue: Problems and improvements with respect to binary size of generated code.
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Aug 22, 2020
added
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Aug 22, 2020
spastorino

spastorino commented on Aug 27, 2020

@spastorino
Member

Assigning P-medium as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

Would be nice to see where (if it's just one PR) this has regressed ...

@rustbot ping cleanup

And also if this affects more complex programs too.

For now considering it as P-medium but feel free to re-assign a different priority or comment on the issue explaining why should we prioritize it higher.

rustbot

rustbot commented on Aug 27, 2020

@rustbot
Collaborator

Hey Cleanup Crew ICE-breakers! This bug has been identified as a good
"Cleanup ICE-breaking candidate". In case it's useful, here are some
instructions for tackling these sorts of bugs. Maybe take a look?
Thanks! <3

cc @AminArria @camelid @chrissimpkins @contrun @DutchGhost @elshize @ethanboxx @h-michael @HallerPatrick @hdhoang @hellow554 @imtsuki @kanru @KarlK90 @LeSeulArtichaut @MAdrianMattocks @matheus-consoli @mental32 @nmccarty @Noah-Kennedy @pard68 @PeytonT @pierreN @Redblueflame @RobbieClarken @RobertoSnap @robjtede @SarthakSingh31 @senden9 @shekohex @sinato @spastorino @turboladen @woshilapin @yerke

added and removed
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Aug 27, 2020
tesuji

tesuji commented on Aug 27, 2020

@tesuji
ContributorAuthor

I think a high regression in nightly is from #74682 . Not that I think we should revert it, but it is worth investigating
to improve the situation somehow.

eddyp

eddyp commented on Feb 15, 2021

@eddyp
Contributor

I just saw this on Windows (x86_64-pc-windows-msvc) in one of my applications on the upgrade from 1.49 to 1.50 and explored if this issue is known and reported.

c:\>rustup toolchain list
stable-x86_64-pc-windows-msvc (default)
beta-x86_64-pc-windows-msvc
nightly-x86_64-pc-windows-msvc
1.45-x86_64-pc-windows-msvc
1.46-x86_64-pc-windows-msvc
1.47-x86_64-pc-windows-msvc
1.48-x86_64-pc-windows-msvc
1.49-x86_64-pc-windows-msvc
1.50-x86_64-pc-windows-msvc

I just did a adaptation of the script to run on windows using cygwin (not using WSL as that would pick up Linux's version and I'm interested in Windows for this particular app).

I installed all versions since 1.45 (I didn't force the usage of 1.x.0), cygwin's strip has no effect on the binaries, so kept only one column.

I got these results:

image

  debug release
1.45 152.064 149.504
1.46 151.040 148.992
1.47 151.040 148.480
1.48 151.040 147.968
1.49 152.064 148.992
1.50 153.088 150.016
beta 146.944 144.384
nightly 146.944 144.384
hellow554

hellow554 commented on Feb 15, 2021

@hellow554
Contributor

Can anybody explain why there is a huge drop in current beta? 😊

eddyp

eddyp commented on Feb 15, 2021

@eddyp
Contributor

Also similar results on my application (on x86_64-pc-windows-msvc) which is a parser using pest:

image

Sizes are as follow:

  debug release
1.45 614.400 175.104
1.46 608.256 175.104
1.47 605.696 175.616
1.48 604.672 168.960
1.49 576.000 170.496
1.50 573.440 173.056
beta 574.464 170.496
nightly 577.024 171.008

The Cargo.lock I have has some slightly older versions pinned but I don't think it shouldn't matter as clearly the compiler affects the size. For reference here are the crates my app depends on:

Compiling proc-macro2 v1.0.24
Compiling unicode-xid v0.2.1
Compiling ucd-trie v0.1.3
Compiling syn v1.0.60
Compiling maplit v1.0.2
Compiling unindent v0.1.7
Compiling pest v2.1.3
Compiling indoc v1.0.3
Compiling quote v1.0.9
Compiling pest_meta v2.1.3
Compiling pest_generator v2.1.3
Compiling pest_derive v2.1.0

L.E.: if older versions of the crates below, only the nightly debug is 576.512 instead of 577.024, but the others are exactly the same:

 Updating byteorder v1.3.4 -> v1.4.2
 Updating quote v1.0.8 -> v1.0.9
 Updating syn v1.0.58 -> v1.0.60
tesuji

tesuji commented on Apr 28, 2024

@tesuji
ContributorAuthor

Closed as this seems to be taken care by https://perf.rust-lang.org/index.html.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-heavyIssue: Problems and improvements with respect to binary size of generated code.ICEBreaker-Cleanup-CrewHelping to "clean up" bugs with minimal examples and bisectionsP-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @spastorino@eddyp@hellow554@Mark-Simulacrum@tesuji

        Issue actions

          "hello world" binary size increase in each release · Issue #75804 · rust-lang/rust