-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fix #8650 for improved hidden files finder performance #8784
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
Conversation
57x is nice 😆 |
@marcandre - I previously tested this, but turns out that the proposed solution is faster. require "benchmark/ips"
Benchmark.ips(7) do |x|
x.report("glob") { hidden_files = Set.new(all_files - find_files(base_dir, 0)) }
x.report("select") { hidden_files = all_files.select { |file| file.include?(HIDDEN_FILE_PATTERN) } }
x.report("grep") { hidden_files = all_files.grep(%r{#{File::SEPARATOR}\.}) }
x.compare!
end
|
c32c9a3
to
8311f71
Compare
Ah, right... Forgot about https://bugs.ruby-lang.org/issues/17030 |
FYI Benchmark.ips(7) do |x|
x.report("glob") { hidden_files = Set.new(all_files - find_files(base_dir, 0)) }
x.report("include?") { hidden_files = all_files.select { |file| file.include?(HIDDEN_FILE_PATTERN) } }
x.report("=~") { hidden_files = all_files.select { |file| file =~ hidden_file_regex } }
x.report("match?") { hidden_files = all_files.select { |file| file.match?(hidden_file_regex) } }
x.report("grep") { hidden_files = all_files.grep(hidden_file_regex) }
x.compare!
end
|
lib/rubocop/target_finder.rb
Outdated
@@ -5,6 +5,8 @@ module RuboCop | |||
# and picking ruby files. | |||
# @api private | |||
class TargetFinder | |||
HIDDEN_FILE_PATTERN = "#{File::SEPARATOR}." |
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 that naming this "pattern" is a good idea, as it makes me think of regular expressions. :-)
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.
updated to HIDDEN_PATH_SUBSTRING
lib/rubocop/target_finder.rb
Outdated
@@ -55,7 +57,7 @@ def target_files_in_dir(base_dir = Dir.pwd) | |||
# Support Windows: Backslashes from command-line -> forward slashes | |||
base_dir = base_dir.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR | |||
all_files = find_files(base_dir, File::FNM_DOTMATCH) | |||
hidden_files = Set.new(all_files - find_files(base_dir, 0)) | |||
hidden_files = all_files.select { |file| file.include?(HIDDEN_FILE_PATTERN) } |
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'd add a note we're doing this for performance reasons, as someone might want to optimize it for readability or whatever.
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.
adde comment
8311f71
to
b19bc2b
Compare
b19bc2b
to
bf35216
Compare
Faster find of hidden files in
TargetFinder
class which improves rubocop initial startup speed.Benchmarks now show a 57x improvement in one large project tested:
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.