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

Reduce binary size. #3

Closed
Tim-Nosco opened this issue Aug 12, 2022 · 4 comments · Fixed by #6
Closed

Reduce binary size. #3

Tim-Nosco opened this issue Aug 12, 2022 · 4 comments · Fixed by #6

Comments

@Tim-Nosco
Copy link
Owner

Tim-Nosco commented Aug 12, 2022

cargo bloat --bin tshr --target mipsel-unknown-linux-musl --profile prof output

 File  .text     Size           Crate Name
 1.2%   5.4%  28.2KiB       [Unknown] main
 1.2%   5.4%  28.2KiB             std addr2line::ResDwarf<R>::parse
 1.1%   4.8%  24.9KiB       [Unknown] _ZN9libunwind10CFI_ParserINS_17LocalAddressSpaceEE20parseFDEInstructionsERS1_RKNS2_8FDE_InfoERKNS2_8CIE_InfoEjiPNS2_10PrologInfoE
 1.0%   4.5%  23.1KiB             std std::backtrace_rs::symbolize::gimli::resolve::{{closure}}
 0.6%   2.7%  14.1KiB             std addr2line::ResUnit<R>::parse_lines
 0.4%   1.9%   9.8KiB             std miniz_oxide::inflate::core::decompress
 0.3%   1.5%   7.9KiB             std gimli::read::unit::parse_attribute
 0.3%   1.5%   7.7KiB       [Unknown] printf_core
 0.3%   1.4%   7.3KiB            p256 p256::arithmetic::scalar::Scalar::mul
 0.2%   1.1%   5.6KiB            sha2 sha2::sha256::compress256
 0.2%   1.0%   5.4KiB             std gimli::read::rnglists::RngListIter<R>::next
 0.2%   0.9%   4.8KiB             std core::slice::sort::recurse
 0.2%   0.9%   4.7KiB       [Unknown] _ZN9libunwind14EHHeaderParserINS_17LocalAddressSpaceEE7findFDEERS1_jjjPNS_10CFI_ParserIS1_E8FDE_InfoEPNS5_8CIE_InfoE
 0.2%   0.9%   4.5KiB elliptic_curve? <elliptic_curve::public_key::PublicKey<C> as alloc::string::ToString>::to_string
 0.2%   0.9%   4.4KiB            p256 p256::arithmetic::field::FieldElement::mul
 0.2%   0.8%   4.3KiB       [Unknown] _ZN9libunwind17DwarfInstructionsINS_17LocalAddressSpaceENS_18Registers_mips_o32EE18evaluateExpressionEjRS1_RKS2_j
 0.2%   0.8%   4.3KiB       rand_core <rand_core::block::BlockRng<R> as rand_core::RngCore>::fill_bytes
 0.2%   0.8%   4.2KiB             std <&T as core::fmt::Display>::fmt
 0.2%   0.8%   4.2KiB             std addr2line::function::Function<R>::parse_children
 0.2%   0.7%   3.8KiB             std gimli::read::line::parse_attribute
13.7%  61.1% 316.2KiB                 And 997 smaller methods. Use -n N to show more.
22.4% 100.0% 517.9KiB                 .text section size, the file size is 2.3MiB
```'

Potentially removing `addr2line` can reduce space.
@Tim-Nosco Tim-Nosco changed the title Remove addr_to_line Reduce binary size. Aug 12, 2022
@Tim-Nosco
Copy link
Owner Author

Tim-Nosco commented Aug 13, 2022

Maybe use conditional code to remove debugging strings/prints/formats. Potentially condition on cfg(debug_assert)
Find occurrences of format! and rework.

@Tim-Nosco
Copy link
Owner Author

Tim-Nosco commented Aug 14, 2022

Turns out, the build was not working as expected:

diff --git a/.cargo/config b/.cargo/config
index 5f1300e..6610cd3 100644
--- a/.cargo/config
+++ b/.cargo/config
@@ -5,6 +5,6 @@ linker = "mipsel-buildroot-linux-uclibc-gcc"
 linker = "mipsel-linux-musl-cross/bin/mipsel-linux-musl-gcc"
 rustflags = ["-Ctarget-feature=+crt-static"]

-[target.mipsel-unknown-linux-musl.unstable]
-build-std = "std,core,alloc,panic_abort"
-build-std-features = "panic_immediate_abort"
+[unstable]
+build-std = ["std","core","alloc","panic_abort"]
+build-std-features = ["panic_immediate_abort"]

These two versions do not perform the same way.

@Tim-Nosco
Copy link
Owner Author

./scripts/bloat.sh
    Finished bloat [optimized] target(s) in 0.04s
    Analyzing target/mipsel-unknown-linux-musl/bloat/tshr

 File  .text     Size           Crate Name
 6.8%  14.6%  26.4KiB       [Unknown] main
 1.9%   4.1%   7.3KiB            p256 p256::arithmetic::scalar::Scalar::mul
 1.6%   3.4%   6.2KiB            sha2 sha2::sha256::compress256
 1.1%   2.5%   4.4KiB            p256 p256::arithmetic::field::FieldElement::mul
 1.1%   2.3%   4.2KiB elliptic_curve? <elliptic_curve::public_key::PublicKey<C> as alloc::string::ToString>::to_string
 1.0%   2.2%   4.0KiB       rand_core <rand_core::block::BlockRng<R> as rand_core::RngCore>::fill_bytes
 0.7%   1.5%   2.7KiB             aes aes::soft::fixslice::aes256_encrypt
 0.6%   1.4%   2.4KiB  universal_hash universal_hash::UniversalHash::update
 0.6%   1.3%   2.4KiB     pem_rfc7468 base64ct::decoder::Decoder<E>::perform_decode
 0.5%   1.1%   2.1KiB            p256 p256::arithmetic::projective::ProjectivePoint::add
 0.5%   1.1%   1.9KiB       [Unknown] malloc
 0.4%   1.0%   1.7KiB            core <str as core::fmt::Debug>::fmt
 0.4%   0.9%   1.6KiB       [Unknown] __bin_chunk
 0.4%   0.9%   1.6KiB   crypto_common crypto_common::KeyInit::new_from_slice
 0.4%   0.8%   1.5KiB             std <std::io::error::ErrorKind as core::fmt::Debug>::fmt
 0.4%   0.8%   1.5KiB            p256 p256::arithmetic::projective::ProjectivePoint::double
 0.4%   0.8%   1.4KiB     pem_rfc7468 <T as base64ct::encoding::Encoding>::decode
 0.3%   0.7%   1.2KiB            p256 p256::arithmetic::field::FieldElement::montgomery_reduce
 0.3%   0.7%   1.2KiB     pem_rfc7468 <T as base64ct::encoding::Encoding>::encode
 0.3%   0.7%   1.2KiB       [Unknown] memcpy
26.5%  57.4% 103.7KiB                 And 568 smaller methods. Use -n N to show more.
46.2% 100.0% 180.7KiB                 .text section size, the file size is 391.3KiB

@Tim-Nosco Tim-Nosco linked a pull request Aug 14, 2022 that will close this issue
@Tim-Nosco
Copy link
Owner Author

rust-lang/cargo#8733

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 a pull request may close this issue.

1 participant