Closed
Description
What it does
Tells you to use const thread_locals because they offer many more performance opportunities due to not having to check for re-initialization on every call.
See this godbolt for the potential performance impact: https://godbolt.org/z/rnPsb6Y7v
Advantage
Performance
Drawbacks
None I think? Honestly I don't understand why this is even a feature, i.e. why the compiler can't do this automatically.
Example
thread_local! {
static BUF: RefCell<String> = RefCell::new(String::new());
}
Could be written as:
thread_local! {
static BUF: RefCell<String> = const { RefCell::new(String::new()) };
}