Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

[].push.apply([], a) results in "Out of stack space" #521

Closed

Description

@alexlamsl
  • Version: 8.11.1
  • Platform: Windows 10 x64

test.js

var a = [];
for (var i = 65536; --i >= 0;) a.push(i);
[].push.apply([], a);

node runs to completion, whereas node-chakracore fails with:

$ node test.js
test.js:3
[].push.apply([], a);
^

Error: Out of stack space
   at Anonymous function (test.js:3:1)
   at Module.prototype._compile (module.js:652:5)
   at Module._extensions[.js] (module.js:663:3)
   at Module.prototype.load (module.js:565:3)
   at tryModuleLoad (module.js:505:5)
   at Module._load (module.js:497:3)
   at Module.runMain (module.js:693:3)
   at startup (bootstrap_node.js:189:9)
   at Anonymous function (bootstrap_node.js:613:3)

I have observed failures with shorter lengths than 65536, but they are not as reliably reproducible. While I appreciate this is a lot of parameters to pass on to Function.apply(), it is an efficient way to construct a large array, e.g. https://github.com/mishoo/UglifyJS2/blob/b5bab254ce2122a43e9ca0fdc757aecda7191576/test/mocha/parentheses.js#L93-L95

Activity

  1. MSLaguana commented on Apr 24, 2018

    @MSLaguana
    Contributor

    I'm curious why you use push rather than concat:

    var start = process.hrtime();
    var c = [1,2];
    for(let i = 0; i < 16; ++i) {c = [].concat.call(c,c)}
    console.log(process.hrtime(start))

    And actually, comparing with node-v8 on the sample in your mocha test, the concat version is faster in addition to using less stack.

  2. alexlamsl commented on Apr 26, 2018

    @alexlamsl
    Author

    I did push() instead of concat() to minimise memory allocation, though I haven't considered call() being faster than apply().

    Thanks for the workaround – will apply to mishoo/UglifyJS#3087

  3. alexlamsl commented on May 26, 2018

    @alexlamsl
    Author

    I shall close this since it's a special case and more to do with deficiencies of ChakraCore than this project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions