Giter VIP home page Giter VIP logo

Comments (14)

RazrFalcon avatar RazrFalcon commented on July 3, 2024

Is there a way to run cargo bloat on crates that are just libraries?

No, because executables and libraries are very different. Especially static libraries, which is the default.

Examples support is a good idea, but note that cargo-bloat will show only stuff that is used by example, so you have to use as many features of your library as possible.

from cargo-bloat.

sunjay avatar sunjay commented on July 3, 2024

Examples support is a good idea, but note that cargo-bloat will show only stuff that is used by example, so you have to use as many features of your library as possible.

That would be fine. I think having that much support would still be extremely helpful. :)

from cargo-bloat.

CryZe avatar CryZe commented on July 3, 2024

I'm compiling my code to a static & dynamic library, so extending it to work on those cases would be really cool too.

from cargo-bloat.

RazrFalcon avatar RazrFalcon commented on July 3, 2024

@CryZe it's not possible due to the way executables and libraries are work. You can measure only executables.

from cargo-bloat.

CryZe avatar CryZe commented on July 3, 2024

Can you elaborate why?

from cargo-bloat.

RazrFalcon avatar RazrFalcon commented on July 3, 2024

I'm not that good in this, but the basics look like this:

  • The static library is just a pile of code (in c/c++/rust it's an actual archive file with objects and some metadata). No optimizations are made afaik.
  • The dynamic library is something in between. It support optimization, but not LTO afaik.
  • The executable file format usually has the .text section in which the compiled code contains. And all this tool doing is measuring so-called symbols size. You can call them functions or methods. But Rust (and C++) has two other problems:
    • Generics (hello Go). The library can define generics, but not use them by itself, so they will be instanced only in the executable, so you can't measure them in the library.
    • Inlining. Rust supports inlining which eliminates some functions completely. But there is no inlining in the static libraries (afaik) and only to some extend in dynamic library, so the results will be different.

from cargo-bloat.

RazrFalcon avatar RazrFalcon commented on July 3, 2024

Done.

from cargo-bloat.

sunjay avatar sunjay commented on July 3, 2024

Thank you! :)

from cargo-bloat.

kupiakos avatar kupiakos commented on July 3, 2024

Any chance we can reconsider this for staticlib? Bloaty supports them, so it's definitely possible in theory.

from cargo-bloat.

RazrFalcon avatar RazrFalcon commented on July 3, 2024

There is nothing interesting in staticlib and it doesn't affect the final binary in any way.
Remember, that staticlib is just an archive of an intermediate compiler output. It still has to be compiled.

from cargo-bloat.

kupiakos avatar kupiakos commented on July 3, 2024

There is interesting info in a staticlib, especially for embedded use cases that don't load in a traditional manner. A staticlib is a collection of .o files - it is compiled, just not linked yet. It's not an rlib. While the output is imperfect (no LTO, for example), it's still useful data.
Bloaty supports analyzing a .a/static lib because it can still provide useful information. You are incorrect about there being nothing interesting.

from cargo-bloat.

RazrFalcon avatar RazrFalcon commented on July 3, 2024

I will rephrase: it's not interested for cargo-bloat use case. cargo-bloat analyzes final binaries. That's it.

from cargo-bloat.

kupiakos avatar kupiakos commented on July 3, 2024

Why? I was planning on implementing this support, and would really rather not maintain a project fork for a feature that I believe should be there in the first place. Right now we have to settle with Bloaty, which doesn't yet have Rust name demangling.

from cargo-bloat.

RazrFalcon avatar RazrFalcon commented on July 3, 2024

Because cargo-bloat prints .text section output. Can we get anything like this from static lib? I don't think so.
Can you show bloaty output?

from cargo-bloat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.