turbo-sprockets-rails4 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93dc4b63a52cdc1eac49f1cb2465a380d547ae89
4
- data.tar.gz: 35b1991e4acb678231774f80f13ef1cdf707c4bc
3
+ metadata.gz: 586a1535f71f9f7df3acd4db632c697ebc9580f4
4
+ data.tar.gz: 4eceb9773988542517ccadcd67b2eeafa29c2693
5
5
  SHA512:
6
- metadata.gz: 06571631ba75f30ee811bca5c54fdb3de1fb8d2e2aa69e7910b44db0ef7e5c427bedcbf52a658cf42dd402af406fa331d88e153098d50af2758d221fb20b9ff8
7
- data.tar.gz: 455c9c46852d8e3acc202e8c1891ae36694ce2a5592b1ab4d6b1c701ec4d373342ceaf52f921035f8c0489666794d1a8bd83c3c183e0d3ac2d890e831f6f6fa5
6
+ metadata.gz: 558451bc96260c09d900bd0c3b7759a4435988996d8688108a15359a0f1ead9604f16b68997158f7ebfdcdcdbe92db3b7bd5b17d41571cef70bdb356363c741b
7
+ data.tar.gz: 22c72028140da901b39001d3b1da1ad93cfa63c18ff0642731dbc77f48d0c0714d4d030ad1a38449eccfc97054584d970ef0052d52d6fc59db6548d35ab57566
data/README.md CHANGED
@@ -13,25 +13,47 @@ gem 'turbo-sprockets-rails4'
13
13
 
14
14
  ### Rationale
15
15
 
16
- In a large Rails application, assets can take a very long time to precompile. It can be a real drag on productivity and deployments to have to wait until your assets are done precompiling. Although the slowness can be attributed to a number of factors, one of the most significant has to do with Ruby's single-threaded execution model. Most servers and laptops these days come with multiple processors or cores, but Rails doesn't take advantage of them. Wouldn't it be nice if we could put all our CPU cores to work precompiling assets?
16
+ Sprockets is slow. Turbo-sprockets uses parallelism to speed it up so your life isn't spent waiting for assets.
17
17
 
18
- That's where this gem comes in. turbo-sprockets is capable of precompiling assets in parallel, using all the CPU cores available on your laptop or server. Generally this translates into a substantial speed increase. In one of the large codebases I've worked on, turbo-sprockets decreased the total precompile time from ~12 minutes to ~2 minutes using the four cores on my laptop.
18
+ Said a little more long-form, a large, long-lived Rails application can have a ton of static assets. It can be a real drag on productivity and deployments to have to wait for Rails to chew through them all. Although the slowness can be attributed to a number of factors, one of the most significant has to do with Ruby's single-threaded execution model. Most servers and laptops these days come with multiple processors or cores, but Rails doesn't take advantage of them. Wouldn't it be nice if we could put all our CPU cores to work precompiling assets? That's where turbo-sprockets comes in.
19
19
 
20
- ### Getting Started
20
+ ### What's Included?
21
21
 
22
- turbo-sprockets is designed to work as a drop-in addition to your Rails app. Adding it to your Gemfile and running `bundle install` should be all that's necessary to enable your application to precompile assets in parallel.
22
+ Turbo-sprockets includes two major components: the asset precompiler and the asset preloader.
23
+
24
+ #### Asset Precompiler
25
+
26
+ The turbo-sprockets precompiler precompiles assets in parallel using potentially all the CPU cores available on your laptop or server. Generally this translates into a substantial speed increase. In one of the large codebases I've worked on, turbo-sprockets decreased the total precompile time from ~12 minutes to ~2 minutes using the four cores on my laptop. Obviously that's a micro benchmark that doesn't mean much, so your mileage may vary. Intuitively however, tasks get done faster when you can do more than one at a time.
27
+
28
+ #### Asset Preloader
29
+
30
+ The asset preloader is a little different. As of Sprockets 3, a Rails server running in the development environment will attempt to compile and cache every asset your application might need _on the first page request_. This is different from how things used to work. In the old days, Rails would compile assets on-the-fly. For example, if your app requested dashboard.css but not home_page.css, Rails would only compile dashboard.css. For applications with a large number of assets, compiling all of them on the first page request can be prohibitively time-consuming. The asset preloader tries to alleviate this pain by compiling and caching assets in parallel when your app boots. It's like the precompiler, but for development.
23
31
 
24
32
  ### Configuration
25
33
 
26
- Rather than guess how many CPU cores your computer has (which can be error prone), turbo-sprockets asks that you set the `SPROCKETS_WORKER_COUNT` environment variable (2 cores are used by default). For example, to precompile using 4 workers, you might run:
34
+ By default, asset preloading is enabled only in the development environment, and only if you're running `rails server`. Precompiling is enabled in every environment _except_ development. You can enable or disable these two components by configuring turbo-sprockets (generally in one of your environment files, or maybe an initializer):
35
+
36
+ ```ruby
37
+ TurboSprockets.configure do |config|
38
+ config.preloader.enabled = false
39
+ config.precompiler.enabled = false
40
+ end
41
+ ```
42
+
43
+ #### Parallelism
27
44
 
28
- ```bash
29
- SPROCKETS_WORKER_COUNT=4 bundle exec rake assets:precompile
45
+ By default, parallel preloading and precompiling will spin up two processes to perform the necessary work. You can set this number in one of two ways. Use the `TURBO_SPROCKETS_WORKER_COUNT` environment variable, eg. `TURBO_SPROCKETS_WORKER_COUNT=2 bundle exec rake assets:precompile` or set it when configuring turbo-sprockets:
46
+
47
+ ```ruby
48
+ TurboSprockets.configure do |config|
49
+ config.preloader.worker_count = 2
50
+ config.precompiler.worker_count = 2
51
+ end
30
52
  ```
31
53
 
32
54
  ### How Does it Work?
33
55
 
34
- Under the hood, turbo-sprockets uses the [parallel](https://github.com/grosser/parallel) gem to divide your assets up amongst the available CPUs. It works by [forking](https://en.wikipedia.org/wiki/Fork_(system_call)) into multiple system processes which are executed in parallel by your operating system.
56
+ Under the hood, turbo-sprockets uses the [parallel](https://github.com/grosser/parallel) gem to divide your assets up amongst the available CPU cores. It works by [forking](https://en.wikipedia.org/wiki/Fork_(system_call)) into multiple system processes which are executed in parallel by your operating system.
35
57
 
36
58
  ### Supported Platforms
37
59
 
@@ -1,3 +1,3 @@
1
1
  module TurboSprockets
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -49,9 +49,10 @@ module TurboSprockets
49
49
  end
50
50
 
51
51
  def configuration
52
+ # hopefully people think these are sane defaults :|
52
53
  @configuration ||= Config.new(
53
- precompiler: { enabled: true },
54
- preloader: { enabled: true }
54
+ precompiler: { enabled: !Rails.env.development? },
55
+ preloader: { enabled: Rails.env.development? && Rails.const_defined?(:Server) }
55
56
  )
56
57
  end
57
58
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbo-sprockets-rails4
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-17 00:00:00.000000000 Z
11
+ date: 2017-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parallel