gh-154756: Fix data race in list.sort() - #154572
Conversation
|
@brijkapadia Thanks for your review. Sure, I’ve created a separate issue. You’re right that this PR introduces quite a few release atomic stores. However, I think most of them are necessary to preserve the required atomicity.
|
|
What is the performance impact for lists of various size? |
@picnixz Hi, I have run
Random data (
All input patterns at size = 16384 (default)
|
|
I think we can use a simpler approach, This keeps the code not too complicated, and should have better performance because we don't need to call atomic operations multiple times. And during the sort process, other threads which may access the old The Lines 141 to 171 in a528a24 |
Great idea! This sounds like RCU (read-copy-update) in Linux kernel. I'll re-implement it and re-run the benchmarks. I expect the numbers to be much better. |
|
@pochmann Thanks for pointing this out. When designing a sort algorithm, space complexity really is something you have to think about carefully — it's a trade-off between performance and memory footprint, and this PR is no exception:
Personally I'm open to either approach Two small notes on the current copy-on-write implementation:
|
|
benchmark result for copy-on-write implementation: Across sizes I see no meaningful regression
|
This PR try to fix #154756, it uses RCU (read-copy-update) method:
ob_itemto a newly allocated memory addressob_itemat the end.Testing
sortperf.pyshows no perf regression