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 +4 -4
- data/README.md +30 -8
- data/lib/turbo-sprockets/version.rb +1 -1
- data/lib/turbo-sprockets-rails4.rb +3 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 586a1535f71f9f7df3acd4db632c697ebc9580f4
|
4
|
+
data.tar.gz: 4eceb9773988542517ccadcd67b2eeafa29c2693
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
16
|
+
Sprockets is slow. Turbo-sprockets uses parallelism to speed it up so your life isn't spent waiting for assets.
|
17
17
|
|
18
|
-
|
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
|
-
###
|
20
|
+
### What's Included?
|
21
21
|
|
22
|
-
|
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
|
-
|
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
|
-
|
29
|
-
|
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
|
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
|
|
@@ -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:
|
54
|
-
preloader: { enabled:
|
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.
|
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-
|
11
|
+
date: 2017-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parallel
|