ninject / Ninject

the ninja of .net dependency injectors
http://ninject.org/
Other
2.68k stars 529 forks source link

Improve performance and reduce allocations for request and binding parameters #334

Closed drieseng closed 5 years ago

drieseng commented 5 years ago

Improves performance and reduce allocations for request and binding parameters.

Instead of lazily determining the parameters of a Request or Context, we now perform this action upfront in the .ctor.

Of course this means that the .ctor is sometimes less performant, but in those cases the gains are much higher when effectively iterating the parameters.

Request:

Method Version Mean Error StdDev Gen 0/1k Op Gen 1/1k Op Gen 2/1k Op Allocated Memory/Op
Constructor_ServiceAndConstraintAndParametersAndScopeCallbackAndIsOptionalAndIsUnique_ParameterEmpty PR 54.35 ns 0.5168 ns 0.4316 ns 0.0304 - - 128 B
Constructor_ServiceAndConstraintAndParametersAndScopeCallbackAndIsOptionalAndIsUnique_ParameterEmpty master 54.07 ns 0.2300 ns 0.2039 ns 0.0304 - - 128 B
Constructor_ServiceAndConstraintAndParametersAndScopeCallbackAndIsOptionalAndIsUnique_MixOfParametersWithShouldInheritSetToTrueAndFalse PR 54.23 ns 0.5680 ns 0.5313 ns 0.0304 - - 128 B
Constructor_ServiceAndConstraintAndParametersAndScopeCallbackAndIsOptionalAndIsUnique_MixOfParametersWithShouldInheritSetToTrueAndFalse master 54.28 ns 0.5449 ns 0.5097 ns 0.0304 - - 128 B
Constructor_ParentContextAndServiceAndTargetAndScopeCallback_ParentContextWithRequestAndBindingParameters PR 554.80 ns 3.5535 ns 3.1501 ns 0.0696 - - 296 B
Constructor_ParentContextAndServiceAndTargetAndScopeCallback_ParentContextWithRequestAndBindingParameters master 230.25 ns 1.2412 ns 1.0365 ns 0.0529 - - 224 B
Constructor_ParentContextAndServiceAndTargetAndScopeCallback_ParentContextWithoutRequestAndBindingParameters PR 201.68 ns 0.7061 ns 0.5513 ns 0.0401 - - 168 B
Constructor_ParentContextAndServiceAndTargetAndScopeCallback_ParentContextWithoutRequestAndBindingParameters master 229.40 ns 0.4477 ns 0.3969 ns 0.0529 - - 224 B
Parameters_RootRequest_ParameterEmpty PR 37.04 ns 0.4033 ns 0.3575 ns - - - -
Parameters_RootRequest_ParameterEmpty master 39.52 ns 0.0463 ns 0.0433 ns - - - -
Parameters_RootRequest_MixOfParametersWithShouldInheritSetToTrueAndFalse PR 147.06 ns 0.3039 ns 0.2694 ns 0.0093 - - 40 B
Parameters_RootRequest_MixOfParametersWithShouldInheritSetToTrueAndFalse master 147.14 ns 0.3394 ns 0.3175 ns 0.0093 - - 40 B
Parameters_ChildRequest_ParentContextWithRequestAndBindingParameters PR 148.31 ns 1.8773 ns 1.5676 ns 0.0093 - - 40 B
Parameters_ChildRequest_ParentContextWithRequestAndBindingParameters master 1,691.39 ns 3.3716 ns 2.8154 ns 0.1049 - - 448 B
Parameters_ChildRequest_ParentContextWithoutRequestAndBindingParameters PR 36.54 ns 0.2082 ns 0.1846 ns - - - -
Parameters_ChildRequest_ParentContextWithoutRequestAndBindingParameters master 244.30 ns 1.0939 ns 0.9697 ns 0.0396 - - 168 B

Context:

Method Version Mean Error StdDev Gen 0/1k Op Gen 1/1k Op Gen 2/1k Op Allocated Memory/Op
Constructor_RequestWithParameters PR 113.72 ns 0.9577 ns 0.8489 ns 0.0284 - - 120 B
Constructor_RequestWithParameters master 131.7 ns 1.3532 ns 1.2658 ns 0.0455 - - 192 B
Constructor_BindingWithParameters PR 204.26 ns 1.3454 ns 1.2584 ns 0.0401 - - 168 B
Constructor_BindingWithParameters master 131.1 ns 1.6992 ns 1.5894 ns 0.0455 - - 192 B
Constructor_RequestAndBindingWithParameters PR 243.79 ns 1.3062 ns 1.1579 ns 0.0453 - - 192 B
Constructor_RequestAndBindingWithParameters master 130.3 ns 0.6916 ns 0.6469 ns 0.0455 - - 192 B
Constructor_RequestAndBindingWithoutParameters PR 112.53 ns 0.3945 ns 0.3497 ns 0.0284 - - 120 B
Constructor_RequestAndBindingWithoutParameters master 131.6 ns 1.2320 ns 1.1524 ns 0.0455 - - 192 B
Parameters_RequestWithParameters PR 119.60 ns 0.3463 ns 0.3070 ns 0.0093 - - 40 B
Parameters_RequestWithParameters master 741.2 ns 5.1511 ns 4.8183 ns 0.0925 - - 392 B
Parameters_RequestAndBindingWithParameters PR 142.39 ns 0.6915 ns 0.6468 ns 0.0074 - - 32 B
Parameters_RequestAndBindingWithParameters master 1,153.6 ns 6.3628 ns 5.6404 ns 0.0916 - - 392 B
Parameters_RequestAndBindingWithoutParameters PR 28.86 ns 0.0360 ns 0.0319 ns - - - -
Parameters_RequestAndBindingWithoutParameters master 169.5 ns 0.6268 ns 0.5557 ns 0.0267 - - 112 B
Parameters_BindingWithParameters PR 92.80 ns 0.1169 ns 0.0976 ns 0.0075 - - 32 B
Parameters_BindingWithParameters master 713.4 ns 7.5029 ns 7.0182 ns 0.0830 - - 352 B