Do a class invariants affect -release builds?

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at
Mon Dec 7 06:52:56 PST 2015

On 12/6/15 6:01 PM, Andrew LaChance wrote:
> On Saturday, 5 December 2015 at 23:27:31 UTC, Steven Schveighoffer wrote:
>> On 12/5/15 6:06 PM, Andrew LaChance wrote:
>>> I was reading a blog post here: which
>>> mentions:
>>> "Calls to the druntime invariant handler are emitted in release build
>>> also and there is no way to turn them off. Even if the class does not
>>> have any invariants the invariant handler will always be called, walk
>>> the class hirarchy and generate multiple cache misses without actually
>>> doing anything."
>>> I was curious if this was still true today (the post was written 3 years
>>> ago in Sept 2012).
>>> Thanks!
>> I don't remember that the invariant was ever called in release mode.
>> But maybe I'm not understanding the statement.
> I think what he was saying was that even in release mode, the druntime
> would keep the invariant "subsystem," but just wouldn't call the
> invariant handlers.  So even in release mode, the code to get a list of
> all handlers would happen, they just wouldn't be invoked.  Rather than
> completely ripping out the invariant system.

I don't think that's true. The invariant is called as part of function 

Using obj2asm, the code emitted for an empty class function is vastly 
larger without -release.


More information about the Digitalmars-d-learn mailing list