mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
V8 keeps objects created from `{ __proto__: null }` literals, and from
v8::Object::New() with names and values, in dictionary mode for their
whole life. The module loader created such objects on every require()
of a builtin and every import(), and kEmptyObject, the cached ESM
resolve results and the requests from getModuleRequests() were all
in dictionary mode as well.
Use classes with a null-prototype prototype for the per-call objects,
null the prototype of plain literals for the long-lived ones, and
build module requests from a DictionaryTemplate.
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/67552
Refs: https://adventures.nodeland.dev/archive/optimizing-objects-with-null-prototypes/
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
18 lines
357 B
JavaScript
18 lines
357 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common.js');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
prefix: ['', 'node:'],
|
|
n: [1e6],
|
|
});
|
|
|
|
function main({ prefix, n }) {
|
|
const ids = ['fs', 'path', 'util', 'events'].map((id) => `${prefix}${id}`);
|
|
bench.start();
|
|
for (let i = 0; i < n; i++) {
|
|
require(ids[i % ids.length]);
|
|
}
|
|
bench.end(n);
|
|
}
|