Skip to content
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

Fast renormalize #14316

Merged
merged 15 commits into from
Jul 22, 2024
Merged

Fast renormalize #14316

merged 15 commits into from
Jul 22, 2024

Conversation

IQuick143
Copy link
Contributor

Objective

Solution

  • Add a fast_remormalize method to Dir2/Dir3/Dir3A and Rot2.

Testing

  • Added tests too

@IQuick143 IQuick143 added C-Feature A new feature, making something new possible A-Math Fundamental domain-agnostic mathematical operations labels Jul 14, 2024
@alice-i-cecile alice-i-cecile added S-Needs-Review Needs reviewer attention (from anyone!) to move forward D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes labels Jul 14, 2024
Copy link
Member

@BD103 BD103 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good docs and unit tests check out. I have one non-blocking nit, but beyond that it looks good!

crates/bevy_math/src/direction.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/direction.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/rotation2d.rs Outdated Show resolved Hide resolved
@BD103 BD103 added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 15, 2024
Co-authored-by: BD103 <59022059+BD103@users.noreply.github.com>
@BD103 BD103 added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Jul 15, 2024
@BD103
Copy link
Member

BD103 commented Jul 15, 2024

Oops, I accidentally though that @Jondolf's review was an approval. Marking this as S-Needs-Review.

Copy link
Member

@janhohenheim janhohenheim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some documentation improvement suggestions, but nothing blocking :)

crates/bevy_math/src/direction.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/direction.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/rotation2d.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/rotation2d.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/direction.rs Show resolved Hide resolved
crates/bevy_math/src/direction.rs Show resolved Hide resolved
crates/bevy_math/src/direction.rs Show resolved Hide resolved
crates/bevy_math/src/rotation2d.rs Show resolved Hide resolved
@janhohenheim janhohenheim added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 16, 2024
@janhohenheim janhohenheim added this to the 0.15 milestone Jul 16, 2024
@janhohenheim janhohenheim added the M-Needs-Release-Note Work that should be called out in the blog due to impact label Jul 16, 2024
Courtesy of @janhohenheim

Co-authored-by: Jan Hohenheim <jan@hohenheim.ch>
@IQuick143
Copy link
Contributor Author

@janhohenheim Great suggestions, thanks a bunch.

@janhohenheim
Copy link
Member

Looks like they had some syntax errors, sorry about that 😅

@IQuick143
Copy link
Contributor Author

We gotta keep the CI on its toes somehow, right?

@IQuick143
Copy link
Contributor Author

ah... are these the infamous doctests I've heard of?

How do I fix this CI failure?

@janhohenheim
Copy link
Member

🎉

Copy link
Contributor

@Jondolf Jondolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Adding a similar method for quaternions would be nice, but we can do that later, either by adding it to Glam directly or by using an extension trait.

crates/bevy_math/src/direction.rs Outdated Show resolved Hide resolved
@janhohenheim
Copy link
Member

janhohenheim commented Jul 16, 2024

Added an issue for this to glam: bitshifter/glam-rs#540
Upstreaming the change to Quat would be nice, if you find the time @IQuick143 :)

Co-authored-by: Joona Aalto <jondolf.dev@gmail.com>
@BD103
Copy link
Member

BD103 commented Jul 17, 2024

I ran benchmarks for this and wrote about them in bitshifter/glam-rs#540 (comment). The speed change, while an improvement, is only in a few picoseconds. This is desirable for hot code, but may not be worth upstreaming.

@Jondolf
Copy link
Contributor

Jondolf commented Jul 18, 2024

I wonder if the performance improvement would be larger when the libm feature is enabled (used for portable and cross-platform deterministic math), since libm might not be able to leverage hardware intrinsics for sqrt on some platforms depending on how it's implemented

@BD103
Copy link
Member

BD103 commented Jul 18, 2024

I wonder if the performance improvement would be larger when the libm feature is enabled (used for portable and cross-platform deterministic math), since libm might not be able to leverage hardware intrinsics for sqrt on some platforms depending on how it's implemented

I'm not sure how to do that myself, but feel free to try it! This is the code that I used to benchmark.

Copy link
Member

@Aceeri Aceeri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat! Hadn't thought about it like this before, but makes sense.

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jul 22, 2024
Merged via the queue into bevyengine:main with commit 420f7f7 Jul 22, 2024
27 checks passed
@alice-i-cecile
Copy link
Member

Thank you to everyone involved with the authoring or reviewing of this PR! This work is relatively important and needs release notes! Head over to bevyengine/bevy-website#1664 if you'd like to help out.

@alice-i-cecile alice-i-cecile removed the M-Needs-Release-Note Work that should be called out in the blog due to impact label Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Math Fundamental domain-agnostic mathematical operations C-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants