Wednesday, 12 April 2017

Why so bad the performance of the NodeJS object creation if num of props greater than 8?

I would like to know that there are any limit in NodeJS when create an object which has more than 8 properties? I made a benchmark test and it seems if the object has more than 8 properties, the performance will be bad.

Test suite: https://github.com/icebob/js-perf-benchmark/blob/master/suites/properties.js

The result:

  • Create object with 1 prop 0% (62,695,620 rps) (avg: 15ns)
  • Create object with 8 prop -31.95% (42,662,752 rps) (avg: 23ns)
  • Create object with 9 prop -95.79% (2,640,046 rps) (avg: 378ns)

Code:

bench.add("Create object with 8 prop", () => {
    let opts = {
        prop1: 5,
        prop2: "",
        prop3: false,
        prop4: 1,
        prop5: 0,
        prop6: null,
        prop7: "Hello",
        prop8: 12345
    };
    return opts;
});

bench.add("Create object with 9 prop", () => {
    let opts = {
        prop1: 5,
        prop2: "",
        prop3: false,
        prop4: 1,
        prop5: 0,
        prop6: null,
        prop7: "Hello",
        prop8: 12345,
        prop9: "asd"
    };
    return opts;
});

Environment:

  • Windows_NT 6.1.7601 x64
  • Node.JS: 6.9.5
  • V8: 5.1.281.89
  • Intel(R) Core(TM) i5-2400 CPU @ 3.10GHz × 4


via Icebob

No comments:

Post a Comment