bootsnap 1.4.4 → 1.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +129 -0
  3. data/README.md +46 -15
  4. data/exe/bootsnap +5 -0
  5. data/ext/bootsnap/bootsnap.c +276 -87
  6. data/ext/bootsnap/extconf.rb +20 -14
  7. data/lib/bootsnap/bundler.rb +1 -0
  8. data/lib/bootsnap/cli/worker_pool.rb +135 -0
  9. data/lib/bootsnap/cli.rb +281 -0
  10. data/lib/bootsnap/compile_cache/iseq.rb +51 -11
  11. data/lib/bootsnap/compile_cache/json.rb +79 -0
  12. data/lib/bootsnap/compile_cache/yaml.rb +141 -39
  13. data/lib/bootsnap/compile_cache.rb +14 -4
  14. data/lib/bootsnap/explicit_require.rb +1 -0
  15. data/lib/bootsnap/load_path_cache/cache.rb +47 -26
  16. data/lib/bootsnap/load_path_cache/change_observer.rb +4 -1
  17. data/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb +18 -20
  18. data/lib/bootsnap/load_path_cache/core_ext/loaded_features.rb +1 -0
  19. data/lib/bootsnap/load_path_cache/loaded_features_index.rb +51 -15
  20. data/lib/bootsnap/load_path_cache/path.rb +3 -2
  21. data/lib/bootsnap/load_path_cache/path_scanner.rb +50 -26
  22. data/lib/bootsnap/load_path_cache/realpath_cache.rb +5 -5
  23. data/lib/bootsnap/load_path_cache/store.rb +39 -15
  24. data/lib/bootsnap/load_path_cache.rb +3 -16
  25. data/lib/bootsnap/setup.rb +2 -36
  26. data/lib/bootsnap/version.rb +2 -1
  27. data/lib/bootsnap.rb +106 -17
  28. metadata +18 -32
  29. data/.github/CODEOWNERS +0 -2
  30. data/.github/probots.yml +0 -2
  31. data/.gitignore +0 -17
  32. data/.rubocop.yml +0 -20
  33. data/.travis.yml +0 -21
  34. data/CODE_OF_CONDUCT.md +0 -74
  35. data/CONTRIBUTING.md +0 -21
  36. data/Gemfile +0 -8
  37. data/README.jp.md +0 -231
  38. data/Rakefile +0 -12
  39. data/bin/ci +0 -10
  40. data/bin/console +0 -14
  41. data/bin/setup +0 -8
  42. data/bin/test-minimal-support +0 -7
  43. data/bin/testunit +0 -8
  44. data/bootsnap.gemspec +0 -45
  45. data/dev.yml +0 -10
  46. data/lib/bootsnap/load_path_cache/core_ext/active_support.rb +0 -106
  47. data/shipit.rubygems.yml +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db7809e0e5fa0f4a018dd7254cb99619ada5c7c26947db858d9b56f29dc76249
4
- data.tar.gz: 1d9d8eed648ce29ea43307d246089a9ea116c6148681a9c43393d458c77049dd
3
+ metadata.gz: 7602567343afc549df266a1b3def7e8c1e755b03a9ce486d17bba7051e97dfda
4
+ data.tar.gz: 607abfa5738cb016172bba2eb94af48b80b9e73dddea1090be77b7ca7d9f121d
5
5
  SHA512:
