fastup 1.0.1 → 1.0.2

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: eff7fb62d73261c1f323338c749f82791546ab1b74de3d257e2254f7d19485ef
4
- data.tar.gz: fc7578d69d7c3da331cd4515da1f25344b9d30597e744aab26802ec929822e66
3
+ metadata.gz: ed16ec41e53affe880060f5a68b2be13f40dda18fed6df09b7fef562aeeffe6c
4
+ data.tar.gz: 53dcd47645e9b560a96c071f3e8445a5cebbdd4bf6083288ccf56a4c721603d8
5
5
  SHA512:
6
- metadata.gz: 3b320c6cfb22ae4c3e9c8cbd3a55d7c009a3503b4b6bd0e090205c5578ffe4564194047bd6e2336e2759431840d3c45cc7c20320bc92bdfe768872e7ae8d94c1
7
- data.tar.gz: 07a1a6f7e9fcc4694a60b9770842bf33e7e8e64fd7b3dd1916c61f8bba4ff2366c78f05875063e118b8dc7e5c6c42a032f2a22027369fe08bac96f622d0baaac
6
+ metadata.gz: 93f1e6f5ec39d3708850e9b7af7fa4e3dd3eb252845680fb2678855281a04476e99767b8fc4dc1d933918281f6029c08a1d508caa53d06633fefa850e23896d1
7
+ data.tar.gz: a1ea36d4c1ce7cdb15db3fd72afa64cc5b9ebb1fde8aec5709cecd8a552ecd110620d70d56fd4dd02b536fd75e1d4df5fbbf44e9aa94e913a7ad80ee0e7388c1
@@ -1,35 +1,37 @@
1
1
  module Fastup
2
- extend self
2
+ def self.require(name, original_require)
3
+ path = @suffixes.map{ |s| @sp.lookup(name.to_s + s) rescue nil }.find do |p|
4
+ p && File.file?(p)
5
+ end
3
6
 
4
- def apply!
5
- warn "fastup: building load path index"
6
- sp = SearchPath.new($LOAD_PATH)
7
- suffixes = Gem.suffixes.lazy
7
+ # require the absolute path if found, otherwise fallback to original name
8
+ ret = original_require.call(path || name)
8
9
 
9
- warn "fastup: patching require"
10
- mod = Module.new do
11
- define_method(:require) do |name|
12
- path = suffixes.map{ |s| sp.lookup(name.to_s + s) rescue nil }.find do |p|
13
- p && File.file?(p)
14
- end
10
+ if ret && ENV['FASTUP_DEBUG']
11
+ if path
12
+ warn "fastup: loaded #{name} => #{path}"
13
+ else
14
+ warn "fastup: super #{name}"
15
+ end
16
+ end
15
17
 
16
- # require the absolute path if found, otherwise fallback to original name
17
- ret = super(path || name)
18
+ ret
19
+ end
18
20
 
19
- if ret && ENV['FASTUP_DEBUG']
20
- if path
21
- warn "fastup: loaded #{name} => #{path}"
22
- else
23
- warn "fastup: super #{name}"
24
- end
25
- end
21
+ def self.apply!
22
+ @sp = SearchPath.new($LOAD_PATH)
23
+ @suffixes = Gem.suffixes.lazy
26
24
 
27
- ret
28
- end
25
+ instance_require = Kernel.instance_method(:require)
26
+ require = Kernel.method(:require)
27
+
28
+ Kernel.send(:define_method, :require) do |name|
29
+ Fastup.require(name, instance_require.bind(self))
29
30
  end
30
31
 
31
- Object.prepend mod # normal "require 'somegem'" invokes this
32
- Kernel.singleton_class.prepend mod # explicit "Kernel.require 'somegem'"
32
+ Kernel.singleton_class.send(:define_method, :require) do |name|
33
+ Fastup.require(name, require)
34
+ end
33
35
  end
34
36
 
35
37
  module XFile
