Quick answer: Godot 4 C# function taking Godot.Collections.Array<T> by ref allocating per call? Marshaling boundary boxes - pass by value or convert to System.Array.

Hot path: pass array; profiler shows 1KB allocation per call.

Pass by value

Marshaling once; no per-call boxing. Faster for hot paths.

Or use System.Array internally

Convert at boundary; use native C# types inside. Manual marshalling but cheap.

Profile allocations

.NET memory profiler. Per-call allocations surface immediately.

“Cross-language marshalling has cost. The cost is real on hot paths.”

For hot paths in Godot C#, the marshalling cost is the dominant overhead. Profile; reduce; ship.

Related reading