#36894·deno

Node-API finalizer deregistration is quadratic in the number of collected objects

Author: wryanzimmermanCreated Sep 24, 2026Updated Sep 24, 2026

Version: Deno 2.9.7 on M3 Max MBP 128gb

While refactoring a project from nodeJS to Deno, I hit a performance issue with @duckdb/node-api, where the same implementation was 10-100 times slower on Deno with real-world data.

Deregistering node-api finalizers is quadratic in deno, whereas node scales linearly. DuckDB creates externals with finalizers per Value, Vector, and DataChunk, so it hits this case pretty hard.

I made a minimum working example here just creating externals with finalizers, dropping them, and forcing GC: https://github.com/wryanzimmerman/deno-napi-wrap-repro

The output from that example:

bash
# node v24.21.0
node --expose-gc minimal.ts;
Average over 10 runs
n=10000 3.2 ms
n=20000 3.6 ms
n=40000 5.8 ms
n=80000 12.2 ms
Total time 247.2 ms

# deno 2.9.7 (stable, release, aarch64-apple-darwin)
deno run --allow-ffi --allow-read --v8-flags=--expose-gc minimal.ts;
Average over 10 runs
n=10000 60.8 ms
n=20000 239.9 ms
n=40000 923.1 ms
n=80000 3870.0 ms
Total time 50937.2 ms

I have a potential fix working locally, just a switch from Vec to BTreeMap, I'll open a PR with a proposed solution.