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

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

问题描述

在我的开发人员沙箱中

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}\t #{context}"
  end
end

推荐答案

棘手的黑客解决方案似乎是在干扰标准sass压缩引擎的补丁.我将此添加到了我的应用程序的顶部.

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天全站免登陆