What are the performance implications of using pointers versus values in function arguments?
Last updated
Passing by value copies the whole struct: cheap for small types and keeps data on the stack (good locality, no GC work), but expensive for large structs.
Passing a pointer copies only an address and allows mutation, but escape analysis may move the value to the heap, adding GC pressure and dereference cost.
Pass small values by value and large structs (or ones needing mutation) by pointer. Profile before optimizing.