Let’s say I make a small change to any class file and make request to some page on my application. Then my response times are increased by anywhere from 10 seconds to a minute or more. The next request I make takes less than a second. Any idea on how I can go about debugging this and bring down the time taken by the first request? What would be the usual culprits for this?
Most likely, webpack takes so much time to build assets. You can confirm that with your log output.
If webpack is the culprit and depending on your app, you can instead switch to esbuild or directly use importmaps (ref).
How would I confirm that with my log output. What should I be looking for specifically?
In your log, you can see something like [Webpacker] Compiling...
. Soon after you access your page for the first time, go to log and measure time the build finishes (you can know it by other log outputs).
You can also try to run bin/webpack-dev-server
along with rails s
and check if it speeds up the first access.
Does “Compiling…” get printed to the terminal or is it something that just shows up on the terminal and goes away? I haven’t seen the “Compiling…” message anywhere in the terminal so far.
I ran bin/webpack-dev-server rails s
on the terminal and I got
Traceback (most recent call last):
6: from bin/webpack-dev-server:15:in `<main>'
5: from /home/redd/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/webpacker-3.5.5/lib/webpacker/runner.rb:6:in `run'
4: from /home/redd/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/webpacker-3.5.5/lib/webpacker/dev_server_runner.rb:12:in `run'
3: from /home/redd/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/webpacker-3.5.5/lib/webpacker/dev_server_runner.rb:54:in `execute_cmd'
2: from /home/redd/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/webpacker-3.5.5/lib/webpacker/dev_server_runner.rb:54:in `chdir'
1: from /home/redd/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/webpacker-3.5.5/lib/webpacker/dev_server_runner.rb:55:in `block in execute_cmd'
/home/redd/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/webpacker-3.5.5/lib/webpacker/dev_server_runner.rb:55:in `exec': No such file or directory - /home/redd/galaxy/node_modules/.bin/webpack-dev-server (Errno::ENOENT)
Though when I checked bin/webpack-dev-server.rb
file It had the following contents.
#!/usr/bin/env ruby
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
ENV["NODE_ENV"] ||= "development"
require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
require "rubygems"
require "bundler/setup"
require "webpacker"
require "webpacker/dev_server_runner"
Webpacker::DevServerRunner.run(ARGV)
Please let me know what you think.
I noticed that the version of Ruby and Webpacker you’re using are quite outdated. Upgrading might solve your problem.
You don’t see “compiling” message once after the compiling finished. When you edit your javascript code, you’ll see the message again.
Hmm. I tried updating ruby version to 2.7.0 but that breaks my application. I am guessing this is because that upgrade breaks by rails application which has rails version 5.1.4. Any ideas on what else I could try to optimize the performance of my development server with the current version of rails 5.1.4.
Also, I did not see “compiling” message. So does that mean webpacker is not the issue?