Permalink
Browse files

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...
  • Loading branch information...
The-Compiler committed Jun 8, 2017
1 parent ef014af commit 939d2823ed3c191303d04a965cc43e3728ab819f
Showing with 10 additions and 0 deletions.
  1. +3 −0 qutebrowser/browser/webkit/webkithistory.py
  2. +7 −0 qutebrowser/misc/utilcmds.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.
@@ -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)

0 comments on commit 939d282

Please sign in to comment.