General Performance: Performance Impact of Sealing Attributes

Microsoft historically recommended sealing attributes for potential performance benefits. In my coding standards book, I advocate sealing any class not intended for inheritance, primarily to communicate the class’s intent and uphold proper OOP design principles. However, benchmarks show that sealing attributes does not provide a meaningful performance advantage.

Performance Breakdown

These benchmark results demonstrate that the non-sealed Attribute is slightly faster.

When I set up my EditorConfig to check for this issue, it looks like this:
dotnet_diagnostic.CA1813.severity = suggestion

I maintain my recommendation: any class not intended for inheritance should be sealed for robust class design.

Pick up any books by David McCarter by going to Amazon.com: http://bit.ly/RockYourCodeBooks

One-Time
Monthly
Yearly

Make a one-time donation

Make a monthly donation

Make a yearly donation

Choose an amount

$5.00
$15.00
$100.00
$5.00
$15.00
$100.00
$5.00
$15.00
$100.00

Or enter a custom amount

$

Your contribution is appreciated.

Your contribution is appreciated.

Your contribution is appreciated.

DonateDonate monthlyDonate yearly

If you liked this article, please buy David a cup of Coffee by going here: https://www.buymeacoffee.com/dotnetdave

© The information in this article is copywritten and cannot be reproduced in any way without express permission from David McCarter.


Discover more from dotNetTips.com

Subscribe to get the latest posts sent to your email.

Leave a Reply