Hello,

I'm working on the Opal project and I've noticed that Array#splice is not 
optimized anymore (ie. 4-8 times slower) when using a recent version of v8.

To reproduce this slowdown I'm using the following code:

const arr = []
for (let j = 0; j < 50000; j++) {
  arr.push('index' + j)
}

Object.setPrototypeOf(Array.prototype, {})

let r
for (let i = 0; i < 1000; i++) {
  r = arr.splice(0, 1)
}
console.log(r)

You can run the above code against Node 10, which is using v8 version < 7, 
and against Node 12, which is using v8 version > 7.8.
Please note that removing "Object.setPrototypeOf(Array.prototype, {})" will 
effectively enable the optimization.

I think the reason is that Array#splice is now using a Torque 
implementation where "fast" splice is only used when Array.prototype is 
pristine :

https://github.com/v8/v8/blob/4b9b23521e6fd42373ebbcb20ebe03bf445494f9/src/builtins/array-splice.tq#L125

I'm well aware that we should not mess with prototypes[2][3] but is there 
any workaround to get an optimized version of splice even if prototype has 
been altered?
Or do you have any idea on how we could mitigate this issue?


Thanks for your help,
Guillaume

[1] https://github.com/opal/opal
[2] https://mathiasbynens.be/notes/prototypes
[3] https://mathiasbynens.be/notes/shapes-ics

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/7e4bcdfa-dbed-4374-aba1-e8f923106cebn%40googlegroups.com.

Reply via email to