Add an lru_cache for configdata.is_valid_prefix()
This gets called a lot, and caused some :bind calls to take ~3s. Stats after starting with a bit of :bind: CacheInfo(hits=25917, misses=139, maxsize=256, currsize=139)
This commit is contained in:
parent
45e7e35233
commit
ad0a961a5f
@ -32,6 +32,7 @@ DATA: A global read-only copy of the default config, an OrderedDict of
|
||||
import sys
|
||||
import re
|
||||
import collections
|
||||
import functools
|
||||
|
||||
from qutebrowser.config import configtypes
|
||||
from qutebrowser.utils import usertypes, qtutils, utils
|
||||
@ -229,6 +230,7 @@ def _read_yaml(yaml_data):
|
||||
return parsed
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=256)
|
||||
def is_valid_prefix(prefix):
|
||||
"""Check whether the given prefix is a valid prefix for some option."""
|
||||
return any(key.startswith(prefix + '.') for key in DATA)
|
||||
|
@ -37,7 +37,7 @@ from PyQt5.QtWidgets import QApplication # pylint: disable=unused-import
|
||||
from qutebrowser.browser import qutescheme
|
||||
from qutebrowser.utils import log, objreg, usertypes, message, debug, utils
|
||||
from qutebrowser.commands import cmdutils, runners, cmdexc
|
||||
from qutebrowser.config import style
|
||||
from qutebrowser.config import style, configdata
|
||||
from qutebrowser.misc import consolewidget
|
||||
|
||||
|
||||
@ -168,7 +168,8 @@ def debug_all_objects():
|
||||
@cmdutils.register(debug=True)
|
||||
def debug_cache_stats():
|
||||
"""Print LRU cache stats."""
|
||||
pass
|
||||
prefix_info = configdata.is_valid_prefix.cache_info()
|
||||
log.misc.debug('is_valid_prefix: {}'.format(prefix_info))
|
||||
|
||||
|
||||
@cmdutils.register(debug=True)
|
||||
|
Loading…
Reference in New Issue
Block a user