Exponential Compilation Time in Compressed Style #337

Closed
yfeldblum opened this Issue Mar 27, 2012 · 14 comments

Projects

None yet

4 participants

@yfeldblum

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.

@nex3

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.

@yfeldblum

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

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

@nex3

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?

@yfeldblum

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.

@tonycoco

+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.

@nex3 nex3 added a commit that closed this issue Mar 28, 2012
@nex3 nex3 Fix a perf bug with CommentNode#normalize_indentation.
When a single line had ridiculously long preceding whitespace,

Closes #337
a69ebc6
@nex3 nex3 closed this in a69ebc6 Mar 28, 2012
@nex3

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.

@yfeldblum

@nex3 Do you still need the sample app?

@nex3

No, I don't.

@lgebhardt

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.

@nex3 nex3 reopened this May 22, 2012
@nex3

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

@lgebhardt

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

@nex3

@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.

@nex3 nex3 closed this Jun 15, 2012
@lgebhardt

@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.

@nex3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment