fix: use global() to get performance API on wasm32-unknown-unknown#107
fix: use global() to get performance API on wasm32-unknown-unknown#107tobz merged 5 commits intometrics-rs:mainfrom
Conversation
tobz
left a comment
There was a problem hiding this comment.
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?
You are right, Reflection is relatively slow since its equal to |
Updated now. I also splitted |
|
Hi @tobz , how's this issue going on? |
tobz
left a comment
There was a problem hiding this comment.
Apologies: life and work have been pretty busy lately. :)
I left a common about how we caching the Performance object, and in particular about how we're overriding the fact that it's !Send/!Sync.
tobz
left a comment
There was a problem hiding this comment.
Overall, these changes seem reasonable to me. 👍🏻
Hi, when can we get this PR merged |
|
👋🏻 Going to merge these now, but I'll have to fix the MSRV and CI afterwards and make sure things are still green before I can cut a release. |
|
Released as Thanks again for your contribution! |
Currently quanta uses
window.performanceto access Performance API in browser, which will not work in WebWorkers. In WebWorkers, there is nowindowobject, butperformanceis in the global space.This PR uses
web_sys::js_sys::global()to access the global scope, and look up forperformancein 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