You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
andClassC
, andClassB
inherits fromClassA
. IfClassC
doesn't inherit fromClassB
(in other forms, if nothing inherits fromClassB
) then we don't need the extra dispatch operations or checks. Thus makingClassB
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
Requirements
Comments
No response
The text was updated successfully, but these errors were encountered: