Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
765 views
in Technique[技术] by (71.8m points)

performance - rake assets:precompile taking extremely long to complete

In my dev sandbox

RAILS_ENV=production rake assets:precompile

is taking over 4 minutes to complete. Is this normal. On heroku it is taking over 10 minutes to do the job and sometimes is timing out. Is there any way to disect this and/or speed it up?

UPDATE

I profiled the CSS vs JS phases of compilation

3.7 s        js
175 s            css

The numbers were made by instrumenting here

----------------------
/Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@gobbq/gems/sprockets-2.1.2/lib/sprockets/processing.rb
----------------------
266     # Assign a compressor to run on `application/javascript` assets.
267     #
268     # The compressor object must respond to `compress` or `compile`.
269     def js_compressor=(compressor)
270       expire_index!
271  
272       unregister_bundle_processor 'application/javascript', :js_compressor
273       return unless compressor
274  
275       register_bundle_processor 'application/javascript', :js_compressor do |context, data|
276  
277         timeit "js" do
278           compressor.compress(data)
279         end
280  
281       end
282     end

and

    ----------------------
    /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@gobbq/gems/sprockets-2.1.2/lib/sprockets/processing.rb
    ----------------------
    241  
    242     # Assign a compressor to run on `text/css` assets.
    243     #
    244     # The compressor object must respond to `compress` or `compile`.
    245     def css_compressor=(compressor)
    246       expire_index!
    247  
    248       unregister_bundle_processor 'text/css', :css_compressor
    249       return unless compressor
    250  
    251       register_bundle_processor 'text/css', :css_compressor do |context, data|
    252         timeit "css" do
    253           compressor.compress(data)
    254         end
    255       end
    256     end

The timeit call is the added bit doing the timing

def timeit context
  s = Time.now
  yield.tap do 
    e = Time.now
    d = e - s
    puts "#{d*1000} #{context}"
  end
end
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I am on Rails 3.2.13 - I had the same problem with css compression taking an extremely long time. To fix:

In Gemfile add:

gem 'yui-compressor'

In config/environments/production.rb:

config.assets.css_compressor = :yui
config.assets.js_compressor = :yui

rake assets:precompile without those changes: 325 seconds

rake assets:precompile with those changes: 79 seconds

rake assets:precompile with no compression: 45 seconds


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...