dogecoin/dogecoin — pull request #264 by somegeekintn (2014-02-20 13:21:59+00:00)
Title: Optim 1.5

This branch contains optimizations for transaction based operations in dogecoind. Specifically any functions that end up calling Solver and/or GetOp2 in script.cpp. In addition, CWalletTx's GetAmounts has been reworked to eliminate redundant calls to Solver. Perhaps these changes can help with some of the issues pool operators have been encountering lately?

I measured performance gains using a php script that repeatedly calls getbalance via RPC. After these changes performances increased as much as 3x over the original. Here are the results (note that my wallet does not contain very many transactions and I don't know how these changes will scale hopefully 1:1):

Original: ~120-130mS
Solver/GetOp2 changes: 64-70mS
+GetAmounts changes: 43-50mS

The specific changes were:
GetOp2: eliminate redundant calls (no need to check end twice). Add scriptEnd var so we don't call end() repeatedly
Solver: The original version tried to match transactions with the following order: TX_PUBKEY, TX_PUBKEYHASH, TX_MULTISIG. Since TX_PUBKEYHASH seems to be far and away the most common transaction we test for that first now. We also don't bother getting the vchResult from GetOp2 for the template scripts since the templates push no data. Oh and we call GetOp2 directly now instead of the avoiding the extra call in GetOp.
CWalletTx::GetAmounts: This was calling Solver on the same transaction as many as 3 times (ExtractDestination, IsChange, IsMine). I created a single function that will get the address and determine if the address "isMine", as well as a HasAddress function in CWallet so we can check the address returned by ExtractDestinationAndMine.

I've tripled checked everything and tested as much as I can, but these changes are deep in the bowels of the source code so additional is definitely needed.