Incrementally build a CompactEntityIndex without a temporary array of objects.
For 4.4M entities the intermediate EntityRef[] costs ~350MB (80 bytes/object).
This builder fills typed arrays directly during the scan, eliminating that spike.
Usage:
const builder = new CompactEntityIndexBuilder(estimatedCount);
for (const ref of tokenizer.scanEntitiesFast()) {
builder.add(ref.expressId, ref.type, ref.offset, ref.length);
}
const index = builder.build();
Incrementally build a CompactEntityIndex without a temporary array of objects.
For 4.4M entities the intermediate EntityRef[] costs ~350MB (80 bytes/object). This builder fills typed arrays directly during the scan, eliminating that spike.
Usage: const builder = new CompactEntityIndexBuilder(estimatedCount); for (const ref of tokenizer.scanEntitiesFast()) { builder.add(ref.expressId, ref.type, ref.offset, ref.length); } const index = builder.build();