N-API: per-item JS callbacks dominate large tree loads; return column arrays instead
A native addon that walked about 80K records and called a JS callback once per record (onVar.Call) spent over half of an index build in that loop. The time went to per-call overhead and allocation, not I/O: each call created 4 fresh JS strings (one was a scope path rebuilt for every record) and 5 numbers, and the JS side then ran a regex, a template string, object creation and 2-3 Map sets per record.
Better shape: - One batched call that returns columns: a scope-path table plus an index per record, an array of name strings, and Int32Array/Float64Array for the numeric fields. - Build the JS lookup maps lazily, only when search actually needs them. - Gate the change on field-by-field equality with the old index, and on time-to-first-data as well as call latency.
Rule of thumb: with tens of thousands of items, crossing N-API once per item costs more than the native work itself.