pieterderycke / Jace

Jace.NET is a calculation engine for the .NET platform.
MIT License
436 stars 94 forks source link

Fix performance issue with CaseSensitivity enabled #76

Open aviita opened 3 years ago

aviita commented 3 years ago

When CaseSensitive is set to true from JaceOptions, performance should be significantly better than without case sensitivity. Case sensitivity setting was not passed to FunctionRegistry and ConstantRegistry constructors, which caused them to do extra lower case conversions in case variable dictionary was passed to the formula. Fixes issue #75.

New benchmark was created to verify the fix. Benchmark needs to have variables which are provided to CalculationEngine.Calculate(), so VerifyVariableNames() gets called, which causes the extra calls to ToLowerFast().

Below results show ~200 ms improvement when Case Sensitive is true. Results table was created by running benchmark separately with and without fix and copying results to one table.

Engine Case Sensitive Formula Total Iteration Total Duration (fix) Total Duration (no fix)
Interpreted False something2 - (var1 + var2 * 3)/(2+3) 1000000 00:00:01.6005267 00:00:01.5919016
Interpreted True something2 - (var1 + var2 * 3)/(2+3) 1000000 00:00:00.6069845 00:00:00.8390435
Compiled False something2 - (var1 + var2 * 3)/(2+3) 1000000 00:00:01.5865326 00:00:01.5770084
Compiled True something2 - (var1 + var2 * 3)/(2+3) 1000000 00:00:00.5930012 00:00:00.8189981

Additionally:

aviita commented 3 years ago

@pieterderycke Any chance of getting this merged?