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

Vector2|3|4: Use Math.trunc() in roundToZero(). #26643

Merged
merged 2 commits into from
Aug 28, 2023
Merged

Conversation

ycw
Copy link
Contributor

@ycw ycw commented Aug 24, 2023

Math.trunc is much faster than current impl

@github-actions
Copy link

github-actions bot commented Aug 24, 2023

📦 Bundle size

Full ESM build, minified and gzipped.

Filesize dev Filesize PR Diff
646.4 kB (160.4 kB) 646.2 kB (160.3 kB) -243 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Filesize dev Filesize PR Diff
439.2 kB (106.4 kB) 439 kB (106.4 kB) -243 B

@WestLangley
Copy link
Collaborator

Math.trunc is much faster than current impl

FWIW, in my testing on Safari/FF MacOS -- it's marginally slower.

@ycw
Copy link
Contributor Author

ycw commented Aug 24, 2023

@WestLangley chrome116 on win11
1

@WestLangley
Copy link
Collaborator

Always test on a variety of OS/Browsers before making performance claims.

Just as in this case, results can be surprising. :-)

@Mugen87
Copy link
Collaborator

Mugen87 commented Aug 25, 2023

Tested on a macMini with M2 Pro:

image image image

Overall, Math.trunc() seems the more performant solution compared to what is implemented now. And it is more readable than the bitwise operation.

@Mugen87 Mugen87 added this to the r156 milestone Aug 28, 2023
@Mugen87 Mugen87 changed the title Vector2|3|4: uses Math.trunc() for roundToZero() Vector2|3|4: Use Math.trunc() in roundToZero(). Aug 28, 2023
@Mugen87
Copy link
Collaborator

Mugen87 commented Aug 28, 2023

Let's give this a try!

@Mugen87 Mugen87 merged commit 0c67b52 into mrdoob:dev Aug 28, 2023
@manthrax
Copy link
Contributor

manthrax commented Sep 2, 2023

Wow.. blows my mind that Math.***( x ) is faster than an x | 0...

@ycw ycw deleted the roundtozero branch September 14, 2023 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants