martindevans / Cassowary.net

An incremental constraint solver for .NET
http://jozilla.net/Software/CassowaryNet
GNU Lesser General Public License v2.1
3 stars 5 forks source link

Performance improvements #10

Open krypt-lynx opened 4 years ago

krypt-lynx commented 4 years ago

It is something I did in my branch, but it heavily altered, so, I can't just make a merge request:

I used AddDel test as performance test:

nCns = 5000; nVars = 6000; nResolves = 1; Strong constraints 12 sec before changes

You can replace ClDouble with double. (in some methods you need to pass it by ref to make it work) 8 sec after that change

overriding ClAbstraitVariable's GtHashCode and Equal implementations with ones returning int variable id (according to profiler lib spends 97% of time looking in dictionaries with ClAbstraitVariable as a key) 7 sec

Replacing rows Dictionary with sparse array: 4 sec

Sparse array implementation I used is not scaleable unfortunately. It requires a dedicated field in key for each array. Using sparse array for columns have no effect on performance. The implementation I used: https://github.com/krypt-lynx/Cassowary.net/blob/master/Cassowary/ClSparseArray.cs