bootsnap 0.3.0 → 0.3.2

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: 3725f53309883dce83894e47eedbb4d8322eabd5
4
- data.tar.gz: 81e14b1d48fc4431f6ac9bb2729cfb4a69aa0f5c
3
+ metadata.gz: 70088eed4fdd70bd8fe272c65b175961a5fa4f42
4
+ data.tar.gz: 50a34792fa1273b8e04d2e86c02209f309bdc9dd
5
5
  SHA512:
6
- metadata.gz: 5a2b45cb55ceffdb5751561b3a35c476ea29bcd3d3a2a68a46521240d35cc1e61cf9ac90265db751b09967655969c7a685725878b5f80a61fd38a0efd7024458
7
- data.tar.gz: 7f7975023cb1856d5ccada63e8be2e3ab94a751d4b80121821f2b01df6cbb94f5172041020ebb9300b63760da3fc2776e3b9b56160b95b4b0c07f82fbce07860
6
+ metadata.gz: 7fd194c0993c6f09454d1a47cc728943cf8ae3e1df2f5e603775b241e533343d0c12e3f64b437d9be728f0fbbe48ae49f2dee3705866a2817bcab4a5d6297074
7
+ data.tar.gz: 73217d9ce9ffdac00a191c87cf18fe0f664bdc025f97cef71db4d2f5343de7fae0e37ac384c1ff2298fe073adeca33260d60a75513455506edc935ac7a919458
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ # 0.3.2
2
+
3
+ * Minor performance savings around checking validity of cache in the presence of relative paths.
4
+ * When coverage is enabled, skips optimization instead of exploding.
5
+
6
+ # 0.3.1
7
+
8
+ * Don't whitelist paths under `RbConfig::CONFIG['prefix']` as stable; instead use `['libdir']` (#41).
9
+ * Catch `EOFError` when reading load-path-cache and regenerate cache.
10
+ * Support relative paths in load-path-cache.
11
+
1
12
  # 0.3.0
2
13
 
3
14
  * Migrate CompileCache from xattr as a cache backend to a cache directory
