Slow loading rails environment
I solved it with downgrating my ruby stack to ree-1.8.7 :(
slow rails stack
That is bothering me also, since I have switched to Rails 3.
To your second question: I found by digging through the framework that the initializers take about half the time of a simple rake or rails call before it actually starts doing its task.
If you put these simple timing lines into the loop of initializer calls in $GEM_PATH/gems/railties-3.0.3/lib/rails/initializable.rb
(or piggy-back it if you like):
def run_initializers(*args)
return if instance_variable_defined?(:@ran)
t0 = Time.now
initializers.tsort.each do |initializer|
t = Time.now
initializer.run(*args)
puts("%60s: %.3f sec" % [initializer.name, Time.now - t])
end
puts "%60s: %.3f sec" % ["for all", Time.now - t0]
@ran = true
end
EDIT: Or, for railties 4.2.1:
def run_initializers(group=:default, *args)
return if instance_variable_defined?(:@ran)
t0 = Time.now
initializers.tsort.each do |initializer|
t = Time.now
initializer.run(*args) if initializer.belongs_to?(group)
puts("%60s: %.3f sec" % [initializer.name, Time.now - t])
end
puts "%60s: %.3f sec" % ["for all", Time.now - t0]
@ran = true
end
... you can follow up what happens. On my system, which is a 2.4 Core 2 Duo MacBook the initializers take about 7 seconds.
There are a few that are especially slow on my system. When I filter all out below a second, I get this result on my system:
load_active_support: 1.123 sec
active_support.initialize_time_zone: 1.579 sec
load_init_rb: 1.118 sec
set_routes_reloader: 1.291 sec
I am sure somebody (is it me?) will take some time to start there and optimize.
Slow loading of rails environment
If you are using Ruby 1.9 then see this blog post it may be the issue you are experiencing. If it is it has to do with the amount of requires in your project and the way that method is implemented in 1.9. There is a patch available to improve this performance.
Rails 3.1, rspec, guard and spork is really slow on windows
Because rspec loads the rails environment, it's slow. The more gems you have the slower it gets
Thats why spork is a great tool. It loads the rails environment and guard can look for the changes without reloading the rails environment. But there is a bug in the guard-spork gem. It does not work with windows because it depends on fork. Even tough spork do not use fork on windows guard-spork does. Fork is not supported on non-UNIX systems.
I researched the problem and ended up with a different aproach. I facture out the logic to the lib folder and do not include the spec_helper file in the specs. Then rails does not get loaded, only the spesific test logic. This is fast and force me to write more readable code.
Check out this video on a talk by Cory Haines, for more on the subject.
rails generate' commands hang when trying to create a model
If your rails generate
commands hangs, it is most likely that the generated binstubs of rails are the issue. As you mentioned, you renamed the project.
My educated guess is that some paths in the binstubs were still set to the old project directory but did not exist any longer.
There is a great article on how binstubs work here: https://github.com/sstephenson/rbenv/wiki/Understanding-binstubs
rails 4
To reset the binstubs, just delete your bin/
directory in rails and run:
# generates binstubs for ALL gems in the bundle
bundle install --binstubs
# ...OR, generate binstubs for a SINGLE gem (recommended)
bundle binstubs rake
rails 5/rails 6
To reset the binstubs, just delete your bin/
directory in rails and run:
rake app:update:bin
Why do we need to use the 'rake' command for rails 5 and higher, and not the 'rails' command itself?
Since rails 5 some 'rake' commands are encapsulated within the 'rails' command. However when one deletes 'bin/' directory one is also removeing the 'rails' command itself, thus one needs to go back to 'rake' for the reset since 'rails' is not available any longer but 'rake' still is.
Ruby on Rails console is hanging when loading
Restarting Spring should fix the hanging commands:
$ bin/spring stop
I experienced hanging commands (rake, bin/rails, etc.) after deleting and recreating a new Ruby on Rails application. Google wasn't that helpful. I hope this is.
Spring will start automatically when you re-run your command.
Related Topics
How to Rescue from a Require "Gem_Name" When the Gem Is Not Installed
MAC Osx Lion and Ruby - [Fatal] Failed to Allocate Memory
Is the .Each Iterator in Ruby Guaranteed to Give the Same Order on the Same Elements Every Time
Session Not Destroyed When Closing Browser - Railstutorial.Org
How to Do Ruby Object Serialization Using JSON
Modifying the Default Hash Value
Install Nokogiri 1.6.1 Under Ruby 2.0.0P353 (Rvm Based Installation) Fails (Osx Mavericks)
Generate All "Unique" Subsets of a Set (Not a Powerset)
Rails Error Method_Missing': Undefined Method 'This' for Gem::Specification
Access Current Git Commit Number from Within Heroku App
Rails 3 Cli Executes Commands Really Slow
Opening Several Threads with Watir-Webdriver Results in 'Connection Refused' Error
How to Convert Boolean Values to Integers
Tcp Socket Communication Between Processes on Heroku Worker Dyno