bootsnap 1.4.1 → 1.4.2.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +2 -0
- data/.github/probots.yml +2 -0
- data/.travis.yml +0 -3
- data/CHANGELOG.md +5 -0
- data/README.md +16 -2
- data/ext/bootsnap/bootsnap.c +6 -6
- data/lib/bootsnap/compile_cache/iseq.rb +2 -0
- data/lib/bootsnap/compile_cache/yaml.rb +9 -5
- data/lib/bootsnap/compile_cache.rb +12 -0
- data/lib/bootsnap/load_path_cache/cache.rb +17 -1
- data/lib/bootsnap/load_path_cache/core_ext/active_support.rb +18 -7
- data/lib/bootsnap/load_path_cache/store.rb +5 -3
- data/lib/bootsnap/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b7e391a76fc9fe8cc2c712d7623f26e6138f24c62acd3cd16a470f50812e554
|
4
|
+
data.tar.gz: 23d068050fd8c1962915608e73418c01dc568cc5371a5d27f77a269ef2926aeb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 815c87a26099673845b530d5a0bb2000ceda89f15a17eeca178b087d3ae4af6230ce8dcaa15a4360a2fdb0fc8d923d0659dc47ac6a7d2b072d43eebadeaebc79
|
7
|
+
data.tar.gz: 46584a5b22e3a64a02302a3ea87dfbe6e99676935838560ec93f938a0c3b86e854aacd48364e4f7161c021d5472497844b3d81074e1a3cc1be82a2aac3bee158
|
data/.github/CODEOWNERS
ADDED
data/.github/probots.yml
ADDED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -4,9 +4,14 @@ Bootsnap is a library that plugs into Ruby, with optional support for `ActiveSup
|
|
4
4
|
to optimize and cache expensive computations. See [How Does This Work](#how-does-this-work).
|
5
5
|
|
6
6
|
#### Performance
|
7
|
-
|
7
|
+
|
8
|
+
- [Discourse](https://github.com/discourse/discourse) reports a boot time reduction of approximately
|
9
|
+
50%, from roughly 6 to 3 seconds on one machine;
|
8
10
|
- One of our smaller internal apps also sees a reduction of 50%, from 3.6 to 1.8 seconds;
|
9
|
-
- The core Shopify platform -- a rather large monolithic application -- boots about 75% faster,
|
11
|
+
- The core Shopify platform -- a rather large monolithic application -- boots about 75% faster,
|
12
|
+
dropping from around 25s to 6.5s.
|
13
|
+
* In Shopify core (a large app), about 25% of this gain can be attributed to `compile_cache_*`
|
14
|
+
features; 75% to path caching, and ~1% to `disable_trace`. This is fairly representative.
|
10
15
|
|
11
16
|
## Usage
|
12
17
|
|
@@ -284,3 +289,12 @@ open /c/nope.bundle -> -1
|
|
284
289
|
```
|
285
290
|
# (nothing!)
|
286
291
|
```
|
292
|
+
|
293
|
+
## When not to use Bootsnap
|
294
|
+
|
295
|
+
*Alternative engines*: Bootsnap is pretty reliant on MRI features, and parts are disabled entirely on alternative ruby
|
296
|
+
engines.
|
297
|
+
|
298
|
+
*Non-local filesystems*: Bootsnap depends on `tmp/cache` (or whatever you set its cache directory
|
299
|
+
to) being on a relatively fast filesystem. If you put it on a network mount, bootsnap is very likely
|
300
|
+
to slow your application down quite a lot.
|
data/ext/bootsnap/bootsnap.c
CHANGED
@@ -468,21 +468,21 @@ static int
|
|
468
468
|
atomic_write_cache_file(char * path, struct bs_cache_key * key, VALUE data, char ** errno_provenance)
|
469
469
|
{
|
470
470
|
char template[MAX_CACHEPATH_SIZE + 20];
|
471
|
-
char * dest;
|
472
471
|
char * tmp_path;
|
473
472
|
int fd, ret;
|
474
473
|
ssize_t nwrite;
|
475
474
|
|
476
|
-
|
477
|
-
strcat(
|
475
|
+
tmp_path = strncpy(template, path, MAX_CACHEPATH_SIZE);
|
476
|
+
strcat(tmp_path, ".tmp.XXXXXX");
|
478
477
|
|
479
|
-
|
480
|
-
fd =
|
478
|
+
// mkstemp modifies the template to be the actual created path
|
479
|
+
fd = mkstemp(tmp_path);
|
481
480
|
if (fd < 0) {
|
482
|
-
if (mkpath(
|
481
|
+
if (mkpath(tmp_path, 0775) < 0) {
|
483
482
|
*errno_provenance = (char *)"bs_fetch:atomic_write_cache_file:mkpath";
|
484
483
|
return -1;
|
485
484
|
}
|
485
|
+
close(fd);
|
486
486
|
fd = open(tmp_path, O_WRONLY | O_CREAT, 0664);
|
487
487
|
if (fd < 0) {
|
488
488
|
*errno_provenance = (char *)"bs_fetch:atomic_write_cache_file:open";
|
@@ -46,11 +46,15 @@ module Bootsnap
|
|
46
46
|
|
47
47
|
klass = class << ::YAML; self; end
|
48
48
|
klass.send(:define_method, :load_file) do |path|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
49
|
+
begin
|
50
|
+
Bootsnap::CompileCache::Native.fetch(
|
51
|
+
cache_dir,
|
52
|
+
path,
|
53
|
+
Bootsnap::CompileCache::YAML
|
54
|
+
)
|
55
|
+
rescue Errno::EACCES
|
56
|
+
Bootsnap::CompileCache.permission_error(path)
|
57
|
+
end
|
54
58
|
end
|
55
59
|
end
|
56
60
|
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
module Bootsnap
|
2
2
|
module CompileCache
|
3
|
+
Error = Class.new(StandardError)
|
4
|
+
PermissionError = Class.new(Error)
|
5
|
+
|
3
6
|
def self.setup(cache_dir:, iseq:, yaml:)
|
4
7
|
if iseq
|
5
8
|
if supported?
|
@@ -20,6 +23,15 @@ module Bootsnap
|
|
20
23
|
end
|
21
24
|
end
|
22
25
|
|
26
|
+
def self.permission_error(path)
|
27
|
+
cpath = Bootsnap::CompileCache::ISeq.cache_dir
|
28
|
+
raise(
|
29
|
+
PermissionError,
|
30
|
+
"bootsnap doesn't have permission to write cache entries in '#{cpath}' " \
|
31
|
+
"(or, less likely, doesn't have permisison to read '#{path}')",
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
23
35
|
def self.supported?
|
24
36
|
# only enable on 'ruby' (MRI), POSIX (darwin, linux, *bsd), and >= 2.3.0
|
25
37
|
RUBY_ENGINE == 'ruby' &&
|
@@ -46,7 +46,7 @@ module Bootsnap
|
|
46
46
|
reinitialize if (@has_relative_paths && dir_changed?) || stale?
|
47
47
|
feature = feature.to_s
|
48
48
|
return feature if absolute_path?(feature)
|
49
|
-
return
|
49
|
+
return expand_path(feature) if feature.start_with?('./')
|
50
50
|
@mutex.synchronize do
|
51
51
|
x = search_index(feature)
|
52
52
|
return x if x
|
@@ -162,6 +162,10 @@ module Bootsnap
|
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
165
|
+
def expand_path(feature)
|
166
|
+
maybe_append_extension(File.expand_path(feature))
|
167
|
+
end
|
168
|
+
|
165
169
|
def stale?
|
166
170
|
@development_mode && @generated_at + AGE_THRESHOLD < now
|
167
171
|
end
|
@@ -174,10 +178,18 @@ module Bootsnap
|
|
174
178
|
def search_index(f)
|
175
179
|
try_index(f + DOT_RB) || try_index(f + DLEXT) || try_index(f + DLEXT2) || try_index(f)
|
176
180
|
end
|
181
|
+
|
182
|
+
def maybe_append_extension(f)
|
183
|
+
try_ext(f + DOT_RB) || try_ext(f + DLEXT) || try_ext(f + DLEXT2) || f
|
184
|
+
end
|
177
185
|
else
|
178
186
|
def search_index(f)
|
179
187
|
try_index(f + DOT_RB) || try_index(f + DLEXT) || try_index(f)
|
180
188
|
end
|
189
|
+
|
190
|
+
def maybe_append_extension(f)
|
191
|
+
try_ext(f + DOT_RB) || try_ext(f + DLEXT) || f
|
192
|
+
end
|
181
193
|
end
|
182
194
|
|
183
195
|
def try_index(f)
|
@@ -185,6 +197,10 @@ module Bootsnap
|
|
185
197
|
p + '/' + f
|
186
198
|
end
|
187
199
|
end
|
200
|
+
|
201
|
+
def try_ext(f)
|
202
|
+
f if File.exist?(f)
|
203
|
+
end
|
188
204
|
end
|
189
205
|
end
|
190
206
|
end
|
@@ -18,6 +18,11 @@ module Bootsnap
|
|
18
18
|
Thread.current[:without_bootsnap_retry] = prev
|
19
19
|
end
|
20
20
|
|
21
|
+
# If a NameError happens several levels deep, don't re-handle it
|
22
|
+
# all the way up the chain: mark it once and bubble it up without
|
23
|
+
# more retries.
|
24
|
+
ERROR_TAG_IVAR = :@__bootsnap_rescued
|
25
|
+
|
21
26
|
module ClassMethods
|
22
27
|
def autoload_paths=(o)
|
23
28
|
super
|
@@ -60,19 +65,22 @@ module Bootsnap
|
|
60
65
|
super
|
61
66
|
end
|
62
67
|
rescue NameError => e
|
68
|
+
raise(e) if e.instance_variable_defined?(ERROR_TAG_IVAR)
|
69
|
+
e.instance_variable_set(ERROR_TAG_IVAR, true)
|
70
|
+
|
63
71
|
# This function can end up called recursively, we only want to
|
64
72
|
# retry at the top-level.
|
65
|
-
raise if Thread.current[:without_bootsnap_retry]
|
73
|
+
raise(e) if Thread.current[:without_bootsnap_retry]
|
66
74
|
# If we already had cache disabled, there's no use retrying
|
67
|
-
raise if Thread.current[:without_bootsnap_cache]
|
75
|
+
raise(e) if Thread.current[:without_bootsnap_cache]
|
68
76
|
# NoMethodError is a NameError, but we only want to handle actual
|
69
77
|
# NameError instances.
|
70
|
-
raise unless e.class == NameError
|
78
|
+
raise(e) unless e.class == NameError
|
71
79
|
# We can only confidently handle cases when *this* constant fails
|
72
80
|
# to load, not other constants referred to by it.
|
73
|
-
raise unless e.name == const_name
|
81
|
+
raise(e) unless e.name == const_name
|
74
82
|
# If the constant was actually loaded, something else went wrong?
|
75
|
-
raise if from_mod.const_defined?(const_name)
|
83
|
+
raise(e) if from_mod.const_defined?(const_name)
|
76
84
|
CoreExt::ActiveSupport.without_bootsnap_cache { super }
|
77
85
|
end
|
78
86
|
|
@@ -80,9 +88,12 @@ module Bootsnap
|
|
80
88
|
# reiterate it with version polymorphism here...
|
81
89
|
def depend_on(*)
|
82
90
|
super
|
83
|
-
rescue LoadError
|
91
|
+
rescue LoadError => e
|
92
|
+
raise(e) if e.instance_variable_defined?(ERROR_TAG_IVAR)
|
93
|
+
e.instance_variable_set(ERROR_TAG_IVAR, true)
|
94
|
+
|
84
95
|
# If we already had cache disabled, there's no use retrying
|
85
|
-
raise if Thread.current[:without_bootsnap_cache]
|
96
|
+
raise(e) if Thread.current[:without_bootsnap_cache]
|
86
97
|
CoreExt::ActiveSupport.without_bootsnap_cache { super }
|
87
98
|
end
|
88
99
|
end
|
@@ -60,9 +60,11 @@ module Bootsnap
|
|
60
60
|
def load_data
|
61
61
|
@data = begin
|
62
62
|
MessagePack.load(File.binread(@store_path))
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
# handle malformed data due to upgrade incompatability
|
64
|
+
rescue Errno::ENOENT, MessagePack::MalformedFormatError, MessagePack::UnknownExtTypeError, EOFError
|
65
|
+
{}
|
66
|
+
rescue ArgumentError => e
|
67
|
+
e.message =~ /negative array size/ ? {} : raise
|
66
68
|
end
|
67
69
|
end
|
68
70
|
|
data/lib/bootsnap/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bootsnap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Burke Libbey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -102,6 +102,8 @@ extensions:
|
|
102
102
|
- ext/bootsnap/extconf.rb
|
103
103
|
extra_rdoc_files: []
|
104
104
|
files:
|
105
|
+
- ".github/CODEOWNERS"
|
106
|
+
- ".github/probots.yml"
|
105
107
|
- ".gitignore"
|
106
108
|
- ".rubocop.yml"
|
107
109
|
- ".travis.yml"
|
@@ -161,12 +163,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
161
163
|
version: 2.0.0
|
162
164
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
165
|
requirements:
|
164
|
-
- - "
|
166
|
+
- - ">"
|
165
167
|
- !ruby/object:Gem::Version
|
166
|
-
version:
|
168
|
+
version: 1.3.1
|
167
169
|
requirements: []
|
168
|
-
|
169
|
-
rubygems_version: 2.7.6
|
170
|
+
rubygems_version: 3.0.2
|
170
171
|
signing_key:
|
171
172
|
specification_version: 4
|
172
173
|
summary: Boot large ruby/rails apps faster
|