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
Memoize the return value of Document#url #6266
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a huge savings! 🎉
Running 'bundle exec rake site:generate' locally, this brings generation time from 16 seconds down to 8 seconds.
e0a74a0
to
0d7cdda
Compare
Lol @ ruby. Also lol @ us not catching this! If you haven't checked out stackprof, it is so cool. $ export BENCHMARK=1
$ bundle install
$ script/stackprof # measures cpu
$ script/stackprof object # measures memory |
@jekyllbot: merge +fix |
@jekyllbot: merge +fix |
@parkr could it be that jekyllbot doesn't accept comments that have multiple spaces in them (like yours did)? |
Perhaps! I'm not sure. Thanks for submitting the correction for me :) |
Backport #6266 for v3.5.x: Memoize the return value of Document#url
Backport #6266 for v3.5.x: Memoize the return value of Document#url
This breaks, e.g., generators that programatically calculate permalinks -- you must now explicitly un-set the I feel that as it used to be a dependent property, changing any of the values it depends on should invalidate the cache. But I don't know how to do that when it depends on values stored in hashes... |
Hey @ianthehenry! Can you give a simple example? We could set the |
Here was a plugin that I had # Because we put our posts in their own directories:
#
# _posts/2017-05-11-foo/index.md
#
# Instead of their own files:
#
# _posts/2017-05-11-foo.md
#
# The default slug is "foo/index". But this is annoying, so we strip it.
module Jekyll
class PermalinkRewriter < Generator
safe true
priority :low
def generate(site)
site.posts.docs.each do |post|
unless post.data.member?('permalink')
post.data['permalink'] = post.data['slug'].sub(/\/index$/, '') + '/'
end
end
end
end
end After upgrading to 3.5.2, I had to make this tweak: module Jekyll
class Document
def invalidate_url
@url = nil
end
end
class PermalinkRewriter < Generator
safe true
priority :low
def generate(site)
site.posts.docs.each do |post|
unless post.data.member?('permalink')
post.data['permalink'] = post.data['slug'].sub(/\/index$/, '') + '/'
# As of 3.5.2, post.url is memoized, and not recalculated when one of
# the properties it's based on changes.
#
# https://github.com/jekyll/jekyll/pull/6266
post.invalidate_url
end
end
end
end
end Which, you know, was after a bit of head-scratching and then looking for probable commit messages. I suppose I could also just override the |
Running
bundle exec rake site:generate
locally, this brings generation time from 16 seconds down to 8 seconds.