Why is the performance of creating a NodeJS object so bad if the number of details is more than 8?

I would like to know that there is a limitation in NodeJS when creating an object with more than 8 properties? I did a test test, and it seems that if an object has more than 8 properties, performance will be poor.

Test suite: https://github.com/icebob/js-perf-benchmark/blob/master/suites/properties.js (full copy at the end of the question)

Result:

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

The 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

:

"use strict";

let Benchmarkify = require("benchmarkify");
let benchmark = new Benchmarkify("Object properties").printHeader();

let bench = benchmark.createSuite("Create object with many properties");

// ----

bench.add("Create object with 1 prop", () => {
    let opts = {
        prop1: 5
    };
    return opts;
});

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;
});

bench.add("Create object with 20 prop", () => {
    let opts = {
        prop1: 5,
        prop2: "",
        prop3: false,
        prop4: 1,
        prop5: 0,
        prop6: null,
        prop7: "Hello",
        prop8: 12345,
        prop9: "asd",
        prop10: false,
        prop11: 5,
        prop12: "",
        prop13: false,
        prop14: 1,
        prop15: 0,
        prop16: null,
        prop17: "Hello",
        prop18: 12345,
        prop19: "asd",
        prop20: false
    };
    return opts;
});

bench.run();
+4
1

- .

v8 :

V8 FAST 8, .

- , .

, (, new X()): V8 ( / ). , - FAST / .


V8 http://jayconrod.com/posts/52/a-tour-of-v8-object-representation

, (, var a = {}) - , " "

8

, -

FAST, , .

+8

Source: https://habr.com/ru/post/1674675/


All Articles