# Aleksey Kladov - Fast Thread Locals in Rust (Highlights)

## Highlights
- Rust thread-locals are slower than they could be.
- Rust’s thread-local implementation(
[1](https://github.com/rust-lang/rust/blob/6f56fbdc1c58992a9db630f5cd2ba9882d32e84b/library/std/src/thread/local.rs#L156-L188),
[2](https://github.com/rust-lang/rust/blob/6f56fbdc1c58992a9db630f5cd2ba9882d32e84b/library/std/src/thread/local.rs#L445-L459)
) comes with built-in support for laziness — thread locals are initialized on the first access.
- There’s an unstable `#[thread_local]` attribute for a zero-cost implementation
- Rust allows cross-language **L**ink **T**ime **O**ptimization ([docs](https://doc.rust-lang.org/rustc/linker-plugin-lto.html)).
- The C compiler, the Rust compiler and the linker must use the same version of LLVM.
- `-flto=thin` in the C compiler flags.
- |
```
export RUSTFLAGS=\
"-Clinker-plugin-lto -Clinker=clang -Clink-arg=-fuse-ld=lld"
```
|