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

Use | operator instead of Math.floor() #73

Merged
merged 1 commit into from
Aug 9, 2018
Merged

Conversation

oriSomething
Copy link
Contributor

Use | operator instead of Math.floor().

Now, my name might be saved in history ;-)

@ai ai merged commit 484ad4c into ai:master Aug 9, 2018
@fengmk2
Copy link

fengmk2 commented Aug 10, 2018

Have benchmark for this performance improve?

@ai
Copy link
Owner

ai commented Aug 10, 2018

Yeap 6781f48

Exact numbers depends on machine and Node.js version. But I saw changes in result after this commit. To be honest, I am not sure way. Maybe math operator works faster because it doesn't call a additional method?

@oriSomething
Copy link
Contributor Author

I think it's related to old optimizations for asm.js. asm.js uses a lot the | 0 expression to cast number to integer so V8 added optimization that consider some expressions that ends with | 0 as integers instead of floats. I'm not sure when Math.floor returned value treated as integer and when it just floored float, but | 0 always become integer.
By the way the BuckleScript compiler also uses | 0 optimization for intergers.

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.

3 participants