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

core/Common.js uses window.performance.now which is less efficient then Date.now and in some cases not even more accurate. #739

Closed
kujukuju opened this issue Apr 11, 2019 · 1 comment

Comments

@kujukuju
Copy link

More on performance.now here: https://developer.mozilla.org/en-US/docs/Web/API/Performance/now

I didn't dive too deep in the code to check out how much this is impacting performance (hopefully not more than a few calls each tick), but in case it is it would be better to use Date.now() rather than +new Date() or window.performance.now().

@kujukuju
Copy link
Author

kujukuju commented Apr 11, 2019

Info from the link in case it's removed later:

The timestamp is not actually high-resolution. To mitigate security threats such as Spectre, browsers currently round the results to varying degrees. (Firefox started rounding to 1 millisecond in Firefox 60.) Some browsers may also slightly randomize the timestamp. The precision may improve again in future releases; browser developers are still investigating these timing attacks and how best to mitigate them.

liabru added a commit that referenced this issue Apr 11, 2021
* render-stats:
  added Date.now fallback to Common.now, closes #739
  added Example.stats
  added debug stats and performance monitoring to Matter.Render
  improve Render.debug
  set render showDebug option on examples stress and stress2
  added lastDelta and lastElapsed to engine.timing

# Conflicts:
#	src/core/Engine.js
#	src/render/Render.js
@liabru liabru closed this as completed in c06c107 Apr 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants