-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
Cache Jekyll.sanitized_path #8424
Conversation
Thank you for this submission, @fauno. I love optimization pull requests.
|
Thanks for the review! Would it be ok to move the cache to a private method in the module? Since it's caching results I don't find it so problematic to share the cache/instance var, since the result is idempotent anyway, no? As per mutability, I didn't take that into account, it could return a duplicated string, the benchmark looks better:
|
Thanks for the numbers! Very inspiring!
In a way, yes this is true. For example consider the following hypothetical plugin: class Foo
extend Jekyll
@sanitization_path_cache = {}
def self.clarify(input)
@sanitization_path_cache[input] ||= begin
lorem = call_business_logic(input)
sanitized_path(base, lorem)
end
end
end The code above would work as the author expected until Jekyll-4.1. The reason I'm saying this is not to discourage you but to err on the safer side. In the past, I myself had used instance variables as cache in a module (see
Ah! That's a nice solution. |
Looking good :)
|
I understand! But I can't think of a solution :) |
Using |
Fixed! |
Nice! Do you see a way to move the implementation into def sanitized_path(base, input)
Jekyll::PathManager.sanitized_path(base, input).dup
end |
Sure! It's benchmarking worse but still a lot better than current.
|
The implementation is looking great, @fauno! Nice work!
|
Done! Not sure if that's what you were thinking about tests (too early
in the morning over here :)
|
Close.. But not exactly.. I'll push a couple of commits some time tomorrow.. |
@fauno I'm satisfied with the current diff. |
The benchmark looks good! Thanks 👍 |
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.
👏 Great work @fauno, thanks for your help making Jekyll a little bit faster
@jekyll: merge +minor |
@fauno Thank you for improving Jekyll. |
I'm glad! Thanks for reviewing the patch and maintaining Jekyll :)
Sure, it's very simple, since I'm just learning to use stackprof. I've put the results on a pastebin since it's 2000 lines long require 'stackprof'
profile = StackProf.run mode: :object do
require 'jekyll'
config = Jekyll.configuration('source' => Dir.pwd,
'quiet' => true,
'watch' => false,
'safe' => true)
config.delete('theme')
config['markdown'] = 'kramdown'
config['plugins'] = []
site = Jekyll::Site.new(config)
site.process
end
StackProf::Report.new(profile).print_text |
Thanks for including the script as well. However, this repository already has a script to stackprof during dev: |
This is a 🔨 code refactoring.
Summary
I was running stackprof over a site with ~600 posts and noticed
Jekyll.sanitize_path
was being called many times over so I tried caching responses. Benchmarks logs forjekyll-sanitize-path
before and after:Before:
After: