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 allocations from URLFilters #7641
Conversation
I do not want to introduce another breaking change in the 4.0 release cycle. Let's write a custom |
Profiler summary--- master branch https://travis-ci.org/jekyll/jekyll/jobs/532959217
+++ PR branch https://travis-ci.org/jekyll/jekyll/jobs/532976771
- Total allocated: 532.65 MB (5301707 objects)
- Total retained: 18.34 MB (96237 objects)
+ Total allocated: 532.22 MB (5295029 objects)
+ Total retained: 18.34 MB (96242 objects) |
@@ -2,7 +2,7 @@ | |||
|
|||
module Jekyll | |||
class Site | |||
attr_reader :source, :dest, :cache_dir, :config | |||
attr_reader :source, :dest, :cache_dir, :config, :sanitized_baseurl, :sanitized_url |
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.
I'm not sure how I feel about adding new public attr_reader
s to Jekyll::Site
, since they'll become part of the public API.
Are there any disadvantages to always returning a sanitized baseurl and a sanitized url?
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.
The disadvantage is unnecessary allocations. Technically, I'm only using site.sanitized_baseurl
. The sanitized_url
is just being provided for completeness.
Since you're on the fence about this, let us wait and see if the optimizations make a difference with a future state of master
Do we need to revisit this after #7793 ? |
No. I don't think it's worth the added complexity. |
Summary
Many temporary objects are repeatedly allocated within
relative_url
andabsolute_url
.This PR attempts to reduce allocating such temporary objects.
In the following lines:
jekyll/lib/jekyll/filters/url_filters.rb
Lines 35 to 39 in 8673cdc
ln#35
callsinput.to_s
but does not store the resultln#37
initializes a two-member array on each call to#relative_url
ln#39
duplicates above array via non-destructivecompact
and non-destructivemap
with each member being subject toto_s
calls.With the proposed changes, the intermediate array objects and the numerous calls to
to_s
have been eliminated.API Changes
private
methodURLFilters#sanitized_baseurl
removed. Classes mixing-in theJekyll::Filters
module may need to update to usingsite.baseurl
directly.site
now responds to:sanitized_baseurl
and:sanitized_url
(getters)Utils.strip_leading_or_trailing_slashes
relative_url
andabsolute_url
now handles multiple leading or trailing slashes in bothconfig["baseurl"]
andconfig["url"]
Context
Additionally resolves #6947