If you process strings heavily, Span<T> is a silent performance killer… in a good way.
Daily micro-tips for C#, SQL, performance, and scalable backend engineering.
If you process strings heavily, Span<T> is a silent performance killer… in a good way.
ReadOnlySpan<char> input = "order:12345".AsSpan();
var idPart = input.Slice(input.IndexOf(':') + 1);
int id = int.Parse(idPart);
Why this is powerful:
No substring allocations
No temporary strings
Works directly on memory
When to use it:
Parsing, slicing, validation, protocol handling.
When NOT to:
Async methods (unless carefully scoped).
This is how modern .NET hits native-level performance.