bootsnap 0.2.15 → 0.3.1

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
  SHA1:
3
- metadata.gz: b0de1ff4a8bdd4478f422a07fba3981778828604
4
- data.tar.gz: d9b7d5cc09e58be7bc31382be47d72870c60bf7f
3
+ metadata.gz: 7c6a61ff4456f0b745e1872ed315eef0d9a644c7
4
+ data.tar.gz: 0515f1b08b95f0d88fb32829f6c99a07494af996
5
5
  SHA512:
6
- metadata.gz: f153d3e9591eb2fb8d2efecb958cbe21f61d93040f891ef63809285418cf76b3883d5490b3aa60d656bd066f96d7489317b13833bdf465058f7a339547177f6c
7
- data.tar.gz: be2f217b2481c5d3eb44226d9861d2890dc7901143ab056e0d1f2fbd5e4f152ef497fb1cd67481ae44c4723dc5b0c93a6f6f6faebd705f4ce321aa0e5949bd2f
6
+ metadata.gz: 4ce3ba2a352a495e8d8f421ca404273013fcf5ee524e224086e78c4fc106de7505e703481f664fb11068735ead27e4e4b606dc1a67c17fc138b6bf58bcf11c58
7
+ data.tar.gz: fb992465d5f226f6f2d26ecf7491db4d41c4061a3e0742d9991f202c9c7db209a13e4ec40e5fe9f210e4c5119ada8e1b56637f764b55ef4640d655c91587eb1e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ # 0.3.1
2
+
3
+ * Don't whitelist paths under `RbConfig::CONFIG['prefix']` as stable; instead use `['libdir']` (#41).
4
+ * Catch `EOFError` when reading load-path-cache and regenerate cache.
5
+ * Support relative paths in load-path-cache.
6
+
7
+ # 0.3.0
8
+
9
+ * Migrate CompileCache from xattr as a cache backend to a cache directory
10
+ * Adds support for Linux and FreeBSD
11
+
1
12
  # 0.2.15
2
13
 
3
14
  * Support more versions of ActiveSupport (`depend_on`'s signature varies; don't reiterate it)
data/README.md CHANGED
@@ -2,9 +2,6 @@
2
2
 
