-
Notifications
You must be signed in to change notification settings - Fork 59
Refactor SharedString to Arc<[u8]>
#577
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
base: master
Are you sure you want to change the base?
Conversation
impl From<[T]> for Arc<[T]> allocates a new copy of the slice.
|
c3cc3fb is unsound. The standard library needs something like Arc::into_inner that works for unsized inner types. |
The best way from my understanding is Miri. |
rust-lang/libs-team#608 Edit:
What we need is the "fail if other strong, disassociate weak" case, and the left or right columns will both work. I think we should prefer the left column because we have an |
|
I've come up with an entirely new strategy. After reading the Arc source code for a while, I've come to understand that once the strong count hits 0, Weak references cannot be upgraded anymore and are effectively locked out. I devised code that drops the arc as early as possible, and then counts on that to plug all the parallelism holes. I hope my reasoning in the comments is correct. Non-Deduplicated SharedString BugI added new logic to prevent removing the wrong Weak reference from the string cache. The bug has to do with what happens when the drop thread tries to acquire the string cache lock while it is held by SharedString::new in the Weak::upgrade's None path. I believe master branch can also suffer from this with a very precise and unlikely order of operations: rbx-dom/rbx_types/src/shared_string.rs Lines 107 to 108 in 7ef7d44
PerformanceI tested on my laptop and there is no discernible performance impact. MiriI installed miri and tried |
This has always bothered me, maybe I am good enough at Rust now to tackle this.
impl AsRef<[u8]>for easy migration of previous callers.I wish I knew how to test for memory leaks!