Vogen icon indicating copy to clipboard operation
Vogen copied to clipboard

Use `ThrowHelper` for exceptions

Open SteveDunn opened this issue 3 years ago • 8 comments

SteveDunn avatar Jan 04 '22 16:01 SteveDunn

I'm still looking at this one, although I haven't been able to find a suitable bit of code that I can benchmark (in benchmark.net) that demonstrates any speed increase.

SteveDunn avatar Feb 12 '22 16:02 SteveDunn

I'm still looking at this one, although I haven't been able to find a suitable bit of code that I can benchmark (in benchmark.net) that demonstrates any speed increase.

Profiling this is quite tricky, although there are performance gains to be had, so this item should be implemented.

SteveDunn avatar Jun 18 '22 12:06 SteveDunn

@SteveDunn What's the purpose for this? Maintainability or performance?

Herdo avatar Aug 29 '22 18:08 Herdo

Performance- using a helper method improves the rendered code from JIT.

https://docs.microsoft.com/en-us/windows/communitytoolkit/developer-tools/throwhelper#technical-details

viceroypenguin avatar Aug 29 '22 19:08 viceroypenguin

@viceroypenguin 👍 The ThrowHelper methods from CommunityToolkit.Diagnostics would only be used for the system exceptions then. Is that the only purpose, or should the ValueObjectValidationException receive a wrapper method as well, to benefit from the performance benefits?

Herdo avatar Aug 29 '22 20:08 Herdo

Yes, other exceptions should be wrapped separately with a similar helper class to benefit from similar performance optimizations. All exceptions receive these optimizations, not just this library or the system exceptions - it's just that the system ones are the ones that make sense to put into CommunityToolkit.Diagnostics. Whether @SteveDunn wants to add a dependency to CommunityToolkit.Diagnostics or copy the relevant exceptions independently for Vogen is up to him.

viceroypenguin avatar Aug 29 '22 20:08 viceroypenguin