Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprockets can't use cache, because SassCompressor#cache_key changes on every run #146

Open
ledestin opened this issue Apr 23, 2020 · 2 comments

Comments

@ledestin
Copy link

Problem

Running a single system test takes about 50 seconds on a project with lots of SASS files. I've investigated Sprockets and found out that SASS files are processed each time a test runs, and Sprockets cache isn't used. And it is not used, because of a random cache key in SassCompressor.

SassCompressor is monkey patched by sassc-rails and uses a random #cache_key:

@cache_key = SecureRandom.uuid

Possible solution

Sprockets uses the following cache key:
@cache_key = "#{self.class.name}:#{Autoload::Sass::VERSION}:#{VERSION}:#{DigestUtils.digest(options)}".freeze
https://github.com/rails/sprockets/blob/386ab2ba215f828602b6e6bfee9bfc95dc23d574/lib/sprockets/sass_compressor.rb#L46

By using the Sprockets @cache_key code, I was able to make the test 2x faster (50 -> 25 seconds).

Would it be possible to use a cache key that doesn't change on each run, when no other things have changed?

@ylecuyer
Copy link

I spent most of my afternoon hunting this bug and I had the same conclusion as yours. Our assets pipeline went from almost 2 minutes to 30 seconds with this fix.

@Aesthetikx
Copy link

Indeed, I just spent most of my evening on this one :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants