faster_require 0.7.3 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +4 -0
- data/Rakefile +1 -0
- data/TODO +2 -1
- data/VERSION +1 -1
- data/lib/faster_require.rb +19 -8
- data/spec/files/attempt_double_load.rb +2 -0
- data/spec/files/attempt_double_load_wrong_version.rb +5 -0
- data/spec/files/require_facets.rb +3 -0
- data/spec/files/socket_load.rb +3 -0
- data/spec/files/time_just_loading_rubygems.rb +2 -0
- data/spec/spec.fast_require.rb +18 -18
- data/todo +2 -1
- metadata +26 -6
data/ChangeLog
CHANGED
data/Rakefile
CHANGED
data/TODO
CHANGED
@@ -2,4 +2,5 @@ advertise if quiet for a week after 3/10/11
|
|
2
2
|
stringio
|
3
3
|
if ruby < 1.9 for autoload stuff
|
4
4
|
benchmarks jruby et al
|
5
|
-
running rails seems to still have some redundancies in there [?]
|
5
|
+
running rails seems to still have some redundancies in there [?]
|
6
|
+
"does it slow us down"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.4
|
data/lib/faster_require.rb
CHANGED
@@ -1,8 +1,18 @@
|
|
1
|
-
|
1
|
+
|
2
|
+
if(defined?($already_using_faster_require))
|
3
|
+
p 'warning: faster_require double load expected?' if $FAST_REQUIRE_DEBUG
|
4
|
+
local_version = File.read(File.dirname(__FILE__) + "/../VERSION")
|
5
|
+
raise 'mismatched faster_require version' unless local_version == FastRequire::VERSION
|
6
|
+
else
|
7
|
+
$already_using_faster_require = true
|
8
|
+
|
9
|
+
# now load it...
|
10
|
+
|
11
|
+
require 'rbconfig' # maybe could cache this one, too?
|
2
12
|
|
3
13
|
module FastRequire
|
4
14
|
$FAST_REQUIRE_DEBUG ||= $DEBUG # can set via $DEBUG, or on its own.
|
5
|
-
|
15
|
+
VERSION = File.read(File.dirname(__FILE__) + "/../VERSION")
|
6
16
|
def self.setup
|
7
17
|
begin
|
8
18
|
@@dir = File.expand_path('~/.ruby_faster_require_cache')
|
@@ -177,11 +187,12 @@ module FastRequire
|
|
177
187
|
no_suffix_lib = lib.gsub(/\.[^.]+$/, '')
|
178
188
|
libs_path = no_suffix_full_path.gsub(no_suffix_lib, '')
|
179
189
|
libs_path = File.expand_path(libs_path) # strip off trailing '/'
|
180
|
-
$: << libs_path unless $:.index(libs_path)
|
190
|
+
$: << libs_path unless $:.index(libs_path) # might not need this anymore, but it feels more sane...does it slow us down, though?
|
191
|
+
|
181
192
|
# try some more autoload conivings...so that it won't attempt to autoload if it runs into it later...
|
182
193
|
relative_full_path = known_loc.sub(libs_path, '')[1..-1]
|
194
|
+
$LOADED_FEATURES << relative_full_path unless $LOADED_FEATURES.index(relative_full_path) # add in with .rb, too, for autoload
|
183
195
|
# $LOADED_FEATURES << relative_full_path.gsub('.rb', '') # don't think you need this one
|
184
|
-
$LOADED_FEATURES << relative_full_path # add in with .rb, too.
|
185
196
|
|
186
197
|
# load(known_loc, false) # too slow
|
187
198
|
contents = File.open(known_loc, 'rb') {|f| f.read}
|
@@ -203,6 +214,7 @@ module FastRequire
|
|
203
214
|
else
|
204
215
|
# we don't know the location--let Ruby's original require do the heavy lifting for us here
|
205
216
|
old = $LOADED_FEATURES.dup
|
217
|
+
p 'doing old non-known location require ' + lib if $FAST_REQUIRE_DEBUG
|
206
218
|
if(original_non_cached_require(lib))
|
207
219
|
# debugger might land here the first time you run a script and it doesn't have a require
|
208
220
|
# cached yet...
|
@@ -265,10 +277,6 @@ end
|
|
265
277
|
|
266
278
|
module Kernel
|
267
279
|
|
268
|
-
if(defined?(@already_using_faster_require))
|
269
|
-
raise 'loading twice not allowed...we should never get here!'
|
270
|
-
end
|
271
|
-
@already_using_faster_require = true
|
272
280
|
# overwrite old require...
|
273
281
|
include FastRequire
|
274
282
|
if defined?(gem_original_require)
|
@@ -298,3 +306,6 @@ module Kernel
|
|
298
306
|
alias :require :require_cached
|
299
307
|
end
|
300
308
|
end
|
309
|
+
|
310
|
+
|
311
|
+
end
|
data/spec/files/socket_load.rb
CHANGED
@@ -4,5 +4,8 @@ require '../lib/faster_require.rb'
|
|
4
4
|
raise if FastRequire.already_loaded.to_a.flatten.grep(/files\/b.rb/).length > 0
|
5
5
|
require 'socket'
|
6
6
|
TCPSocket
|
7
|
+
require 'stringio'
|
8
|
+
StringIO
|
7
9
|
raise 'lacking socket ' + FastRequire.already_loaded.to_a.join(' ') unless FastRequire.already_loaded.to_a.flatten.grep(/socket/).length > 0
|
10
|
+
raise 'lacking stringio ' + FastRequire.already_loaded.to_a.join(' ') unless FastRequire.already_loaded.to_a.flatten.grep(/stringio/).length > 0
|
8
11
|
p 'success'
|
data/spec/spec.fast_require.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
if RUBY_VERSION < '1.9'
|
4
|
-
require 'rubygems' # faster_rubygems, perhaps?
|
5
|
-
end
|
1
|
+
# could also set this here if desired: $FAST_REQUIRE_DEBUG = true
|
6
2
|
|
3
|
+
require 'rubygems' # faster_rubygems, perhaps?
|
7
4
|
require 'sane'
|
8
5
|
require 'benchmark'
|
9
6
|
|
7
|
+
raise 'double faster_require' if defined?($already_using_faster_require) # disallowed, since who knows what version the gem one is...
|
8
|
+
|
10
9
|
unless RUBY_PLATFORM =~ /java/
|
11
10
|
require_relative '../lib/faster_require'
|
12
11
|
cached = '.cached_spec_locs' + RUBY_VERSION
|
@@ -68,11 +67,15 @@ describe "requires faster!" do
|
|
68
67
|
end
|
69
68
|
end
|
70
69
|
|
70
|
+
it "should load rubygems for speed look" do
|
71
|
+
slow = Benchmark.realtime { assert system("#{OS.ruby_bin} files/time_just_loading_rubygems.rb")}
|
72
|
+
fast = Benchmark.realtime { assert system("#{OS.ruby_bin} files/time_just_loading_rubygems.rb")}
|
73
|
+
pps 'just loading rubygems [obviously depends on number of gems installed] at all: fast', fast, 'slow', slow
|
74
|
+
end
|
75
|
+
|
71
76
|
it "should work with large complex gem" do
|
72
77
|
Dir.chdir('files') do
|
73
|
-
assert(system("#{OS.ruby_bin} large.rb"))
|
74
|
-
assert(system("#{OS.ruby_bin} large.rb"))
|
75
|
-
assert(system("#{OS.ruby_bin} large.rb"))
|
78
|
+
3.times { assert(system("#{OS.ruby_bin} large.rb")) }
|
76
79
|
end
|
77
80
|
end
|
78
81
|
|
@@ -82,7 +85,7 @@ describe "requires faster!" do
|
|
82
85
|
|
83
86
|
it "should load .so files still, and only load them once" do
|
84
87
|
# ruby-prof gem
|
85
|
-
|
88
|
+
3.times { require 'ruby_prof.so'; RubyProf }
|
86
89
|
assert $LOADED_FEATURES.length == (@old_length + 1)
|
87
90
|
end
|
88
91
|
|
@@ -106,17 +109,13 @@ describe "requires faster!" do
|
|
106
109
|
assert system("ruby -I../../lib e.rb")
|
107
110
|
assert system("ruby -C.. -I../lib files/e.rb")
|
108
111
|
end
|
109
|
-
# require 'ruby-debug'
|
110
|
-
# debugger
|
111
112
|
assert Dir[FastRequire.dir + '/*'].length == 3
|
112
113
|
assert Dir[FastRequire.dir + '/*d.rb*'].length == 1 # use full path
|
113
114
|
assert Dir[FastRequire.dir + '/*e.rb*'].length == 2 # different Dir.pwd's
|
114
115
|
end
|
115
116
|
|
116
|
-
|
117
|
-
|
118
|
-
end
|
119
|
-
|
117
|
+
it "should work with encoded files too" # most are binary, so...low prio
|
118
|
+
|
120
119
|
private
|
121
120
|
|
122
121
|
def ruby filename
|
@@ -132,7 +131,7 @@ describe "requires faster!" do
|
|
132
131
|
ruby "files/gem_before.rb"
|
133
132
|
end
|
134
133
|
|
135
|
-
['gem_after.rb', 'load_various_gems.rb', 'load_various_gems2.rb', 'active_support_no_double_load.rb', 'fast.rb'].each{|filename|
|
134
|
+
['require_facets.rb', 'gem_after.rb', 'load_various_gems.rb', 'load_various_gems2.rb', 'active_support_no_double_load.rb', 'fast.rb'].each{|filename|
|
136
135
|
it "should not double load gems #{filename}" do
|
137
136
|
3.times {
|
138
137
|
a = `#{@ruby} -v files/#{filename} 2>&1`
|
@@ -144,9 +143,10 @@ describe "requires faster!" do
|
|
144
143
|
end
|
145
144
|
}
|
146
145
|
|
147
|
-
it "should
|
146
|
+
it "should be ok if you require itself twice" do
|
148
147
|
Dir.chdir('files') do
|
149
|
-
assert
|
148
|
+
3.times { assert system(@ruby + 'attempt_double_load.rb') }
|
149
|
+
assert `#{@ruby + 'attempt_double_load.rb'}` =~ /double load expected/
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
data/todo
CHANGED
@@ -2,4 +2,5 @@ advertise if quiet for a week after 3/10/11
|
|
2
2
|
stringio
|
3
3
|
if ruby < 1.9 for autoload stuff
|
4
4
|
benchmarks jruby et al
|
5
|
-
running rails seems to still have some redundancies in there [?]
|
5
|
+
running rails seems to still have some redundancies in there [?]
|
6
|
+
"does it slow us down"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faster_require
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 7
|
9
|
-
-
|
10
|
-
version: 0.7.
|
9
|
+
- 4
|
10
|
+
version: 0.7.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Roger Pack
|
@@ -107,7 +107,7 @@ dependencies:
|
|
107
107
|
type: :development
|
108
108
|
version_requirements: *id006
|
109
109
|
- !ruby/object:Gem::Dependency
|
110
|
-
name:
|
110
|
+
name: facets
|
111
111
|
prerelease: false
|
112
112
|
requirement: &id007 !ruby/object:Gem::Requirement
|
113
113
|
none: false
|
@@ -120,6 +120,20 @@ dependencies:
|
|
120
120
|
version: "0"
|
121
121
|
type: :development
|
122
122
|
version_requirements: *id007
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
name: ruby-prof
|
125
|
+
prerelease: false
|
126
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
hash: 3
|
132
|
+
segments:
|
133
|
+
- 0
|
134
|
+
version: "0"
|
135
|
+
type: :development
|
136
|
+
version_requirements: *id008
|
123
137
|
description: A tool designed to speedup library loading in Ruby by caching library locations
|
124
138
|
email: rogerdpack@gmail.com
|
125
139
|
executables:
|
@@ -141,7 +155,9 @@ files:
|
|
141
155
|
- lib/faster_require.rb
|
142
156
|
- lib/rubygems_plugin.rb
|
143
157
|
- spec/files/a_requires_b.rb
|
158
|
+
- spec/files/active_support_no_double_load.rb
|
144
159
|
- spec/files/attempt_double_load.rb
|
160
|
+
- spec/files/attempt_double_load_wrong_version.rb
|
145
161
|
- spec/files/b.rb
|
146
162
|
- spec/files/c.rb
|
147
163
|
- spec/files/clear.bat
|
@@ -155,20 +171,21 @@ files:
|
|
155
171
|
- spec/files/load_various_gems.rb
|
156
172
|
- spec/files/load_various_gems2.rb
|
157
173
|
- spec/files/non_dot_rb.rb
|
174
|
+
- spec/files/require_facets.rb
|
158
175
|
- spec/files/require_full_path.rb
|
159
176
|
- spec/files/require_non_dot_rb_fails.rb
|
160
177
|
- spec/files/require_twice_in_dir_pwd.rb
|
161
178
|
- spec/files/requires_itself.rb
|
162
179
|
- spec/files/should_put_modules_in_right_place.rb
|
163
180
|
- spec/files/slow.rb
|
181
|
+
- spec/files/socket_load.rb
|
182
|
+
- spec/files/time_just_loading_rubygems.rb
|
164
183
|
- spec/spec.fast_require.rb
|
165
184
|
- todo
|
166
185
|
- TODO
|
167
186
|
- spec/eval_me1.rb
|
168
187
|
- spec/eval_me2.rb
|
169
188
|
- spec/files/a.rb
|
170
|
-
- spec/files/active_support_no_double_load.rb
|
171
|
-
- spec/files/socket_load.rb
|
172
189
|
- spec/temp/slow.rb
|
173
190
|
- spec/temp/yo.rb
|
174
191
|
has_rdoc: true
|
@@ -211,6 +228,7 @@ test_files:
|
|
211
228
|
- spec/files/a.rb
|
212
229
|
- spec/files/active_support_no_double_load.rb
|
213
230
|
- spec/files/attempt_double_load.rb
|
231
|
+
- spec/files/attempt_double_load_wrong_version.rb
|
214
232
|
- spec/files/a_requires_b.rb
|
215
233
|
- spec/files/b.rb
|
216
234
|
- spec/files/c.rb
|
@@ -225,12 +243,14 @@ test_files:
|
|
225
243
|
- spec/files/load_various_gems2.rb
|
226
244
|
- spec/files/non_dot_rb.rb
|
227
245
|
- spec/files/requires_itself.rb
|
246
|
+
- spec/files/require_facets.rb
|
228
247
|
- spec/files/require_full_path.rb
|
229
248
|
- spec/files/require_non_dot_rb_fails.rb
|
230
249
|
- spec/files/require_twice_in_dir_pwd.rb
|
231
250
|
- spec/files/should_put_modules_in_right_place.rb
|
232
251
|
- spec/files/slow.rb
|
233
252
|
- spec/files/socket_load.rb
|
253
|
+
- spec/files/time_just_loading_rubygems.rb
|
234
254
|
- spec/spec.fast_require.rb
|
235
255
|
- spec/temp/slow.rb
|
236
256
|
- spec/temp/yo.rb
|