From 33d9d4fe90597d6c383b132ddb5e1bfaeaeebabe Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Sat, 10 Feb 2018 13:21:04 -0500 Subject: [PATCH] Improve performance of startup and shutdown We call 'update_tab_titles' a lot of times which calls 'setTabText' on every tab. 'setTabText' calls tabSizeHint and minTabSizeHint on every tab as well, meaning this is an n^2 operation repeated many times. First, this prevents setTabText from being called unless it's needed, removing most of the work done. Second, I remove tabs in reverse, to avoid recomputing the above for every tab on shutdown (which is at least n^3) --- qutebrowser/mainwindow/tabbedbrowser.py | 5 ++++- qutebrowser/mainwindow/tabwidget.py | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index cd9f52b37..8cee35524 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -253,7 +253,10 @@ class TabbedBrowser(tabwidget.TabWidget): def shutdown(self): """Try to shut down all tabs cleanly.""" self.shutting_down = True - for tab in self.widgets(): + # Reverse tabs so we don't have to recacluate tab titles over and over + # Removing first causes [2..-1] to be recomputed + # Removing the last causes nothing to be recomputed + for tab in reversed(self.widgets()): self._remove_tab(tab) def tab_close_prompt_if_pinned( diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py index da1f2624b..6cded2a71 100644 --- a/qutebrowser/mainwindow/tabwidget.py +++ b/qutebrowser/mainwindow/tabwidget.py @@ -150,8 +150,9 @@ class TabWidget(QTabWidget): title = '' if fmt is None else fmt.format(**fields) tabbar = self.tabBar() - tabbar.setTabText(idx, title) - tabbar.setTabToolTip(idx, title) + if tabbar.tabText(idx) != title: + tabbar.setTabText(idx, title) + tabbar.setTabToolTip(idx, title) def get_tab_fields(self, idx): """Get the tab field data."""