blueswen/mkdocs-swagger-ui-tag

[performance] Looking up every file is slow

Opened this issue · 1 comments

Hello, I've noticed that the processing here can significantly slows down building the docs, probably because of BeautifulSoup.

On my website, running the plugin added an overhead of about 27s. Because I know the files where I want the swagger-ui tags to be used, I've added a simple filename filter patch to avoid trying to lookup on every single file. That improved the performance to only 2s!

def on_post_page(self, output, page, config, **kwargs):
    """Replace swagger-ui tag with iframe
    Add javascript code to update iframe height
    Create a html with Swagger UI for iframe
    """
    if page.file.name not in ("rest_api", "rest-api"):
        return output
    ...

Proposal

My proposal is:

  • Add an option (e.g, filter_filenames), which provides an optional list of filenames to match before proceding the processing.
  • For backward-compat, if this option is not provided the plugin continue with its current behavior.

What do you think? I can open a PR next week

Another similar approach is to mark specific markdown pages using the yaml frontmatter and add a global option to not process a page unless its marked.

# some markdown page frontmatter
---
swagger-ui:
  process-page: true
---

# mkdocs.yaml
plugins:
  mkdocs-swagger-ui:
    process_all: false  # default true for compatibility