bootsnap 1.17.0 → 1.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a17ea0a302554fd131e2941fa8b97b1ff9441750fb4182247bb44d91aa1174e8
4
- data.tar.gz: 9ba8386281c2dbb6896b1032e4b6a6c949b81164d54848beac032a977ee43e44
3
+ metadata.gz: 6227028d2a559d0e5129ef91915f65a064082b2e1326517dd67da2f11d91d194
4
+ data.tar.gz: 1c7cbf82581f9162601a7723812201d240661c0d3477373b820cf7e942b9d416
5
5
  SHA512:
6
- metadata.gz: a1653ddc2779d492f3e5c50719c07a0cdc7a9fab27748dd82096ec923232f9c8b04ddbee738325d13a3aa8c87a38825581677408512437e12933fe18434bcdce
7
- data.tar.gz: 9c0f5d4fe058c13577d97011083b7bab23b290cd16b955937b00aaafb5a62239532df4e0d090e576c85dae45dcf504ffa63f9fedd5b2c5dca67afc4457cdbb59
6
+ metadata.gz: 385183b9de17b6f72634b7307fdfc5481108afc06554b48bb2dede97e51ba4275d076357934d338286fceb3a221f1468ec2ea10e2f0f869de5a7b5b97fc444a8
7
+ data.tar.gz: c74bb8bdfe0e6f3615bbc4a6ea4f7c5a7a1d8589a3469da964c25b44451fbb3f54f10521b8549dc6ac400d7fb17ba4a686b5b289115e8b3bac81d7a5449e3c0b
data/CHANGELOG.md CHANGED
@@ -1,9 +1,146 @@
1
1
  # Unreleased
2
2
 
3
+ # 1.26.0
4
+
5
+ * Handle top level `Coverage` constant being defined, but without it being the true stdlib `coverage` module.
6
+ * Fix `bootsnap precompile` that could generate a corrupted cache entry if an already cached YAML file was modified
7
+ without changing its size.
8
+ * Workaround a potential Ruby SEGV if `Bootsnap.instrumentation` raised an error.
9
+
10
+ # 1.25.0
11
+
12
+ * Improve YAML parsing cache to more efficiently handle `Time`, `Date` and `DateTime`.
13
+
14
+ * Don't invalidate the compile cache when YJIT is toggled. YJIT is a runtime JIT and doesn't change the
15
+ serialized instruction sequences that are cached, but enabling it (via `--yjit`, `RUBYOPT`, or
16
+ `RubyVM::YJIT.enable`) adds a ` +YJIT` marker to `RUBY_DESCRIPTION` (` +YJIT <token>` on `YJIT_SUPPORT`
17
+ builds), which is part of the cache key. This previously discarded the entire compile cache whenever YJIT
18
+ was enabled at runtime but not at precompile time (or vice versa). The marker is now stripped before hashing.
19
+
20
+ * Fix `CompileCache::Native.fetch` and `.precompile` reading a non-`String` path argument (e.g. a `Pathname`)
21
+ with `RSTRING_PTR`. Regression from 1.24.0.
22
+
23
+ # 1.24.6
24
+
25
+ * Fix detection of Ruby bug #22023 on some patch versions of Ruby 3.4, and properly apply the workaround.
26
+
27
+ # 1.24.5
28
+
29
+ * No longer load the config file by default when setup is done manually. This is so cli applications like homebrew
30
+ don't mistakenly load another app's boostnap config.
31
+
32
+ # 1.24.4
33
+
34
+ * Fix several compatibility issues with Ruby `4.0.4`, particularly the `should not compile with coverage` error. See #547.
35
+ * Fix `Bootsnap.enable_frozen_string_literal` to work even when coverage is enabled. Unfortunately only possible on Ruby `4.0.4+`.
36
+ On older rubies if coverage is enabled a warning will be issued and the feature won't work.
37
+ * Reduced cache files header size from 64 to 32 bytes, and got rid of the random padding element.
38
+ * Avoid leaking a private method in `Object` when testing for Parse.y bugs.
39
+
40
+ # 1.24.3
41
+
42
+ * Fix the `1.24.2` workaround to parse Ruby files with UTF-8 even when the `LANG` environment variable
43
+ is unset or set to `C`.
44
+
45
+ # 1.24.2
46
+
47
+ * Workaround two Ruby bugs in `RubyVM::InstructionSequence.compile_file`, that were causing
48
+ files to be loaded with the old Ruby parser instead of Prism, causing issues with some pattern matching syntax.
49
+ Ref: https://bugs.ruby-lang.org/issues/22023
50
+
51
+ # 1.24.1
52
+
53
+ * Fix encoding of Ruby source files loaded when `BOOTSNAP_READONLY` is set.
54
+ Files would incorectly be loaded in `ASCII-8BIT` causing literal strings outside
55
+ the pure ASCII range to have `ASCII-8BIT` encoding instead of `UTF-8`.
56
+ This bug was introduced in `1.24.0`.
57
+
58
+ # 1.24.0
59
+
60
+ * Added a hook API to customize Ruby compilation.
61
+
62
+ # 1.23.0
63
+
64
+ * Require Ruby 2.7.
65
+ * Fix support for absolute paths in `BOOTSNAP_IGNORE_DIRECTORIES`.
66
+
67
+ # 1.22.0
68
+
69
+ * Better fix for the `opendir` crash.
70
+ * Add `bootsnap/rake` for cleaning the bootsnap cache as part of `rake clobber`.
71
+
72
+ # 1.21.1
73
+
74
+ * Prevent a Ruby crash while scanning load path if `opendir` fails without setting `errno`.
75
+ According to the C spec this should not happen, but according to user reports, it did.
76
+
77
+ # 1.21.0
78
+
79
+ * Fix the `require` decorator to handle `Bootsnap.unload_cache!` being called.
80
+ * Minor optimization: Eagerly clear cache buffers to appease the GC.
81
+
82
+ # 1.20.1
83
+
84
+ * Handle broken symlinks in load path scanning code.
85
+ Should fix `Errno::ENOENT fstatat` issues some users have encountered after upgrading to 1.20.0.
86
+
87
+ # 1.20.0
88
+
89
+ * Optimized load path scanning with a C extension. Should be about 2x faster on supported platforms.
90
+
91
+ # 1.19.0
92
+
93
+ * Remove JSON parsing cache. Recent versions of the `json` gem are as fast as `msgpack` if not faster.
94
+
95
+ # 1.18.6
96
+
97
+ * Fix cgroup CPU limits detection in CLI.
98
+
99
+ # 1.18.5
100
+
101
+ * Attempt to detect a QEMU bug that can cause `bootsnap precompile` to hang forever when building ARM64 docker images
102
+ from x86_64 machines. See #495.
103
+ * Improve CLI to detect cgroup CPU limits and avoid spawning too many worker processes.
104
+
105
+ # 1.18.4
106
+
107
+ * Allow using bootsnap without bundler. See #488.
108
+ * Fix startup failure if the cache directory points to a broken symlink.
109
+
110
+ # 1.18.3
111
+
112
+ * Fix the cache corruption issue in the revalidation feature. See #474.
113
+ The cache revalidation feature remains opt-in for now, until it is more battle tested.
114
+
115
+ # 1.18.2
116
+
117
+ * Disable stale cache entries revalidation by default as it seems to cause cache corruption issues. See #471 and #474.
118
+ Will be re-enabled in a future version once the root cause is identified.
119
+ * Fix a potential compilation issue on some systems. See #470.
120
+
121
+ # 1.18.1
122
+
123
+ * Handle `EPERM` errors when opening files with `O_NOATIME`.
124
+
125
+ # 1.18.0
126
+
127
+ * `Bootsnap.instrumentation` now receive `:hit` events.
128
+ * Add `Bootsnap.log_stats!` to print hit rate statistics on process exit. Can also be enabled with `BOOTSNAP_STATS=1`.
129
+ * Revalidate stale cache entries by digesting the source content.
130
+ This should significantly improve performance in environments where `mtime` isn't preserved (e.g. CI systems doing a git clone, etc).
131
+ See #468.
132
+ * Open source files and cache entries with `O_NOATIME` when available to reduce disk accesses. See #469.
133
+ * `bootsnap precompile --gemfile` now look for `.rb` files in the whole gem and not just the `lib/` directory. See #466.
134
+
135
+ # 1.17.1
136
+
137
+ * Fix a compatibility issue with the `prism` library that ships with Ruby 3.3. See #463.
138
+ * Improved the `Kernel#require` decorator to not cause a method redefinition warning. See #461.
139
+
3
140
  # 1.17.0
4
141
 
5
- * Ensure `$LOAD_PATH.dup` is Ractor shareable to fix an conflit with `did_you_mean`.
6
- * Allow to ignore direcotries using absolute paths.
142
+ * Ensure `$LOAD_PATH.dup` is Ractor shareable to fix a conflict with `did_you_mean`.
143
+ * Allow to ignore directories using absolute paths.
7
144
  * Support YAML and JSON CompileCache on TruffleRuby.
8
145
  * Support LoadPathCache on TruffleRuby.
9
146
 
