mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
Enable node:ffi by default in builds with FFI support. Keep --experimental-ffi as a compatibility no-op and --no-experimental-ffi as an opt-out. Loading the module still emits an experimental warning. Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: https://github.com/nodejs/node/pull/65475 Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
// Measures symbol resolution rather than call throughput. Creating a callable
|
|
// for a fast-eligible signature emits a native trampoline, so this benchmark
|
|
// covers the trampoline allocation path that the call benchmarks never reach.
|
|
//
|
|
// The `fast` variant is eligible for a generated trampoline; `slow` exceeds the
|
|
// x86_64 register budget and falls back, so it resolves without allocating one.
|
|
// Comparing the two isolates trampoline creation cost from the rest of symbol
|
|
// resolution.
|
|
|
|
const common = require('../common.js');
|
|
const { DynamicLibrary } = require('node:ffi');
|
|
const { libraryPath, ensureFixtureLibrary } = require('./common.js');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
signature: ['fast', 'slow'],
|
|
n: [1e3],
|
|
});
|
|
|
|
ensureFixtureLibrary();
|
|
|
|
const signatures = {
|
|
fast: { name: 'add_i32', return: 'i32', arguments: ['i32', 'i32'] },
|
|
slow: {
|
|
name: 'sum_8_i32',
|
|
return: 'i32',
|
|
arguments: ['i32', 'i32', 'i32', 'i32', 'i32', 'i32', 'i32', 'i32'],
|
|
},
|
|
};
|
|
|
|
function main({ n, signature }) {
|
|
const { name, ...definition } = signatures[signature];
|
|
const lib = new DynamicLibrary(libraryPath);
|
|
|
|
// Warm up one-time initialization (libffi setup, executable memory probe) so
|
|
// it is not attributed to the measured resolutions.
|
|
lib.getFunction(name, definition);
|
|
|
|
bench.start();
|
|
for (let i = 0; i < n; ++i)
|
|
lib.getFunction(name, definition);
|
|
bench.end(n);
|
|
|
|
lib.close();
|
|
}
|