Skip to main content

Allocations and data transfer

Shared bridges, cached binding plans, and explicit policies reduce interop costs. Allocation depends on type, direction, engine, and call shape; not every call is allocation-free.

Reduce boundary crossings first​

Batch operations and cache delegates, type objects, and closures. Avoid repeated export lookups and fine-grained JS/CLR loops. Measure first binding/generic closing separately from steady-state execution.

Representation costs​

RepresentationCost or constraint
CLR wrapperIdentity and GC-root tracking
ByVal structCopy; managed references require safe writeback
JS Array / TablePer-element/member conversion and possible allocation
Bytes / to_bytesExplicit copies, not zero-copy
OpaqueBorrow valid only during a call; never across await
out tupleJS result array; nested results remain nested

WASM memory growth can invalidate old TypedArray views. Adapter view refresh does not authorize long-term retention of arbitrary addresses.

Measure on target​

Use Unity Profiler and the target JS tools for steady-state allocation, CPU, peak memory, and long-running GC. Distinguish Mono/IL2CPP and V8/platform VMs; record inputs, batch sizes, and warmup. Correctness validation is not a public performance ranking.

ABI, copy, and writeback rules take precedence over local allocation optimizations. Optimization must not change overload selection, views, or value semantics.