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)
This commit is contained in:
Jay Kamat 2018-02-10 13:21:04 -05:00
parent 80ee43beca
commit 33d9d4fe90
No known key found for this signature in database
GPG Key ID: 5D2E399600F4F7B5
2 changed files with 7 additions and 3 deletions

View File

@ -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(

View File

@ -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."""