6
- metadata.gz: fc0befd695ab9ef47a405fea7e83b856a422f70f8f59bd2737067b4951dc20c85210d562d332e5161a3dd7816258b14295e1a91a7e2ec62a8d8dc0e5bc0fb3bf
7
- data.tar.gz: 7a408b74a5e57dc0feaf2fdfd47930a4f22f048888f0643b316e3a139fc35eaeec358599a8846dde45395db55e8f66d398704de651ba67f4cd0bdfc7d9190469
6
+ metadata.gz: 7effd658adb07d075cfbc883f47382c23f774a872fcfa2daa0b137ff5f903057a1f825a90cd96cd5784a2e72fcb583ce05b4fcf98201a2a2cb6830c90109e096
7
+ data.tar.gz: ed2f42c2e5e91c373c8882fbe17abfab93c43e6ab39b83a7aa3031d6dba48088da9c3a271b52bbb7bc83ace117d677ec25e4865936972d939a00b08580f5e45e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,132 @@
1
+ # Unreleased
2
+
3
+ # 1.9.4
4
+
5
+ * Ignore absolute paths in the loaded feature index. (#385)
6
+ This fixes a compatibility issue with Zeitwerk when Zeitwerk is loaded before bootsnap. It also should
7
+ reduce the memory usage and improve load performance of Zeitwerk managed files.
8
+
9
+ * Automatically invalidate the load path cache whenever the Ruby version change. (#387)
10
+ This is to avoid issues in case the same installation path is re-used for subsequent ruby patch releases.
11
+
12
+ # 1.9.3
13
+
14
+ * Only disable the compile cache for source files impacted by [Ruby 3.0.3 [Bug 18250]](https://bugs.ruby-lang.org/issues/18250).
15
+ This should keep the performance loss to a minimum.
16
+
17
+ # 1.9.2
18
+
19
+ * Disable compile cache if [Ruby 3.0.3's ISeq cache bug](https://bugs.ruby-lang.org/issues/18250) is detected.
20
+ AKA `iseq.rb:13 to_binary: wrong argument type false (expected Symbol)`
21
+ * 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.
22
+
23
+ # 1.9.1
24
+
25
+ * Removed a forgotten debug statement in JSON precompilation.
26
+
27
+ # 1.9.0
28
+
29
+ * Added a compilation cache for `JSON.load_file`. (#370)
30
+
31
+ # 1.8.1
32
+
33
+ * Fixed support for older Psych. (#369)
34
+
35
+ # 1.8.0
36
+
37
+ * Improve support for Pysch 4. (#368)
38
+
39
+ # 1.7.7
40
+
41
+ * Fix `require_relative` in evaled code on latest ruby 3.1.0-dev. (#366)
42
+
43
+ # 1.7.6
44
+
45
+ * Fix reliance on `set` to be required.
46
+ * Fix `Encoding::UndefinedConversionError` error for Rails applications when precompiling cache. (#364)
47
+
48
+ # 1.7.5
49
+
50
+ * Handle a regression of Ruby 2.7.3 causing Bootsnap to call the deprecated `untaint` method. (#360)
51
+ * Gracefully handle read-only file system as well as other errors preventing to persist the load path cache. (#358)
52
+
53
+ # 1.7.4
54
+
55
+ * Stop raising errors when encoutering various file system errors. The cache is now best effort,
56
+ if somehow it can't be saved, bootsnapp will gracefully fallback to the original operation (e.g. `Kernel.require`).
57
+ (#353, #177, #262)
58
+
59
+ # 1.7.3
60
+
61
+ * Disable YAML precompilation when encountering YAML tags. (#351)
62
+
63
+ # 1.7.2
64
+
65
+ * Fix compatibility with msgpack < 1. (#349)
66
+
67
+ # 1.7.1
68
+
69
+ * Warn Ruby 2.5 users if they turn ISeq caching on. (#327, #244)
70
+ * Disable ISeq caching for the whole 2.5.x series again.
71
+ * Better handle hashing of Ruby strings. (#318)
72
+
73
+ # 1.7.0
74
+
75
+ * Fix detection of YAML files in gems.
76
+ * Adds an instrumentation API to monitor cache misses.
77
+ * Allow to control the behavior of `require 'bootsnap/setup'` using environment variables.
78
+ * Deprecate the `disable_trace` option.
79
+ * Deprecate the `ActiveSupport::Dependencies` (AKA Classic autoloader) integration. (#344)
80
+
81
+ # 1.6.0
82
+
83
+ * Fix a Ruby 2.7/3.0 issue with `YAML.load_file` keyword arguments. (#342)
84
+ * `bootsnap precompile` CLI use multiple processes to complete faster. (#341)
85
+ * `bootsnap precompile` CLI also precompile YAML files. (#340)
86
+ * Changed the load path cache directory from `$BOOTSNAP_CACHE_DIR/bootsnap-load-path-cache` to `$BOOTSNAP_CACHE_DIR/bootsnap/load-path-cache` for ease of use. (#334)
87
+ * Changed the compile cache directory from `$BOOTSNAP_CACHE_DIR/bootsnap-compile-cache` to `$BOOTSNAP_CACHE_DIR/bootsnap/compile-cache` for ease of use. (#334)
88
+
89
+ # 1.5.1
90
+
91
+ * Workaround a Ruby bug in InstructionSequence.compile_file. (#332)
92
+
93
+ # 1.5.0
94
+
95
+ * Add a command line to statically precompile the ISeq cache. (#326)
96
+
97
+ # 1.4.9
98
+
99
+ * [Windows support](https://github.com/Shopify/bootsnap/pull/319)
100
+ * [Fix potential crash](https://github.com/Shopify/bootsnap/pull/322)
101
+
102
+ # 1.4.8
103
+
104
+ * [Prevent FallbackScan from polluting exception cause](https://github.com/Shopify/bootsnap/pull/314)
105
+
106
+ # 1.4.7
107
+
108
+ * Various performance enhancements
109
+ * Fix race condition in heavy concurrent load scenarios that would cause bootsnap to raise
110
+
111
+ # 1.4.6
112
+
113
+ * Fix bug that was erroneously considering that files containing `.` in the names were being
114
+ required if a different file with the same name was already being required
115
+
116
+ Example:
117
+
118
+ require 'foo'
119
+ require 'foo.en'
120
+
121
+ Before bootsnap was considering `foo.en` to be the same file as `foo`
122
+
123
+ * Use glibc as part of the ruby_platform cache key
124
+
125
+ # 1.4.5
126
+
127
+ * MRI 2.7 support
128
+ * Fixed concurrency bugs
129
+
1
130
  # 1.4.4
2
131
 
3
132
  * Disable ISeq cache in `bootsnap/setup` by default in Ruby 2.5
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Bootsnap [![Build Status](https://travis-ci.org/Shopify/bootsnap.svg?branch=master)](https://travis-ci.org/Shopify/bootsnap)
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 `ActiveSupport` and `YAML`,
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, and ~1% to `disable_trace`. This is fairly representative.
14
+ features; 75% to path caching. This is fairly representative.
15
15
 
16
16
  ## Usage
17
17
 
@@ -29,7 +29,8 @@ 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`, and that directory *must* be writable. Rails will fail to
32
+ Note that bootsnap writes to `tmp/cache` (or the path specified by `ENV['BOOTSNAP_CACHE_DIR']`),
33
+ and that directory *must* be writable. Rails will fail to
33
34
  boot if it is not. If this is unacceptable (e.g. you are running in a read-only container and
34
35
  unwilling to mount in a writable tmpdir), you should remove this line or wrap it in a conditional.
35
36
 
@@ -53,15 +54,11 @@ Bootsnap.setup(
53
54
  cache_dir: 'tmp/cache', # Path to your cache
54
55
  development_mode: env == 'development', # Current working environment, e.g. RACK_ENV, RAILS_ENV, etc
55
56
  load_path_cache: true, # Optimize the LOAD_PATH with a cache
56
- autoload_paths_cache: true, # Optimize ActiveSupport autoloads with cache
57
- disable_trace: true, # Set `RubyVM::InstructionSequence.compile_option = { trace_instruction: false }`
58
57
  compile_cache_iseq: true, # Compile Ruby code into ISeq cache, breaks coverage reporting.
59
58
  compile_cache_yaml: true # Compile YAML into a cache
60
59
  )
61
60
  ```
62
61
 
63
- **Note that `disable_trace` will break debuggers and tracing.**
64
-
65
62
  **Protip:** You can replace `require 'bootsnap'` with `BootLib::Require.from_gem('bootsnap',
66
63
  'bootsnap')` using [this trick](https://github.com/Shopify/bootsnap/wiki/Bootlib::Require). This
67
64
  will help optimize boot time further if you have an extremely large `$LOAD_PATH`.
@@ -71,12 +68,39 @@ speeds up the loading of individual source files, Spring keeps a copy of a pre-b
71
68
  on hand to completely skip parts of the boot process the next time it's needed. The two tools work
72
69
  well together, and are both included in a newly-generated Rails applications by default.
73
70
 
71
+ ### Environment variables
72
+
73
+ `require 'bootsnap/setup'` behavior can be changed using environment variables:
74
+
75
+ - `BOOTSNAP_CACHE_DIR` allows to define the cache location.
76
+ - `DISABLE_BOOTSNAP` allows to entirely disable bootsnap.
77
+ - `DISABLE_BOOTSNAP_LOAD_PATH_CACHE` allows to disable load path caching.
78
+ - `DISABLE_BOOTSNAP_COMPILE_CACHE` allows to disable ISeq and YAML caches.
79
+ - `BOOTSNAP_LOG` configure bootsnap to log all caches misses to STDERR.
80
+
74
81
  ### Environments
75
82
 
76
83
  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.
77
84
 
78
85
  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.
79
86
 
87
+ ### Instrumentation
88
+
89
+ Bootsnap cache misses can be monitored though a callback:
90
+
91
+ ```ruby
92
+ Bootsnap.instrumentation = ->(event, path) { puts "#{event} #{path}" }
93
+ ```
94
+
95
+ `event` is either `:miss` or `:stale`. You can also call `Bootsnap.log!` as a shortcut to
96
+ log all events to STDERR.
97
+
98
+ To turn instrumentation back off you can set it to nil:
99
+
100
+ ```ruby
101
+ Bootsnap.instrumentation = nil
102
+ ```
103
+
80
104
  ## How does this work?
81
105
 
82
106
  Bootsnap optimizes methods to cache results of expensive computations, and can be grouped
@@ -84,8 +108,6 @@ into two broad categories:
84
108
 
85
109
  * [Path Pre-Scanning](#path-pre-scanning)
86
110
  * `Kernel#require` and `Kernel#load` are modified to eliminate `$LOAD_PATH` scans.
87
- * `ActiveSupport::Dependencies.{autoloadable_module?,load_missing_constant,depend_on}` are
88
- overridden to eliminate scans of `ActiveSupport::Dependencies.autoload_paths`.
89
111
  * [Compilation caching](#compilation-caching)
90
112
  * `RubyVM::InstructionSequence.load_iseq` is implemented to cache the result of ruby bytecode
91
113
  compilation.
@@ -124,10 +146,6 @@ open y/foo.rb
124
146
  ...
125
147
  ```
126
148
 
127
- Exactly the same strategy is employed for methods that traverse
128
- `ActiveSupport::Dependencies.autoload_paths` if the `autoload_paths_cache` option is given to
129
- `Bootsnap.setup`.
130
-
131
149
  The following diagram flowcharts the overrides that make the `*_path_cache` features work.
132
150
 
133
151
  ![Flowchart explaining
@@ -214,7 +232,7 @@ Bootsnap writes a cache file containing a 64 byte header followed by the cache c
214
232
  is a cache key including several fields:
215
233
 
216
234
  * `version`, hardcoded in bootsnap. Essentially a schema version;
217
- * `os_version`, A hash of the current kernel version (on macOS, BSD) or glibc version (on Linux);
235
+ * `ruby_platform`, A hash of `RUBY_PLATFORM` (e.g. x86_64-linux-gnu) variable and glibc version (on Linux) or OS version (`uname -v` on BSD, macOS)
218
236
  * `compile_option`, which changes with `RubyVM::InstructionSequence.compile_option` does;
219
237
  * `ruby_revision`, the version of Ruby this was compiled with;
220
238
  * `size`, the size of the source file;
@@ -294,6 +312,19 @@ open /c/nope.bundle -> -1
294
312
  # (nothing!)
295
313
  ```
296
314
 
315
+ ## Precompilation
316
+
317
+ In development environments the bootsnap compilation cache is generated on the fly when source files are loaded.
318
+ But in production environments, such as docker images, you might need to precompile the cache.
319
+
320
+ To do so you can use the `bootsnap precompile` command.
321
+
322
+ Example:
323
+
324
+ ```bash
325
+ $ bundle exec bootsnap precompile --gemfile app/ lib/
326
+ ```
327
+
297
328
  ## When not to use Bootsnap
298
329
 
299
330
  *Alternative engines*: Bootsnap is pretty reliant on MRI features, and parts are disabled entirely on alternative ruby
data/exe/bootsnap ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bootsnap/cli'
5
+ exit Bootsnap::CLI.new(ARGV).run