Description
Description
Related to #4180.
Unsealed classes introduce extra overhead for running each virtual method/type checks because the compiler/JIT has to do extra inheritance checks.
For example, there are three non-sealed classes called ClassA
, ClassB
and ClassC
, and ClassB
inherits from ClassA
. If ClassC
doesn't inherit from ClassB
(in other forms, if nothing inherits from ClassB
) then we don't need the extra dispatch operations or checks. Thus making ClassB
sealed removes that overhead when calling virtual methods or doing type checks.
See https://devblogs.microsoft.com/dotnet/performance-improvements-in-net-6/#peanut-butter for more in-depth details.
Concerned code
Most C# source files in the entire app solution.
Gains
- Slightly better performance.
Requirements
- Make classes that don't need to be inherited sealed.
Comments
No response
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
✅ Done