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

Switch from lazy_static to once_cell #1165

Closed
jplatte opened this issue Dec 30, 2020 · 5 comments
Closed

Switch from lazy_static to once_cell #1165

jplatte opened this issue Dec 30, 2020 · 5 comments
Labels
kind/feature New feature or request

Comments

@jplatte
Copy link
Member

jplatte commented Dec 30, 2020

It would be nice if tracing could switch from lazy_static to once_cell like tokio did. I don't think there are any downsides, and it reduces the number of dependencies for crates that depend on both tracing and tokio (for example through hyper).

Crates

  • tracing-core

Motivation

Fewer dependencies, less work to later switch to std's Lazy type if / when it is stabilized.

Proposal

Replace usage of lazy_static! with once_cell::sync::Lazy.

Alternatives

Do nothing. That would mean lots of applications have two crates that do the same thing in their dependency tree (though they're not big, so it's not that bad).

@taiki-e
Copy link
Member

taiki-e commented Dec 30, 2020

This also allows removing some vendored code (#424).

EDIT: #1165 (comment)

@hawkw
Copy link
Member

hawkw commented Dec 30, 2020

I'm fine with this. I've been conservative about switching away from lazy_static due to stability, but it seems once_cell has been 1.0 for a while.

This also allows removing some vendored code (#424).

I don't think this is correct, though. The vendored code is the no_std version of lazy_static using a spinlock. We're vendoring it because it's not possible to conditionally enable a feature flag of a dependency when tracing's "std" feature is disabled, only to disable feature flags. once_cell, AFAICT, has no no_std support whatsoever. Therefore, we would still need our own Once implementation on no-std.

@hawkw hawkw added the kind/feature New feature or request label Dec 30, 2020
@jplatte
Copy link
Member Author

jplatte commented Dec 30, 2020

Yeah, it doesn't (yet): matklad/once_cell#61

@taiki-e
Copy link
Member

taiki-e commented Dec 30, 2020

I don't think this is correct, though. The vendored code is the no_std version of lazy_static using a spinlock. We're vendoring it because it's not possible to conditionally enable a feature flag of a dependency when tracing's "std" feature is disabled, only to disable feature flags. once_cell, AFAICT, has no no_std support whatsoever. Therefore, we would still need our own Once implementation on no-std.

Oh, you are right. I missed no-std support is only unsync module.

@jplatte
Copy link
Member Author

jplatte commented Jun 29, 2023

Done in #2147.

@jplatte jplatte closed this as completed Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants