Skip to content

Commit ff8035d

Browse files
committed
Defer requiring Rake until it's needed.
Eagerly requiring Rake could put 100ms on to the Rails boot time. Shimmy that down to 0 by requiring Rake when no native Rails command exists and we try to run a Rake task. Or when printing all the Rake commands through `rails help`. Fixes rails#25029
1 parent 8f26f31 commit ff8035d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

railties/lib/rails/commands/rake_proxy.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
require "rake"
21
require "active_support"
32

43
module Rails
54
module RakeProxy #:nodoc:
65
private
76
def run_rake_task(command)
7+
require_rake
8+
89
ARGV.unshift(command) # Prepend the command, so Rake knows how to run it.
910

1011
Rake.application.standard_exception_handling do
@@ -15,6 +16,8 @@ def run_rake_task(command)
1516
end
1617

1718
def rake_tasks
19+
require_rake
20+
1821
return @rake_tasks if defined?(@rake_tasks)
1922

2023
ActiveSupport::Deprecation.silence do
@@ -30,5 +33,9 @@ def rake_tasks
3033
def formatted_rake_tasks
3134
rake_tasks.map { |t| [ t.name_with_args, t.comment ] }
3235
end
36+
37+
def require_rake
38+
require "rake" # Defer booting Rake until we know it's needed.
39+
end
3340
end
3441
end

0 commit comments

Comments
 (0)