-
-
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/fix track_caller
attribute on panicking entity accessor methods
#8951
Conversation
track_caller
attribute on panicking entity accessors methodstrack_caller
attribute on panicking entity accessor methods
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.
Being able to debug this better would be incredible: I was confused about why track_caller wouldn't work.
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 had to remember why you'd want the #[inline(never)]
and #[cold]
, but I recall its' because it will avoid too much overhead from that panic
call. I would have preferred to see an explanation for them, but alright.
would running benches be relevant when changing those functions? |
Yeah, it's worth checking. I'll do a bench before merging this. |
Yes, this will avoid having the panic in the hot code path. Maybe adding some comment for that is a good idea.
I suspect there to be little difference between this and the previous version, they should effectively result in the same codegen, but the additional |
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've seen similar uses in the stdlib pretty often, so the practice makes plenty of sense. Though I'd love to see concrete benches before merging. Wish there was a better way to do this without the boilerplate 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.
LGTM
Co-authored-by: Giacomo Stevanato <[email protected]>
Results are main vs this PR, for relevant benchmarks:
|
These benchmarks are noisy for me, even with every other program closed. I'd call this "probably performance-neutral", and this is very impactful for UX. @james7132, if you agree please merge <3 |
These do look like they're within margin of error, sans the insert_commands results, which is typically pretty stable and a 10-13% improvement is indeed welcome. Merging. |
Objective
World::entity
,World::entity_mut
andCommands::entity
should be marked withtrack_caller
to display where (in user code) the call with the invalidEntity
was made.Commands::entity
already has the attibute, but it does nothing due to the call tounwrap_or_else
.Solution
track_caller
attribute to theWorld::entity_mut
andWorld::entity
.unwrap_or_else
which makes thetrack_caller
attribute useless (becauseunwrap_or_else
is nottrack_caller
itself). The avoid eager evaluation of the panicking branch it is never inlined.