Skip to content

Commit a51bee2

Browse files
committed
Coins tab: Speedup for wallets with very many utxos
The essense of this commit is to move the call to self._update_utxo_count_display() to *before* we rebuild the QTreeWidget for the Coins tab. The reason this is faster is that updating this header item count is faster if done with an empty QTreeWidget than if done with a populated one. There are no negative effects from this change other than the speedup. Also in this commit: - Fix copyright and year for utxo_list.py - Fix imports for utxo_list.py - Added some debug-mode only @profiler printing for UTXOList.on_update method.
1 parent 36e7065 commit a51bee2

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

electroncash_gui/qt/utxo_list.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# Electrum - lightweight Bitcoin client
44
# Copyright (C) 2015 Thomas Voegtlin
55
#
6+
# Electron Cash - lightweight Bitcoin Cash client
7+
# Copyright (C) 2017-2026 The Electron Cash Developers
8+
#
69
# Permission is hereby granted, free of charge, to any person
710
# obtaining a copy of this software and associated documentation files
811
# (the "Software"), to deal in the Software without restriction,
@@ -23,17 +26,17 @@
2326
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2427
# SOFTWARE.
2528
from .util import *
26-
from electroncash.i18n import _, ngettext
27-
from electroncash.plugins import run_hook
2829
from electroncash.address import Address
2930
from electroncash.bitcoin import COINBASE_MATURITY
30-
from electroncash import cashacct
31+
from electroncash.i18n import _, ngettext
32+
from electroncash.plugins import run_hook
33+
from electroncash.util import profiler, PrintError
3134
from collections import defaultdict
3235
from functools import wraps
3336
from enum import IntEnum
3437

3538

36-
class UTXOList(MyTreeWidget):
39+
class UTXOList(MyTreeWidget, PrintError):
3740
class Col(IntEnum):
3841
'''Column numbers. This is to make code in on_update easier to read.
3942
If you modify these, make sure to modify the column header names in
@@ -79,6 +82,9 @@ def __init__(self, parent=None):
7982

8083
self.cleaned_up = False
8184

85+
def diagnostic_name(self):
86+
return f"{super().diagnostic_name()}/{self.wallet.diagnostic_name()}"
87+
8288
def clean_up(self):
8389
self.cleaned_up = True
8490
try: self.parent.ca_address_default_changed_signal.disconnect(self._ca_on_address_default_change)
@@ -110,6 +116,7 @@ def update(self):
110116
super().update()
111117

112118
@if_not_dead
119+
@profiler
113120
def on_update(self):
114121
local_maturity_height = (self.wallet.get_local_height()+1) - COINBASE_MATURITY
115122
prev_selection = self.get_selected() # cache previous selection, if any
@@ -128,6 +135,7 @@ def on_update(self):
128135
del addr_set # clean-up. We don't want the below code to ever depend on the existence of this cell.
129136
else:
130137
self.utxos = self.wallet.get_utxos(exclude_slp=False, exclude_tokens=False)
138+
self._update_utxo_count_display(len(self.utxos))
131139
for x in self.utxos:
132140
address = x['address']
133141
address_text = address.to_ui_string()
@@ -207,7 +215,6 @@ def on_update(self):
207215
if name in prev_selection:
208216
# NB: This needs to be here after the item is added to the widget. See #979.
209217
utxo_item.setSelected(True) # restore previous selection
210-
self._update_utxo_count_display(len(self.utxos))
211218

212219
def _update_utxo_count_display(self, num_utxos: int):
213220
headerItem = self.headerItem()

0 commit comments

Comments
 (0)