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

Improve the performance of performance. #5944

Merged
merged 1 commit into from May 23, 2022
Merged

Conversation

zhangenming
Copy link
Contributor

function test(f) {
    console.time()
    let i = 0
    while (i++ < 1e6) {
        f()
    }
    console.timeEnd()
}
test(performance.now.bind(performance))
test(()=>performance.now())

// VM2470:7 default: 120.751220703125 ms
// VM2470:7 default: 453.26416015625 ms```

@zhmushan
Copy link
Contributor

image

Copy link
Contributor

@zhmushan zhmushan left a comment

Choose a reason for hiding this comment

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

Can you explain why it is so fast? I've come to the exact opposite conclusion in Nodejs than in the browser. I'm worried that as browsers upgrade, the optimizations we're doing now won't make sense or will even be a hindrance.

@zhangenming
Copy link
Contributor Author

zhangenming commented May 21, 2022

Can you explain why it is so fast?

const foo = performance.now;
const bar = ()=>performance.now();

// foo() is fast than bar()
// Because less one(1 VS 2) property access need to find, and use `bind` just for fix `this`

I've come to the exact opposite conclusion in Nodejs than in the browser.

I'm not sure, but as far as I know, node's performance seems to be a bit special,
try console.log(performance.now.toString()) in node maybe find something
but I forget the details.

discuss welcome
tested with chrome/firefox/safari, In line with expectations
I don't know if this line of code in vue is in hot path
If not may not have too much necessity of this PR

Copy link
Contributor

@zhmushan zhmushan left a comment

Choose a reason for hiding this comment

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

LGTM

@yyx990803
Copy link
Member

We already cache getNow() done in the same tick so this likely won't make noticeable difference, but making it faster shouldn't hurt.

@yyx990803 yyx990803 merged commit 3bdc41d into vuejs:main May 23, 2022
9 checks passed
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.

None yet

4 participants