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

Array.shift is very slow #3402

Closed
ahaoboy opened this issue Oct 20, 2023 · 3 comments · Fixed by #3405
Closed

Array.shift is very slow #3402

ahaoboy opened this issue Oct 20, 2023 · 3 comments · Fixed by #3405
Labels
bug Something isn't working performance Performance related changes and issues

Comments

@ahaoboy
Copy link
Contributor

ahaoboy commented Oct 20, 2023

Describe the bug
Array.shift is very slow

To Reproduce

let n = 5000;
let a = Array(n).fill(0);

while (a.length) a.shift()

node 92ms

 time node  ./test.js

________________________________________________________
Executed in   92.91 millis    fish           external
   usr time    0.00 millis    0.00 micros    0.00 millis
   sys time   15.00 millis    0.00 micros   15.00 millis

boa 37s

 time boa-windows-amd64 ./test.js 
0

________________________________________________________
Executed in   37.36 secs      fish           external
   usr time   16.00 millis   16.00 millis    0.00 millis
   sys time   15.00 millis    0.00 millis   15.00 millis

qjs 45ms

 time qjs ./test.js 

________________________________________________________
Executed in   45.28 millis    fish           external
   usr time    0.00 micros    0.00 micros    0.00 micros
   sys time    0.00 micros    0.00 micros    0.00 micros

Expected behavior
Array.shift should have better performance

Build environment (please complete the following information):

  • OS: win11 boa 0.17.3
  • Version: [e.g. 32]
  • Target triple: [e.g. x86_64-unknown-linux-gnu]
  • Rustc version: [e.g. rustc 1.43.0 (4fb7144ed 2020-04-20), running rustc -V]

Additional context

The performance of the Array.pop function is the same as the others, all taking around 100ms. However, the Array.pop operation is exceptionally slow, especially when the array length exceeds 10,000.

let n = 5000;
let a = Array(n).fill(0);

while (a.length) a.pop()
@ahaoboy ahaoboy added the bug Something isn't working label Oct 20, 2023
@jedel1043 jedel1043 added the performance Performance related changes and issues label Oct 20, 2023
@ahaoboy
Copy link
Contributor Author

ahaoboy commented Oct 21, 2023

@jedel1043 How about Array.unshift, unshift and shift functions are quite similar, and both are very slow. Can similar methods be used for optimization?

Array.splice is also a commonly used method for modifying arrays, and it's slow in Boa as well.

let a = [];
let n = 10000;
while(n--) a.splice(0,0,n)
console.log(a)

@jedel1043
Copy link
Member

jedel1043 commented Oct 21, 2023

@jedel1043 How about Array.unshift, unshift and shift functions are quite similar, and both are very slow. Can similar methods be used for optimization?

Array.splice is also a commonly used method for modifying arrays, and it's slow in Boa as well.

let a = [];
let n = 10000;
while(n--) a.splice(0,0,n)
console.log(a)

Yeah, arrays in general need a lot of extra work. I'll open a tracking issue for that.

@jedel1043
Copy link
Member

#3407

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working performance Performance related changes and issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants