bootsnap 1.6.0 → 1.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +174 -0
- data/LICENSE.txt +1 -1
- data/README.md +41 -18
- data/exe/bootsnap +1 -1
- data/ext/bootsnap/bootsnap.c +133 -105
- data/ext/bootsnap/extconf.rb +21 -14
- data/lib/bootsnap/bundler.rb +1 -0
- data/lib/bootsnap/cli/worker_pool.rb +6 -1
- data/lib/bootsnap/cli.rb +84 -49
- data/lib/bootsnap/compile_cache/iseq.rb +43 -13
- data/lib/bootsnap/compile_cache/json.rb +93 -0
- data/lib/bootsnap/compile_cache/yaml.rb +299 -61
- data/lib/bootsnap/compile_cache.rb +24 -7
- data/lib/bootsnap/explicit_require.rb +4 -3
- data/lib/bootsnap/load_path_cache/cache.rb +63 -35
- data/lib/bootsnap/load_path_cache/change_observer.rb +17 -2
- data/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb +27 -95
- data/lib/bootsnap/load_path_cache/core_ext/loaded_features.rb +1 -0
- data/lib/bootsnap/load_path_cache/loaded_features_index.rb +36 -25
- data/lib/bootsnap/load_path_cache/path.rb +39 -17
- data/lib/bootsnap/load_path_cache/path_scanner.rb +25 -7
- data/lib/bootsnap/load_path_cache/store.rb +64 -24
- data/lib/bootsnap/load_path_cache.rb +31 -38
- data/lib/bootsnap/setup.rb +2 -36
- data/lib/bootsnap/version.rb +2 -1
- data/lib/bootsnap.rb +125 -36
- metadata +8 -79
- data/lib/bootsnap/load_path_cache/core_ext/active_support.rb +0 -107
- data/lib/bootsnap/load_path_cache/realpath_cache.rb +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68bf895082a1d27386514357e36c1b53972f7f2e22f50b2f9b77cde53fec9110
|
4
|
+
data.tar.gz: dcc033dc6522aa59d853f7840d228430aa5591892d063d91c061fb1c7edcb820
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b640bf89d0448536c17f88352e97aa4b5a321cec6abfcd011d1f442ec9c9170b0b08e0329e398919140da1b0d1e65d343b761be392d25eb75540425c42d766cb
|
7
|
+
data.tar.gz: 97080b27ccca5dd741bfccc0c3cd412c7fcea917fad2e79961ef2a7c18a1dd5478fc33f2a4d9f59a5f8765696760aef76799f401b1cf13b9a68d7ffc0d0a326b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,179 @@
|
|
1
1
|
# Unreleased
|
2
2
|
|
3
|
+
# 1.15.0
|
4
|
+
|
5
|
+
* Add a readonly mode, for environments in which the updated cache wouldn't be persisted. See #428 and #423.
|
6
|
+
|
7
|
+
# 1.14.0
|
8
|
+
|
9
|
+
* Require Ruby 2.6.
|
10
|
+
* Add a way to skip directories during load path scanning.
|
11
|
+
If you have large non-ruby directories in the middle of your load path, it can severely slow down scanning.
|
12
|
+
Typically this is a problem with `node_modules`. See #277.
|
13
|
+
* Fix `Bootsnap.unload_cache!`, it simply wouldn't work at all becaue of a merge mistake. See #421.
|
14
|
+
|
15
|
+
# 1.13.0
|
16
|
+
|
17
|
+
* Stop decorating `Kernel.load`. This used to be very useful in development because the Rails "classic" autoloader
|
18
|
+
was using `Kernel.load` in dev and `Kernel.require` in production. But Zeitwerk is now the default, and it doesn't
|
19
|
+
use `Kernel.load` at all.
|
20
|
+
|
21
|
+
People still using the classic autoloader might want to stick to `bootsnap 1.12`.
|
22
|
+
|
23
|
+
* Add `Bootsnap.unload_cache!`. Applications can call it at the end of their boot sequence when they know
|
24
|
+
no more code will be loaded to reclaim a bit of memory.
|
25
|
+
|
26
|
+
# 1.12.0
|
27
|
+
|
28
|
+
* `bootsnap precompile` CLI will now also precompile `Rakefile` and `.rake` files.
|
29
|
+
|
30
|
+
* Stop decorating `Module#autoload` as it was only useful for supporting Ruby 2.2 and older.
|
31
|
+
|
32
|
+
* Remove `uname` and other patform specific version from the cache keys. `RUBY_PLATFORM + RUBY_REVISION` should be
|
33
|
+
enough to ensure bytecode compatibility. This should improve caching for alpine based setups. See #409.
|
34
|
+
|
35
|
+
# 1.11.1
|
36
|
+
|
37
|
+
* Fix the `can't modify frozen Hash` error on load path cache mutation. See #411.
|
38
|
+
|
39
|
+
# 1.11.0
|
40
|
+
|
41
|
+
* Drop dependency on `fileutils`.
|
42
|
+
|
43
|
+
* Better respect `Kernel#require` duck typing. While it almost never comes up in practice, `Kernel#require`
|
44
|
+
follow a fairly intricate duck-typing protocol on its argument implemented as `rb_get_path(VALUE)` in MRI.
|
45
|
+
So when applicable we bind `rb_get_path` and use it for improved compatibility. See #396 and #406.
|
46
|
+
|
47
|
+
* Get rid of the `Kernel.require_relative` decorator by resolving `$LOAD_PATH` members to their real path.
|
48
|
+
This way we handle symlinks in `$LOAD_PATH` much more efficiently. See #402 for the detailed explanation.
|
49
|
+
|
50
|
+
* Drop support for Ruby 2.3 (to allow getting rid of the `Kernel.require_relative` decorator).
|
51
|
+
|
52
|
+
# 1.10.3
|
53
|
+
|
54
|
+
* Fix Regexp and Date type support in YAML compile cache. (#400)
|
55
|
+
|
56
|
+
* Improve the YAML compile cache to support `UTF-8` symbols. (#398, #399)
|
57
|
+
[The default `MessagePack` symbol serializer assumes all symbols are ASCII](https://github.com/msgpack/msgpack-ruby/pull/211),
|
58
|
+
because of this, non-ASCII compatible symbol would be restored with `ASCII_8BIT` encoding (AKA `BINARY`).
|
59
|
+
Bootsnap now properly cache them in `UTF-8`.
|
60
|
+
|
61
|
+
Note that the above only apply for actual YAML symbols (e..g `--- :foo`).
|
62
|
+
The issue is still present for string keys parsed with `YAML.load_file(..., symbolize_names: true)`, that is a bug
|
63
|
+
in `msgpack` that will hopefully be solved soon, see: https://github.com/msgpack/msgpack-ruby/pull/246
|
64
|
+
|
65
|
+
* Entirely disable the YAML compile cache if `Encoding.default_internal` is set to an encoding not supported by `msgpack`. (#398)
|
66
|
+
`Psych` coerce strings to `Encoding.default_internal`, but `MessagePack` doesn't. So in this scenario we can't provide
|
67
|
+
YAML caching at all without returning the strings in the wrong encoding.
|
68
|
+
This never came up in practice but might as well be safe.
|
69
|
+
|
70
|
+
# 1.10.2
|
71
|
+
|
72
|
+
* Reduce the `Kernel.require` extra stack frames some more. Now bootsnap should only add one extra frame per `require` call.
|
73
|
+
|
74
|
+
* Better check `freeze` option support in JSON compile cache.
|
75
|
+
Previously `JSON.load_file(..., freeze: true)` would be cached even when the msgpack version is missing support for it.
|
76
|
+
|
77
|
+
# 1.10.1
|
78
|
+
|
79
|
+
* Fix `Kernel#autoload`'s fallback path always being executed.
|
80
|
+
|
81
|
+
* Consider `unlink` failing with `ENOENT` as a success.
|
82
|
+
|
83
|
+
# 1.10.0
|
84
|
+
|
85
|
+
* Delay requiring `FileUtils`. (#285)
|
86
|
+
`FileUtils` can be installed as a gem, so it's best to wait for bundler to have setup the load path before requiring it.
|
87
|
+
|
88
|
+
* Improve support of Psych 4. (#392)
|
89
|
+
Since `1.8.0`, `YAML.load_file` was no longer cached when Psych 4 was used. This is because `load_file` loads
|
90
|
+
in safe mode by default, so the Bootsnap cache could defeat that safety.
|
91
|
+
Now when precompiling YAML files, Bootsnap first try to parse them in safe mode, and if it can't fallback to unsafe mode,
|
92
|
+
and the cache contains a flag that records whether it was generated in safe mode or not.
|
93
|
+
`YAML.unsafe_load_file` will use safe caches just fine, but `YAML.load_file` will fallback to uncached YAML parsing
|
94
|
+
if the cache was generated using unsafe parsing.
|
95
|
+
|
96
|
+
* Minimize the Kernel.require extra stack frames. (#393)
|
97
|
+
This should reduce the noise generated by bootsnap on `LoadError`.
|
98
|
+
|
99
|
+
# 1.9.4
|
100
|
+
|
101
|
+
* Ignore absolute paths in the loaded feature index. (#385)
|
102
|
+
This fixes a compatibility issue with Zeitwerk when Zeitwerk is loaded before bootsnap. It also should
|
103
|
+
reduce the memory usage and improve load performance of Zeitwerk managed files.
|
104
|
+
|
105
|
+
* Automatically invalidate the load path cache whenever the Ruby version change. (#387)
|
106
|
+
This is to avoid issues in case the same installation path is re-used for subsequent ruby patch releases.
|
107
|
+
|
108
|
+
# 1.9.3
|
109
|
+
|
110
|
+
* Only disable the compile cache for source files impacted by [Ruby 3.0.3 [Bug 18250]](https://bugs.ruby-lang.org/issues/18250).
|
111
|
+
This should keep the performance loss to a minimum.
|
112
|
+
|
113
|
+
# 1.9.2
|
114
|
+
|
115
|
+
* Disable compile cache if [Ruby 3.0.3's ISeq cache bug](https://bugs.ruby-lang.org/issues/18250) is detected.
|
116
|
+
AKA `iseq.rb:13 to_binary: wrong argument type false (expected Symbol)`
|
117
|
+
* Fix `Kernel.load` behavior: before `load 'a'` would load `a.rb` (and other tried extensions) and wouldn't load `a` unless `development_mode: true`, now only `a` would be loaded and files with extensions wouldn't be.
|
118
|
+
|
119
|
+
# 1.9.1
|
120
|
+
|
121
|
+
* Removed a forgotten debug statement in JSON precompilation.
|
122
|
+
|
123
|
+
# 1.9.0
|
124
|
+
|
125
|
+
* Added a compilation cache for `JSON.load_file`. (#370)
|
126
|
+
|
127
|
+
# 1.8.1
|
128
|
+
|
129
|
+
* Fixed support for older Psych. (#369)
|
130
|
+
|
131
|
+
# 1.8.0
|
132
|
+
|
133
|
+
* Improve support for Psych 4. (#368)
|
134
|
+
|
135
|
+
# 1.7.7
|
136
|
+
|
137
|
+
* Fix `require_relative` in evaled code on latest ruby 3.1.0-dev. (#366)
|
138
|
+
|
139
|
+
# 1.7.6
|
140
|
+
|
141
|
+
* Fix reliance on `set` to be required.
|
142
|
+
* Fix `Encoding::UndefinedConversionError` error for Rails applications when precompiling cache. (#364)
|
143
|
+
|
144
|
+
# 1.7.5
|
145
|
+
|
146
|
+
* Handle a regression of Ruby 2.7.3 causing Bootsnap to call the deprecated `untaint` method. (#360)
|
147
|
+
* Gracefully handle read-only file system as well as other errors preventing to persist the load path cache. (#358)
|
148
|
+
|
149
|
+
# 1.7.4
|
150
|
+
|
151
|
+
* Stop raising errors when encountering various file system errors. The cache is now best effort,
|
152
|
+
if somehow it can't be saved, bootsnap will gracefully fallback to the original operation (e.g. `Kernel.require`).
|
153
|
+
(#353, #177, #262)
|
154
|
+
|
155
|
+
# 1.7.3
|
156
|
+
|
157
|
+
* Disable YAML precompilation when encountering YAML tags. (#351)
|
158
|
+
|
159
|
+
# 1.7.2
|
160
|
+
|
161
|
+
* Fix compatibility with msgpack < 1. (#349)
|
162
|
+
|
163
|
+
# 1.7.1
|
164
|
+
|
165
|
+
* Warn Ruby 2.5 users if they turn ISeq caching on. (#327, #244)
|
166
|
+
* Disable ISeq caching for the whole 2.5.x series again.
|
167
|
+
* Better handle hashing of Ruby strings. (#318)
|
168
|
+
|
169
|
+
# 1.7.0
|
170
|
+
|
171
|
+
* Fix detection of YAML files in gems.
|
172
|
+
* Adds an instrumentation API to monitor cache misses.
|
173
|
+
* Allow to control the behavior of `require 'bootsnap/setup'` using environment variables.
|
174
|
+
* Deprecate the `disable_trace` option.
|
175
|
+
* Deprecate the `ActiveSupport::Dependencies` (AKA Classic autoloader) integration. (#344)
|
176
|
+
|
3
177
|
# 1.6.0
|
4
178
|
|
5
179
|
* Fix a Ruby 2.7/3.0 issue with `YAML.load_file` keyword arguments. (#342)
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Bootsnap [![Actions Status](https://github.com/Shopify/bootsnap/workflows/ci/badge.svg)](https://github.com/Shopify/bootsnap/actions)
|
2
2
|
|
3
|
-
Bootsnap is a library that plugs into Ruby, with optional support for `
|
3
|
+
Bootsnap is a library that plugs into Ruby, with optional support for `YAML`,
|
4
4
|
to optimize and cache expensive computations. See [How Does This Work](#how-does-this-work).
|
5
5
|
|
6
6
|
#### Performance
|
@@ -11,7 +11,7 @@ to optimize and cache expensive computations. See [How Does This Work](#how-does
|
|
11
11
|
- The core Shopify platform -- a rather large monolithic application -- boots about 75% faster,
|
12
12
|
dropping from around 25s to 6.5s.
|
13
13
|
* In Shopify core (a large app), about 25% of this gain can be attributed to `compile_cache_*`
|
14
|
-
features; 75% to path caching
|
14
|
+
features; 75% to path caching. This is fairly representative.
|
15
15
|
|
16
16
|
## Usage
|
17
17
|
|
@@ -29,7 +29,7 @@ If you are using Rails, add this to `config/boot.rb` immediately after `require
|
|
29
29
|
require 'bootsnap/setup'
|
30
30
|
```
|
31
31
|
|
32
|
-
Note that bootsnap writes to `tmp/cache` (or the path specified by `ENV['BOOTSNAP_CACHE_DIR']`),
|
32
|
+
Note that bootsnap writes to `tmp/cache` (or the path specified by `ENV['BOOTSNAP_CACHE_DIR']`),
|
33
33
|
and that directory *must* be writable. Rails will fail to
|
34
34
|
boot if it is not. If this is unacceptable (e.g. you are running in a read-only container and
|
35
35
|
unwilling to mount in a writable tmpdir), you should remove this line or wrap it in a conditional.
|
@@ -41,7 +41,7 @@ getting progressively slower, this is almost certainly the cause.**
|
|
41
41
|
It's technically possible to simply specify `gem 'bootsnap', require: 'bootsnap/setup'`, but it's
|
42
42
|
important to load Bootsnap as early as possible to get maximum performance improvement.
|
43
43
|
|
44
|
-
You can see how this require works [here](https://github.com/Shopify/bootsnap/blob/
|
44
|
+
You can see how this require works [here](https://github.com/Shopify/bootsnap/blob/main/lib/bootsnap/setup.rb).
|
45
45
|
|
46
46
|
If you are not using Rails, or if you are but want more control over things, add this to your
|
47
47
|
application setup immediately after `require 'bundler/setup'` (i.e. as early as possible: the sooner
|
@@ -52,17 +52,15 @@ require 'bootsnap'
|
|
52
52
|
env = ENV['RAILS_ENV'] || "development"
|
53
53
|
Bootsnap.setup(
|
54
54
|
cache_dir: 'tmp/cache', # Path to your cache
|
55
|
+
ignore_directories: ['node_modules'], # Directory names to skip.
|
55
56
|
development_mode: env == 'development', # Current working environment, e.g. RACK_ENV, RAILS_ENV, etc
|
56
57
|
load_path_cache: true, # Optimize the LOAD_PATH with a cache
|
57
|
-
autoload_paths_cache: true, # Optimize ActiveSupport autoloads with cache
|
58
|
-
disable_trace: true, # Set `RubyVM::InstructionSequence.compile_option = { trace_instruction: false }`
|
59
58
|
compile_cache_iseq: true, # Compile Ruby code into ISeq cache, breaks coverage reporting.
|
60
|
-
compile_cache_yaml: true
|
59
|
+
compile_cache_yaml: true, # Compile YAML into a cache
|
60
|
+
readonly: true, # Use the caches but don't update them on miss or stale entries.
|
61
61
|
)
|
62
62
|
```
|
63
63
|
|
64
|
-
**Note that `disable_trace` will break debuggers and tracing.**
|
65
|
-
|
66
64
|
**Protip:** You can replace `require 'bootsnap'` with `BootLib::Require.from_gem('bootsnap',
|
67
65
|
'bootsnap')` using [this trick](https://github.com/Shopify/bootsnap/wiki/Bootlib::Require). This
|
68
66
|
will help optimize boot time further if you have an extremely large `$LOAD_PATH`.
|
@@ -72,12 +70,43 @@ speeds up the loading of individual source files, Spring keeps a copy of a pre-b
|
|
72
70
|
on hand to completely skip parts of the boot process the next time it's needed. The two tools work
|
73
71
|
well together, and are both included in a newly-generated Rails applications by default.
|
74
72
|
|
73
|
+
### Environment variables
|
74
|
+
|
75
|
+
`require 'bootsnap/setup'` behavior can be changed using environment variables:
|
76
|
+
|
77
|
+
- `BOOTSNAP_CACHE_DIR` allows to define the cache location.
|
78
|
+
- `DISABLE_BOOTSNAP` allows to entirely disable bootsnap.
|
79
|
+
- `DISABLE_BOOTSNAP_LOAD_PATH_CACHE` allows to disable load path caching.
|
80
|
+
- `DISABLE_BOOTSNAP_COMPILE_CACHE` allows to disable ISeq and YAML caches.
|
81
|
+
- `BOOTSNAP_READONLY` configure bootsnap to not update the cache on miss or stale entries.
|
82
|
+
- `BOOTSNAP_LOG` configure bootsnap to log all caches misses to STDERR.
|
83
|
+
- `BOOTSNAP_IGNORE_DIRECTORIES` a comma separated list of directories that shouldn't be scanned.
|
84
|
+
Useful when you have large directories of non-ruby files inside `$LOAD_PATH`.
|
85
|
+
It default to ignore any directory named `node_modules`.
|
86
|
+
|
75
87
|
### Environments
|
76
88
|
|
77
89
|
All Bootsnap features are enabled in development, test, production, and all other environments according to the configuration in the setup. At Shopify, we use this gem safely in all environments without issue.
|
78
90
|
|
79
91
|
If you would like to disable any feature for a certain environment, we suggest changing the configuration to take into account the appropriate ENV var or configuration according to your needs.
|
80
92
|
|
93
|
+
### Instrumentation
|
94
|
+
|
95
|
+
Bootsnap cache misses can be monitored though a callback:
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
Bootsnap.instrumentation = ->(event, path) { puts "#{event} #{path}" }
|
99
|
+
```
|
100
|
+
|
101
|
+
`event` is either `:miss` or `:stale`. You can also call `Bootsnap.log!` as a shortcut to
|
102
|
+
log all events to STDERR.
|
103
|
+
|
104
|
+
To turn instrumentation back off you can set it to nil:
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
Bootsnap.instrumentation = nil
|
108
|
+
```
|
109
|
+
|
81
110
|
## How does this work?
|
82
111
|
|
83
112
|
Bootsnap optimizes methods to cache results of expensive computations, and can be grouped
|
@@ -85,8 +114,6 @@ into two broad categories:
|
|
85
114
|
|
86
115
|
* [Path Pre-Scanning](#path-pre-scanning)
|
87
116
|
* `Kernel#require` and `Kernel#load` are modified to eliminate `$LOAD_PATH` scans.
|
88
|
-
* `ActiveSupport::Dependencies.{autoloadable_module?,load_missing_constant,depend_on}` are
|
89
|
-
overridden to eliminate scans of `ActiveSupport::Dependencies.autoload_paths`.
|
90
117
|
* [Compilation caching](#compilation-caching)
|
91
118
|
* `RubyVM::InstructionSequence.load_iseq` is implemented to cache the result of ruby bytecode
|
92
119
|
compilation.
|
@@ -125,10 +152,6 @@ open y/foo.rb
|
|
125
152
|
...
|
126
153
|
```
|
127
154
|
|
128
|
-
Exactly the same strategy is employed for methods that traverse
|
129
|
-
`ActiveSupport::Dependencies.autoload_paths` if the `autoload_paths_cache` option is given to
|
130
|
-
`Bootsnap.setup`.
|
131
|
-
|
132
155
|
The following diagram flowcharts the overrides that make the `*_path_cache` features work.
|
133
156
|
|
134
157
|
![Flowchart explaining
|
@@ -144,7 +167,7 @@ The only directories considered "stable" are things under the Ruby install prefi
|
|
144
167
|
"volatile".
|
145
168
|
|
146
169
|
In addition to the [`Bootsnap::LoadPathCache::Cache`
|
147
|
-
source](https://github.com/Shopify/bootsnap/blob/
|
170
|
+
source](https://github.com/Shopify/bootsnap/blob/main/lib/bootsnap/load_path_cache/cache.rb),
|
148
171
|
this diagram may help clarify how entry resolution works:
|
149
172
|
|
150
173
|
![How path searching works](https://cloud.githubusercontent.com/assets/3074765/25388270/670b5652-299b-11e7-87fb-975647f68981.png)
|
@@ -215,9 +238,9 @@ Bootsnap writes a cache file containing a 64 byte header followed by the cache c
|
|
215
238
|
is a cache key including several fields:
|
216
239
|
|
217
240
|
* `version`, hardcoded in bootsnap. Essentially a schema version;
|
218
|
-
* `ruby_platform`, A hash of `RUBY_PLATFORM` (e.g. x86_64-linux-gnu) variable
|
241
|
+
* `ruby_platform`, A hash of `RUBY_PLATFORM` (e.g. x86_64-linux-gnu) variable.
|
219
242
|
* `compile_option`, which changes with `RubyVM::InstructionSequence.compile_option` does;
|
220
|
-
* `ruby_revision`,
|
243
|
+
* `ruby_revision`, A hash of `RUBY_REVISION`, the exact version of Ruby;
|
221
244
|
* `size`, the size of the source file;
|
222
245
|
* `mtime`, the last-modification timestamp of the source file when it was compiled; and
|
223
246
|
* `data_size`, the number of bytes following the header, which we need to read it into a buffer.
|
data/exe/bootsnap
CHANGED