Skip to content

Commit 4a0f8e6

Browse files
authored
Merge pull request #508 from byroot/remove-json-caching
Remove Bootsnap::CompileCache::JSON
2 parents e6272f8 + 5df6e04 commit 4a0f8e6

File tree

9 files changed

+16
-229
lines changed

9 files changed

+16
-229
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Unreleased
22

3+
* Remove JSON parsing cache. Recent versions of the `json` gem are as fast as `msgpack` if not faster.
4+
35
# 1.18.6
46

57
* Fix cgroup CPU limits detection in CLI.

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ Bootsnap.setup(
5757
load_path_cache: true, # Optimize the LOAD_PATH with a cache
5858
compile_cache_iseq: true, # Compile Ruby code into ISeq cache, breaks coverage reporting.
5959
compile_cache_yaml: true, # Compile YAML into a cache
60-
compile_cache_json: true, # Compile JSON into a cache
6160
readonly: true, # Use the caches but don't update them on miss or stale entries.
6261
)
6362
```

lib/bootsnap.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ def setup(
5454
revalidation: false,
5555
compile_cache_iseq: true,
5656
compile_cache_yaml: true,
57-
compile_cache_json: true
57+
compile_cache_json: (compile_cache_json_unset = true)
5858
)
59+
unless compile_cache_json_unset
60+
warn("Bootsnap.setup `compile_cache_json` argument is deprecated and has no effect")
61+
end
62+
5963
if load_path_cache
6064
Bootsnap::LoadPathCache.setup(
6165
cache_path: "#{cache_dir}/bootsnap/load-path-cache",
@@ -69,7 +73,6 @@ def setup(
6973
cache_dir: "#{cache_dir}/bootsnap/compile-cache",
7074
iseq: compile_cache_iseq,
7175
yaml: compile_cache_yaml,
72-
json: compile_cache_json,
7376
readonly: readonly,
7477
revalidation: revalidation,
7578
)
@@ -115,7 +118,6 @@ def default_setup
115118
load_path_cache: enabled?("BOOTSNAP_LOAD_PATH_CACHE"),
116119
compile_cache_iseq: enabled?("BOOTSNAP_COMPILE_CACHE"),
117120
compile_cache_yaml: enabled?("BOOTSNAP_COMPILE_CACHE"),
118-
compile_cache_json: enabled?("BOOTSNAP_COMPILE_CACHE"),
119121
readonly: bool_env("BOOTSNAP_READONLY"),
120122
revalidation: bool_env("BOOTSNAP_REVALIDATE"),
121123
ignore_directories: ignore_directories,

lib/bootsnap/cli.rb

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def match?(string)
2020

2121
attr_reader :cache_dir, :argv
2222

23-
attr_accessor :compile_gemfile, :exclude, :verbose, :iseq, :yaml, :json, :jobs
23+
attr_accessor :compile_gemfile, :exclude, :verbose, :iseq, :yaml, :jobs
2424

2525
def initialize(argv)
2626
@argv = argv
@@ -31,7 +31,6 @@ def initialize(argv)
3131
self.jobs = nil
3232
self.iseq = true
3333
self.yaml = true
34-
self.json = true
3534
end
3635

3736
def precompile_command(*sources)
@@ -42,21 +41,18 @@ def precompile_command(*sources)
4241
cache_dir: cache_dir,
4342
iseq: iseq,
4443
yaml: yaml,
45-
json: json,
4644
revalidation: true,
4745
)
4846

4947
@work_pool = WorkerPool.create(size: jobs, jobs: {
5048
ruby: method(:precompile_ruby),
5149
yaml: method(:precompile_yaml),
52-
json: method(:precompile_json),
5350
})
5451
@work_pool.spawn
5552

5653
main_sources = sources.map { |d| File.expand_path(d) }
5754
precompile_ruby_files(main_sources)
5855
precompile_yaml_files(main_sources)
59-
precompile_json_files(main_sources)
6056

6157
if compile_gemfile
6258
# Gems that include JSON or YAML files usually don't put them in `lib/`.
@@ -70,7 +66,6 @@ def precompile_command(*sources)
7066

7167
precompile_ruby_files(gem_paths, exclude: gem_exclude)
7268
precompile_yaml_files(gem_paths, exclude: gem_exclude)
73-
precompile_json_files(gem_paths, exclude: gem_exclude)
7469
end
7570

7671
if (exitstatus = @work_pool.shutdown)
@@ -145,29 +140,6 @@ def precompile_yaml(*yaml_files)
145140
end
146141
end
147142

148-
def precompile_json_files(load_paths, exclude: self.exclude)
149-
return unless json
150-
151-
load_paths.each do |path|
152-
if !exclude || !exclude.match?(path)
153-
list_files(path, "**/*.json").each do |json_file|
154-
# We ignore hidden files to not match the various .config.json files
155-
if !File.basename(json_file).start_with?(".") && (!exclude || !exclude.match?(json_file))
156-
@work_pool.push(:json, json_file)
157-
end
158-
end
159-
end
160-
end
161-
end
162-
163-
def precompile_json(*json_files)
164-
Array(json_files).each do |json_file|
165-
if CompileCache::JSON.precompile(json_file) && verbose
166-
$stderr.puts(json_file)
167-
end
168-
end
169-
end
170-
171143
def precompile_ruby_files(load_paths, exclude: self.exclude)
172144
return unless iseq
173145

@@ -276,9 +248,9 @@ def parser
276248
opts.on("--no-yaml", help) { self.yaml = false }
277249

278250
help = <<~HELP
279-
Disable JSON precompilation.
251+
Disable JSON precompilation. Deprecated.
280252
HELP
281-
opts.on("--no-json", help) { self.json = false }
253+
opts.on("--no-json", help) { $stderr.puts("The --no-json option is deprecated and now a noop.") }
282254
end
283255
end
284256
end

lib/bootsnap/compile_cache.rb

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ def UNCOMPILABLE.inspect
99

1010
Error = Class.new(StandardError)
1111

12-
def self.setup(cache_dir:, iseq:, yaml:, json:, readonly: false, revalidation: false)
12+
def self.setup(cache_dir:, iseq:, yaml:, json: (json_unset = true), readonly: false, revalidation: false)
13+
unless json_unset
14+
warn("Bootsnap::CompileCache.setup `json` argument is deprecated and has no effect")
15+
end
16+
1317
if iseq
1418
if supported?
1519
require_relative "compile_cache/iseq"
@@ -28,15 +32,6 @@ def self.setup(cache_dir:, iseq:, yaml:, json:, readonly: false, revalidation: f
2832
end
2933
end
3034

31-
if json
32-
if supported?
33-
require_relative "compile_cache/json"
34-
Bootsnap::CompileCache::JSON.install!(cache_dir)
35-
elsif $VERBOSE
36-
warn("[bootsnap/setup] JSON parsing caching is not supported on this implementation of Ruby")
37-
end
38-
end
39-
4035
if supported? && defined?(Bootsnap::CompileCache::Native)
4136
Bootsnap::CompileCache::Native.readonly = readonly
4237
Bootsnap::CompileCache::Native.revalidation = revalidation

lib/bootsnap/compile_cache/json.rb

Lines changed: 0 additions & 89 deletions
This file was deleted.

test/compile_cache/json_test.rb

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)