rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

use std::lazy::SyncLazy instead of lazy_static

Open light4 opened this issue 3 years ago • 5 comments

Can we use the nightly feature once_cell?

light4 avatar Mar 03 '22 04:03 light4

Thanks for your first PR!

Can we use the nightly feature once_cell?

Speaking for myself, I don't see why we couldn't use it. I'm personally not too familiar with the once_cell feature. It would be great if you could elaborate on the advantages to using this over lazy_static!. Is the idea just to replace a 3rd party dependency?

ytmimi avatar Mar 03 '22 14:03 ytmimi

  1. Remove a 3rd party dependency
  2. Macro free
  3. When the feature is stabled, we can just switch over it
  4. Performance improvement according to this https://github.com/async-rs/async-std/issues/406

This is the once_cell tracing issue: https://github.com/rust-lang/rust/issues/74465

light4 avatar Mar 03 '22 14:03 light4

That all sounds awesome! Thanks for including those links. I'll be sure to give them a read 😄

ytmimi avatar Mar 03 '22 16:03 ytmimi

Thanks for the PR!

We've historically stayed away from any gated features (obviously excluding rustc_private which we need for consuming compiler internals). However, while I'm not sure I'm ready to take the plunge into using unstable features I also think we're kidding ourselves if we continue that refrain based on hopes of being able to build with a stable compiler some day.

That being said, I'm still on the fence about this one as I don't think it buys us all that much just yet, given that lazy_static is still in our build graph due to various transitive dependencies and we'd technically be pulling in once_cell too.

I concur that this is the right move strategically, but not quite convinced yet that it's all that beneficial today. Will leave it parked for a bit in case I change my mind.

calebcartwright avatar Mar 16 '22 02:03 calebcartwright

This one is still on hold, but I wanted to mention that the latest tracking issue for this is https://github.com/rust-lang/rust/issues/109736.

ytmimi avatar Feb 17 '24 17:02 ytmimi

lazy_static was removed in #6154

ytmimi avatar Aug 14 '24 14:08 ytmimi