duktape icon indicating copy to clipboard operation
duktape copied to clipboard

A possible performance problem about Array.prototype.unshift

Open YaoHouyou opened this issue 3 years ago • 1 comments

Description

When calling Array.prototype.unshift, the execution speed of duktape is much slower than other JavaScript engines. In terms of memory allocation strategy, can duktape be optimized?

Version

2.6.0

Testcase

var foo = function(v) {
    for(var t = [], r = 0; r < 10000; r++) {
        t.unshift(1);
    }
}
var res = foo();

Execution time

duktape: 2572ms JerryScript: 29ms XS: 79ms

Build setp

make -f Makefile.cmdline

CPU

Intel(R) Core(TM) i9-9940X CPU @ 3.30GHzz

YaoHouyou avatar Mar 04 '21 05:03 YaoHouyou

Array methods must work on Array instances but also on any object that is "Array-like". Some functions have a fast path for the Array case and a slow path for the generic case (e.g. push()). At present unshift() has no fast path so it falls back to very generic processing which probably explains the performance.

svaarala avatar Mar 04 '21 20:03 svaarala