Skip to content
Browse files
Add an lru cache for WebHistoryInterface.historyContains
When loading, 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 939d282
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
@@ -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):
self._history = webhistory

def addHistoryEntry(self, url_string):
"""Required for a QWebHistoryInterface impl, obsoleted by add_url."""

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


0 comments on commit 939d282

Please sign in to comment.