CW-1024 Improve performance of xmr wallet (#2128)

* - enabled development options in CI builds.
- Implemented caching for account retrieval.
- refactor transaction handling in `dashboard_view_model.dart` to improve efficiency and reduce unnecessary updates in xmr.
- `DevMoneroCallProfilerPage`, for profiling performance of xmr,wow,zano wallet calls.

* use FeatureFlag.hasDevOptions

* prevent crashes in monero_c by using mutexes properly
improve performance of _transactionDisposer
remove unnecessary checks

* remove logging, bring back simplified logic

* update _transactionDisposer on length and confirmation of first and last transaction

* address comments from review

* don't throw unhandled exceptions in unawaited async code

* use cached transaction list in getAllSubaddresses, fix usage of txHistoryMutex

* [DNM] fix: crashes when opening wallet, performance issue when syncing and update dependencies

* Revert "use cached transaction list in getAllSubaddresses, fix usage of txHistoryMutex"

This reverts commit 4c4c33ac6a47603e970a6c8d940e90204525b241.

* Revert "[DNM] fix: crashes when opening wallet, performance issue when syncing and update dependencies"

This reverts commit d7603445ad6ae76d76bf179c34728ce242c8c610.

* Revert "use cached transaction list in getAllSubaddresses, fix usage of txHistoryMutex"

This reverts commit 4c4c33ac6a47603e970a6c8d940e90204525b241.

* update shared_preferences

* improve state management performance by not rendering multiple changes in transaction screen on a single frame

* fix wallet switching
This commit is contained in:
cyan
2025-04-03 03:31:25 +02:00
committed by GitHub
parent 27eaa1b1cc
commit cbca4c9c77
25 changed files with 498 additions and 105 deletions
@@ -271,32 +271,10 @@ abstract class DashboardViewModelBase with Store {
});
_transactionDisposer?.reaction.dispose();
_transactionDisposer = reaction(
(_) => appStore.wallet!.transactionHistory.transactions.values.toList(),
(List<TransactionInfo> txs) {
transactions.clear();
transactions.addAll(
txs.where((tx) {
if (wallet.type == WalletType.monero) {
return monero!.getTransactionInfoAccountId(tx) == monero!.getCurrentAccount(wallet).id;
}
if (wallet.type == WalletType.wownero) {
return wow.wownero!.getTransactionInfoAccountId(tx) == wow.wownero!.getCurrentAccount(wallet).id;
}
return true;
}).map(
(tx) => TransactionListItem(
transaction: tx,
balanceViewModel: balanceViewModel,
settingsStore: appStore.settingsStore,
key: ValueKey('${wallet.type.name}_transaction_history_item_${tx.id}_key'),
),
),
);
}
(_) => appStore.wallet!.transactionHistory.transactions.length *
appStore.wallet!.transactionHistory.transactions.values.first.confirmations,
_transactionDisposerCallback
);
if (hasSilentPayments) {
@@ -311,6 +289,50 @@ abstract class DashboardViewModelBase with Store {
reaction((_) => settingsStore.mwebAlwaysScan, (bool value) => _checkMweb());
}
bool _isTransactionDisposerCallbackRunning = false;
void _transactionDisposerCallback(int _) async {
// Simple check to prevent the callback from being called multiple times in the same frame
if (_isTransactionDisposerCallbackRunning) return;
_isTransactionDisposerCallbackRunning = true;
await Future.delayed(Duration.zero);
try {
final currentAccountId = wallet.type == WalletType.monero
? monero!.getCurrentAccount(wallet).id
: wallet.type == WalletType.wownero
? wow.wownero!.getCurrentAccount(wallet).id
: null;
final List<TransactionInfo> relevantTxs = [];
for (final tx in appStore.wallet!.transactionHistory.transactions.values) {
bool isRelevant = true;
if (wallet.type == WalletType.monero) {
isRelevant = monero!.getTransactionInfoAccountId(tx) == currentAccountId;
} else if (wallet.type == WalletType.wownero) {
isRelevant = wow.wownero!.getTransactionInfoAccountId(tx) == currentAccountId;
}
if (isRelevant) {
relevantTxs.add(tx);
}
}
// printV("Transaction disposer callback (relevantTxs: ${relevantTxs.length} current: ${transactions.length})");
transactions.clear();
transactions.addAll(relevantTxs.map((tx) => TransactionListItem(
transaction: tx,
balanceViewModel: balanceViewModel,
settingsStore: appStore.settingsStore,
key: ValueKey('${wallet.type.name}_transaction_history_item_${tx.id}_key'),
)));
} finally {
_isTransactionDisposerCallbackRunning = false;
}
}
void _checkMweb() {
if (hasMweb) {
mwebEnabled = bitcoin!.getMwebEnabled(wallet);
@@ -789,30 +811,9 @@ abstract class DashboardViewModelBase with Store {
_transactionDisposer?.reaction.dispose();
_transactionDisposer = reaction(
(_) => appStore.wallet!.transactionHistory.transactions.values.toList(),
(List<TransactionInfo> txs) {
transactions.clear();
transactions.addAll(
txs.where((tx) {
if (wallet.type == WalletType.monero) {
return monero!.getTransactionInfoAccountId(tx) == monero!.getCurrentAccount(wallet).id;
}
if (wallet.type == WalletType.wownero) {
return wow.wownero!.getTransactionInfoAccountId(tx) == wow.wownero!.getCurrentAccount(wallet).id;
}
return true;
}).map(
(tx) => TransactionListItem(
transaction: tx,
balanceViewModel: balanceViewModel,
settingsStore: appStore.settingsStore,
key: ValueKey('${wallet.type.name}_transaction_history_item_${tx.id}_key'),
),
),
);
}
(_) => appStore.wallet!.transactionHistory.transactions.length *
appStore.wallet!.transactionHistory.transactions.values.first.confirmations,
_transactionDisposerCallback
);
}