Merge pull request #4518 from jgkamat/jay/configcache-cache
Optimize configcache for critical path
This commit is contained in:
commit
dcd2184f97
@ -46,7 +46,9 @@ class ConfigCache:
|
||||
self._cache[attr] = config.instance.get(attr)
|
||||
|
||||
def __getitem__(self, attr: str) -> typing.Any:
|
||||
if attr not in self._cache:
|
||||
try:
|
||||
return self._cache[attr]
|
||||
except KeyError:
|
||||
assert not config.instance.get_opt(attr).supports_pattern
|
||||
self._cache[attr] = config.instance.get(attr)
|
||||
return self._cache[attr]
|
||||
return self._cache[attr]
|
||||
|
@ -50,3 +50,17 @@ def test_configcache_get_after_set(config_stub):
|
||||
assert not config.cache['auto_save.session']
|
||||
config_stub.val.auto_save.session = True
|
||||
assert config.cache['auto_save.session']
|
||||
|
||||
|
||||
def test_configcache_naive_benchmark(config_stub, benchmark):
|
||||
def _run_bench():
|
||||
for _i in range(10000):
|
||||
# pylint: disable=pointless-statement
|
||||
config.cache['tabs.padding']
|
||||
config.cache['tabs.indicator.width']
|
||||
config.cache['tabs.indicator.padding']
|
||||
config.cache['tabs.min_width']
|
||||
config.cache['tabs.max_width']
|
||||
config.cache['tabs.pinned.shrink']
|
||||
# pylint: enable=pointless-statement
|
||||
benchmark(_run_bench)
|
||||
|
Loading…
Reference in New Issue
Block a user