jwagner / simplex-noise.js

A fast simplex noise implementation in Javascript / Typescript.
MIT License
1.61k stars 130 forks source link

Improve performance on mobile browsers #23

Closed xaroth8088 closed 6 years ago

xaroth8088 commented 6 years ago

On desktop browsers, there's no practical difference between the various ways to truncate a float to an int. However, on Android Chrome, Math.floor() is significantly (~18%) slower than using a bitshift operation. jsperf to test for yourself

Browser profiling in Chrome pointed to this being the most expensive operation while generating the noise. In my particular application, this change dropped the total 3D noise rendering time by ~50%.

jwagner commented 6 years ago

Interesting probably indicates something in the inliner in v8 was off. I've ran the benchmark on my phone now and get the expected result, they equivalent. Do you still get the 10% difference with a modern chrome mobile?

xaroth8088 commented 6 years ago

Oh, funny. When I tested, it was on Chrome 66, and the difference was consistent. Chrome 67 rolled out between then and now, and now there's no difference.

Closing this PR.