bootsnap 1.14.0 → 1.15.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6f2b4691e78336f28b1f78e9751235bc558b0f6ad86dee541acd478fc23ef510
4
- data.tar.gz: 51eb44a77465f49db0d15425536e17d94f8d3fe77433ab48260b4c81613d9c72
3
+ metadata.gz: 68bf895082a1d27386514357e36c1b53972f7f2e22f50b2f9b77cde53fec9110
4
+ data.tar.gz: dcc033dc6522aa59d853f7840d228430aa5591892d063d91c061fb1c7edcb820
5
5
  SHA512:
6
- metadata.gz: 64e98271863cf3dec676eea43ecaecf4d97a543ba5c0d840160d9862b4f212906910e3654263db49457320b5783150c719a8ef479266be96df5243a04addc43b
7
- data.tar.gz: 46aa01dff95699d6148ed539c8a56e1d749801ee89e953a37f32b4a3974f1da99fe594c4fb1b04c99a42f030cb4b12bd6dd892fac5b00af4de1f7a560cb420ba
6
+ metadata.gz: b640bf89d0448536c17f88352e97aa4b5a321cec6abfcd011d1f442ec9c9170b0b08e0329e398919140da1b0d1e65d343b761be392d25eb75540425c42d766cb
7
+ data.tar.gz: 97080b27ccca5dd741bfccc0c3cd412c7fcea917fad2e79961ef2a7c18a1dd5478fc33f2a4d9f59a5f8765696760aef76799f401b1cf13b9a68d7ffc0d0a326b
data/CHANGELOG.md CHANGED
@@ -1,10 +1,14 @@
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
+
3
7
  # 1.14.0
4
8
 
5
9
  * Require Ruby 2.6.
6
10
  * Add a way to skip directories during load path scanning.
7
- If you have large non-ruby directories in the middle of your load path, it can severly slow down scanning.
11
+ If you have large non-ruby directories in the middle of your load path, it can severely slow down scanning.
8
12
  Typically this is a problem with `node_modules`. See #277.
9
13
  * Fix `Bootsnap.unload_cache!`, it simply wouldn't work at all becaue of a merge mistake. See #421.
10
14
 
data/README.md CHANGED
@@ -52,11 +52,12 @@ require 'bootsnap'
52
52
  env = ENV['RAILS_ENV'] || "development"
53
53
  Bootsnap.setup(
54
54
  cache_dir: 'tmp/cache', # Path to your cache
55
- ignored_directories ['node_modules'], # Directory names to skip.
55
+ ignore_directories: ['node_modules'], # Directory names to skip.
56
56
  development_mode: env == 'development', # Current working environment, e.g. RACK_ENV, RAILS_ENV, etc
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
+ readonly: true, # Use the caches but don't update them on miss or stale entries.
60
61
  )
