Files
Donghoon Kang 4c14b9f58a ffi: add getFunction cache-miss benchmark
The existing get-function benchmark reuses the callable cached during
warmup, so it no longer measures trampoline creation.

Add a cache-miss benchmark that resolves a function once per library
instance. Construct the instances before timing to exclude library
loading while including symbol resolution, signature preparation,
and callable creation.

Update the existing benchmark comments to describe cache-hit lookups.

Signed-off-by: HoonDongKang <d159123@naver.com>
Assisted-by: Codex:Astra-medium
PR-URL: https://github.com/nodejs/node/pull/66456
Refs: https://github.com/nodejs/node/pull/64969
Refs: https://github.com/nodejs/node/pull/64971
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
2026-10-20 02:50:14 +00:00

42 lines
1.2 KiB
JavaScript

'use strict';
// Measures repeated getFunction() calls with a cached callable rather than
// call throughput. The warmup populates the cache for the measured symbol.
// See get-function-cache-miss.js for first-time resolution, including trampoline
// creation for fast-eligible signatures on supported platforms.
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);
// Populate the callable cache before measuring repeated lookups.
lib.getFunction(name, definition);
bench.start();
for (let i = 0; i < n; ++i)
lib.getFunction(name, definition);
bench.end(n);
lib.close();
}