Hacker News new | past | comments | ask | show | jobs | submit login

Please show your work. I cannot reproduce "3gb of dependencies".

Here is my test:

Cargo.toml

   [package]
   name = "serde-test"
   version = "0.1.0"
   edition = "2021"
   
   [dependencies]
   serde = { version = "1.0.208", features = ["derive"] }
   serde_json = "1.0.127"
src/main.rs

    use serde::Deserialize;
    
    #[derive(Deserialize)]
    struct Foo {
        bar: String,
    }
    
    fn main() {
        let foo: Foo = serde_json::from_str("\"bar\": \"baz\"").unwrap();
    
        println!("{}", foo.bar);
    }
$ cargo build && cargo build --release && du -sh target

    ...

    78M target



I arrive at almost the same result as you, with 76MB.

I've also checked .cargo, .rustup, and my various cache folders (just in case) and haven't found any additional disk usage.

OP is clearly mistaken.


The first thing that jumps out is that the code example doesn't work.

The next thing is that the example merely calls cargo build. Using an IDE of any sort will typically invoke rust-analyzer which will bloat the target directory quite a bit. I've also found that stale build artifacts tend to chew up a lot of space (especially if you're trying to measure the typically smaller release builds).

Beyond that, none of the serde features that will tend to generate a ton of code are being used.

So yeah a minimal example won't use a lot of space but if you start to use the bells and whistles serde brings you will definitely bloat your target directory. I expect a typical rust project to take around 3–4 gigs for build artifacts depending.


> The first thing that jumps out is that the code example doesn't work.

Good catch. I forgot the braces. It does not change the target directory size in a significant way.

As for your other comments: sure! We can have a real conversation about rust-analyzer and other serde features (though I am not sure which specific features you are referring to) causing the target directory to increase drastically in size. However, a sensationalist comment that claims the _dependencies_ are 3gb appears to be misleading at best.


> So yeah a minimal example won't use a lot of space but if you start to use the bells and whistles serde brings you will definitely bloat your target directory.

Which seems orthogonal to the number of dependencies?


Jesus, 78MB is still a lot for such a simple program.


That’s not the size of the program but the size of the build artifacts folder that includes all the intermediate files like .o in a C project and more.


That still seems like a lot of build artifacts for a 10 line program?


It deserializes a unicode string to a custom structure. Do not mistake it with C character-shuffling hello-world-programs.

Edit: s/to JSON/to a custom structure/


I’m on mobile so I can’t check at the moment. But I’d be shocked if the equivalent go binary was anywhere near as big, or took anywhere near as long to build.

I’ll check later


I don't know what you consider big and long, but on my computer (Ryzen 5700X) it took 7 seconds to build, and the resulting binary is 556 kB.


I'm on an M1 mac, and I followed the instructions above (cargo build --release && du -sh target) and it took 6 seconds, and the target dir is 35MB. I ran it twice to make sure I wasn't pulling the remote dependencies

go.mod

    module json-test

    go 1.21.1
main.go package main

    import (
        "encoding/json"
        "fmt"
    )

    type Foo struct {
        Bar string `json:"bar"`
    }

    func main() {
        var foo Foo

        json.Unmarshal([]byte(`{"bar": "Hello, World!"}`), &foo)

        fmt.Println(foo.Bar)
    }

time go build && du -sh .

    go build  0.07s user 0.11s system 348% cpu 0.051 total
    2.4M .
I'd say 15x larger and 12x slower "bigger and longer" at least.


A 10 line program with two dependencies and all their transitive dependencies.




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

Search: