Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> I don't like Rust because it seems overly bloated (the recommended way to parse command-line arguments - "clap" - involves downloading 400 megabytes of dependencies off crates.io, which just seems unreasonable), although the borrow checker is a very interesting idea.

Where do you get that from? https://lib.rs/crates/clap states that the code itself is 1MB, and the maximal amount of dependency code is 7mb, with all optional features enabled.



`du -h` of a project that did nothing but use clap was 380 megabytes or there abouts.

EDIT: A blank "cargo new" project plus a clap dependency weighs 143 megabytes, not 400. Maybe the 400 megabyte project had another dependency as well, I can't remember. I've edited the comment to say 140 instead of 400.

    $ cargo build
        Updating crates.io index
      Downloaded clap v3.2.23
      Downloaded textwrap v0.16.0
      Downloaded proc-macro2 v1.0.47
      Downloaded clap_lex v0.2.4
      Downloaded hashbrown v0.12.3
      Downloaded clap_derive v3.2.18
      Downloaded once_cell v1.16.0
      Downloaded libc v0.2.137
      Downloaded os_str_bytes v6.3.1
      Downloaded unicode-ident v1.0.5
      Downloaded syn v1.0.103
      Downloaded 11 crates (1.4 MB) in 3.71s
       Compiling proc-macro2 v1.0.47
       Compiling version_check v0.9.4
       Compiling unicode-ident v1.0.5
       Compiling quote v1.0.21
       Compiling syn v1.0.103
       Compiling autocfg v1.1.0
       Compiling libc v0.2.137
       Compiling os_str_bytes v6.3.1
       Compiling heck v0.4.0
       Compiling hashbrown v0.12.3
       Compiling textwrap v0.16.0
       Compiling strsim v0.10.0
       Compiling termcolor v1.1.3
       Compiling once_cell v1.16.0
       Compiling bitflags v1.3.2
       Compiling clap_lex v0.2.4
       Compiling proc-macro-error-attr v1.0.4
       Compiling proc-macro-error v1.0.4
       Compiling indexmap v1.9.1
       Compiling atty v0.2.14
       Compiling clap_derive v3.2.18
       Compiling clap v3.2.23
       Compiling clapdemo v0.1.0 (/home/jes/clapdemo)
        Finished dev [unoptimized + debuginfo] target(s) in 36.61s
    $ du -h | tail -n1
    143M


> Finished dev [unoptimized + debuginfo] target(s) in 36.61s

As anyone who is used to languages like C or C++ knows, debuginfo tends to be huge. It's not surprising that your "target" directory (where both the intermediate and final objects are stored) is that big.

> Downloaded 11 crates (1.4 MB) in 3.71s

Here, you see that 11 of your dependencies together (including clap) were a download of only 1.4 megabytes.

And you won't see these 1.4 megabytes in your "du" output, since the downloaded crates are stored in ~/.cargo instead of within your project directory.


> It's not surprising that your "target" directory (where both the intermediate and final objects are stored) is that big.

Actually this is surprising to me. All it does is parse command-line arguments. I am surprised that this creates 143 million bytes of information.

I accept that I was wrong to say this data is "downloaded" off crates.io, since it is in fact created locally.

> 11 of your dependencies together (including clap)

This is obviously a matter of taste, but to me, this is too many. In the event that sensible command line parsing is not part of the core language, it could at least only be a single dependency.


There are several reasons:

1. Unoptimized builds tend to be excessively large. LLVM's opt binary (citing this because it's something I have easy access to) is 30x larger on an unoptimized build than an optimized build. [I think Rust is even worse than C++ at the unoptimized/optimized size ratio]

2. Debugging information is also excessively large. It's not counted in the above statistics I gave because I use split debug information (which keeps it out of the final executable for easier linking), but you're looking at debug information being a significant fraction of code size--maybe half of the total binary size could be debug information.

3. Because you include the build directory, you're carrying two copies of everything, minimum--both the .o files and the executable they link into.

For a rough comparison of LLVM, the llvm source directory I have is 1.5G, the optimized release build I have is 15G (of which 1.7G is the actual binary executables), and the unoptimized debug build I have is 86G. Of course LLVM is unusual in producing a very large number of statically linked executables.

4. One of the dependencies inside clap is the procedural macros stuff (specifically, quote/syn crates), which basically requires building your own copy of the Rust parser. If you drop that dependency, the build directory sizes should be far, far smaller.


Doing it with 'clap = "4.0"' gives me 46MB. Still surprisingly large.


I have:

    clap = { version = "3.2", features = ["derive"] }


  $ du -h | tail -n1
  =>
  $ du -sh




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: