Files
node/lib
Trivikram Kamat bf2f995661 ffi: reuse the callable created per symbol
CreateFunction() ran on every getFunction() call, every getFunctions()
call, and every read of the functions accessor, each time emitting a
trampoline, allocating an FFIFunctionInfo, and on the SharedBuffer path
an ArrayBuffer. lib.functions.foo was therefore a different function on
each read, and calling through the accessor in a loop leaked a page per
iteration until GC: 20000 calls grew RSS by 58 MiB.

Cache the created callable per symbol in function_wrappers_, and
memoize the JS wrapper composed around it. Both entries are weak, so
dropping the last user reference still releases the wrapper and its
trampoline. The JS side stores a WeakRef because V8 can keep a raw
function alive after the wrapper is gone, and a strong value would pin
every wrapper for the lifetime of the library.

Signed-off-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com>
Assisted-by: claude:opus-5
PR-URL: https://github.com/nodejs/node/pull/64971
Fixes: https://github.com/nodejs/node/issues/64970
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
2026-08-09 16:18:33 -07:00
..
…
…
…
2026-07-05 08:04:44 +00:00
…
…
2026-08-06 09:25:51 +00:00
2026-04-05 10:12:21 +00:00
2026-06-21 19:42:03 +00:00
2026-05-31 12:49:51 -07:00
…
…
…
…
2026-07-25 23:56:46 -07:00
…
2026-02-21 16:30:23 +00:00
…
2026-04-01 10:09:41 +00:00
…
2026-04-26 19:36:36 +00:00
2026-05-23 18:43:31 +00:00