@@ -24,7 +161,7 @@
24
161
  * Add a way to skip directories during load path scanning.
25
162
  If you have large non-ruby directories in the middle of your load path, it can severely slow down scanning.
26
163
  Typically this is a problem with `node_modules`. See #277.
27
- * Fix `Bootsnap.unload_cache!`, it simply wouldn't work at all becaue of a merge mistake. See #421.
164
+ * Fix `Bootsnap.unload_cache!`, it simply wouldn't work at all because of a merge mistake. See #421.
28
165
 
29
166
  # 1.13.0
30
167
 
@@ -43,7 +180,7 @@
43
180
 
44
181
  * Stop decorating `Module#autoload` as it was only useful for supporting Ruby 2.2 and older.
45
182
 
46
- * Remove `uname` and other patform specific version from the cache keys. `RUBY_PLATFORM + RUBY_REVISION` should be
183
+ * Remove `uname` and other platform specific version from the cache keys. `RUBY_PLATFORM + RUBY_REVISION` should be
47
184
  enough to ensure bytecode compatibility. This should improve caching for alpine based setups. See #409.
48
185
 
49
186
  # 1.11.1
@@ -60,7 +197,7 @@
60
197
 
61
198
  * Get rid of the `Kernel.require_relative` decorator by resolving `$LOAD_PATH` members to their real path.
62
199
  This way we handle symlinks in `$LOAD_PATH` much more efficiently. See #402 for the detailed explanation.
63
-
200
+
64
201
  * Drop support for Ruby 2.3 (to allow getting rid of the `Kernel.require_relative` decorator).
65
202
 
66
203
  # 1.10.3
@@ -186,7 +323,7 @@
186
323
  * Adds an instrumentation API to monitor cache misses.
187
324
  * Allow to control the behavior of `require 'bootsnap/setup'` using environment variables.
188
325
  * Deprecate the `disable_trace` option.
