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

Caching of expensive templates during rendering (trending-tags) #1094

Closed
jakerr opened this issue Jun 18, 2023 · 1 comment · Fixed by #1097 or #1098
Closed

Caching of expensive templates during rendering (trending-tags) #1094

jakerr opened this issue Jun 18, 2023 · 1 comment · Fixed by #1097 or #1098
Labels
enhancement New feature or request

Comments

@jakerr
Copy link
Contributor

jakerr commented Jun 18, 2023

Rendering _includes/trending-tags.html for site with many tags / posts is quite slow.

Description

In an unmodified new repo from the chirpy template, as well as on a fresh checkout of main. Importing a blog with 330 posts including 750 tags the site build takes about 4 minutes timed with jekyll s --profile

Build Process Summary:

| PHASE    |     TIME |
+----------+----------+
| RESET    |   0.0001 |
| READ     |   3.2577 |
| GENERATE |   0.0311 |
| RENDER   | 238.4877 |
| CLEANUP  |   0.0143 |
| WRITE    |   0.1458 |

Site Render Stats:

| Filename                                                           | Count |      Bytes |    Time |
+--------------------------------------------------------------------+-------+------------+---------+
| _includes/trending-tags.html                                       |  2346 | 225841.45K | 227.050 |
| _layouts/page.html                                                 |  1173 | 122030.48K | 121.067 |
| _layouts/default.html                                              |  1173 | 252854.99K | 116.072 |
| _includes/search-results.html                                      |  1173 | 113272.39K | 113.785 |
| _includes/related-posts.html                                       |   327 |   3533.14K |   6.505 |
| _includes/head.html                                                |  1173 |   8299.20K |   1.181 |

...

To Reproduce

Create a new chirpy site from the template and place many posts that have tags into the _posts directory.

Desired behavior

It would be nice if templates that are known to produce the same output site-wide could somehow be cached while rendering.

I experimented with the jekyll-include-cache and saw good results.

By adding jekyll-include-cache as a plugin and then overriding the _layout & _includes files which reference trending-tags.html I was able to render the same site in ~11 seconds.

Build Process Summary:

| PHASE    |    TIME |
+----------+---------+
| RESET    |  0.0001 |
| READ     |  1.6198 |
| GENERATE |  0.0346 |
| RENDER   | 10.6490 |
| CLEANUP  |  0.0087 |
| WRITE    |  0.1347 |


Site Render Stats:

| Filename                                                           | Count |      Bytes |  Time |
+--------------------------------------------------------------------+-------+------------+-------+
| _layouts/page.html                                                 |  1172 | 121722.75K | 7.679 |
| jekyll-theme-chirpy-6.0.1/_includes/related-posts.html             |   327 |   3533.11K | 6.397 |
| _layouts/default.html                                              |  1172 | 248347.79K | 1.818 |
| jekyll-theme-chirpy-6.0.1/_includes/update-list.html               |  1172 |     72.11K | 0.897 |

...

The diff that produces this faster output

diff generated with this git command

git diff --no-index --diff-filter=M $(bundle info --path jekyll-theme-chirpy)/_layouts _layouts
git diff --no-index --diff-filter=M $(bundle info --path jekyll-theme-chirpy)/_includes _includes
diff --git a/Users/jakerr/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/jekyll-theme-chirpy-6.0.1/_layouts/page.html b/./_layouts/page.html
index 447977d..233ee18 100644
--- a/Users/jakerr/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/jekyll-theme-chirpy-6.0.1/_layouts/page.html
+++ b/./_layouts/page.html
@@ -45,7 +45,7 @@ layout: default
   <div id="panel-wrapper" class="col-xl-3 ps-2 text-muted">
     <div class="access">
       {% include update-list.html lang=lang %}
-      {% include trending-tags.html lang=lang %}
+      {% include_cached trending-tags.html lang=lang %}
     </div>
 
     {% for _include in layout.panel_includes %}
diff --git a/Users/jakerr/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/jekyll-theme-chirpy-6.0.1/_includes/search-results.html b/_includes/search-results.html
index e4ffb48..07981ff 100644
--- a/Users/jakerr/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/jekyll-theme-chirpy-6.0.1/_includes/search-results.html
+++ b/_includes/search-results.html
@@ -3,7 +3,7 @@
 <div id="search-result-wrapper" class="d-flex justify-content-center unloaded">
   <div class="col-11 post-content">
     <div id="search-hints">
-      {% include trending-tags.html %}
+      {% include_cached trending-tags.html %}
     </div>
     <div id="search-results" class="d-flex flex-wrap justify-content-center text-muted mt-3"></div>
   </div>

Environment

Command Version
ruby -v ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
gem -v 3.4.14
bundle -v Bundler version 2.4.14
bundle exec jekyll -v jekyll 4.3.2
bundle info jekyll-theme-chirpy jekyll-theme-chirpy (6.0.1)

Desktop

  • OS: [e.g. macOS 13.4]
@jakerr jakerr added the enhancement New feature or request label Jun 18, 2023
@cotes2020
Copy link
Owner

Thank you for raising this issue, it is very detailed and has provided an improved solution. I will improve it as soon as possible.

cotes2020 added a commit that referenced this issue Jun 18, 2023
Resolves #1094

Co-authored-by: Jake Kerr <kodafox@gmail.com>
cotes2020 added a commit that referenced this issue Jun 19, 2023
Resolve #1094 and add margin bottom for layout tags

Co-authored-by: Jake Kerr <kodafox@gmail.com>
cotes2020 added a commit that referenced this issue Jun 19, 2023
…1098)

Resolve #1094 and add margin bottom for layout tags

Co-authored-by: Jake Kerr <kodafox@gmail.com>
otzslayer pushed a commit to otzslayer/otzslayer.github.io that referenced this issue Jun 21, 2023
…otes2020#1098)

Resolve cotes2020#1094 and add margin bottom for layout tags

Co-authored-by: Jake Kerr <kodafox@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants