Skip to content

Something wrong with the implementation of the "promise.then" #3414

Description

@Daeren

Win 7 x64 | Node.js v4.2.1

Code:

var t = 1000 * 1000 * 1;

function fCookie(x, z) {
    return new Promise(resolve => resolve(x + z));
}

console.time("#1 | Promise");
while(t--) fCookie(1, 3).then(function(r) {});
console.timeEnd("#1 | Promise");

Results:

//-] Without: ".then"
//>  1m - 400ms - 20Mb RAM (nodejs Promise)
//>  1m - 300ms - 15Mb RAM (bluebird Promise)

//-] With: ".then"
//>  1m - 4899ms - 1.1Gb RAM (nodejs Promise) ~ (4x | 3x)
//>  1m - 1255ms - 370Mb RAM (bluebird Promise)

So a lot of memory, so slow ...

Activity

  1. thefourtheye commented on Oct 17, 2015

    @thefourtheye
    Contributor

    Most likely a v8 thing, as Node.js uses underlying v8's Promise implementation.

  2. added
    v8 engineIssues and PRs related to the V8 dependency.
    on Oct 17, 2015
  3. benjamingr commented on Oct 18, 2015

    @benjamingr
    Member

    Yes, native promises are slower and consume more memory than bluebird promises, this is a well known fact. I think the issue can be closed.

  4. Trott commented on Oct 18, 2015

    @Trott
    Member

    According to this from the v8 mailing list:

    This is a known problem. Several reasons:

    1. V8 promises haven't been optimised at all. It's on our agenda once our ES6 support is feature complete.
    2. V8 promises support various callback hooks into devtools, which cause a certain overhead.
    3. Alternative promise implementations tend to take shortcuts relative to the official ES6 semantics (e.g., goog.Promise.all you use below does not support subclassing correctly).

    We assume that (1) is the main factor, and will go away eventually, but due to the others some (hopefully minor) differences might remain.

    If you have further questions/concerns, I would recommend participating over there. (Promises aren't in Node core. They're supplied by v8.)

  5. added
    memoryIssues and PRs related to Node.js memory management or memory footprint.
    on Oct 18, 2015
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

    memoryIssues and PRs related to Node.js memory management or memory footprint.v8 engineIssues and PRs related to the V8 dependency.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions