Skip to content

perf(runtime-dom): Array.from and concat is more efficient than ... #1367

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

Closed
wants to merge 1 commit into from
Closed

Conversation

shengxinjing
Copy link
Contributor

@buns-li
Copy link

buns-li commented Jun 15, 2020

hello, in you test case and the result I get .... :
image

@shengxinjing
Copy link
Contributor Author

@buns-li I'm surprised it's not stable. that's interesting

@shengxinjing
Copy link
Contributor Author

it's stable in my [email protected]
It may be version-related.

@shengxinjing
Copy link
Contributor Author

@buns-li wtf.... Only God knows why.
test in local index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
<script>


let set = new Set()
set.add(1)
set.add(2)
set.add(3)
set.add(4)
let val = 0

console.log([val,...set])
console.log([val].concat(Array.from(set)))
console.time('...')
for (let i = 0; i < 10000; i++) {
    let val1 = [val,...set]
}
console.timeEnd('...')

console.time('concat')
for (let i = 0; i < 10000; i++) {
    let val2 = [val].concat(Array.from(set))
}
console.timeEnd('concat')
</script>

</body>
</html>

image

@shengxinjing
Copy link
Contributor Author

forget it . It's not important logic.

@Justineo
Copy link
Member

Justineo commented Jun 15, 2020

I created a performance benchmark for this:

image

It seems that [...transitionClasses, value] is the fastest in most cases (even much faster than [value, ...transitionClasses] in Chrome when the set is relatively large).

@shengxinjing
Copy link
Contributor Author

@Justineo good job, thanks

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.

3 participants