Don't check the filesystem for edits to template files during a build#2261
Merged
Conversation
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
Contributor
|
Wow, I didn't even realize that was a thing that Jinja did, let alone that there was an option to disable it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 amkdocs servecreates 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
-- 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: