internal: no std mutex#6058
Conversation
b7b3dae to
7d53f79
Compare
9bb808d to
465c958
Compare
Merging this PR will not alter performance
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ | into_i128_pos_max |
1.5 µs | 2 µs | -24.69% |
| ⚡ | drop_many_objects_without_gil |
48.1 µs | 36.9 µs | +30.57% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing Person-93:no_std_mutex (8db26fd) with main (5c6807d)
e393415 to
2988f07
Compare
acf2af4 to
9dec55b
Compare
| #[cfg(feature = "parking_lot")] | ||
| type OnceInner = parking_lot::Once; | ||
|
|
||
| #[cfg(not(feature = "parking_lot"))] | ||
| #[allow(clippy::disallowed_types)] | ||
| type OnceInner = std::sync::Once; |
There was a problem hiding this comment.
I think we should have (in order of preference)
- std mutex
- if std not enabled, fallback to parking_lot mutex
- if parking_lot not enabled, compile error
In the absence of a std feature at the moment, perhaps we can have a #[cfg(wip_no_std)] which is the equivalent of what will become #[cfg(not(feature = "std"))]. We could tweak the noxfile to send this via a cfg for one of the test combinations.
There was a problem hiding this comment.
In the absence of a
stdfeature at the moment, perhaps we can have a#[cfg(wip_no_std)]which is the equivalent of what will become#[cfg(not(feature = "std"))]. We could tweak the noxfile to send this via a cfg for one of the test combinations.
That's a good idea, but I think that the custom cfg should be the other way around; something like wip_feature_std so that we can do #[cfg(wip_feature_std)] or #[cfg(not(wip_feature_std))] and then just search-and-replace when we are ready to add the std feature.
There was a problem hiding this comment.
I think we should have (in order of preference)
- std mutex
- if std not enabled, fallback to parking_lot mutex
- if parking_lot not enabled, compile error
I thought I'd try for the low-hanging performance gain of parking lot's mutex, but I can do it this way instead.
There was a problem hiding this comment.
I believe it is context-dependent what mutex performs better, see e.g. https://blog.cuongle.dev/p/inside-rusts-std-and-parking-lot-mutexes-who-win
My take is that generally PyO3 internal mutexes mostly sit in the low-contention space where zero dependencies is a perk.
There was a problem hiding this comment.
In the absence of a
stdfeature at the moment, perhaps we can have a#[cfg(wip_no_std)]which is the equivalent of what will become#[cfg(not(feature = "std"))]. We could tweak the noxfile to send this via a cfg for one of the test combinations.That's a good idea, but I think that the custom cfg should be the other way around; something like
wip_feature_stdso that we can do#[cfg(wip_feature_std)]or#[cfg(not(wip_feature_std))]and then just search-and-replace when we are ready to add thestdfeature.
If that works, also happy with it. The constraint I think we have is that we can't apply a non-feature cfg by default, so we'll need to make sure that whatever we add evaluates to true unless the cfg is explicitly passed by flags.
This PR is to prepare for
no_stdsupport.I've added
non_poison::MutexandOnceto theplatformmod.There was once place that relied on poisoning for correctness:
err_state.rs, but that didn't really need a mutex because it was guarding aCopytype, I've replaced it with aCell.