Skip to content
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

(Performance) Remove unnecessary I/O syscalls for FileTasks #393

Merged
merged 2 commits into from
Mar 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/rake/file_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ class FileTask < Task
# Is this file task needed? Yes if it doesn't exist, or if its time stamp
# is out of date.
def needed?
!File.exist?(name) || out_of_date?(timestamp) || @application.options.build_all
begin
out_of_date?(File.mtime(name)) || @application.options.build_all
Copy link
Contributor Author

@da2x da2x Sep 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling File.mtime here directly instead of timestamp because checking to see if it returned Rake::LATE was significantly slower. This is functionally the same as before as out_of_date? would never receive Rake::LATE except if there was a race condition between the first and second File.exist checks.

rescue Errno::ENOENT
true
end
end

# Time stamp for file task.
def timestamp
if File.exist?(name)
File.mtime(name.to_s)
else
begin
File.mtime(name)
rescue Errno::ENOENT
Rake::LATE
end
end
Expand Down