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 std synchronization primitives with parking_lot #210

Merged

Conversation

lachlansneff
Copy link
Contributor

@lachlansneff lachlansneff commented Aug 16, 2020

parking_lot:0.10.2 is already in the dependency tree, so this shouldn't add any compile-time. parking_lot::Mutex is smaller, generally much faster, and has a more ergonomic api than std::sync::Mutex. Same with RwLock.

@lachlansneff lachlansneff changed the title Replace std::sync::Mutex with parking_lot::Mutex Replace std synchronization primitives with parking_lot Aug 16, 2020
@karroffel karroffel added A-Build-System Related to build systems or continuous integration C-Enhancement A new feature C-Dependencies A change to the crates that Bevy depends on labels Aug 16, 2020
@cart
Copy link
Member

cart commented Aug 18, 2020

I'm definitely into the simpler api. I need to do a bit of research into the parking lot Mutex impl, but on paper I like this a lot!

@lachlansneff
Copy link
Contributor Author

The parking_lot crate is essentially a reimplementation of the WTF Webkit locking library in rust. These libraries reimplement locks as sort of userspace futexes, where there's a global hashmap of address -> lock metastate. In most cases, when there is little contention, the lock just performs an atomic operation on the byte (or word in the case of a RwLock) contained inside it, so performance is very good. In cases of contention, the lock looks up its associated data in the global hashmap and can add itself as a sleeping thread to it.

@cart
Copy link
Member

cart commented Aug 20, 2020

This looks good to go as soon as conflicts are resolved.

@lachlansneff lachlansneff force-pushed the replace-std-mutex-with-parking-lot branch from e80b316 to ff4d9a8 Compare August 20, 2020 21:53
@lachlansneff
Copy link
Contributor Author

lachlansneff commented Aug 20, 2020

@cart Alright, I think this should be good.

@cart cart merged commit 1eca55e into bevyengine:master Aug 21, 2020
BimDav pushed a commit to BimDav/bevy that referenced this pull request Aug 26, 2020
* Replace std::sync::Mutex with parking_lot::Mutex
* Replace std::sync::RwLock with parking_lot::RwLock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Build-System Related to build systems or continuous integration C-Dependencies A change to the crates that Bevy depends on C-Enhancement A new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants