claunia / plist-cil

C#/.NET parser for Apple and GnuStep Property List (aka plist), based on Java's dd-plist
Other
54 stars 17 forks source link

Use Span.Slice instead of creating new arrays #40

Closed qmfrederik closed 6 years ago

qmfrederik commented 6 years ago

A lot of code in the BinaryPropertyListParser works with sections of arrays. Instead of creating a new array and copying that data to the new array, we can now use Span.Slice, which reduces a lot of allocations and improves performance.

qmfrederik commented 6 years ago

~30% performance improvement on Windows and ~20% performance improvement on Linux:

Windows

Before

Method Mean Error StdDev Gen 0 Gen 1 Allocated
ReadLargePropertylistTest 4.211 ms 0.0835 ms 0.1706 ms 304.6875 148.4375 1.84 MB

After

Method Mean Error StdDev Gen 0 Gen 1 Allocated
ReadLargePropertylistTest 2.943 ms 0.0560 ms 0.1206 ms 195.3125 93.7500 1.18 MB

Linux

Before

Method Mean Error StdDev Gen 0 Gen 1 Allocated
ReadLargePropertylistTest 4.164 ms 0.1006 ms 0.1410 ms 296.8750 148.4375 1.84 MB

After

Method Mean Error StdDev Gen 0 Gen 1 Allocated
ReadLargePropertylistTest 5.224 ms 0.0521 ms 0.0487 ms 187.5000 93.7500 1.18 MB