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
refactor: performance timers for node.js and browser #4340
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4340 +/- ##
==========================================
+ Coverage 98.43% 98.51% +0.07%
==========================================
Files 206 206
Lines 7344 7333 -11
Branches 2088 2084 -4
==========================================
- Hits 7229 7224 -5
+ Misses 55 51 -4
+ Partials 60 58 -2
Continue to review full report at Codecov.
|
browser/performance.ts
Outdated
@@ -0,0 +1 @@ | |||
export default performance; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore this comment if it's a known issue with this Draft PR.
I think a level of indirection is needed here - via typeof
or function
. Although this would work in a recent browser, referencing the global performance
at top level causes the browser bundle and its tests to fail on node <= v14:
$ node-v10.4.1 -e performance 2>/dev/null && echo OK || echo FAIL
FAIL
$ node-v12.13.0 -e performance 2>/dev/null && echo OK || echo FAIL
FAIL
$ node-v14.16.0 -e performance 2>/dev/null && echo OK || echo FAIL
FAIL
$ node-v16.1.0 -e performance 2>/dev/null && echo OK || echo FAIL
OK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, ideally the global performance object would be used for both browser and node.js. I was under the impression it was supported as a global in v14, but you are right, it's only available in v16, unless someone would do a backport 😞
if I understood the bundle process correctly, the file used for the node.js build would be this one: https://github.com/rollup/rollup/pull/4340/files#diff-56aca2bfe43f23ab215af1f0c17d5ac2abbed4deb560487408bc588c47c2fc44R1 being replaced with this call:
Line 160 in da3bb43
replaceBrowserModules(), |
originally I wrapped and exported the now
function only, but I was thinking it's probably better to make the entire performance
object (for future use) available. I was also thinking to remove the timer Map, and use performance.measure
and/or performance observer
instead. but it seems currently it wouldn't be possible to attach any other metadata, e.g. for the value for the memory consumption. (detail
param was added in v16)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, I see. did you mean this: https://github.com/rollup/rollup/runs/4723627853?check_suite_focus=true#step:7:5615 just noticed. I have to check it out. I suppose those tests are not running in any browser but in node.js 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the browser bundle name is a bit of a misnomer. It really means JS platform independent.
bbb5681
to
885f51e
Compare
885f51e
to
9b8034b
Compare
@lukastaegert I was wondering if this is a bug: I added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
I think the reason is that since some versions, |
ah, gotcha, makes sense. I'll put up another PR to remove those. |
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Description
distinguishes between bundled files for node.js and browsers (alternative envs). replaces
process.hrtime
withperf_hooks
/globalThis.performance