-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Removed once_cell
#10079
Removed once_cell
#10079
Conversation
Replaced 1 instance of `OnceBox<T>` with `OnceLock<Box<T>>` in `NonGenericTypeCell`
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.
It's not clear this is 100% equivalent since the once_cell version allows racing to initialize, while the std implementation is unclear what its behavior is, or if it uses a lock underneath or not. These come with semantic and potential performance differences depending on the underlying implementation.
Since this seems to be a fairly foundational type within bevy_reflect, I'd defer to the reflection SMEs to make a final call on whether this ambiguity is acceptable or not.
Perfectly reasonable. Comparing Based on the handful of locations I can see the // Snip from bevy_asset/src/path.rs
impl Typed for AssetPath<'static> {
fn type_info() -> &'static TypeInfo {
static CELL: NonGenericTypeInfoCell = NonGenericTypeInfoCell::new();
CELL.get_or_set(|| {
let info = ValueInfo::new::<Self>();
TypeInfo::Value(info)
})
// ^--------------------------------------^
// This will always produce the same value
}
} So the value won't change moving from race to block behaviour, leaving timing as the only other possible change. Again, all the calls to |
Note that the race can happen only once. Moreover they are very likely to be initialized at the start of the program, when an If anything, I would remove the |
Just got some time to test that, and removing the closure and |
Checking the usage patterns a bit more deeply, I'm inclined to agree that this shouldn't be too big of an issue outside of building the type registry. Still unfortunate that we need this at all since this does seem to be necessary only because there's no const constructor for TypeId or type_name. |
Completely agree. I was looking at the |
# Objective - Fixes bevyengine#8303 ## Solution - Replaced 1 instance of `OnceBox<T>` with `OnceLock<T>` in `NonGenericTypeCell` ## Notes All changes are in the private side of Bevy, and appear to have no observable change in performance or compilation time. This is purely to reduce the quantity of direct dependencies in Bevy.
# Objective - Fixes bevyengine#8303 ## Solution - Replaced 1 instance of `OnceBox<T>` with `OnceLock<T>` in `NonGenericTypeCell` ## Notes All changes are in the private side of Bevy, and appear to have no observable change in performance or compilation time. This is purely to reduce the quantity of direct dependencies in Bevy.
# Objective - Fixes bevyengine#8303 ## Solution - Replaced 1 instance of `OnceBox<T>` with `OnceLock<T>` in `NonGenericTypeCell` ## Notes All changes are in the private side of Bevy, and appear to have no observable change in performance or compilation time. This is purely to reduce the quantity of direct dependencies in Bevy.
Objective
once_cell
with std lib's implementation #8303Solution
OnceBox<T>
withOnceLock<T>
inNonGenericTypeCell
Notes
All changes are in the private side of Bevy, and appear to have no observable change in performance or compilation time. This is purely to reduce the quantity of direct dependencies in Bevy.