耙资产:预编译需要很长时间才能完成 [英] rake assets:precompile taking extremely long to complete

查看:35
本文介绍了耙资产:预编译需要很长时间才能完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的开发沙箱中

RAILS_ENV=production rake assets:precompile

需要 4 多分钟才能完成.这正常吗.在 heroku 上,完成这项工作需要 10 多分钟,有时会超时.有什么办法可以剖析这个和/或加快速度吗?

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?

更新

我分析了编译的 CSS 与 JS 阶段

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

    ----------------------
    /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

timeit 调用是进行计时的附加位

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

推荐答案

hackety hack 解决方案似乎是给标准的 sass 压缩引擎打补丁.我将此添加到我的 application.rb 的顶部

The hackety hack solution seems to be to monkey patch the standard sass compression engine out of the way. I added this to the top of my application.rb

module Sass
  module Rails
    class CssCompressor
      def compress(css)
        css
      end
    end
  end
end

猴子补丁之前的文件大小差异为 124k,之后为 125k,速度提升了一个数量级.

The difference in file size was 124k before the monkey patch and 125k after and an order of magnitude speed improvement.

这篇关于耙资产:预编译需要很长时间才能完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