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

fix: use global() to get performance API on wasm32-unknown-unknown #107

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Officeyutong
Copy link

Currently quanta uses window.performance to access Performance API in browser, which will not work in WebWorkers. In WebWorkers, there is no window object, but performance is in the global space.

This PR uses web_sys::js_sys::global() to access the global scope, and look up for performance in that, which will both work on webpage and WebWorkers.

See https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Functions_and_classes_available_to_workers for more details

@Officeyutong Officeyutong marked this pull request as ready for review November 23, 2024 14:02
Copy link
Member

@tobz tobz left a comment

Choose a reason for hiding this comment

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

Thanks for opening this PR!

Taking a look at the code, it seems like this is going to be somewhat inefficient, reflecting through the global scope on every single call.

Is my intuition wrong here? Could we not instead simply query for the Performance class when constructing Monotonic so that there's always a live reference to it to directly use?

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.

2 participants