189
- * Deprecate the `ActiveSupport::Dependencies` (AKA Classic autoloader) integration. (#344)
326
+ * Deprecate the `ActiveSupport::Dependencies` (AKA Classic autoloader) integration. (#344)
190
327
 
191
328
  # 1.6.0
192
329
 
@@ -206,12 +343,12 @@
206
343
 
207
344
  # 1.4.9
208
345
 
209
- * [Windows support](https://github.com/Shopify/bootsnap/pull/319)
210
- * [Fix potential crash](https://github.com/Shopify/bootsnap/pull/322)
346
+ * [Windows support](https://github.com/rails/bootsnap/pull/319)
347
+ * [Fix potential crash](https://github.com/rails/bootsnap/pull/322)
211
348
 
212
349
  # 1.4.8
213
350
 
214
- * [Prevent FallbackScan from polluting exception cause](https://github.com/Shopify/bootsnap/pull/314)
351
+ * [Prevent FallbackScan from polluting exception cause](https://github.com/rails/bootsnap/pull/314)
215
352
 
216
353
  # 1.4.7
217
354
 
@@ -224,7 +361,7 @@
224
361
  required if a different file with the same name was already being required
225
362
 
226
363
  Example:
227
-
364
+
228
365
  require 'foo'
229
366
  require 'foo.en'
230
367
 
@@ -278,7 +415,7 @@
278
415
 
279
416
  # 1.3.0
280
417
 
281
- * Handle cases where load path entries are symlinked (https://github.com/Shopify/bootsnap/pull/136)
418
+ * Handle cases where load path entries are symlinked (https://github.com/rails/bootsnap/pull/136)
282
419
 
283
420
  # 1.2.1
284
421
 
data/LICENSE.txt CHANGED
@@ -1,6 +1,7 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2017-present Shopify, Inc.
3
+ Copyright (c) 2017-2025 Shopify, Inc.
4
+ Copyright (c) 2025-present Rails Foundation
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Bootsnap [![Actions Status](https://github.com/Shopify/bootsnap/workflows/ci/badge.svg)](https://github.com/Shopify/bootsnap/actions)
1
+ # Bootsnap [![Actions Status](https://github.com/rails/bootsnap/workflows/ci/badge.svg)](https://github.com/rails/bootsnap/actions)
2
2
 
3
3
  Bootsnap is a library that plugs into Ruby, with optional support for `YAML` and `JSON`,
4
4
  to optimize and cache expensive computations. See [How Does This Work](#how-does-this-work).
@@ -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/main/lib/bootsnap/setup.rb).
44
+ You can see how this require works [here](https://github.com/rails/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
@@ -57,13 +57,12 @@ Bootsnap.setup(
57
57
  load_path_cache: true, # Optimize the LOAD_PATH with a cache
58
58
  compile_cache_iseq: true, # Compile Ruby code into ISeq cache, breaks coverage reporting.
59
59
  compile_cache_yaml: true, # Compile YAML into a cache
60
- compile_cache_json: true, # Compile JSON into a cache
61
60
  readonly: true, # Use the caches but don't update them on miss or stale entries.
62
61
  )
63
62
  ```
64
63
 
65
64
  **Protip:** You can replace `require 'bootsnap'` with `BootLib::Require.from_gem('bootsnap',
66
- 'bootsnap')` using [this trick](https://github.com/Shopify/bootsnap/wiki/Bootlib::Require). This
65
+ 'bootsnap')` using [this trick](https://github.com/rails/bootsnap/wiki/Bootlib::Require). This
67
66
  will help optimize boot time further if you have an extremely large `$LOAD_PATH`.
68
67
 
69
68
  Note: Bootsnap and [Spring](https://github.com/rails/spring) are orthogonal tools. While Bootsnap
@@ -76,11 +75,13 @@ well together.
76
75
  `require 'bootsnap/setup'` behavior can be changed using environment variables:
77
76
 
78
77
  - `BOOTSNAP_CACHE_DIR` allows to define the cache location.
78
+ - `BOOTSNAP_CONFIG` allows to change the default config location (`config/bootsnap.rb`).
79
79
  - `DISABLE_BOOTSNAP` allows to entirely disable bootsnap.
80
80
  - `DISABLE_BOOTSNAP_LOAD_PATH_CACHE` allows to disable load path caching.
81
81
  - `DISABLE_BOOTSNAP_COMPILE_CACHE` allows to disable ISeq and YAML caches.
82
82
  - `BOOTSNAP_READONLY` configure bootsnap to not update the cache on miss or stale entries.
83
83
  - `BOOTSNAP_LOG` configure bootsnap to log all caches misses to STDERR.
84
+ - `BOOTSNAP_STATS` log hit rate statistics on exit. Can't be used if `BOOTSNAP_LOG` is enabled.
84
85
  - `BOOTSNAP_IGNORE_DIRECTORIES` a comma separated list of directories that shouldn't be scanned.
85
86
  Useful when you have large directories of non-ruby files inside `$LOAD_PATH`.
86
87
  It defaults to ignore any directory named `node_modules`.
@@ -99,8 +100,8 @@ Bootsnap cache misses can be monitored though a callback:
99
100
  Bootsnap.instrumentation = ->(event, path) { puts "#{event} #{path}" }
100
101
  ```
101
102
 
102
- `event` is either `:miss` or `:stale`. You can also call `Bootsnap.log!` as a shortcut to
103
- log all events to STDERR.
103
+ `event` is either `:hit`, `:miss`, `:stale` or `:revalidated`.
104
+ You can also call `Bootsnap.log!` as a shortcut to log all events to STDERR.
104
105
 
105
106
  To turn instrumentation back off you can set it to nil:
106
107
 
@@ -169,7 +170,7 @@ The only directories considered "stable" are things under the Ruby install prefi
169
170
  "volatile".
170
171
 
171
172
  In addition to the [`Bootsnap::LoadPathCache::Cache`
172
- source](https://github.com/Shopify/bootsnap/blob/main/lib/bootsnap/load_path_cache/cache.rb),
173
+ source](https://github.com/rails/bootsnap/blob/main/lib/bootsnap/load_path_cache/cache.rb),
173
174
  this diagram may help clarify how entry resolution works:
174
175
 
175
176
  ![How path searching works](https://cloud.githubusercontent.com/assets/3074765/25388270/670b5652-299b-11e7-87fb-975647f68981.png)
@@ -187,7 +188,7 @@ result too, raising a `LoadError` without touching the filesystem at all.
187
188
 
188
189
  Ruby has complex grammar and parsing it is not a particularly cheap operation. Since 1.9, Ruby has
189
190
  translated ruby source to an internal bytecode format, which is then executed by the Ruby VM. Since
190
- 2.3.0, Ruby [exposes an API](https://ruby-doc.org/core-2.3.0/RubyVM/InstructionSequence.html) that
191
+ 2.3.0, Ruby [exposes an API](https://docs.ruby-lang.org/en/master/RubyVM/InstructionSequence.html) that
191
192
  allows caching that bytecode. This allows us to bypass the relatively-expensive compilation step on
192
193
  subsequent loads of the same file.
193
194
 
@@ -236,14 +237,15 @@ This may look worse at a glance, but underlies a large performance difference.
236
237
  useful. [This ruby patch](https://bugs.ruby-lang.org/issues/13378) optimizes them out when coupled
237
238
  with bootsnap.)*
238
239
 
239
- Bootsnap writes a cache file containing a 64 byte header followed by the cache contents. The header
240
+ Bootsnap writes a cache file containing a 32 byte header followed by the cache contents. The header
240
241
  is a cache key including several fields:
241
242
 
242
- * `version`, hardcoded in bootsnap. Essentially a schema version;
243
- * `ruby_platform`, A hash of `RUBY_PLATFORM` (e.g. x86_64-linux-gnu) variable.
244
- * `compile_option`, which changes with `RubyVM::InstructionSequence.compile_option` does;
245
- * `ruby_revision`, A hash of `RUBY_REVISION`, the exact version of Ruby;
243
+ * `ruby_version_digest`, a digest of:
244
+ * The `RUBY_DESCRIPTION` constant e.g. `"ruby 4.0.2 (2026-03-17 revision d3da9fec82) +PRISM [arm64-darwin25]"`.
245
+ * Bootsnap's cache version. Hardcoded in bootsnap. Essentially a schema version;
246
+ * The content of `RubyVM::InstructionSequence.compile_option`.
246
247
  * `size`, the size of the source file;
248
+ * `digest`, a fnv1a_64 hash of the source file;
247
249
  * `mtime`, the last-modification timestamp of the source file when it was compiled; and
248
250
  * `data_size`, the number of bytes following the header, which we need to read it into a buffer.
249
251
 
@@ -320,6 +322,38 @@ open /c/nope.bundle -> -1
320
322
  # (nothing!)
321
323
  ```
322
324
 
325
+ ## Custom Compilers
326
+
327
+ Bootsnap allows substituing the default Ruby compiler by another one.
328
+ This can be configured from the bootsnap config file (defaults to `config/bootsnap.rb`).
329
+
330
+ The main use case is to programmatically enable frozen string literals for your project without impacting dependencies:
331
+
332
+ ```ruby
333
+ Bootsnap.enable_frozen_string_literal(app_only: true)
334
+ ```
335
+
336
+ But it can also be used for more fine grained logic, or to implement all sort of Ruby code preprocessing:
337
+
338
+ ```ruby
339
+ # config/bootsnap.rb
340
+ gems_root = File.join(Bundler.bundle_path.cleanpath, "")
341
+ app_root = File.join(Dir.pwd, "")
342
+ Bootsnap::CompileCache::ISeq.compiler_selector = ->(path) do
343
+ # Enable `frozen_string_literal: true` for app code, but not gems.
344
+
345
+ if path.start_with?(app_root) && !path.start_with?(gems_root)
346
+ Bootsnap::CompileCache::ISeq::FROZEN_STRING_LITERAL
347
+ else
348
+ Bootsnap::CompileCache::ISeq::DEFAULT
349
+ end
350
+ end
351
+ ```
352
+
353
+ *Important note*: This feature is only fully supported by Ruby `4.0.4` and newer.
354
+ On older rubies the feature work except if the `Coverage` module is enabled, in which case a warning will be emitted
355
+ and the default Ruby compiler will be used.
356
+
323
357
  ## Precompilation
324
358
 
325
359
  In development environments the bootsnap compilation cache is generated on the fly when source files are loaded.
@@ -330,9 +364,23 @@ To do so you can use the `bootsnap precompile` command.
330
364
  Example:
331
365
 
332
366
  ```bash
333
- $ bundle exec bootsnap precompile --gemfile app/ lib/
367
+ $ bundle exec bootsnap precompile --gemfile app/ lib/ config/
334
368
  ```
335
369
 
370
+ ## Known issues
371
+
372
+ ### QEMU environments
373
+
374
+ When building cross-platform Docker images, QEMU is often used for emulation and can be the source of a limitation that causes forked processes to hang. While Bootsnap includes automatic detection for this issue (as of [PR #501](https://github.com/rails/bootsnap/pull/501)), the detection may not always be sufficient.
375
+
376
+ If you encounter hangs during precompilation in QEMU-based environments (such as when using Docker buildx for cross-platform builds), you can work around this by disabling parallelization with the `-j 0` option:
377
+
378
+ ```bash
379
+ $ bundle exec bootsnap precompile -j 0 --gemfile app/ lib/ config/
380
+ ```
381
+
382
+ See [Issue #495](https://github.com/rails/bootsnap/issues/495) for more details about this QEMU-related issue.
383
+
336
384
  ## When not to use Bootsnap
337
385
 
338
386
  *Alternative engines*: Bootsnap is pretty reliant on MRI features, and parts are disabled entirely on alternative ruby