Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce time to render pages with thousands of code blocks #3643

Closed
5 tasks done
wilhelmer opened this issue Mar 1, 2022 · 3 comments
Closed
5 tasks done

Reduce time to render pages with thousands of code blocks #3643

wilhelmer opened this issue Mar 1, 2022 · 3 comments
Labels
change request Issue requests a new feature or improvement resolved Issue is resolved, yet unreleased if open

Comments

@wilhelmer
Copy link
Contributor

wilhelmer commented Mar 1, 2022

Contribution guidelines

I've found a bug and checked that ...

  • ... the problem doesn't occur with the mkdocs or readthedocs themes
  • ... the problem persists when all overrides are removed, i.e. custom_dir, extra_javascript and extra_css
  • ... the documentation does not mention anything about my problem
  • ... there are no open or closed issues that are related to my problem

Description

As outlined and demoed here, large topics can take a long time to render, up to 30 seconds, which makes them unusable. This only occurs when using the Material template.

@squidfunk has already looked at it, and it is most probably caused by the large amount of code blocks used in the sample topic. Other templates have less sophisticated handling of code blocks, which is why the issue doesn't occur when using other templates.

Expected behaviour

Pages should render fast in all browsers, regardless of the template used.

Actual behaviour

See description.

Steps to reproduce

See sample project linked in the description.

Package versions

  • Python: 3.9.10
  • MkDocs: 1.2.3
  • Material: 8.2.3+insiders.4.10.0

Configuration

See sample project linked in the description.

System information

  • Operating system: macOS
  • Browser: Firefox, Chrome, Safari
@squidfunk squidfunk added the change request Issue requests a new feature or improvement label Mar 1, 2022
@squidfunk squidfunk changed the title Poor render time for large topics with lots of code blocks Reduce time to render pages with thousands of code blocks Mar 1, 2022
@squidfunk
Copy link
Owner

squidfunk commented Mar 1, 2022

Thanks for reporting. Just for anyone else coming here – the problem is observed on a page with over 1.7k code blocks, so very likely nothing to worry about for the average project. It applies to Insiders, as well as the community edition.

@squidfunk
Copy link
Owner

squidfunk commented Mar 6, 2022

This was an interesting problem to solve. The problem stems from excessive reading of the Element.offset* and Element.scroll* properties in order to determine whether a code block overflows or not, which is necessary to make it focusable via keyboard to allow for better accessibility, as requested in #1514. Since all code blocks are mounted on load, and the page in question has more than 1.700 of them, this process took forever to complete:

Bildschirmfoto 2022-03-06 um 13 43 59

While the initial layout takes the browser 1.4s, the user had to wait for another 35s until the browser becomes responsive again. Oops. Even worse: most of the work done is probably unnecessary, because the page is so long and most of the code blocks will probably never be interacted with.

This is now fixed in e71891f, as code blocks will now only be mounted when they are visible. The initial layout still takes around 1.4s, but the application will now mount in less than 500ms! I think that's a pretty good result:

Bildschirmfoto 2022-03-06 um 13 47 03

@squidfunk squidfunk added the resolved Issue is resolved, yet unreleased if open label Mar 6, 2022
@squidfunk
Copy link
Owner

Released as part of 8.2.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
change request Issue requests a new feature or improvement resolved Issue is resolved, yet unreleased if open
Projects
None yet
Development

No branches or pull requests

2 participants