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
3.x super #507
3.x super #507
Changes from 14 commits
28d9de1
bc5167e
7258906
2ddd769
6276753
54056d7
05a6c9a
7edd51f
3c666b4
7f85cd3
3d03b3f
4a24c4d
83db3e3
dd4d948
b847baf
6e66d69
fc3fcc6
7432e83
2bbba2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,6 +153,12 @@ def parse_accept_options(mime_type, types) | |
end | ||
|
||
def path_matches(load_path, logical_name, logical_basename) | ||
@@gorilla_djungle_banana_cache ||= {} | ||
app_root = Sprockets.check_modified_root | ||
is_in_app = load_path[0...app_root.size] == app_root | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might make sense to stringify There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, that method call is used in several places. Might make sense to always return a string from it instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if !is_in_app && @@gorilla_djungle_banana_cache.has_key?([load_path, logical_name, logical_basename]) | ||
return @@gorilla_djungle_banana_cache[[load_path, logical_name, logical_basename]] | ||
end | ||
dirname = File.dirname(File.join(load_path, logical_name)) | ||
candidates = dirname_matches(dirname, logical_basename) | ||
deps = file_digest_dependency_set(dirname) | ||
|
@@ -170,11 +176,18 @@ def path_matches(load_path, logical_name, logical_basename) | |
end | ||
|
||
deps.merge(file_digest_dependency_set(dirname)) | ||
|
||
return candidates.select { |fn, _| file?(fn) }, deps | ||
result = candidates.select { |fn, _| file?(fn) }, deps | ||
@@gorilla_djungle_banana_cache[[load_path, logical_name, logical_basename]] = result if !is_in_app | ||
result | ||
end | ||
|
||
def dirname_matches(dirname, basename) | ||
@@gorilla_djungle_banana_tree_cache ||= {} | ||
app_root = Sprockets.check_modified_root | ||
is_in_app = dirname[0...app_root.size] == app_root | ||
if !is_in_app && @@gorilla_djungle_banana_tree_cache.has_key?([dirname, basename]) | ||
return @@gorilla_djungle_banana_cache[[dirname, basename]] | ||
end | ||
candidates = [] | ||
entries = self.entries(dirname) | ||
entries.each do |entry| | ||
|
@@ -184,6 +197,7 @@ def dirname_matches(dirname, basename) | |
candidates << [File.join(dirname, entry), type] | ||
end | ||
end | ||
@@gorilla_djungle_banana_tree_cache[[dirname, basename]] = candidates if !is_in_app | ||
candidates | ||
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.
this isn't significantly faster, only 10% on ruby 2.4 and even slower on older versions
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.
oh, interesting, it makes the digest completely disappear from my callgraph,
what os, cpu are did you try on?
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.
well, if 10% is not significant ...
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.
10% improvement looks nice, but if this call takes for instance only 5% of the entire compilation process, than it's only a microoptimization without any significant effect.
I was wondering how fast this digest optimization is, so I tested it on our pipeline (big project) and here're my numbers (spent time in this method, same hw)
ruby 2.4.2 windows 29,4% faster
ruby 2.4.2 linux 17,1% faster
ruby 2.1.9 windows 8,6% slower
ruby 2.1.9 linux 17.6% faster
jruby 9.1.13.0 windows 10,3% slower
jruby 9.1.13.0 linux 11,1% slower
I didn't have time to dig deeper. In my opinion your implementation should be faster, but optimizations are sometimes tricky :)
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.
Thanks for the numbers, terrific :)
With the compilation time going down 10 times, the digest became very well visible in the call graph, therefore i looked at it, because that small improvement became more significant with overall times going down that much.
ruby 2.1.* is obsolete since spring 2017
jruby only supports rails 4, which is, except for severe security issues, out of support too
And if a case is slower on jruby, and if this project really wants to support jruby, this may be a good case for opening a 'performance: case' ticket over at jruby. :)
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.
Originally I optimized this using refinements, it's even faster than what we ended up with in MRI. But it made it way slower on jruby.
If you're going to do microbenchmarks, please use benchmark-ips as in
Last time we looked at this the hash method was faster than the case method. A big improvement was added when we started using compare with identity https://github.com/rails/sprockets/pull/439/files.