Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use once_cell instead of lazy_static #406

Closed
yoshuawuyts opened this issue Oct 29, 2019 · 3 comments · Fixed by #416

Comments

@yoshuawuyts
Copy link
Member

@yoshuawuyts yoshuawuyts commented Oct 29, 2019

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

@matklad

This comment has been minimized.

Copy link
Member

@matklad matklad commented Oct 29, 2019

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
@wusyong

This comment has been minimized.

Copy link
Contributor

@wusyong wusyong commented Oct 30, 2019

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

wusyong added a commit to wusyong/async-std that referenced this issue Oct 30, 2019
`once_cell` provides a neat way of initializing lazy singletons without
macro. This PR use `sync::Lazy` to streamline same pattern proposed in
related rust RFC.

Resolve async-rs#406
wusyong added a commit to wusyong/async-std that referenced this issue Oct 30, 2019
`once_cell` provides a neat way of initializing lazy singletons without
macro. This PR use `sync::Lazy` to streamline same pattern proposed in
related rust RFC.

Resolve async-rs#406
@stjepang

This comment has been minimized.

Copy link
Member

@stjepang stjepang commented Oct 30, 2019

@wusyong Of course :) thank you!

stjepang added a commit that referenced this issue Oct 30, 2019
`once_cell` provides a neat way of initializing lazy singletons without
macro. This PR use `sync::Lazy` to streamline same pattern proposed in
related rust RFC.

Resolve #406
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.