Async-std: use once_cell instead of lazy_static

Created on 29 Oct 2019  Â·  3Comments  Â·  Source: async-rs/async-std

once_cell by @matklad provides a neat way of initializing lazy singletons. There's a related RFC out now to add this to the stdlib.

In anticipation of this, and in order to help test it, it might be nice if we switched our code over to use once_cell from lazy-static.

references

enhancement good first issue

Most helpful comment

Note that once_cell is also slightly faster than lazy_static (due to compiler bug?) for the hot get operation, which might actually matter for hot task switching code?

10:04:54|~/projects/once_cell|pl-tests✓
λ cargo run --release --example bench_vs_lazy_static
   Compiling once_cell v1.2.0 (/home/matklad/projects/once_cell)
    Finished release [optimized] target(s) in 0.39s
     Running `target/release/examples/bench_vs_lazy_static`
once_cell:   486.122531ms (total time of many accesses accesses)
lazy_static: 579.513044ms

All 3 comments

Note that once_cell is also slightly faster than lazy_static (due to compiler bug?) for the hot get operation, which might actually matter for hot task switching code?

10:04:54|~/projects/once_cell|pl-tests✓
λ cargo run --release --example bench_vs_lazy_static
   Compiling once_cell v1.2.0 (/home/matklad/projects/once_cell)
    Finished release [optimized] target(s) in 0.39s
     Running `target/release/examples/bench_vs_lazy_static`
once_cell:   486.122531ms (total time of many accesses accesses)
lazy_static: 579.513044ms

Hello, I'm interested in this. Could I give it a try?

@wusyong Of course :) thank you!

Was this page helpful?
0 / 5 - 0 ratings