-
-
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
Reduce string allocations from generating doc URLs #8392
Reduce string allocations from generating doc URLs #8392
Conversation
@@ -94,7 +94,8 @@ def possible_keys(key) | |||
|
|||
def generate_url_from_drop(template) | |||
template.gsub(%r!:([a-z_]+)!) do |match| | |||
pool = possible_keys(match.sub(":", "")) | |||
name = Regexp.last_match(1) | |||
pool = name.end_with?("_") ? [name, name.chomp!("_")] : [name] |
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.
Notes:
Regexp.last_match(1)
here is equivalent tomatch.sub(":", "")
but without the extra allocation.- The
#possible_keys
public method does not mutate the argumentkey
but this inlined version modifies the string in-place.
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.
Given possible_keys
is not used anywhere else, should rewrite or remove it?
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.
Sadly, It is not a private method. So we'll have to bear the tech debt until v5.0
match.sub(":#{winner}", replacement) | ||
end.squeeze("/") | ||
match.sub!(":#{winner}", replacement) | ||
end |
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.
Notes:
- Calling
String#squeeze
here is redundant with respect to the bigger picture (Jekyll::URL.new.to_s
) because the result from this method is passed ontoJekyll::URL#sanitize_url
that removes extra"/"
from input strings. - The local
match
variable value is not further required. So it can be mutated.
- Total allocated: 300.38 MB (3084063 objects)
- Total retained: 20.75 MB (113527 objects)
+ Total allocated: 300.31 MB (3082539 objects)
+ Total retained: 20.75 MB (113529 objects) This seems to have an impact on build time: - Docs site build: 6.03 seconds
+ Docs site build: 3.969 seconds |
Its at times like these that I wish we could revive Utterson from its ashes.. |
Third Party Repo Profile Summary--- master
+++ PR
- Total allocated: 282.43 MB (2467827 objects)
- Total retained: 37.81 MB (112069 objects)
+ Total allocated: 281.22 MB (2441051 objects)
+ Total retained: 37.81 MB (112070 objects) |
@jekyllbot: merge +fix |
Summary
Generating URLs from a drop (current route for all documents of a collection) results in a lot of string allocations because of use of non-mutating methods to manipulate strings.
This pull request replaces those non-mutating methods that mutate a duplicated version of long-term strings and mutate temporary strings.