Simple performance improvement

Mar 21, 2008 at 11:05 PM
Edited Mar 21, 2008 at 11:40 PM
Hi all,

The PolicyKey struct in PolicyList does not override Equals or GetHashCode, and consequently does reflection (default FX implementation), which adds some significant overhead when constructing lots of transient instances.

If I call Resolve for a transient instance 10000 times, without the overrides on PolicyList, it takes about 300ms, with overrides takes 100ms! That's a 3x improvement for this (admittedly conjured) test.

I discovered this, as I was testing / profiling OB1 to OB2 performance differences (as close as possible), and the same 10000 instances take about 1,800ms on OB1. So with a little change, it could be 18x faster than OB1 in this scenario.

Cheers,

Stu
Mar 22, 2008 at 2:25 AM

scarnie wrote:
Hi all,

The PolicyKey struct in PolicyList does not override Equals or GetHashCode, and consequently does reflection (default FX implementation), which adds some significant overhead when constructing lots of transient instances.

If I call Resolve for a transient instance 10000 times, without the overrides on PolicyList, it takes about 300ms, with overrides takes 100ms! That's a 3x improvement for this (admittedly conjured) test.

I discovered this, as I was testing / profiling OB1 to OB2 performance differences (as close as possible), and the same 10000 instances take about 1,800ms on OB1. So with a little change, it could be 18x faster than OB1 in this scenario.

Cheers,

Stu


Wow, that's a fantastic catch. Initial experiments on my end bear out your conclusion. Thank you so much for finding this!

-Chris
Mar 22, 2008 at 11:19 PM


ctavares wrote:

scarnie wrote:
Hi all,

The PolicyKey struct in PolicyList does not override Equals or GetHashCode, and consequently does reflection (default FX implementation), which adds some significant overhead when constructing lots of transient instances.

If I call Resolve for a transient instance 10000 times, without the overrides on PolicyList, it takes about 300ms, with overrides takes 100ms! That's a 3x improvement for this (admittedly conjured) test.

I discovered this, as I was testing / profiling OB1 to OB2 performance differences (as close as possible), and the same 10000 instances take about 1,800ms on OB1. So with a little change, it could be 18x faster than OB1 in this scenario.

Cheers,

Stu


Wow, that's a fantastic catch. Initial experiments on my end bear out your conclusion. Thank you so much for finding this!

-Chris



No worries at all. I was running under AQTime and found another fix that doubled the performance again, so we're down to about 50ms for 10,000 objects :-) It is related to using a dictionary for the stages in the StagedStrategyChain<TStageEnum> type. Changing this to an array dropped the time from just over 100ms down to just over 50ms, therefore seems a worthy update too.

Cheers,

Stu