-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Name::from<&str> always heap-allocates which is a footgun #24465
Copy link
Copy link
Open
Labels
A-UtilsUtility functions and typesUtility functions and typesC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorC-PerformanceA change motivated by improving speed, memory usage or compile timesA change motivated by improving speed, memory usage or compile timesD-StraightforwardSimple bug fixes and API improvements, docs, test and examplesSimple bug fixes and API improvements, docs, test and examplesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!This issue is ready for an implementation PR. Go for it!
Metadata
Metadata
Assignees
Labels
A-UtilsUtility functions and typesUtility functions and typesC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorC-PerformanceA change motivated by improving speed, memory usage or compile timesA change motivated by improving speed, memory usage or compile timesD-StraightforwardSimple bug fixes and API improvements, docs, test and examplesSimple bug fixes and API improvements, docs, test and examplesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!This issue is ready for an implementation PR. Go for it!
Type
Fields
Give feedbackNo fields configured for issues without a type.
Bevy version and features
main
What went wrong
Nameinternally isCow<'static, str>, but creatingNameby"str".intois always heap-allocated even if&strhas static lifetime:bevy/crates/bevy_ecs/src/name.rs
Lines 173 to 175 in 564eb4f
The correct way is
Name::new("str")bevy/crates/bevy_ecs/src/name.rs
Lines 79 to 81 in 564eb4f
To avoid the unexpected allocation I suggest change
impl From<&str> for Nametoimpl From<&'static str> for Name