Skip to content

Conversation

Veykril
Copy link
Member

@Veykril Veykril commented Aug 3, 2025

No description provided.

Copy link

netlify bot commented Aug 3, 2025

Deploy Preview for salsa-rs canceled.

Name Link
🔨 Latest commit 1b15e41
🔍 Latest deploy log https://app.netlify.com/projects/salsa-rs/deploys/688f17b5bfc9f40008bad483

Copy link

codspeed-hq bot commented Aug 3, 2025

CodSpeed Performance Report

Merging #958 will not alter performance

Comparing Veykril:veykril/push-rqyrkyttxpol (1b15e41) with master (c3f86b8)

Summary

✅ 12 untouched benchmarks

@MichaReiser
Copy link
Contributor

Is there any other benefit than code size reduction. It seems codspeed doesn't like it at all.

@Veykril Veykril force-pushed the veykril/push-rqyrkyttxpol branch from 7a3884e to ef1c5dc Compare August 3, 2025 08:02
@Veykril
Copy link
Member Author

Veykril commented Aug 3, 2025

No there isn't. I was curious about the perf impact, I agree this isn't great. Checking if we can actually simplify our impl now

@Veykril Veykril force-pushed the veykril/push-rqyrkyttxpol branch from ef1c5dc to 1b15e41 Compare August 3, 2025 08:02
@Veykril Veykril changed the title Replace manual WaitGroup impl with crossbeam's Simplify WaitGroup implementation Aug 3, 2025
@Veykril
Copy link
Member Author

Veykril commented Aug 3, 2025

Hm, we could get rid of the additional Arc as well and re-use the Zalsa arc but that makes the code a lot more ugly (thanks to having to deal with drop order), so this is the best I can come up with. Trading an unwrap with unsafe solely due to polonius borrow checking not being a thing yet :(

@MichaReiser MichaReiser requested a review from ibraheemdev August 5, 2025 07:49
@MichaReiser
Copy link
Contributor

@ibraheemdev could you take a look at this PR?

Comment on lines +161 to +164
if let Some(zalsa) = Arc::get_mut(&mut self.handle.zalsa_impl) {
// SAFETY: Polonius when ... https://github.com/rust-lang/rfcs/blob/master/text/2094-nll.md#problem-case-3-conditional-control-flow-across-functions
break unsafe { mem::transmute::<&mut Zalsa, &mut Zalsa>(zalsa) };
}
Copy link
Member

@ibraheemdev ibraheemdev Aug 5, 2025

Choose a reason for hiding this comment

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

Suggested change
if let Some(zalsa) = Arc::get_mut(&mut self.handle.zalsa_impl) {
// SAFETY: Polonius when ... https://github.com/rust-lang/rfcs/blob/master/text/2094-nll.md#problem-case-3-conditional-control-flow-across-functions
break unsafe { mem::transmute::<&mut Zalsa, &mut Zalsa>(zalsa) };
}
if Arc::strong_count(&self.handle.zalsa_impl) == 1 {
// SAFETY: The strong count is 1, and we never create any weak pointers,
// so we have a unique reference.
break unsafe { &mut *(Arc::as_ptr(&self.handle.zalsa_impl) as *mut Zalsa) };
}

This should avoid the Polonius issue and is a bit cheaper. There is a little question about writing through Arc::as_ptr, but it is valid in the current implementation and nothing is really blocking it being guaranteed (see rust-lang/rust#104337).

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