-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Optimize label comparisons and remove restrictions on types that can be labels #5377
Conversation
92ea11e
to
6b57afc
Compare
2605865
to
1118a6b
Compare
aa3a462
to
3df37e4
Compare
This PR is now at a point where I'm happy with it. I'll get CI passing once we yeet stringly-typed labels. |
On second thought, I realized that I can implement string-labels in this design. This PR is no longer blocked, not sure what that last CI failure is about though. |
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.
Nowhere near a full review
MIRI is buggy so we can't use fn pointers for comparisons
8864321
to
989b916
Compare
I've iterated a lot on this PR. In that time, the design and precise motivations have changed considerably and the history has gotten quite messy. I'm going to close this out and open a new PR. |
Objective
Solution
Label
to return au64
value that distinguishes between labels of the same type.&mut Formatter
fn pointer.TypeId
and formatter behind the same pointer, shrinking the stack size of labels to 16 bytes (down from 24).u64
can get stored on the stack for free.Examples
Basic labels.
Complex labels require boxing and interning.
Notes
Label
traits are no longer object safe, but this is probably a good thing since it makes it easier to catch obsolete instances ofBox<dyn Label>
.LabelId
should always be used instead.parking_lot
andindexmap
as dependencies forbevy_utils
.indexmap
only has one dependency (hashbrown
), which is already a dependency ofbevy_utils
.Benchmarks
If we unnecessarily intern most of the labels in the benchmark, we see that it's still significantly faster than before #4957, which is the PR that originally removed boxed labels.
Changelog
as_str()
andtype_id()
from label traits.data()
andfmt()
to label traits.Label
derive macros.Migration Guide
The
Label
family of traits (SystemLabel
,StageLabel
, etc) is no longer object safe. Any use ofBox<dyn *Label>
should be replaced with*LabelId
- this family of types serves the same purpose but isCopy
and does not usually require allocations. Any use of&dyn *Label
should be replaced withimpl *Label
if possible, or*LabelId
if you cannot use generics.For manual implementers of this family of traits, the implementation has been changed entirely. Now, comparisons are done using the method
.data()
, which returns au64
used to distinguish labels of the same type. Formatting is done through the associated fnfmt()
, which writes to an&mut Formatter
and is allowed to depend on runtime values.