Build a cache of already processed transactions is sufficient to fix this.CWalletTx::IsConfirmed displays exceptionally poor performance when there are multiple unconfirmed transactions where IsFromMe() is true.
A cache of already processed transactions is sufficient to largely fix this.
This is still optimized for the common case where most dependent transactions are not IsFromMe()
As part of this change the logic has been simplified.
Simple benchmark results:
generate 200 blocks with regtest, create 300 transactions using standard sendtoaddress rpc and a new address for each transaction
95 seconds
for the IsConfirmed this is replacing... well it still hasn't finished running at transactions 216 1414 seconds and getting worse

after transaction 175 the time per transaction grows exponentially 1.25 * e ^ (0.107 * x)