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

Improve BinaryPropertyListWriter performance #45

Closed qmfrederik closed 6 years ago

qmfrederik commented 6 years ago

This PR improves the performance of the BinaryPropertyListWriter by using a Dictionary<NSObject, int> to store the indices of binary objects instead of a Collection<NSObject>. It removes the need to do an IndexOf, which scans the entire list. That is a very expensive O(N) operation.

This results in a 97% performance improvement on Windows (i.e. 30 times as fast) and a 98% performance improvement on Linux.

qmfrederik commented 6 years ago

Windows

Before

Method Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
WriteLargePropertylistTest 1.831 s 0.0361 s 0.0721 s 53187.5000 375.0000 62.5000 319.66 MB

After

Method Mean Error StdDev Gen 0 Gen 1 Allocated
ReadLargePropertylistTest 1.587 ms 0.0335 ms 0.0755 ms 117.1875 54.6875 720.21 KB
qmfrederik commented 6 years ago

@claunia This one is ready to go I think 😄 . I'll then finish #38 and that would be a great starting point for a new release.

There may be a couple of follow up PRs the next couple of weeks but these changes already have a very big performance impact.

qmfrederik commented 6 years ago

OK, build is looking green again. The benchmarks which I added perform so badly on the master branch that they caused the Travis build to time out :)