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 unnecessary Arc by Box #635

Merged
merged 3 commits into from
Dec 23, 2024

Conversation

Veykril
Copy link
Member

@Veykril Veykril commented Dec 22, 2024

QueryEdges were Arced before, but we only ever clone them for LRU evictions (and there the original one will drop right after eviction), this is a rare occurence. Additionally to save on constantly allocating an empty Arc in the case where no deps exist, we needed a lazy_static. Instead, we Box the slice now, dropping the need for ref-counting as well as the lazy_static as an empty slice never allocates in a Box.

Another improvement we should make is use a ThinBox once that's a thing, we don't really make use of the length directly and it would shave off 4/8 bytes for Memo/QueryRevisions.

Copy link

netlify bot commented Dec 22, 2024

Deploy Preview for salsa-rs canceled.

Name Link
🔨 Latest commit 38207e4
🔍 Latest deploy log https://app.netlify.com/sites/salsa-rs/deploys/67694e2784fbad0008d31d9d

Copy link

codspeed-hq bot commented Dec 22, 2024

CodSpeed Performance Report

Merging #635 will not alter performance

Comparing Veykril:veykril/push-vktlqysrmlmv (38207e4) with master (0ac5c1c)

Summary

✅ 9 untouched benchmarks

@Veykril Veykril force-pushed the veykril/push-vktlqysrmlmv branch 3 times, most recently from 5778f5b to 98d7005 Compare December 22, 2024 17:21
@Veykril Veykril changed the title Couple of perf/memory improvements Replace unnecessary Arc by Box Dec 22, 2024
@Veykril Veykril force-pushed the veykril/push-vktlqysrmlmv branch 2 times, most recently from 5778f5b to c2da7c3 Compare December 22, 2024 17:24
@Veykril
Copy link
Member Author

Veykril commented Dec 22, 2024



---- parallel_map::execute_cancellation stdout ----
[tests/parallel/signal.rs:11:9] format!("signal({})", stage) = "signal(1)"
[tests/parallel/signal.rs:11:9] format!("signal({})", stage) = "signal(2)"
thread 'parallel_map::execute_cancellation' panicked at tests/parallel/parallel_map.rs:91:10:
called `Result::unwrap_err()` on an `Ok` value: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

seems spurious to me as I can't reproduce it

@Veykril Veykril marked this pull request as ready for review December 22, 2024 17:29
@Veykril Veykril force-pushed the veykril/push-vktlqysrmlmv branch from c2da7c3 to 754f678 Compare December 22, 2024 17:45
src/table/memo.rs Outdated Show resolved Hide resolved
@MichaReiser
Copy link
Contributor

MichaReiser commented Dec 23, 2024



---- parallel_map::execute_cancellation stdout ----
[tests/parallel/signal.rs:11:9] format!("signal({})", stage) = "signal(1)"
[tests/parallel/signal.rs:11:9] format!("signal({})", stage) = "signal(2)"
thread 'parallel_map::execute_cancellation' panicked at tests/parallel/parallel_map.rs:91:10:
called `Result::unwrap_err()` on an `Ok` value: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

seems spurious to me as I can't reproduce it

I don't remember the test being spurious before... But @davidbarsky might know more

@Veykril Veykril force-pushed the veykril/push-vktlqysrmlmv branch from 754f678 to 1dc7ff4 Compare December 23, 2024 11:48
Likewise, an empty `Box`ed slice does not allocate so we can remove the `lazy_static` that was needed before
@Veykril Veykril force-pushed the veykril/push-vktlqysrmlmv branch from 1dc7ff4 to 38207e4 Compare December 23, 2024 11:48
@Veykril Veykril enabled auto-merge December 23, 2024 11:48
@Veykril Veykril added this pull request to the merge queue Dec 23, 2024
Merged via the queue into salsa-rs:master with commit c8d47cc Dec 23, 2024
5 checks passed
@Veykril
Copy link
Member Author

Veykril commented Dec 23, 2024

Uuh, I cancelled the first CI run as I pushed twice and apparently that just skips the merge queue? 🤨

@Veykril Veykril deleted the veykril/push-vktlqysrmlmv branch December 23, 2024 11:50
@Veykril
Copy link
Member Author

Veykril commented Dec 23, 2024



---- parallel_map::execute_cancellation stdout ----
[tests/parallel/signal.rs:11:9] format!("signal({})", stage) = "signal(1)"
[tests/parallel/signal.rs:11:9] format!("signal({})", stage) = "signal(2)"
thread 'parallel_map::execute_cancellation' panicked at tests/parallel/parallel_map.rs:91:10:
called `Result::unwrap_err()` on an `Ok` value: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

seems spurious to me as I can't reproduce it

I don't remember the test being spurious before... But @davidbarsky might know more

Not the first time it seems, it even failed on master before https://github.com/salsa-rs/salsa/actions/runs/12397086201/job/34606629011

@davidbarsky
Copy link
Contributor

I don't remember the test being spurious before... But @davidbarsky might know more

This was a recent development, but it seems consistently spurious on CI. I'm unable to reproduce this issue locally, however, which feels a bit concerning to me.

@Veykril
Copy link
Member Author

Veykril commented Dec 23, 2024

I can reproduce it by making the main thread sleep for a bit after spawning the other thread it seems

@davidbarsky
Copy link
Contributor

I can reproduce it by making the main thread sleep for a bit after spawning the other thread it seems

Ah, yeah, this is sufficient for me to reproduce:

diff --git a/tests/parallel/parallel_map.rs b/tests/parallel/parallel_map.rs
index 80e4ebeafe..278bbfedd8 100644
--- a/tests/parallel/parallel_map.rs
+++ b/tests/parallel/parallel_map.rs
@@ -79,6 +79,7 @@
         let db = db.clone();
         move || a1(&db, input)
     });
+    std::thread::sleep(std::time::Duration::from_millis(100));

     let counts = (2..=20).collect::<Vec<u32>>();

@Veykril
Copy link
Member Author

Veykril commented Dec 23, 2024

Ah I can see the problem I think, by the time the signal passes we will no longer do any cancellable work in the a1 function, so we never end up cancelling (note how the test in parallel_cancellation differs by calling a query after the wait_for call)

Callofdump

This comment was marked as spam.

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.

4 participants