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
(perf) bump "string-cache" crate for per-bucket mutex #6980
Conversation
Rust newbie.
Looking at the issue in |
Waiting on the breaking change getting reverted and a new |
71b5c5a
to
70b04b0
Compare
fix: move debug_assert check Fix needed after #268 The fix is only for debug_assert correctness. There's no functional effect. i.e. version 0.8.6 might cause debug tests to fail, but it isn't a (functionally) breaking change. **Explanation** Moving the lock to be per-bucket changed the `DYNAMIC_SET`'s API so that it doesn't need to be locked (i.e. `DYANMIC_SET` is not wrapped with a `Mutex`). The `Atom`'s `fn drop` changed from ```rust fn drop(&mut self) { if self.tag() == DYNAMIC_TAG { let entry = self.unsafe_data.get() as *const Entry; if unsafe { &*entry }.ref_count.fetch_sub(1, SeqCst) == 1 { drop_slow(self) } } // Out of line to guide inlining. fn drop_slow<Static>(this: &mut Atom<Static>) { DYNAMIC_SET .lock() .remove(this.unsafe_data.get() as *mut Entry); } } ``` to ```rust impl<Static> Drop for Atom<Static> { #[inline] fn drop(&mut self) { if self.tag() == DYNAMIC_TAG { let entry = self.unsafe_data.get() as *const Entry; if unsafe { &*entry }.ref_count.fetch_sub(1, SeqCst) == 1 { drop_slow(self) } } // Out of line to guide inlining. fn drop_slow<Static>(this: &mut Atom<Static>) { DYNAMIC_SET.remove(this.unsafe_data.get() as *mut Entry); } } ``` (the `lock()` is gone) Now when we enter `DYNAMIC_SET.remove()`, there's no longer a lock guarantee. Until we lock the bucket, another thread could be in the middle of performing a `DYNAMIC_SET.insert()` for the same string. Therefore, the `debug_assert!(value.ref_count.load(SeqCst) == 0)` is premature - it needs to occur after we take the lock for the bucket. Caught at swc-project/swc#6980 in a [failed test](https://github.com/swc-project/swc/actions/runs/4326536698/jobs/7554083939).
7348aeb
to
279fa89
Compare
780b63b
to
e67297d
Compare
@kdy1 |
I think the post-merge benchmark is fine, as we can revert them easily |
Is something missing for merge? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
swc-bump:
- swc_atoms
Description:
Bump the "string-cache" crate to 0.8.5, which includes this PR.
Internally, it now locks on each individual bucket within the DYNAMIC_SET struct, rather than locking on the whole data structure.
Parallel performance should improve.
BREAKING CHANGE:
Related issue (if exists):