Skip to content
This repository was archived by the owner on Jun 20, 2019. It is now read-only.

Conversation

ibuclaw
Copy link
Member

@ibuclaw ibuclaw commented Aug 12, 2015

This is an interesting optimization that turns:

if (this != 0B)
  {
    _D9invariant12_d_invariantFC6ObjectZv (this);
  }

Into:

  if (this != 0B)
    {
      if (**(struct TypeInfo_Class * * *) this == (struct TypeInfo_Class *) &MyClass.__Class)
        {
          (void) 0;
        }
      else
        {
          _D9invariant12_d_invariantFC6ObjectZv (this);
        }
    }

If the given MyClass object has no invariants found in it's vtable.

In some contrived benchmarks, I found this to achieve 2% better runtime results in non-release builds vs. turning off invariants altogether with -fno-invariants (with -O2, I should try non-optimized builds too).

Just waiting to here back if there are any thoughts in the community on this, but I can't think of a problem on my end.

@ibuclaw
Copy link
Member Author

ibuclaw commented Aug 12, 2015

Discussion here: http://forum.dlang.org/post/[email protected]

@dnadlinger
Copy link

Do you handle static arrays correctly?

@ibuclaw
Copy link
Member Author

ibuclaw commented Aug 12, 2015

@klickverbot - Unless that's a recent thing. No. The virtual invariant calls are created in the frontend (see func.c for addPreInvariant/addPostInvariant)

@ibuclaw
Copy link
Member Author

ibuclaw commented Aug 12, 2015

Unless you mean:

NoInvariantClass[42] arr;
assert(arr[0]);

Which will do a test for classinfo equality before calling _d_invariant

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants