From ee452025218c3afbdf50ba40b60ab3d7cf55db8e Mon Sep 17 00:00:00 2001 From: Steven Barclay Date: Sat, 11 Feb 2023 09:30:57 +0800 Subject: [PATCH] Remove redundant listener from TransactionsListItem Eliminate a minor quadratic time bug, caused by the unnecessary addition of a (BtcWalletService) TxConfidenceListener for each list item in the Transactions view. (Since the confidence listeners are internally held in a CopyOnWriteArraySet, this sadly runs in quadratic time, slowing down the Transactions view load a little.) The confidence listener is apparently redundant because of a set of calls to 'TransactionsListItem.cleanup' immediately upon construction of the item list, which removes all the listeners just added. (This code appears to date from at least February 2016, in commit c70df86.) (The confidence indicators are kept up to date by simply reloading the entire list upon each wallet change event.) --- .../transactions/TransactionsListItem.java | 18 ------------------ .../funds/transactions/TransactionsView.java | 2 -- 2 files changed, 20 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionsListItem.java b/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionsListItem.java index c7da5056b5..6b67ee2d5d 100644 --- a/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionsListItem.java +++ b/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionsListItem.java @@ -22,7 +22,6 @@ import bisq.desktop.util.DisplayUtils; import bisq.desktop.util.GUIUtil; import bisq.desktop.util.filtering.FilterableListItem; -import bisq.core.btc.listeners.TxConfidenceListener; import bisq.core.btc.wallet.BsqWalletService; import bisq.core.btc.wallet.BtcWalletService; import bisq.core.btc.wallet.WalletService; @@ -59,7 +58,6 @@ import javax.annotation.Nullable; @Slf4j class TransactionsListItem implements FilterableListItem { - private final BtcWalletService btcWalletService; private final CoinFormatter formatter; private String dateString; private final Date date; @@ -69,7 +67,6 @@ class TransactionsListItem implements FilterableListItem { private String details = ""; private String addressString = ""; private String direction = ""; - private TxConfidenceListener txConfidenceListener; private boolean received; private Coin amountAsCoin = Coin.ZERO; private String memo = ""; @@ -91,7 +88,6 @@ class TransactionsListItem implements FilterableListItem { // used at exportCSV TransactionsListItem() { date = null; - btcWalletService = null; txId = null; formatter = null; isDustAttackTx = false; @@ -105,7 +101,6 @@ class TransactionsListItem implements FilterableListItem { DaoFacade daoFacade, CoinFormatter formatter, long ignoreDustThreshold) { - this.btcWalletService = btcWalletService; this.formatter = formatter; this.memo = transaction.getMemo(); @@ -303,19 +298,6 @@ class TransactionsListItem implements FilterableListItem { GUIUtil.updateConfidence(confidence, tooltip, txConfidenceIndicator); confirmations = confidence.getDepthInBlocks(); }}); - - txConfidenceListener = new TxConfidenceListener(txId) { - @Override - public void onTransactionConfidenceChanged(TransactionConfidence confidence) { - GUIUtil.updateConfidence(confidence, lazy().tooltip, lazy().txConfidenceIndicator); - confirmations = confidence.getDepthInBlocks(); - } - }; - btcWalletService.addTxConfidenceListener(txConfidenceListener); - } - - public void cleanup() { - btcWalletService.removeTxConfidenceListener(txConfidenceListener); } diff --git a/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionsView.java b/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionsView.java index 3fa3bdb401..39945f799c 100644 --- a/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionsView.java +++ b/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionsView.java @@ -279,7 +279,6 @@ public class TransactionsView extends ActivatableView { protected void deactivate() { filterBox.deactivate(); sortedList.comparatorProperty().unbind(); - observableList.forEach(TransactionsListItem::cleanup); btcWalletService.removeChangeEventListener(walletChangeEventListener); if (scene != null) @@ -328,7 +327,6 @@ public class TransactionsView extends ActivatableView { }) .collect(Collectors.toList()); // are sorted by getRecentTransactions - transactionsListItems.forEach(TransactionsListItem::cleanup); observableList.setAll(transactionsListItems); }