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

Replace InitializedOnce with OnceLock #1231

Open
wks opened this issue Nov 7, 2024 · 0 comments
Open

Replace InitializedOnce with OnceLock #1231

wks opened this issue Nov 7, 2024 · 0 comments
Labels
A-utils Area: Utilities C-cleanup Category: Cleanup F-good-first-issue Call For Participation: Suitable issues for first-time contributors G-safety Goal: Safety

Comments

@wks
Copy link
Collaborator

wks commented Nov 7, 2024

We introduced std::util::rust_util::InitializeOnce in 21 January 2022 as a faster replacement of lazy_static. Rust 1.70.0 (1 June 2023) introduced std::cell::OnceCell and std::sync::OnceLock into the standard library. OnceLock provides the same functionality as InitializeOnce. Since we already bumped MSRV to 1.71.1 (as in package.rust-version in Cargo.toml), we can switch to the OnceLock in the standard library.

@qinsoon did a microbenchmark in #1142 (comment), showing that the performance difference between InitializeOnce, std::sync::OnceLock and the third-party once_cell crate is negligible. To be safe, we should do a similar microbenchmark with a use pattern of SFTMap (which is currently the sole user of InitializeOnce) and add it to the mmtk-core/benches/regular_bench directory.

Note that std::sync::OnceLock only provides get() and get_mut(), both of which perform a check of whether it is initialized. We should also see if the checking is a bottleneck by comparing initializeOnce::deref(), std::sync::OnceLock.get and once_cell::sync::OnceCell::get_unchecked.

@wks wks added C-cleanup Category: Cleanup G-safety Goal: Safety A-utils Area: Utilities F-good-first-issue Call For Participation: Suitable issues for first-time contributors labels Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-utils Area: Utilities C-cleanup Category: Cleanup F-good-first-issue Call For Participation: Suitable issues for first-time contributors G-safety Goal: Safety
Projects
None yet
Development

No branches or pull requests

1 participant