Skip to content

Commit

Permalink
perf: Call update_env only once per Markdown instance
Browse files Browse the repository at this point in the history
The follow-up calls for each block make no difference at all, and are getting quite expensive.
  • Loading branch information
oprypin committed Dec 26, 2020
1 parent 3b28c58 commit b198c74
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/mkdocstrings/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def __init__(self, parser: BlockParser, md: Markdown, config: dict, handlers: Ha
self.md = md
self._config = config
self._handlers = handlers
self._updated_env = False

def test(self, parent: Element, block: Element) -> bool:
"""
Expand Down Expand Up @@ -199,8 +200,10 @@ def process_block(self, identifier: str, yaml_block: str, heading_level: int = 0
log.error(f"Could not collect '{identifier}'")
raise

log.debug("Updating renderer's env")
handler.renderer.update_env(self.md, self._config)
if not self._updated_env:
log.debug("Updating renderer's env")
handler.renderer.update_env(self.md, self._config)
self._updated_env = True

log.debug("Rendering templates")
try:
Expand Down

0 comments on commit b198c74

Please sign in to comment.