<p>This PR speeds up the loading of the deposit ("Receive funds") and transactions views (under the "Funds" tab), by adding some caches to <code>WalletService</code> and <code>DisputeListService</code>, lazily loading tx confidence tooltips for the two respective lists of items (<code>DepositListItem</code> and <code>TransactionsListItem</code>) and applying some low level optimisations to <code>TransactionsAwareTrade.isRelatedToTransaction</code>.</p>
<p>This also fixes a fairly minor bug in the transactions view due to a broken <code>TranscationsAwareTrade.isRefundPayoutTx</code> method, as well as a somewhat serious memory leak in the deposit view due to missing <code>BalanceListener</code> removals from the <code>BtcWalletService</code> instance.</p>
<p>The performance issues in these two views had started to become severe with the number of transactions and addresses now in my Bisq wallet. The deposit view was the worst, taking around 25 seconds to load, with bottlenecks in <code>WalletService.getTransactionConfidence</code> & <code>WalletService.getNumTxOutputsForAddress</code> as seen with JProfiler:</p>
<p><a target="_blank" rel="noopener noreferrer" href="https://user-images.githubusercontent.com/54855381/105935157-621ed900-6049-11eb-91bb-2cf83e28984e.png"><img src="https://user-images.githubusercontent.com/54855381/105935157-621ed900-6049-11eb-91bb-2cf83e28984e.png" alt="Screenshot from 2021-01-27 02-41-06" style="max-width:100%;"></a></p>
<p>The transactions view (with 1210 rows) was taking around 5 seconds to load, with bottlenecks in <code>TransactionsAwareTrade.isRelatedToTransaction</code> & <code>Tooltip.<init></code>:</p>
<p><a target="_blank" rel="noopener noreferrer" href="https://user-images.githubusercontent.com/54855381/105935191-6f3bc800-6049-11eb-8d6c-526ba9a96aa8.png"><img src="https://user-images.githubusercontent.com/54855381/105935191-6f3bc800-6049-11eb-8d6c-526ba9a96aa8.png" alt="Screenshot from 2021-01-27 02-41-25" style="max-width:100%;"></a></p>
<p>They both seem significantly faster (in my Bisq client) with the changes in this PR, with the biggest improvement to the deposit view via the two caches added to <code>WalletService</code>. The quadratic time issue (# transactions * # past trades) causing the slowness of the transactions view is alleviated but not completely fixed by these changes. It may be possible to do more extensive lazy loading of the relevant <code>TransactionsListItem</code> fields to get further speedups.</p>

<hr>

<h4>You can view, comment on, or merge this pull request online at:</h4>
<p>  <a href='https://github.com/bisq-network/bisq/pull/5120'>https://github.com/bisq-network/bisq/pull/5120</a></p>

<h4>Commit Summary</h4>
<ul>
  <li>Refactor: add & remove wallet listeners from the same class</li>
  <li>Use cache for WalletService.getNumTxOutputsForAddress</li>
  <li>Use cache for WalletService.getConfidenceForAddress</li>
  <li>Optimise TransactionAwareTrade.isRelatedToTransaction</li>
  <li>Add missing WalletService.removeBalanceListener to fix leak</li>
  <li>Load (Deposit|Transactions)ListItem tooltips lazily</li>
</ul>

<h4>File Changes</h4>
<ul>
  <li>
    <strong>M</strong>
    <a href="https://github.com/bisq-network/bisq/pull/5120/files#diff-ad1ae5fe768f7b1b85d73655e580b4799d29c71eaa7fed3363c43c5418fd116a">core/src/main/java/bisq/core/btc/wallet/BsqWalletService.java</a>
    (73)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/bisq-network/bisq/pull/5120/files#diff-75820b5165905d1e3a47d5fe31e4b5dba017c6b25a322aad955ffa592a67b362">core/src/main/java/bisq/core/btc/wallet/BtcWalletService.java</a>
    (8)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/bisq-network/bisq/pull/5120/files#diff-7f839642c099f9c286c0f26df5f69ded7608f780f0ee5f3fbc59175c6ac7fbda">core/src/main/java/bisq/core/btc/wallet/WalletService.java</a>
    (108)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/bisq-network/bisq/pull/5120/files#diff-29216781abb89af5b4d1afe0500798025fc38cbff28739c97ef392cfc34eae54">core/src/main/java/bisq/core/support/dispute/DisputeListService.java</a>
    (6)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/bisq-network/bisq/pull/5120/files#diff-4918defdef4db0fca38f6eaf020e25581c0d0b5d80871898ad764410cc5dcc45">core/src/main/java/bisq/core/support/dispute/DisputeManager.java</a>
    (4)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/bisq-network/bisq/pull/5120/files#diff-72c05306ff3b1bd4ea193f0f79b85dae2d574923e3ae5eb4543a814a72beb156">desktop/src/main/java/bisq/desktop/main/funds/deposit/DepositListItem.java</a>
    (80)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/bisq-network/bisq/pull/5120/files#diff-1eadffb9720b0bd840895d64a314d6de16e9c819c332c54afd78e9d4301743f7">desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionAwareTrade.java</a>
    (70)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/bisq-network/bisq/pull/5120/files#diff-0f3cab3039cfd96fd86e1a0488b77197d12c60ba76f0028163a050e6cde0fa84">desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionsListItem.java</a>
    (79)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/bisq-network/bisq/pull/5120/files#diff-7bef43df0b43ca4ca3944fd8008211769aa9e904c5403834a00ba58fa1b07b8a">desktop/src/test/java/bisq/desktop/main/funds/transactions/TransactionAwareTradeTest.java</a>
    (9)
  </li>
</ul>

<h4>Patch Links:</h4>
<ul>
  <li><a href='https://github.com/bisq-network/bisq/pull/5120.patch'>https://github.com/bisq-network/bisq/pull/5120.patch</a></li>
  <li><a href='https://github.com/bisq-network/bisq/pull/5120.diff'>https://github.com/bisq-network/bisq/pull/5120.diff</a></li>
</ul>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/bisq-network/bisq/pull/5120">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AJFFTNW25DS2SGY6NY2NH6TS36CL7ANCNFSM4WUQ5CFA">unsubscribe</a>.<img src="https://github.com/notifications/beacon/AJFFTNQZ4BJLMUV2XRUCVL3S36CL7A5CNFSM4WUQ5CFKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4L26XIFQ.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/bisq-network/bisq/pull/5120",
"url": "https://github.com/bisq-network/bisq/pull/5120",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>