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

Only call class invariant if one provably exists in any base classes#132

Open
ibuclaw wants to merge 1 commit into
D-Programming-GDC:masterfrom
ibuclaw:inv_optimisation
Open

Only call class invariant if one provably exists in any base classes#132
ibuclaw wants to merge 1 commit into
D-Programming-GDC:masterfrom
ibuclaw:inv_optimisation

Conversation

@ibuclaw

@ibuclaw ibuclaw commented Aug 12, 2015

Copy link
Copy Markdown
Member

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

ibuclaw commented Aug 12, 2015

Copy link
Copy Markdown
Member Author

@dnadlinger

Copy link
Copy Markdown

Do you handle static arrays correctly?

@ibuclaw

ibuclaw commented Aug 12, 2015

Copy link
Copy Markdown
Member Author

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

@ibuclaw

ibuclaw commented Aug 12, 2015

Copy link
Copy Markdown
Member Author

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