Merge pull request #4518 from jgkamat/jay/configcache-cache

Optimize configcache for critical path
This commit is contained in:
Florian Bruhin 2019-01-10 14:04:46 +01:00 committed by GitHub
commit dcd2184f97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -46,7 +46,9 @@ class ConfigCache:
self._cache[attr] = config.instance.get(attr) self._cache[attr] = config.instance.get(attr)
def __getitem__(self, attr: str) -> typing.Any: 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 assert not config.instance.get_opt(attr).supports_pattern
self._cache[attr] = config.instance.get(attr) self._cache[attr] = config.instance.get(attr)
return self._cache[attr] return self._cache[attr]

View File

@ -50,3 +50,17 @@ def test_configcache_get_after_set(config_stub):
assert not config.cache['auto_save.session'] assert not config.cache['auto_save.session']
config_stub.val.auto_save.session = True config_stub.val.auto_save.session = True
assert config.cache['auto_save.session'] 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)