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

Fixed lockfree frozen vec being too small. #81

Merged

Conversation

davidv1992
Copy link
Contributor

The current implementation accidently divides by 4 instead of 2 when calculating the number of buffers required. This means that on 32 bit systems only 65535 items can be in a LockFreeFrozenVec, which the rust compiler exceeds. (See also https://github.com/rust-lang-ci/rust/actions/runs/12980407836/job/36197397174, triggered by rust-lang/rust#136094)

Is it possible to release a new version after this bugfix has been merged?

@Manishearth
Copy link
Owner

r? @oli-obk

const NUM_BUFFERS: usize = (usize::BITS >> 2) as usize;
/// Each buffer covers 2 bits of address space, so we need half as many
/// buffers as bits in a usize.
const NUM_BUFFERS: usize = (usize::BITS / 2) as usize;
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch. I had an off by one here in my head because I always calculated the total buffer size including the buffer at index NUM_BUFFERS.

Maybe we should grow buffers faster instead of increasing the number of buffers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The buffers are already growing at 4x each time it grows, which is quite aggresive. Not increasing the buffer size would require an 8x growth factor, which just seems excessive to me. Especially given that a few non-breaking versions ago (1.7.1/1.8.1) this was only growing 2x at each cutover point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that this also means that in some cases 8 times more storage would be used than is strictly required to store the elements. I think that that is not worth the small reduction in number of pointers used.

@davidv1992 davidv1992 force-pushed the lockfreefrozenvec-too-small branch from 1db9f2f to 9c75ab5 Compare January 29, 2025 06:40
@Manishearth Manishearth merged commit 750bcc4 into Manishearth:master Jan 29, 2025
1 check passed
@Manishearth
Copy link
Owner

I'll make a release with this and #82 when I get a chance

@davidv1992
Copy link
Contributor Author

awesome, thanks for handling this as quickly as you have.

@Manishearth
Copy link
Owner

Published

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants