-
-
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
Add #[track_caller]
to Query
methods
#12984
Conversation
cc @Themayu |
@@ -922,6 +922,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> { | |||
/// | |||
/// - [`get_many`](Self::get_many) for the non-panicking version. | |||
#[inline] | |||
#[track_caller] |
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.
Iirc track_caller
does introduce some minor runtime overhead. For high frequency usage this might show up on benchmarks. Can we do a sanity check here with before / after benches.
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.
I created a benchmark comparing the overhead of #[track_caller]
on my M1 MacBook. (See the gist.) There appears to be little to no overhead whatsoever.
tracked false time: [1.5369 ns 1.5376 ns 1.5383 ns]
Found 8 outliers among 100 measurements (8.00%)
5 (5.00%) high mild
3 (3.00%) high severe
untracked false time: [1.5371 ns 1.5376 ns 1.5382 ns]
Found 5 outliers among 100 measurements (5.00%)
3 (3.00%) high mild
2 (2.00%) high severe
If you look at the average time, they both take 1.5376
nanoseconds. The #[track_caller]
has a greater deviation, with both a lower minimum and greater maximum, but this is sub-nanosecond behavior.
Furthermore, you can compare the generated assembly here.
untracked:
test edi, edi
jne .LBB7_2
ret
.LBB7_2: ; panicking code, no `#[track_caller]`
push rax
lea rdi, [rip + .L__unnamed_3] ; returns panic message
lea rdx, [rip + .L__unnamed_4] ; different
mov esi, 9
call _ZN3std9panicking11begin_panic17he275593115e721e6E
tracked:
test edi, edi
jne .LBB8_2
ret
.LBB8_2: ; panicking code, with `#[track_caller]`
push rax
mov rdx, rsi ; different
lea rdi, [rip + .L__unnamed_5] ; returns panic message
mov esi, 7
call _ZN3std9panicking11begin_panic17he275593115e721e6E
The only difference in the generated code is a lea
instruction being replaced with a mov
instruction. This change is only noticeable when the function panics, where time is not an issue.
Objective
#[track_caller]
inconsistency in bevy's Query types. #12958Solution
Query
that mention panicking, and add#[track_caller]
to them.Changelog
#[track_caller]
toQuery::many
,Query::many_mut
,Query::transmute_lens
, andQuery::transmute_lens_filtered
.For reviewers
I'm unfamiliar with the depths of the
Query
struct. Please check whether it makes since for the updated methods to have#[track_caller]
, and if I missed any!