Skip to content

Conversation

hinto-janai
Copy link
Contributor

@hinto-janai hinto-janai commented Aug 9, 2024

What

Closes #236.

This replaces the OnceLock + fns that were used in a LazyLock type of way for the entire codebase. There's other OnceLocks remaining but they are used differently.

@github-actions github-actions bot added A-test-utils Area: Related to test-utils. A-consensus Area: Related to consensus. A-storage Area: Related to storage. A-helper Area: Related to cuprate-helper. labels Aug 9, 2024
@hinto-janai hinto-janai marked this pull request as ready for review August 9, 2024 21:42
@hinto-janai hinto-janai requested a review from Boog900 August 9, 2024 21:42
DECOMPOSED_AMOUNTS.get_or_init(|| {
[
/// Decomposed amount table.
pub static DECOMPOSED_AMOUNTS: LazyLock<[u64; 172]> = LazyLock::new(|| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the LazyLock here, keep it a static though. I don't know why I made this a OnceLock, the data is still in the binary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must say I'm confused on why this isn't a const

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static is a ref to 1 memory address containing the data, const inlines the data everywhere it gets used.

I assume @Boog900 doesn't want it inlined in the binary everywhere it gets used.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was confused, I thought const weren't inlined. Thanks for the heads-up

@hinto-janai hinto-janai requested a review from Boog900 August 20, 2024 20:45
@Boog900 Boog900 merged commit aeb070a into Cuprate:main Aug 20, 2024
6 checks passed
@hinto-janai hinto-janai deleted the lazy branch August 20, 2024 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-consensus Area: Related to consensus. A-helper Area: Related to cuprate-helper. A-storage Area: Related to storage. A-test-utils Area: Related to test-utils.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Usage of LazyLock over OnceLock + fn
3 participants