This PR reworks the incoming IRC message handler by reducing GC pressure caused by unnecessary allocations.
The message handler could sometimes receive multiple IRC messages in a single raw message and was relying string-based splitting in order to be able to deconstruct singular IRC messages. This at the cost of short-lived string allocations and array allocations.
The new approach is span-based. This means that we create new ReadOnlySpan<char> wrappers that still point to the same memory block under the hood, given that those wrappers are readonly ref struct's, they're much lighter on the GC than the old approach. It also makes sense to use the new approach as the IrcExtensions.ParseIrcMessage(...) method was already using those under the hood.
Other than having reduced GC pressure, it became overall faster, as can be seen in the resultset below.
This PR reworks the incoming IRC message handler by reducing GC pressure caused by unnecessary allocations. The message handler could sometimes receive multiple IRC messages in a single raw message and was relying string-based splitting in order to be able to deconstruct singular IRC messages. This at the cost of short-lived string allocations and array allocations.
The new approach is span-based. This means that we create new
ReadOnlySpan<char>
wrappers that still point to the same memory block under the hood, given that those wrappers arereadonly ref struct
's, they're much lighter on the GC than the old approach. It also makes sense to use the new approach as theIrcExtensions.ParseIrcMessage(...)
method was already using those under the hood.Other than having reduced GC pressure, it became overall faster, as can be seen in the resultset below.
BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19044.1526 (21H2) AMD Ryzen 9 3900X, 1 CPU, 24 logical and 12 physical cores [Host] : .NET Framework 4.8 (4.8.4470.0), X64 RyuJIT Job-CIRMVA : .NET 5.0.14 (5.0.1422.5710), X64 RyuJIT Job-NVAYXH : .NET 6.0.2 (6.0.222.6406), X64 RyuJIT Job-ZSFKTD : .NET Framework 4.8 (4.8.4470.0), X64 RyuJIT Job-XTWDPN : Mono 5.11.0 (Visual Studio), X86 Job-UGEEKR : Mono 6.13.0 (Visual Studio), X86 Job-LJOXDK : Mono 6.13.0 (Visual Studio), X86