Skip to content

Binary size reduction after overriding default allocator to system allocator (nightly) #55910

@osa1

Description

@osa1

Tried with rustc 1.32.0-nightly (65204a9 2018-11-12).

To reproduce:

  • Clone https://github.com/osa1/tiny
  • cargo build --release && ls -lha target/release/tiny. You'll see a 2.4M binary.
  • Apply this diff
      diff --git a/src/lib.rs b/src/lib.rs
      index 8a41e51..9cae724 100644
      --- a/src/lib.rs
      +++ b/src/lib.rs
      @@ -5,9 +5,6 @@
       #![feature(nll)]
       #![feature(ptr_offset_from)]
    
      -#[global_allocator]
      -static ALLOC: std::alloc::System = std::alloc::System;
      -
       #[cfg(test)]
       extern crate quickcheck;
    
  • Repeat the same command. The binary size is now 2.5M.

Originally reported on /r/rust thread.

The reason why I think this is a bug is because the default allocator should already be the system allocator, so overriding the allocator to system allocator should have no effect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions