From 9b0395db087f320e150626df7e182c66f9a47c86 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 8 Jun 2017 13:03:44 +0200 Subject: [PATCH] Add an lru cache for WebHistoryInterface.historyContains When loading heise.de, for some crazy reason QtWebKit calls historyContains about 16'000 times. With this cache (which we simply clear when *any* page has been loaded, as then the links which have been visited can change), that's down to 250 or so... --- qutebrowser/browser/webkit/webkithistory.py | 3 +++ qutebrowser/misc/utilcmds.py | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/qutebrowser/browser/webkit/webkithistory.py b/qutebrowser/browser/webkit/webkithistory.py index 64b7bf295..0edbb3fa3 100644 --- a/qutebrowser/browser/webkit/webkithistory.py +++ b/qutebrowser/browser/webkit/webkithistory.py @@ -19,6 +19,7 @@ """QtWebKit specific part of history.""" +import functools from PyQt5.QtWebKit import QWebHistoryInterface @@ -36,11 +37,13 @@ class WebHistoryInterface(QWebHistoryInterface): def __init__(self, webhistory, parent=None): super().__init__(parent) self._history = webhistory + self._history.changed.connect(self.historyContains.cache_clear) def addHistoryEntry(self, url_string): """Required for a QWebHistoryInterface impl, obsoleted by add_url.""" pass + @functools.lru_cache(maxsize=32768) def historyContains(self, url_string): """Called by WebKit to determine if a URL is contained in the history. diff --git a/qutebrowser/misc/utilcmds.py b/qutebrowser/misc/utilcmds.py index 41b44de1f..d1771c212 100644 --- a/qutebrowser/misc/utilcmds.py +++ b/qutebrowser/misc/utilcmds.py @@ -170,8 +170,15 @@ def debug_cache_stats(): """Print LRU cache stats.""" config_info = objreg.get('config').get.cache_info() style_info = style.get_stylesheet.cache_info() + try: + from PyQt5.QtWebKit import QWebHistoryInterface + interface = QWebHistoryInterface.defaultInterface() + history_info = interface.historyContains.cache_info() + except ImportError: + history_info = None log.misc.debug('config: {}'.format(config_info)) log.misc.debug('style: {}'.format(style_info)) + log.misc.debug('history: {}'.format(history_info)) @cmdutils.register(debug=True)