Rutherther / NosSmooth

Nostale bot library written in C#. May describe the current state of the game/character from packets. Multiple sources available for capturing the packets from running game.
MIT License
6 stars 3 forks source link

Use stackalloc and Span for packet serialization #82

Closed Rutherther closed 1 year ago

Rutherther commented 1 year ago

Before (serialize used StringBuilder, allocations)

Method Mean Error StdDev
NosSmooth_In_Serialize 3,721.7 ns 59.86 ns 79.91 ns
NosSmooth_Fc_Serialize 2,826.8 ns 48.06 ns 49.35 ns

After (serialize uses Span and stackalloc)

Method Mean Error StdDev
NosSmooth_In_Serialize 1,083.2 ns 21.69 ns 61.18 ns
NosSmooth_Fc_Serialize 891.1 ns 17.42 ns 28.13 ns
Rutherther commented 1 year ago

And with allocation:

before:

Method Mean Error StdDev Median Gen0 Allocated
NosSmooth_In_Serialize 4,501.4 ns 89.18 ns 215.37 ns 4,475.0 ns 0.0305 2608 B
NosSmooth_Fc_Serialize 3,101.6 ns 61.24 ns 62.89 ns 3,118.7 ns 0.0229 1984 B
after: Method Mean Error StdDev Gen0 Allocated
NosSmooth_In_Serialize 987.5 ns 11.92 ns 10.56 ns 0.0076 648 B
NosSmooth_Fc_Serialize 862.3 ns 17.25 ns 49.50 ns 0.0067 576 B