61
62
  ```
62
63
 
@@ -77,6 +78,7 @@ well together, and are both included in a newly-generated Rails applications by
77
78
  - `DISABLE_BOOTSNAP` allows to entirely disable bootsnap.
78
79
  - `DISABLE_BOOTSNAP_LOAD_PATH_CACHE` allows to disable load path caching.
79
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.
80
82
  - `BOOTSNAP_LOG` configure bootsnap to log all caches misses to STDERR.
81
83
  - `BOOTSNAP_IGNORE_DIRECTORIES` a comma separated list of directories that shouldn't be scanned.
82
84
  Useful when you have large directories of non-ruby files inside `$LOAD_PATH`.
@@ -90,9 +90,11 @@ static ID instrumentation_method;
90
90
  static VALUE sym_miss;
91
91
  static VALUE sym_stale;
92
92
  static bool instrumentation_enabled = false;
93
+ static bool readonly = false;
93
94
 
94
95
  /* Functions exposed as module functions on Bootsnap::CompileCache::Native */
95
96
  static VALUE bs_instrumentation_enabled_set(VALUE self, VALUE enabled);
97
+ static VALUE bs_readonly_set(VALUE self, VALUE enabled);
96
98
  static VALUE bs_compile_option_crc32_set(VALUE self, VALUE crc32_v);
97
99
  static VALUE bs_rb_fetch(VALUE self, VALUE cachedir_v, VALUE path_v, VALUE handler, VALUE args);
98
100
  static VALUE bs_rb_precompile(VALUE self, VALUE cachedir_v, VALUE path_v, VALUE handler);
@@ -166,6 +168,7 @@ Init_bootsnap(void)
166
168
  rb_global_variable(&sym_stale);
167
169
 
168
170
  rb_define_module_function(rb_mBootsnap, "instrumentation_enabled=", bs_instrumentation_enabled_set, 1);
171
+ rb_define_module_function(rb_mBootsnap_CompileCache_Native, "readonly=", bs_readonly_set, 1);
169
172
  rb_define_module_function(rb_mBootsnap_CompileCache_Native, "coverage_running?", bs_rb_coverage_running, 0);
170
173
  rb_define_module_function(rb_mBootsnap_CompileCache_Native, "fetch", bs_rb_fetch, 4);
171
174
  rb_define_module_function(rb_mBootsnap_CompileCache_Native, "precompile", bs_rb_precompile, 3);
@@ -182,6 +185,13 @@ bs_instrumentation_enabled_set(VALUE self, VALUE enabled)
182
185
  return enabled;
183
186
  }
184
187
 
188
+ static VALUE
189
+ bs_readonly_set(VALUE self, VALUE enabled)
190
+ {
191
+ readonly = RTEST(enabled);
192
+ return enabled;
193
+ }
194
+
185
195
  /*
186
196
  * Bootsnap's ruby code registers a hook that notifies us via this function
187
197
  * when compile_option changes. These changes invalidate all existing caches.
@@ -945,12 +955,17 @@ try_input_to_storage(VALUE arg)
945
955
  static int
946
956
  bs_input_to_storage(VALUE handler, VALUE args, VALUE input_data, VALUE pathval, VALUE * storage_data)
947
957
  {
948
- int state;
949
- struct i2s_data i2s_data = {
950
- .handler = handler,
951
- .input_data = input_data,
952
- .pathval = pathval,
953
- };
954
- *storage_data = rb_protect(try_input_to_storage, (VALUE)&i2s_data, &state);
955
- return state;
958
+ if (readonly) {
959
+ *storage_data = rb_cBootsnap_CompileCache_UNCOMPILABLE;
960
+ return 0;
961
+ } else {
962
+ int state;
963
+ struct i2s_data i2s_data = {
964
+ .handler = handler,
965
+ .input_data = input_data,
966
+ .pathval = pathval,
967
+ };
968
+ *storage_data = rb_protect(try_input_to_storage, (VALUE)&i2s_data, &state);
969
+ return state;
970
+ }
956
971
  }
@@ -10,7 +10,7 @@ module Bootsnap
10
10
  Error = Class.new(StandardError)
11
11
  PermissionError = Class.new(Error)
12
12
 
13
- def self.setup(cache_dir:, iseq:, yaml:, json:)
13
+ def self.setup(cache_dir:, iseq:, yaml:, json:, readonly: false)
14
14
  if iseq
15
15
  if supported?
16
16
  require_relative("compile_cache/iseq")
@@ -37,6 +37,10 @@ module Bootsnap
37
37
  warn("[bootsnap/setup] JSON parsing caching is not supported on this implementation of Ruby")
38
38
  end
39
39
  end
40
+
41
+ if supported? && defined?(Bootsnap::CompileCache::Native)
42
+ Bootsnap::CompileCache::Native.readonly = readonly
43
+ end
40
44
  end
41
45
 
42
46
  def self.permission_error(path)
@@ -13,10 +13,11 @@ module Bootsnap
13
13
  NestedTransactionError = Class.new(StandardError)
14
14
  SetOutsideTransactionNotAllowed = Class.new(StandardError)
15
15
 
16
- def initialize(store_path)
16
+ def initialize(store_path, readonly: false)
17
17
  @store_path = store_path
18
18
  @txn_mutex = Mutex.new
19
19
  @dirty = false
20
+ @readonly = readonly
20
21
  load_data
21
22
  end
22
23
 
@@ -63,7 +64,7 @@ module Bootsnap
63
64
  end
64
65
 
65
66
  def commit_transaction
66
- if @dirty
67
+ if @dirty && !@readonly
67
68
  dump_data
68
69
  @dirty = false
69
70
  end
@@ -28,13 +28,13 @@ module Bootsnap
28
28
  alias_method :enabled?, :enabled
29
29
  remove_method(:enabled)
30
30
 
31
- def setup(cache_path:, development_mode:, ignore_directories:)
31
+ def setup(cache_path:, development_mode:, ignore_directories:, readonly: false)
32
32
  unless supported?
33
33
  warn("[bootsnap/setup] Load path caching is not supported on this implementation of Ruby") if $VERBOSE
34
34
  return
35
35
  end
36
36
 
37
- store = Store.new(cache_path)
37
+ store = Store.new(cache_path, readonly: readonly)
38
38
 
39
39
  @loaded_features_index = LoadedFeaturesIndex.new
40
40
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bootsnap
4
- VERSION = "1.14.0"
4
+ VERSION = "1.15.0"
5
5
  end
data/lib/bootsnap.rb CHANGED
@@ -40,6 +40,7 @@ module Bootsnap
40
40
  development_mode: true,
41
41
  load_path_cache: true,
42
42
  ignore_directories: nil,
43
+ readonly: false,
43
44
  compile_cache_iseq: true,
44
45
  compile_cache_yaml: true,
45
46
  compile_cache_json: true
@@ -49,6 +50,7 @@ module Bootsnap
49
50
  cache_path: "#{cache_dir}/bootsnap/load-path-cache",
50
51
  development_mode: development_mode,
51
52
  ignore_directories: ignore_directories,
53
+ readonly: readonly,
52
54
  )
53
55
  end
54
56
 
@@ -57,6 +59,7 @@ module Bootsnap
57
59
  iseq: compile_cache_iseq,
58
60
  yaml: compile_cache_yaml,
59
61
  json: compile_cache_json,
62
+ readonly: readonly,
60
63
  )
61
64
  end
62
65
 
@@ -101,6 +104,7 @@ module Bootsnap
101
104
  compile_cache_iseq: !ENV["DISABLE_BOOTSNAP_COMPILE_CACHE"],
102
105
  compile_cache_yaml: !ENV["DISABLE_BOOTSNAP_COMPILE_CACHE"],
103
106
  compile_cache_json: !ENV["DISABLE_BOOTSNAP_COMPILE_CACHE"],
107
+ readonly: !!ENV["BOOTSNAP_READONLY"],
104
108
  ignore_directories: ignore_directories,
105
109
  )
106
110
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootsnap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.0
4
+ version: 1.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Burke Libbey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-18 00:00:00.000000000 Z
11
+ date: 2022-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack