optim: mark a few classes final #10809

Open
wants to merge 2 commits into
from

Conversation

Projects
None yet
8 participants
Member

theuni commented Jul 12, 2017

Using gcc's -Wsuggest-final-types and lto, I identified a few easy devirtualization wins:

wallet/wallet.h:651:7: warning: Declaring type 'struct CWallet' final would enable devirtualization of 26 calls [-Wsuggest-final-types]

coins.h:201:7: warning: Declaring type 'struct CCoinsViewCache' final would enable devirtualization of 13 calls [-Wsuggest-final-types]

txdb.h:67:7: warning: Declaring type 'struct CCoinsViewDB' final would enable devirtualization of 5 calls [-Wsuggest-final-types]

zmq/zmqnotificationinterface.h:16:7: warning: Declaring type 'struct CZMQNotificationInterface' final would enable devirtualization of 4 calls [-Wsuggest-final-types]

httpserver.cpp:42:7: warning: Declaring type 'struct HTTPWorkItem' final would enable devirtualization of 2 calls [-Wsuggest-final-types]

test/coins_tests.cpp:74:7: error: cannot derive from ‘final’ base ‘CCoinsViewCache’ in derived type ‘{anonymous}::CCoinsViewCacheTest’ class CCoinsViewCacheTest : public CCoinsViewCache

Owner

sipa commented Jul 12, 2017

test/coins_tests.cpp:74:7: error: cannot derive from ‘final’ base ‘CCoinsViewCache’ in derived type ‘{anonymous}::CCoinsViewCacheTest’ class CCoinsViewCacheTest : public CCoinsViewCache

You can fix that by renaming the existing CCoinsViewCache to a non-final CCoinsViewCacheBase, and have CCoinsViewCache become a final subclass of that with no implementation except a constructor. Then CCoinsViewCacheTest can become another subclass of CCoinsViewCacheBase.

Contributor

practicalswift commented Jul 17, 2017

@theuni Two more devirtualization opportunities (from closed PR #10847):

  • Declaring CCoinsViewErrorCatcher final enables devirtualization of two calls
  • Declaring CReserveKey final enables devirtualization of one call
Member

theuni commented Jul 17, 2017

@practicalswift I'll pull in the other two, but I think we should drop the CCoinsViewCache one. The inheritance there is hard enough to follow already.

Contributor

practicalswift commented Jul 17, 2017

@theuni Sounds great! :-)

theuni and others added some commits Jul 12, 2017

@theuni theuni optim: mark a few classes final 9a1675e
@practicalswift @theuni practicalswift Enable devirtualization opportunities by using the final specifier (C…
…++11)

* Declaring CCoinsViewErrorCatcher final enables devirtualization of two calls
* Declaring CReserveKey final enables devirtualization of one call
40a0f9f
@gmaxwell

utACK

Contributor

practicalswift commented Jul 19, 2017

utACK 40a0f9f

Contributor

TheBlueMatt commented Jul 19, 2017

utACK 40a0f9f

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