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?
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.
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'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.
Here is my test:
Cargo.toml
src/main.rs $ cargo build && cargo build --release && du -sh target