Slow build time with jekyll-rtd-theme - numerous liquid include's


Sorry for breaking this post up into pieces but apparently I cannot post more than two links in a single post. Not sure what problem this solves…

I’m on Jekyll 3.9.0 (which is dictated by github-pages 215). I’m using a remote theme jekyll-rtd-theme that I really like the looks of.

Currently my site consists of 221 markdown files (or 283 if to include the for jekyll-readme-index) and about 30 directories and subdirectories with those files.

The site takes more than 2 minutes to build, which I think is a rather long time.

Enabling incremental regeneration does not make any difference to the build time. So the problem does not seem to be there. Incidentally, it creates .jekyll-metadata file that balloons in size even when there are tiny changes (1 md file added). In the last few builds it went from 0.7 → 1.4 → 2.0 → 2.7 → 3.6MB. At this rate this file will be larger than the whole website soon…

Back to the build time, I’ve tried with the liquid profiler and below are the results, I’m only listing the top entries that took longer than a second:

Filename                                              | Count |     Bytes |    Time
remote-theme/_includes/templates/_toctree.liquid      |   226 | 27665.45K | 194.416
_layouts/default.liquid                               |   226 | 17805.59K |  95.993
remote-theme/_includes/templates/sidebar.liquid       |   226 | 10253.76K |  84.314
remote-theme/_includes/templates/toctree.liquid       |   226 | 10024.89K |  84.014
remote-theme/_includes/common/rest/workdir.liquid     |   257 |     0.00K |  43.060
remote-theme/_includes/common/rest/defaults.liquid    |   226 |     0.00K |   9.287
remote-theme/_includes/common/rest/site_pages.liquid  |   259 |     0.00K |   8.444
remote-theme/_includes/list.liquid                    |    31 |    45.12K |   2.894
remote-theme/_includes/common/core/list.liquid        |    31 |    45.12K |   2.892
remote-theme/_includes/common/core/_list.liquid       |    11 |    52.20K |   2.755
remote-theme/_includes/common/rest/nav.liquid         |   226 |     0.00K |   1.389
remote-theme/_includes/common/rest/variables.liquid   |   226 |     0.00K |   1.127
                    done in 110.377 seconds.

Interestingly the top item took longer than the entire build…

The whole chain of calls seems to originate from templates/sidebar.liquid, then there is a looped include of templates/toctree.liquid.

Finally templates/_toctree.liquid that include’s itself in a loop. Presumably each include counts as 1 in the profiler’s output. So 226 include’s, quite a few but not some massive number, and if I understand the profiler output correctly close to a second per each include of _toctree.liquid.

1 second seems quite a long time. I’ve just started with Jekyll and I’m unfamiliar with Liquid so can someone help identify the slow bit, please?

The slow bit is the loops used in that theme. Didn’t dig into it too deeply, but it appears to be looping through files in various directories to create the sidebar and other parts of the site.

These sorts of loops along with looping over all posts/pages are notoriously costly in Jekyll-land. The more files you add the longer your build times will become.

1 Like

A previous discussion on speed, that might be of interest:

Thanks for your replies. I tinkered with that theme, got rid of GitHub Pages and managed to upgrade to Jekyll 4.2, and that cut the build time down to 60 seconds, so reduced by almost half.

I also wanted to try with Liquid 5 and see what that does to performance but unfortunately Jekyll doesn’t allow such upgrade and it seems that in Ruby world there is no straightforward way to override the dependency version restrictions.

What I’m planning to do next is to get rid of this awful Liquid thing used for generating the sidebar in the theme anyway and try with JavaScript instead.

I thought I could use JavaScript magic in Liquid templates because I came across a {% javascript %} or something like that mentioned somewhere but it must have been some random custom tag and I didn’t know anything about custom tags at the time.

That however put me on the right path and I rewrote the sidebar generation and made it into a Ruby plugin which reduced the build time to a mere 7 seconds! That’s more like it :slightly_smiling_face: