Browse Source

perf: load matplotlib on-demand

it takes ~1.7 seconds to import electrum.plot, slowing down app-startup considerably
master
SomberNight 3 years ago
parent
commit
227ccc65d4
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 15
      electrum/gui/qt/history_list.py
  2. 2
      electrum/plot.py

15
electrum/gui/qt/history_list.py

@ -61,12 +61,6 @@ if TYPE_CHECKING:
_logger = get_logger(__name__) _logger = get_logger(__name__)
try:
from electrum.plot import plot_history, NothingToPlotException
except:
_logger.info("could not import electrum.plot. This feature needs matplotlib to be installed.")
plot_history = None
# note: this list needs to be kept in sync with another in kivy # note: this list needs to be kept in sync with another in kivy
TX_ICONS = [ TX_ICONS = [
"unconfirmed.png", "unconfirmed.png",
@ -631,10 +625,15 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
d.exec_() d.exec_()
def plot_history_dialog(self): def plot_history_dialog(self):
if plot_history is None: try:
from electrum.plot import plot_history, NothingToPlotException
except Exception as e:
_logger.error(f"could not import electrum.plot. This feature needs matplotlib to be installed. exc={e!r}")
self.parent.show_message( self.parent.show_message(
_("Can't plot history.") + '\n' + _("Can't plot history.") + '\n' +
_("Perhaps some dependencies are missing...") + " (matplotlib?)") _("Perhaps some dependencies are missing...") + " (matplotlib?)" + '\n' +
f"Error: {e!r}"
)
return return
try: try:
plt = plot_history(list(self.hm.transactions.values())) plt = plot_history(list(self.hm.transactions.values()))

2
electrum/plot.py

@ -1,3 +1,5 @@
# note: This module takes 1-2 seconds to import. It should be imported *on-demand*.
import datetime import datetime
from collections import defaultdict from collections import defaultdict

Loading…
Cancel
Save