When crafting custom attributes, Microsoft advises sealing them to enhance performance. In my coding standards manual, I advocate sealing any class not intended for inheritance, primarily to convey the class’s intent. However, do sealing attributes actually result in improved performance?
Benchmark Results
These benchmark tests demonstrate that the performance difference between sealing and not sealing attributes is negligible, with both options resulting in a memory allocation of 24 bytes.
I maintain my recommendation: any class not intended for inheritance should be sealed for robust class design.
This is how I have it setup checking for this issue in my EditorConfig: dotnet_diagnostic.CA1813.severity = suggestion
Pick up any books by David McCarter by going to Amazon.com: http://bit.ly/RockYourCodeBooks
Make a one-time donation
Make a monthly donation
Make a yearly donation
Choose an amount
Or enter a custom amount
Your contribution is appreciated.
Your contribution is appreciated.
Your contribution is appreciated.
DonateDonate monthlyDonate yearlyIf 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 preproduced in any way without express permission from David McCarter.