chriseldredge / Lucene.Net.Linq

LINQ provider to run native queries on a Lucene.Net index
Other
151 stars 66 forks source link

Review of usage of reflection #91

Closed khalidsalomao closed 8 years ago

khalidsalomao commented 9 years ago

Review to remove the usage of PropertyInfo.GetValue and PropertyInfo.SetValue in favor of a compiled methods by using Lambda Expression - a much faster way of dealing with reflection to get and set values. Also use StringComparer.Ordinal for dictionary hash function with is faster than the default.

chriseldredge commented 9 years ago

Do you have any bencnmarks that give some idea of how much better performance is with these changes?

The changes look pretty straight forward to me. Thanks for the submission.

khalidsalomao commented 9 years ago

The compiled getters and setters methods tends to be 10-15X faster.

In a quick and dirty benchmark with 5.000.000 iterations: Reflection took 2.610 ms Compiled method took 168 ms

Here is the code that you can open in LinqPad and test it! https://gist.github.com/khalidsalomao/facf4e1f5d61523dbd14