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 Page data Vec with boxed fixed array #628

Merged
merged 3 commits into from
Dec 16, 2024

Conversation

Veykril
Copy link
Member

@Veykril Veykril commented Dec 13, 2024

No need to use a Vec here, we have a comptime length of the page so we unnecessarily store an extra length and capacity

Copy link

netlify bot commented Dec 13, 2024

Deploy Preview for salsa-rs canceled.

Name Link
🔨 Latest commit 1eaf262
🔍 Latest deploy log https://app.netlify.com/sites/salsa-rs/deploys/675ed043c38a570008c08b69

@@ -169,15 +171,11 @@ impl Table {
impl<T: Slot> Page<T> {
#[allow(clippy::uninit_vec)]
fn new(ingredient: IngredientIndex) -> Self {
let mut data = Vec::with_capacity(PAGE_LEN);
unsafe {
data.set_len(PAGE_LEN);
Copy link
Member Author

Choose a reason for hiding this comment

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

Afaik this considered UB as we now have a Vec containing uninitialized values (UnsafeCell does not make this sound either, MaybeUninit would I believe)

Copy link

codspeed-hq bot commented Dec 13, 2024

CodSpeed Performance Report

Merging #628 will not alter performance

Comparing Veykril:veykril/push-sqqurotonstp (1eaf262) with master (5cd2b63)

Summary

✅ 9 untouched benchmarks

@Veykril Veykril force-pushed the veykril/push-sqqurotonstp branch from 0404bb5 to 950fb63 Compare December 13, 2024 15:01
@@ -62,7 +64,7 @@ pub(crate) struct Page<T: Slot> {

/// Vector with data. This is always created with the capacity/length of `PAGE_LEN`
/// and uninitialized data. As we initialize new entries, we increment `allocated`.
data: Vec<UnsafeCell<T>>,
data: Box<[UnsafeCell<MaybeUninit<T>>; PAGE_LEN]>,
Copy link
Member Author

@Veykril Veykril Dec 14, 2024

Choose a reason for hiding this comment

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

We could drop the Box here entirely if we wanted as a Page is currently always allocated as a Box<dyn> anyways, but we'd need to be careful in that we never put a Page on the stack when we construct it then which is rather tricky in today's Rust. Alternatively we could get rid of the Box<dyn Page> by type erasing manually without a trait object, as a Page always has the same size and alignment irrevelant to its contained T (as it is behind an indirection)

@Veykril Veykril force-pushed the veykril/push-sqqurotonstp branch from 950fb63 to 1eaf262 Compare December 15, 2024 12:49
Copy link
Contributor

@davidbarsky davidbarsky left a comment

Choose a reason for hiding this comment

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

lgtm, modulo clarification around the fixme in unsafe code

@davidbarsky davidbarsky added this pull request to the merge queue Dec 16, 2024
Merged via the queue into salsa-rs:master with commit 3c7f169 Dec 16, 2024
10 checks passed
@Veykril Veykril deleted the veykril/push-sqqurotonstp branch December 17, 2024 07:58
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.

2 participants