TGViewer
Everyday Unity Everyday Unity @everydayunity · 1.18K subscribers
Post #1961 192
Performance traps of ref locals and ref returns in C#

Be cautious with ref returns because they can break encapsulation.
Be cautious with readonly ref returns because they’re more performant only for readonly structs and could cause performance issues for regular structs.
Be cautious with readonly ref locals because they also could cause performance issues for non-readonly structs causing defensive copy each time the variable is used.

https://devblogs.microsoft.com/premier-developer/performance-traps-of-ref-locals-and-ref-returns-in-c/

#struct #readonly #ref #performance
Microsoft News Performance traps of ref locals and ref returns in C# The C# language from the very first version supported passing arguments by value or by reference. But before C# 7 the C# compiler supported only one way of returning a value from a method (or a property) – returning by value.
  • 👍 2
More from @everydayunity
  1. Oct 2, 2026Customize Claude Code with mods in TypeScript You can now make mods for Claude cli and app…
  2. Sep 24, 2026Now you can change the effort mid session in new Claude. So the advice about caching from…
  3. Sep 24, 2026We were wondering in the comments what Claude reset does. Here is the answer https://www.r…
  4. Sep 22, 2026Introducing GPT‑6 Sol and Luna And better & cheaper sol and luna as an immediate response…
  5. Sep 22, 2026Introducing Claude Opus 5.5 \ Anthropic Cost and speed. Opus 5.5 requires less compute to…
  6. Sep 21, 2026Claude Code effort level and model selection effort means more than just "thinking time."…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →