Does using in
ever result in worse performance for structs?
#6054
-
Specifically for structs with multiple fields. I ask because I'm working on a game and I'm passing around a lot of |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
This is not a csharplang question. This is a perf question which will be affected by many factors (including basic things like what runtime/not you're using). The only way to answer this is to measure. Note: in practice 'in' can absolutely make things slower as it may just be faster to copy something and use it directly versus going through a reference. But it will depend on many factors, and profiling it's the only way to answer. |
Beta Was this translation helpful? Give feedback.
-
There are many cases, even with multiple fields, where Typically:
There is various nuance and other considerations here. The number of parameters you're passing, the platform or architecture you're targeting, the calling convention of the method, and more can all come into play and drive things in a different direction. |
Beta Was this translation helpful? Give feedback.
This is not a csharplang question. This is a perf question which will be affected by many factors (including basic things like what runtime/not you're using). The only way to answer this is to measure.
Note: in practice 'in' can absolutely make things slower as it may just be faster to copy something and use it directly versus going through a reference. But it will depend on many factors, and profiling it's the only way to answer.