DEV Community

Discussion on: Rust's lazy_static! usage benchmarks and code deep dive

Collapse
 
chayimfriedman2 profile image
Chayim Friedman • Edited

Looks nice.

However, don't use lazy_static today. Use once_cell, as it's going to be integrated into std. Also it seems like it's faster?.

It also has wider API, for example, non-thread-safe lazy.

In addition to that, the perf effects of lazy values are really hard to measure. Will it be performant? Probably yes, until the branch prediction will be unable to predict it for too many branches. Will parameters be faster? Maybe, but they may cause pressure on the register allocator which is very hard to benchmark, and tend to only show in real-world programs.

Collapse
 
rimutaka profile image
Max

Thanks Chayim! I updated the post with your comment.