mirror of
https://github.com/Noratrieb/website.git
synced 2026-01-14 17:05:02 +01:00
parent
14053a50b9
commit
a54248f099
1 changed files with 45 additions and 20 deletions
|
|
@ -123,7 +123,7 @@
|
||||||
</section>
|
</section>
|
||||||
<section data-markdown>
|
<section data-markdown>
|
||||||
<textarea data-template>
|
<textarea data-template>
|
||||||
## and thne you're done
|
## and then you're done
|
||||||
|
|
||||||
```
|
```
|
||||||
<add>:
|
<add>:
|
||||||
|
|
@ -277,7 +277,8 @@ fn main() { math::add() }
|
||||||
<textarea data-template>
|
<textarea data-template>
|
||||||
# so compile times just depend on the amount of functions?
|
# so compile times just depend on the amount of functions?
|
||||||
|
|
||||||
- no!
|
- yes...
|
||||||
|
- but not source functions!
|
||||||
</textarea>
|
</textarea>
|
||||||
</section>
|
</section>
|
||||||
<section data-markdown>
|
<section data-markdown>
|
||||||
|
|
@ -371,16 +372,16 @@ fn main() { math::add() }
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section data-markdown>
|
||||||
<textarea data-markdown>
|
<textarea data-template>
|
||||||
# generics are slow to compile
|
# generics are slow to compile
|
||||||
|
|
||||||
- spend N times optimizing the function
|
- spend N times optimizing the function
|
||||||
- and there's duplicate instances!
|
- and there's duplicate instances!
|
||||||
</textarea>
|
</textarea>
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section data-markdown>
|
||||||
<textarea data-markdown>
|
<textarea data-template>
|
||||||
# and the duplicates get worse
|
# and the duplicates get worse
|
||||||
</textarea>
|
</textarea>
|
||||||
</section>
|
</section>
|
||||||
|
|
@ -500,16 +501,28 @@ fn main() { math::add() }
|
||||||
<section data-markdown>
|
<section data-markdown>
|
||||||
<textarea data-template>
|
<textarea data-template>
|
||||||
## `#[inline]` (⚙️)
|
## `#[inline]` (⚙️)
|
||||||
- `#[inline]` enables cross-crate inlining of non-generic functions
|
- for non-generic functions
|
||||||
- for very small functions, this happens automatically
|
- for very small functions, this happens automatically
|
||||||
- for other functions, it doesn't, because it would be slow (try with `-Zcross-crate-inline-threshold=always`)
|
- for other functions, it doesn't, because it would be slow
|
||||||
- don't over-apply it in a library, but also don't forget about it
|
- don't over-apply it in a library, but also don't forget about it
|
||||||
- benchmark!
|
- benchmark!
|
||||||
</textarea>
|
</textarea>
|
||||||
</section>
|
</section>
|
||||||
<section data-markdown>
|
<section data-markdown>
|
||||||
<textarea data-template>
|
<textarea data-template>
|
||||||
## what if I want to be able to inline everything across crates?
|
## being lazy has advantages
|
||||||
|
|
||||||
|
- that's why i wrote most of this talk last week
|
||||||
|
- `#[inline]` means that the function is *never* instantiated if it's never used!
|
||||||
|
|
||||||
|
https://blog.rust-lang.org/inside-rust/2025/07/15/call-for-testing-hint-mostly-unused/
|
||||||
|
</textarea>
|
||||||
|
</section>
|
||||||
|
<section data-markdown>
|
||||||
|
<textarea data-template>
|
||||||
|
## but performance is great, i love performance
|
||||||
|
|
||||||
|
- its ok i can wait forever
|
||||||
</textarea>
|
</textarea>
|
||||||
</section>
|
</section>
|
||||||
<section data-markdown>
|
<section data-markdown>
|
||||||
|
|
@ -612,28 +625,40 @@ fn main() { math::add() }
|
||||||
</section>
|
</section>
|
||||||
<section data-markdown>
|
<section data-markdown>
|
||||||
<textarea data-template>
|
<textarea data-template>
|
||||||
## inlining across codegen units in the same crate
|
## there was some LTO all along
|
||||||
|
|
||||||
- ThinLTO across different codegen units by default
|
- in release mode, automatic ThinLTO across codegen units in the same crate
|
||||||
</textarea>
|
</textarea>
|
||||||
</section>
|
</section>
|
||||||
<section data-markdown>
|
<section data-markdown>
|
||||||
<textarea data-template>
|
<textarea data-template>
|
||||||
## all of this sucks
|
## how do i make my program run quickly?
|
||||||
|
|
||||||
- wasted duplicate work
|
- let the compiler inline functions
|
||||||
- missing optimizations without LTO
|
- libraries: remember `#[inline]`
|
||||||
|
- binaries: you want LTO
|
||||||
|
- really, it really needs to inline your functions
|
||||||
|
- without it, it's so over
|
||||||
|
- and read this: https://nnethercote.github.io/perf-book
|
||||||
</textarea>
|
</textarea>
|
||||||
</section>
|
</section>
|
||||||
<section data-markdown>
|
<section data-markdown>
|
||||||
<textarea data-template>
|
<textarea data-template>
|
||||||
## `Cargo.toml` config
|
## how do i make my program compile quickly?
|
||||||
|
|
||||||
```toml
|
- reduce the amount and size of functions
|
||||||
[profile.release]
|
- importantly: in LLVM IR, not necessarily source!
|
||||||
lto = "thin"
|
- duplicate and frequent instantiations are bad
|
||||||
codegen-units = 1
|
- and read this:
|
||||||
```
|
- https://corrode.dev/blog/tips-for-faster-rust-compile-times
|
||||||
|
- https://doc.rust-lang.org/nightly/cargo/guide/build-performance.html
|
||||||
|
</textarea>
|
||||||
|
</section>
|
||||||
|
<section data-markdown>
|
||||||
|
<textarea data-template>
|
||||||
|
## and both? 🥺👉👈
|
||||||
|
|
||||||
|
- no
|
||||||
</textarea>
|
</textarea>
|
||||||
</section>
|
</section>
|
||||||
<section data-markdown>
|
<section data-markdown>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue