Skip to content

Don't check the filesystem for edits to template files during a build#2261

Merged
waylan merged 1 commit into
mkdocs:masterfrom
oprypin:mtime
Dec 22, 2020
Merged

Don't check the filesystem for edits to template files during a build#2261
waylan merged 1 commit into
mkdocs:masterfrom
oprypin:mtime

Conversation

@oprypin

@oprypin oprypin commented Dec 21, 2020

Copy link
Copy Markdown

MkDocs templates are quite heavily split into files and can even be nested (particularly for navs, which also repeat on every page).

Any time a template is referenced, even though it's cached in memory, Jinja ends up doing a filesystem access, to check whether the template file has been modified and so would need to be recompiled.
But it's not even useful to be able to modify a template file on disk in the middle of a mkdocs build.

So, by disabling autoreload, we eliminate all these filesystem accesses (on the order of thousands), other than the initial one per template.

The lifetime of the Jinja environment is the lifetime of a mkdocs build, and a mkdocs serve creates a new one each time anyway, so that is not affected.


For my site of 134 pages with a heavily nested nav (w/ material theme), this changes from

ncalls tottime percall cumtime percall filename:lineno(function)
24735 0.01567 6.335e-07 0.1135 4.587e-06 loaders.py:190(uptodate)

-- to (considered negligible by the profiler). Overall that site's build time goes from 3.02s to 2.91s

And that's on an SSD; maybe some people have a worse disk where the effect would be greater.

Code references:

MkDocs templates are quite heavily split into files and can even be nested [1] (particularly for navs, which also repeat on every page).

Any time a template is referenced, even though it's cached in memory, Jinja ends up doing a filesystem access, to check whether the template file has been modified and so would need to be recompiled.
But it's not even useful to be able to modify a template file on disk in the middle of a mkdocs build.

So, by disabling autoreload, we eliminate all these filesystem accesses (on the order of thousands), other than the initial one per template.

[1]: https://github.com/mkdocs/mkdocs/blob/master/mkdocs/themes/mkdocs/nav-sub.html
@waylan

waylan commented Dec 22, 2020

Copy link
Copy Markdown
Contributor

Wow, I didn't even realize that was a thing that Jinja did, let alone that there was an option to disable it.

@waylan waylan merged commit c5e4018 into mkdocs:master Dec 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants