Making a Rust crate compile faster

preview_player
Показать описание
In this stream, we try to figured out why the `cargo` crate takes so long to build. We don't ultimately make a meaningful improvement, but we do explore the many tools that exist to help with both analysis and remediation, and the value (and shortcomings) of each one.

0:00:00 Introduction
0:02:27 Setting up a test project
0:08:25 cargo build --timings
0:16:45 Linking
0:29:30 cargo bloat
0:40:50 -Zshare-generics
0:47:00 cargo-llvm-lines
1:24:56 rustc -Zself-profile
2:04:36 perf record rustc
2:13:10 miniserde
2:16:35 watt
2:25:00 Conclusion
2:25:40 Q&A
2:26:58 Overhead of monomorphization
2:27:51 Rust build time in 2-3 years
2:30:04 Do this again with new tools?
2:30:59 Breaking Cargo into subcrates
2:32:20 Is --release time important?
2:32:56 Automatic inner functions
2:34:46 Rust build time and adoption
2:37:00 Proc macro build time
2:41:25 Feature creep in Rust
2:43:05 Outroduction

Рекомендации по теме
Комментарии
Автор

"ASMR rust compiling video (2 HOURS)"

qwfp
Автор

5:55
- cargo space?
- car no do that, car no fly
(I apologize, couldn't resist)

japedr
Автор

Your videos are showing up in my recommended feed after a week or so of my partner watching your videos daily when winding down for the night, I no longer fall asleep to rain sounds or gentle piano it’s just the sound of Jon Rust’s voice after the end of a long day.

Elemenoful
Автор

Well, my outtakes from this stream boil down to 'mold', thanks for that

simdimdim
Автор

Great info... would be interesting having a mention around improving timings of a CI/CD process - e.g. cargo chef, sscache

nieldrummond
Автор

Nice to see someone other than me spend 3h trying to fix something that's obviously broken, and fail :)

davidboreham
Автор

Learnt new things about 'strip', 'cargo bloat' and 'cargo llvm-lines'.
In general I am more concerned about the binary size instead of the compile time. Would be great if you could do a video on hints how to improving file size.

alexs
Автор

This is going to be very helpful with building Deno on the Raspberry Pi 4. I have a Raspberry Pi 4 (8GB) that runs out of memory and takes an hour to build a single artifact (mostly because it swaps out to the SD card.) Anything I can do to cut down some time on that build will save me and a few other people that are prooping up the arm64 builds.

Dygear
Автор

So borrow checking takes some time... why not start compiling and linking before the borrow checking completes? If the borrow checking fails while compiling and linking then it can abort it. The borrow checking is used to make sure that you are not doing some unsafe stuff but it should not be needed to compile the binary.

tomaspecl
Автор

One thought I had about the perf tools, it might be nice if instead of the per-crate numbers, if you get numbers relative to the salsa-esque compiler internal query evaluation model, which has a much finer grained dependency graph than per-crate. I at least wonder if there is anything in the self-profile like the "args" that could somehow include queries, that either exists, or could be added.

mattrice
Автор

I'm very certain that Jon has taught rust to its developers before it was even there

justaguy
Автор

Another master class; thank you so much!

PrettyGrossMKay
Автор

That was interesting to watch. Thanks Jon!!

rodelias
Автор

Replace the default linker with 'mold really help in my case.
Also check KAS gui. It has feature flag 'dynamic for faster build time.

drsensor
Автор

How do you set up the function parameter completion in Nvim? Mind sharing your vim file?

michaelbcker-larsen
Автор

Turns out the real faster build was the friends we made along the way

OferSadan
Автор

Jon, have you heard yet? It's all over the Rust community. I invented "impl vars" ... me ! little ole me ... crusty ole me.
I was thinking about it more, and it kinda brings about another concept here, which is "mixins". By tying the data to the trait impl, it's really off on it's own in a way even if it contains a portion of the instance variables. Feels like this could be "segregrated out" in a way so that an implemented trait (full with instance variables) that can be "mixed in" to several classes. This is more than just a "default trait" implementation, because as I understand it, those don't allow shared instance data between the default method implementations of the trait. So, this really opens up 2 things - keep each traits data separate from one another, and enable 'mixin' functionality with instance level data (possibly).
I know they won't want to credit me, but ... I'm the one ... It was me... ALL ME... In the words of the famous Mr William Hung, "I have no professional training"

jeffg
Автор

The slow compile time is one of the reasons why i continue to use c++, i have interest in Rust, but for me it is not enough, I'm still waiting for more optimizations in the compiler and better computers to reduce the compilation time.

danielsan
Автор

i was told these abstractions would be zero cost

foobargorch
Автор

For some reason, my previous two comments have been deleted by Youtube. Anyway...
If you want to know for sure that a certain process was executed, you can use the "execsnoop" utility from "bcc-tools" Arch package
sudo -n mold

The biggest impact on build times I've observed is due to sccache by Mozilla: my first build of a project with cargo dependency took 1m 50s, then, after "cargo clean", the next build took only 18s.

bytefu