data/README.md CHANGED
@@ -12,6 +12,8 @@ methods to optimize and cache expensive computations. See [the How Does This Wor
12
12
 
13
13
  ## Usage
14
14
 
15
+ This gem works on MacOS and Linux.
16
+
15
17
  Add `bootsnap` to your `Gemfile`:
16
18
 
17
19
  ```ruby
@@ -12,6 +12,12 @@ module Bootsnap
12
12
  RubyVM::InstructionSequence.compile_file(path).to_binary
13
13
  rescue SyntaxError
14
14
  raise Uncompilable, 'syntax error'
15
+ rescue RuntimeError => e
16
+ if e.message == 'should not compile with coverage'
17
+ raise Uncompilable, 'coverage is enabled'
18
+ else
19
+ raise
20
+ end
15
21
  end
16
22
 
17
23
  def self.storage_to_output(binary)
@@ -46,7 +46,7 @@ module Bootsnap
46
46
  # Try to resolve this feature to an absolute path without traversing the
47
47
  # loadpath.
48
48
  def find(feature)
49
- reinitialize if stale?
49
+ reinitialize if (@has_relative_paths && dir_changed?) || stale?
50
50
  feature = feature.to_s
51
51
  return feature if feature.start_with?(SLASH)
52
52
  return File.expand_path(feature) if feature.start_with?('./')
@@ -116,15 +116,26 @@ module Bootsnap
116
116
 
117
117
  private
118
118
 
119
+ def dir_changed?
120
+ @prev_dir ||= Dir.pwd
121
+ if @prev_dir == Dir.pwd
122
+ false
123
+ else
124
+ @prev_dir = Dir.pwd
125
+ true
126
+ end
127
+ end
128
+
119
129
  def push_paths_locked(*paths)
120
130
  @store.transaction do
121
131
  paths.map(&:to_s).each do |path|
122
132
  p = Path.new(path)
133
+ @has_relative_paths = true if p.relative?
123
134
  next if p.non_directory?
124
135
  entries, dirs = p.entries_and_dirs(@store)
125
136
  # push -> low precedence -> set only if unset
126
137
  dirs.each { |dir| @dirs[dir] ||= true }
127
- entries.each { |rel| @index[rel] ||= path }
138
+ entries.each { |rel| @index[rel] ||= p.expanded_path }
128
139
  end
129
140
  end
130
141
  end
@@ -137,7 +148,7 @@ module Bootsnap
137
148
  entries, dirs = p.entries_and_dirs(@store)
138
149
  # unshift -> high precedence -> unconditional set
139
150
  dirs.each { |dir| @dirs[dir] = true }
140
- entries.each { |rel| @index[rel] = path }
151
+ entries.each { |rel| @index[rel] = p.expanded_path }
141
152
  end
142
153
  end
143
154
  end
@@ -30,34 +30,42 @@ module Bootsnap
30
30
  false
31
31
  end
32
32
 
33
+ def relative?
34
+ !path.start_with?(SLASH)
35
+ end
36
+
33
37
  # Return a list of all the requirable files and all of the subdirectories
34
38
  # of this +Path+.
35
39
  def entries_and_dirs(store)
36
40
  if stable?
37
41
  # the cached_mtime field is unused for 'stable' paths, but is
38
42
  # set to zero anyway, just in case we change the stability heuristics.
39
- _, entries, dirs = store.get(path)
43
+ _, entries, dirs = store.get(expanded_path)
40
44
  return [entries, dirs] if entries # cache hit
41
45
  entries, dirs = scan!
42
- store.set(path, [0, entries, dirs])
46
+ store.set(expanded_path, [0, entries, dirs])
43
47
  return [entries, dirs]
44
48
  end
45
49
 
46
- cached_mtime, entries, dirs = store.get(path)
50
+ cached_mtime, entries, dirs = store.get(expanded_path)
47
51
 
48
- current_mtime = latest_mtime(path, dirs || [])
52
+ current_mtime = latest_mtime(expanded_path, dirs || [])
49
53
  return [[], []] if current_mtime == -1 # path does not exist
50
54
  return [entries, dirs] if cached_mtime == current_mtime
51
55
 
52
56
  entries, dirs = scan!
53
- store.set(path, [current_mtime, entries, dirs])
57
+ store.set(expanded_path, [current_mtime, entries, dirs])
54
58
  [entries, dirs]
55
59
  end
56
60
 
61
+ def expanded_path
62
+ File.expand_path(path)
63
+ end
64
+
57
65
  private
58
66
 
59
67
  def scan! # (expensive) returns [entries, dirs]
60
- PathScanner.call(path)
68
+ PathScanner.call(expanded_path)
61
69
  end
62
70
 
63
71
  # last time a directory was modified in this subtree. +dirs+ should be a
@@ -83,15 +91,15 @@ module Bootsnap
83
91
  VOLATILE = :volatile
84
92
 
85
93
  # Built-in ruby lib stuff doesn't change, but things can occasionally be
86
- # installed into sitedir, which often lives under prefix.
87
- RUBY_PREFIX = RbConfig::CONFIG['prefix']
88
- SITE_DIR = RbConfig::CONFIG['sitedir']
94
+ # installed into sitedir, which generally lives under libdir.
95
+ RUBY_LIBDIR = RbConfig::CONFIG['libdir']
96
+ RUBY_SITEDIR = RbConfig::CONFIG['sitedir']
89
97
 
90
98
  def stability
91
99
  @stability ||= begin
92
- if Gem.path.detect { |p| path.start_with?(p.to_s) }
100
+ if Gem.path.detect { |p| expanded_path.start_with?(p.to_s) }
93
101
  STABLE
94
- elsif path.start_with?(RUBY_PREFIX) && !path.start_with?(SITE_DIR)
102
+ elsif expanded_path.start_with?(RUBY_LIBDIR) && !expanded_path.start_with?(RUBY_SITEDIR)
95
103
  STABLE
96
104
  else
97
105
  VOLATILE
@@ -3,8 +3,6 @@ require_relative '../load_path_cache'
3
3
  module Bootsnap
4
4
  module LoadPathCache
5
5
  module PathScanner
6
- RelativePathNotSupported = Class.new(StandardError)
7
-
8
6
  REQUIRABLES_AND_DIRS = "/**/*{#{DOT_RB},#{DL_EXTENSIONS.join(',')},/}"
9
7
  IS_DIR = %r{(.*)/\z}
10
8
  NORMALIZE_NATIVE_EXTENSIONS = !DL_EXTENSIONS.include?(LoadPathCache::DOT_SO)
@@ -13,7 +11,6 @@ module Bootsnap
13
11
 
14
12
  def self.call(path)
15
13
  path = path.to_s
16
- raise RelativePathNotSupported unless path.start_with?(SLASH)
17
14
 
18
15
  relative_slice = (path.size + 1)..-1
19
16
  # If the bundle path is a descendent of this path, we do additional
@@ -59,7 +59,7 @@ module Bootsnap
59
59
  @data = begin
60
60
  MessagePack.load(File.binread(@store_path))
61
61
  # handle malformed data due to upgrade incompatability
62
- rescue Errno::ENOENT, MessagePack::MalformedFormatError, MessagePack::UnknownExtTypeError
62
+ rescue Errno::ENOENT, MessagePack::MalformedFormatError, MessagePack::UnknownExtTypeError, EOFError
63
63
  {}
64
64
  end
65
65
  end
@@ -1,3 +1,3 @@
1
1
  module Bootsnap
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.2"
3
3
  end
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: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Burke Libbey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-26 00:00:00.000000000 Z
11
+ date: 2017-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler