bootsnap 0.2.15 → 1.0.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
  SHA1:
3
- metadata.gz: b0de1ff4a8bdd4478f422a07fba3981778828604
4
- data.tar.gz: d9b7d5cc09e58be7bc31382be47d72870c60bf7f
3
+ metadata.gz: 77b33ef59e01f0ddaa1de86a002ce286018b870d
4
+ data.tar.gz: 958ec1e45c50803261866ade91f9300dd6975d03
5
5
  SHA512:
6
- metadata.gz: f153d3e9591eb2fb8d2efecb958cbe21f61d93040f891ef63809285418cf76b3883d5490b3aa60d656bd066f96d7489317b13833bdf465058f7a339547177f6c
7
- data.tar.gz: be2f217b2481c5d3eb44226d9861d2890dc7901143ab056e0d1f2fbd5e4f152ef497fb1cd67481ae44c4723dc5b0c93a6f6f6faebd705f4ce321aa0e5949bd2f
6
+ metadata.gz: bcb190169610158178bff1fbf16ed6d43a4f986d06c7e07c16c5199aa658512749490b43e42b1e2e431a1099aa5ebd50e5905a35a0170f75e2cc2d468037eca1
7
+ data.tar.gz: 17fe5e20e585fce572bc39a47febe146abba4ec0aea70934c9d39f88fd271f158b3dd0fc3b0fe103e3060c97ade3bd890cf9e74d28f7ba4fb6b7836a401dac14
data/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ # 1.0.0
2
+
3
+ * (none)
4
+
5
+ # 0.3.2
6
+
7
+ * Minor performance savings around checking validity of cache in the presence of relative paths.
8
+ * When coverage is enabled, skips optimization instead of exploding.
9
+
10
+ # 0.3.1
11
+
12
+ * Don't whitelist paths under `RbConfig::CONFIG['prefix']` as stable; instead use `['libdir']` (#41).
13
+ * Catch `EOFError` when reading load-path-cache and regenerate cache.
14
+ * Support relative paths in load-path-cache.
15
+
16
+ # 0.3.0
17
+
18
+ * Migrate CompileCache from xattr as a cache backend to a cache directory
19
+ * Adds support for Linux and FreeBSD
20
+
1
21
  # 0.2.15
2
22
 
3
23
  * 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
 
@@ -15,6 +12,8 @@ methods to optimize and cache expensive computations. See [the How Does This Wor
15
12
 
16
13
  ## Usage
17
14
 
15
+ This gem works on MacOS and Linux.
16
+
18
17
  Add `bootsnap` to your `Gemfile`:
19
18
 
20
19
  ```ruby
@@ -120,7 +119,8 @@ result too, raising a `LoadError` without touching the filesystem at all.
120
119
 
121
120
  ### Compilation Caching
122
121
 
123
- *(A simpler implementation of this concept can be found in [yomikomu](https://github.com/ko1/yomikomu)).*
122
+ *(A more readable implementation of this concept can be found in
123
+ [yomikomu](https://github.com/ko1/yomikomu)).*
124
124
 
125
125
  Ruby has complex grammar and parsing it is not a particularly cheap operation. Since 1.9, Ruby has
126
126
  translated ruby source to an internal bytecode format, which is then executed by the Ruby VM. Since
@@ -134,9 +134,8 @@ implementation. We use the same strategy of compilation caching for YAML documen
134
134
  equivalent of Ruby's "bytecode" format being a MessagePack document (or, in the case of YAML
135
135
  documents with types unsupported by MessagePack, a Marshal stream).
136
136
 
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.
137
+ These compilation results are stored in a cache directory, with filenames generated by taking a hash
138
+ of the full expanded path of the input file (FNV1a-64).
140
139
 
141
140
  Whereas before, the sequence of syscalls generated to `require` a file would look like:
142
141
 
@@ -158,32 +157,36 @@ With bootsnap, we get:
158
157
  ```
159
158
  open /c/foo.rb -> n
160
159
  fstat64 n
161
- fgetxattr n
162
- fgetxattr n
160
+ close n
161
+ open /c/foo.rb -> n
162
+ fstat64 n
163
+ open (cache) -> m
164
+ read m
165
+ read m
166
+ close m
163
167
  close n
164
168
  ```
165
169
 
166
- Bootsnap writes two `xattrs` attached to each file read:
170
+ This may look worse at a glance, but underlies a large performance difference.
167
171
 
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.
172
+ *(The first three syscalls in both listings -- `open`, `fstat64`, `close` -- are not inherently
173
+ useful. [This ruby patch](https://bugs.ruby-lang.org/issues/13378) optimizes them out when coupled
174
+ with bootsnap.)*
170
175
 
171
- The key includes several fields:
176
+ Bootsnap writes a cache file containing a 64 byte header followed by the cache contents. The header
177
+ is a cache key including several fields:
172
178
 
173
179
  * `version`, hardcoded in bootsnap. Essentially a schema version;
180
+ * `os_version`, A hash of the current kernel version (on macOS, BSD) or glibc version (on Linux);
174
181
  * `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.
182
+ * `ruby_revision`, the version of Ruby this was compiled with;
183
+ * `size`, the size of the source file;
184
+ * `mtime`, the last-modification timestamp of the source file when it was compiled; and
185
+ * `data_size`, the number of bytes following the header, which we need to read it into a buffer.
179
186
 
180
187
  If the key is valid, the result is loaded from the value. Otherwise, it is regenerated and clobbers
181
188
  the current cache.
182
189
 
183
- This diagram may help illustrate how it works:
184
-
185
- ![Compilation Caching](https://burkelibbey.s3.amazonaws.com/bootsnap-compile-cache.png)
186
-
187
190
  ### Putting it all together
188
191
 
189
192
  Imagine we have this file structure:
@@ -227,8 +230,13 @@ With bootsnap, we get:
227
230
  ```
228
231
  open /c/foo.rb -> n
229
232
  fstat64 n
230
- fgetxattr n
231
- fgetxattr n
233
+ close n
234
+ open /c/foo.rb -> n
235
+ fstat64 n
236
+ open (cache) -> m
237
+ read m
238
+ read m
239
+ close m
232
240
  close n
233
241
  ```
234
242
 
@@ -253,8 +261,8 @@ open /c/nope.bundle -> -1
253
261
 
254
262
  We use the `*_path_cache` features in production and haven't experienced any issues in a long time.
255
263
 
256
- The `compile_cache_*` features work well for us in development on macOS, but probably don't work on
257
- Linux at all.
264
+ The `compile_cache_*` features work well for us in development on macOS. It should work on Linux,
265
+ and we intend to deploy it in production, but haven't we haven't yet.
258
266
 
259
267
  `disable_trace` should be completely safe, but we don't really use it because some people like to
260
268
  use tools that make use of `trace` instructions.
@@ -264,5 +272,5 @@ use tools that make use of `trace` instructions.
264
272
  | `load_path_cache` | everywhere |
265
273
  | `autoload_path_cache` | everywhere |
266
274
  | `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 |
275
+ | `compile_cache_iseq` | development, but probably safe to use everywhere |
276
+ | `compile_cache_yaml` | development, but probably safe to use everywhere |