3
3
  **Beta-quality. See [the last section of this README](#trustworthiness).**
4
4
 
5
- **`compile_cache_*` features are only supported on MacOS (extremely likely to error on Linux;
6
- won't even compile on other platforms).**
7
-
8
5
  Bootsnap is a library that plugs into a number of Ruby and (optionally) `ActiveSupport` and `YAML`
9
6
  methods to optimize and cache expensive computations. See [the How Does This Work section](#how-does-this-work) for more information.
10
7
 
@@ -120,7 +117,8 @@ result too, raising a `LoadError` without touching the filesystem at all.
120
117
 
121
118
  ### Compilation Caching
122
119
 
123
- *(A simpler implementation of this concept can be found in [yomikomu](https://github.com/ko1/yomikomu)).*
120
+ *(A more readable implementation of this concept can be found in
121
+ [yomikomu](https://github.com/ko1/yomikomu)).*
124
122
 
125
123
  Ruby has complex grammar and parsing it is not a particularly cheap operation. Since 1.9, Ruby has
126
124
  translated ruby source to an internal bytecode format, which is then executed by the Ruby VM. Since
@@ -134,9 +132,8 @@ implementation. We use the same strategy of compilation caching for YAML documen
134
132
  equivalent of Ruby's "bytecode" format being a MessagePack document (or, in the case of YAML
135
133
  documents with types unsupported by MessagePack, a Marshal stream).
136
134
 
137
- These compilation results are stored using `xattr`s on the source files. This is likely to change in
138
- the future, as it has some limitations (notably precluding Linux support except where the user feels
139
- like changing mount flags). However, this is a very performant implementation.
135
+ These compilation results are stored in a cache directory, with filenames generated by taking a hash
136
+ of the full expanded path of the input file (FNV1a-64).
140
137
 
141
138
  Whereas before, the sequence of syscalls generated to `require` a file would look like:
142
139
 
@@ -158,32 +155,36 @@ With bootsnap, we get:
158
155
  ```
159
156
  open /c/foo.rb -> n
160
157
  fstat64 n
161
- fgetxattr n
162
- fgetxattr n
158
+ close n
159
+ open /c/foo.rb -> n
160
+ fstat64 n
161
+ open (cache) -> m
162
+ read m
163
+ read m
164
+ close m
163
165
  close n
164
166
  ```
165
167
 
166
- Bootsnap writes two `xattrs` attached to each file read:
168
+ This may look worse at a glance, but underlies a large performance difference.
167
169
 
168
- * `user.aotcc.value`, the binary compilation result; and
169
- * `user.aotcc.key`, a cache key to determine whether `user.aotcc.value` is still valid.
170
+ *(The first three syscalls in both listings -- `open`, `fstat64`, `close` -- are not inherently
171
+ useful. [This ruby patch](https://bugs.ruby-lang.org/issues/13378) optimizes them out when coupled
172
+ with bootsnap.)*
170
173
 
171
- The key includes several fields:
174
+ Bootsnap writes a cache file containing a 64 byte header followed by the cache contents. The header
175
+ is a cache key including several fields:
172
176
 
173
177
  * `version`, hardcoded in bootsnap. Essentially a schema version;
178
+ * `os_version`, A hash of the current kernel version (on macOS, BSD) or glibc version (on Linux);
174
179
  * `compile_option`, which changes with `RubyVM::InstructionSequence.compile_option` does;
175
- * `data_size`, the number of bytes in `user.aotcc.value`, which we need to read it into a buffer
176
- using `fgetxattr(2)`;
177
- * `ruby_revision`, the version of Ruby this was compiled with; and
178
- * `mtime`, the last-modification timestamp of the source file when it was compiled.
180
+ * `ruby_revision`, the version of Ruby this was compiled with;
181
+ * `size`, the size of the source file;
182
+ * `mtime`, the last-modification timestamp of the source file when it was compiled; and
183
+ * `data_size`, the number of bytes following the header, which we need to read it into a buffer.
179
184
 
180
185
  If the key is valid, the result is loaded from the value. Otherwise, it is regenerated and clobbers
181
186
  the current cache.
182
187
 
183
- This diagram may help illustrate how it works:
184
-
185
- ![Compilation Caching](https://burkelibbey.s3.amazonaws.com/bootsnap-compile-cache.png)
186
-
187
188
  ### Putting it all together
188
189
 
189
190
  Imagine we have this file structure:
@@ -227,8 +228,13 @@ With bootsnap, we get:
227
228
  ```
228
229
  open /c/foo.rb -> n
229
230
  fstat64 n
230
- fgetxattr n
231
- fgetxattr n
231
+ close n
232
+ open /c/foo.rb -> n
233
+ fstat64 n
234
+ open (cache) -> m
235
+ read m
236
+ read m
237
+ close m
232
238
  close n
233
239
  ```
234
240
 
@@ -253,8 +259,8 @@ open /c/nope.bundle -> -1
253
259
 
254
260
  We use the `*_path_cache` features in production and haven't experienced any issues in a long time.
255
261
 
256
- The `compile_cache_*` features work well for us in development on macOS, but probably don't work on
257
- Linux at all.
262
+ The `compile_cache_*` features work well for us in development on macOS. It should work on Linux,
263
+ and we intend to deploy it in production, but haven't we haven't yet.
258
264
 
259
265
  `disable_trace` should be completely safe, but we don't really use it because some people like to
260
266
  use tools that make use of `trace` instructions.
@@ -264,5 +270,5 @@ use tools that make use of `trace` instructions.
264
270
  | `load_path_cache` | everywhere |
265
271
  | `autoload_path_cache` | everywhere |
266
272
  | `disable_trace` | nowhere, but it's safe unless you need tracing |
267
- | `compile_cache_iseq` | development, unlikely to work on Linux |
268
- | `compile_cache_yaml` | development, unlikely to work on Linux |
273
+ | `compile_cache_iseq` | development, but probably safe to use everywhere |
274
+ | `compile_cache_yaml` | development, but probably safe to use everywhere |