Skip to content
This repository

Exponential Compilation Time in Compressed Style #337

Closed
yfeldblum opened this Issue March 26, 2012 · 14 comments

4 participants

Jay Feldblum Nathan Weizenbaum Tony Coconate Larry Gebhardt
Jay Feldblum

Some people are experiencing seemingly exponential blowups in time taken to compile in compressed style.

This happens when compiling with production settings in the Rails asset pipeline (rake assets:precompile) when config.assets.compress = true.

When running rake with --trace and INTerrupting at any time during the compilation, one discovers that the hang is inside Sass::Tree::CommentNode#normalize_indentation every time.

In this method, a very large number of large arrays is being created. So many arrays that perhaps the GC is thrashing.

The inner loop of this method should be modified to be much more memory-conservative. In particular, instead of Array#+, favor rewriting to use Array#<<.

This should dramatically reduce the number of large arrays being created, and speed up compilation in compressed style.

Nathan Weizenbaum
Owner
nex3 commented March 27, 2012

Can you provide an example of input that causes this exponential increase? I'd like to have something to test against so I can know when I've solved the problem.

Jay Feldblum

twbs/bootstrap-sass#62 provides a good example.

I've gisted that example here: https://gist.github.com/e302bb4bc1f373a9b934.

Nathan Weizenbaum
Owner
nex3 commented March 27, 2012

Is there a way to do it without setting up a Rails app? If not, could you put the Rails app in a repo somewhere?

Jay Feldblum

It's really just a brand new rails app.

Add the gem bootstrap-sass to Gemfile.

Create the following app/assets/stylesheets/application.css.sass:

@import bootstrap
@import bootstrap-responsive

I have created a Rails application repo: yfeldblum/sass-337. I've removed everything except the bare necessity for running rake assets:precompile.

Tony Coconate

+1 I can see the code hang on Sass::Tree::CommentNode#normalize_indentation when attaching the perftools.rb to use as a profiler with a blank Rails app containing the bootstrap-sass gem.

Nathan Weizenbaum nex3 closed this issue from a commit March 28, 2012
Nathan Weizenbaum Fix a perf bug with CommentNode#normalize_indentation.
When a single line had ridiculously long preceding whitespace,

Closes #337
a69ebc6
Nathan Weizenbaum nex3 closed this in a69ebc6 March 28, 2012
Nathan Weizenbaum
Owner
nex3 commented March 28, 2012

This was also related to sass-rails#101, which was causing the massive input to #normalize_indentation in the first place by running the already-compressed Sass code through Sass again.

Chris Nicola chrisnicola referenced this issue in twbs/bootstrap-sass April 04, 2012
Closed

SCSS compilation is very slow with jruby #90

Chris Nicola chrisnicola referenced this issue in vwall/compass-twitter-bootstrap April 04, 2012
Closed

Asset precompile seems significantly slower #25

Chris Nicola chrisnicola referenced this issue in Compass/compass-rails April 04, 2012
Closed

assets:precompile still incredibly slow #26

Jay Feldblum

@nex3 Do you still need the sample app?

Nathan Weizenbaum
Owner
nex3 commented April 06, 2012

No, I don't.

Larry Gebhardt

I am still experiencing this issue. On an older and slower test server I was getting times of about an hour to precompile assets. Turning off the compression it drops to a couple of minutes. I am using bootstrap-sass 2.3.1 on a windows machine with ruby 1.9.3p125.

Nathan Weizenbaum nex3 reopened this May 22, 2012
Nathan Weizenbaum
Owner
nex3 commented May 22, 2012

@lgebhardt Can you produce a sample app that demonstrates the issue?

Larry Gebhardt

@nex3, I have an app up at https://github.com/lgebhardt/simple_bs_app_demo. Sorry it took so long.

Nathan Weizenbaum nex3 closed this June 15, 2012
Nathan Weizenbaum
Owner
nex3 commented June 15, 2012

@lgebhardt As far as I can tell, your example doesn't have exponential compile time. Adding more content to the stylesheet doesn't seem to increase the compile time any more than linearly. It looks like the "compress" flag just adds some additional, constant overhead (about 5s on my machine).

Closing again because I can't reproduce.

Larry Gebhardt

@nex3, what platform did you test this on? I was running it on a Windows box. I'll test the same code on mac or linux soon.

Nathan Weizenbaum
Owner
nex3 commented June 22, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.