@@ -2,4 +2,4 @@ require 'bundler/setup'
2
2
  require 'fastup/autoapply' if ENV['USE_FASTUP']
3
3
  Bundler.require
4
4
 
5
- puts $LOADED_FEATURES.join("\n")
5
+ puts $LOADED_FEATURES.map{|f| "feature:#{f}" }.join("\n")
@@ -0,0 +1,15 @@
1
+ require 'benchmark'
2
+
3
+ require 'bundler/setup'
4
+ require 'fastup/autoapply' if ENV['USE_FASTUP']
5
+
6
+ total = Benchmark.measure{ Bundler.require }.total
7
+
8
+ puts ['gems_count', 'load_path_size', 'loaded_features_size', 'time'].join("\t") if ENV['PRINT_HEADER']
9
+
10
+ puts "%d\t%d\t%d\t%.5f" % [
11
+ ENV['GEMS_COUNT'].to_i,
12
+ $LOAD_PATH.size,
13
+ $LOADED_FEATURES.size,
14
+ total,
15
+ ]
@@ -1,35 +1,38 @@
1
1
  require 'benchmark'
2
+ require 'open3'
2
3
  require 'tmpdir'
3
4
 
4
5
  require 'test_helper'
5
6
 
6
7
  module Fastup
7
8
  class TestAppBoot < Minitest::Test
9
+ def capture(*args)
10
+ out, status = Open3.capture2e(*args)
11
+ raise "#{args} exited with error:\n#{out}" unless status.success?
12
+ out
13
+ end
14
+
8
15
  tag :slow
9
16
  def test_app_boot
10
17
  results = {}
11
18
 
12
19
  Bundler.with_original_env do
13
20
  Dir.chdir(File.expand_path('../app', __FILE__)) do
14
- results[:setup] = `bundle --quiet`
15
- raise "bundle exited with error: #{results[:setup]}" unless $?.success?
21
+ results[:setup] = capture "bundle --quiet"
22
+
23
+ filter = ->(line) do
24
+ line =~ /^feature:/ && line !~ %r{/lib/fastup}
25
+ end
16
26
 
17
27
  results[:total_fastup] = Benchmark.measure {
18
- out = `USE_FASTUP=1 bundle exec ruby boot.rb 2>/dev/null`
19
- raise "fastup exited with error: #{out}" unless $?.success?
20
- results[:output_fastup] = out.lines.reject{ |p| p =~ %r{/lib/fastup} }
28
+ results[:output_fastup] = capture("USE_FASTUP=1 BUNDLE_FROZEN=true bundle exec ruby boot.rb").lines.select(&filter)
21
29
  }
22
30
  results[:total_nofastup] = Benchmark.measure {
23
- out = `bundle exec ruby boot.rb`
24
- raise "nofastup exited with error: #{out}" unless $?.success?
25
- results[:output_nofastup] = out.lines.reject{ |p| p =~ %r{/lib/fastup} }
31
+ results[:output_nofastup] = capture("BUNDLE_FROZEN=true bundle exec ruby boot.rb").lines.select(&filter)
26
32
  }
27
33
  end
28
34
  end
29
35
 
30
- results[:output_fastup].reject!{ |p| p =~ %r{fastup/lib/fastup} }
31
- results[:output_nofastup].reject!{ |p| p =~ %r{fastup/lib/fastup} }
32
-
33
36
  warn("\nfastup: %.2f nofastup: %.2f" % [results[:total_fastup].total, results[:total_nofastup].total])
34
37
 
35
38
  assert results[:total_fastup].total < results[:total_nofastup].total,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastup
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Mahoney
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-21 00:00:00.000000000 Z
11
+ date: 2018-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -94,6 +94,7 @@ files:
94
94
  - lib/fastup.rb
95
95
  - lib/fastup/autoapply.rb
96
96
  - test/app/boot.rb
97
+ - test/app/counts.rb
97
98
  - test/fastup_test.rb
98
99
  - test/test_helper.rb
99
100
  homepage: https://github.com/raisemarketplace/fastup