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

Remove usage of chars() iterator when bytes() can be used for ascii text #57

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

klensy
Copy link

@klensy klensy commented Sep 3, 2021

No description provided.

@klensy klensy marked this pull request as draft September 3, 2021 16:52
@alexcrichton
Copy link
Member

Thanks for the PR! Can you detail a bit more as to the motivation of this change though?

@klensy
Copy link
Author

klensy commented Sep 3, 2021

Purpose was (when i wrote it, before recent updates to rustc_demangle) was reduce size of demangler, because it get inserted in almost every rust binary:

I.e.

fn main() {
    println!("Hello world!");
}
rustc +nightly -Clto  -Cpanic=abort --emit=llvm-ir -Zsymbol-mangling-version=legacy -O main.rs`
cargo llvm-lines -f main.ll

  Lines         Copies      Function name
  -----         ------      -------------
  23541 (100%)  200 (100%)  (TOTAL)
   1153 (4.9%)    1 (0.5%)  rustc_demangle::v0::Printer::print_type
   1056 (4.5%)    1 (0.5%)  rustc_demangle::v0::Printer::print_const
    977 (4.2%)    1 (0.5%)  rustc_demangle::v0::Printer::print_path
    886 (3.8%)    1 (0.5%)  rustc_demangle::try_demangle
    882 (3.7%)    6 (3.0%)  <&T as core::fmt::Display>::fmt
    808 (3.4%)    1 (0.5%)  std::sys_common::backtrace::output_filename

Btw, why v0 demangler used, if symbol-mangling-version=legacy is default and explicitly selected?

@alexcrichton
Copy link
Member

Ah ok, nice! Can you post before/after measurements to see the size impact that this has?

The v0 demangler isn't necessarily used there, it's just compiled in. Runtime detection determines whether the legacy or v0 demangler is used. It so-happens though that most Rust libraries don't use the v0 demangler at this time.

@klensy
Copy link
Author

klensy commented Sep 3, 2021

Ah ok, nice! Can you post before/after measurements to see the size impact that this has?

Ok

used i mean compiled into binary. At compile time we knew what symbol-mangling-version will be used (legacy, in this example), but still this unused pieces inserted into resulting binary, blowing it's minimal size a lot (~ 17% from top 4 fn).

@alexcrichton
Copy link
Member

There's no way really in how libstd is built to have a rustc flag affect what code is compiled in, so both are compiled in. If desired, though, since v0 is so uncommon it could be placed behing a compile-time feature for this crate and turned off in libstd, although I don't think that's a great solution either because then if v0 is used it won't be demangled properly.

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