tags:

views:

85

answers:

1

My team is wrestling with the sealed class debate internally and I would like to simplify the debate down to a matter of design and get the performance myth off the debate agenda.

Can anyone post some code that demonstrates a performance boost introduced by declaring a class as sealed? At 20 million virtual method calls per second I cannot see much benefit, perhaps 1 or 2 milliseconds on 10 million iterations but even then I am not sure because the result jumps around. This applies to debug and release runs.

p.s. I follow some of the John Skeet received wisdom about the benefit of sealed class design, particularly when software is delivered across a team or org boundary and/or classes are packaged component style in an assembly.

+1  A: 

To my knowledge there is none. Sealed is there for a different reason - to block extensibility, which may be usefull / needed in a lot of cases. Performance optimization was not a goal here.

TomTom
... but if you think about the compiler: if your class is sealed, you know the address of a method you call on your class at compile time. If your class isn't sealed, you have to resolve the method at run-time because you might need to call an override. It's certainly going to be negligible, but I could see that there would be *some* difference.
Dan Puzey
Yes, but that sort of does not translate into real benefits, as the OP has pointed out. Architectural differences are / may be a lot more relevant.
TomTom