faster_require 0.7.4 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,5 @@
1
+ 0.7.5: unique hash now, for the cache file [hopefuly]
2
+
1
3
  0.7.4: allow double loading, for rails apps and gems to load it.
2
4
 
3
5
  0.7.3: work with 1.9 require_relative
data/README CHANGED
@@ -1,105 +1,134 @@
1
- A little utility to make
2
-
3
- require 'xxx'
4
-
5
- take much less time. As in much less. Well, on windows at least. And to speedup how long it takes things to load in windows, like rails apps.
6
-
7
- Well, mostly on windows--on linux it's a speedup of only 0.41 to 0.45s, or so. [1]
8
-
9
- If you've ever wondered why ruby feels slow on doze...sometimes it's just the startup time. This really helps.
10
-
11
- Benchmarks:
12
-
13
- loading a (blank) rspec file:
14
-
15
- 1.9.1
16
- without 3.20s
17
- with 0.34s (10x improvement)
18
-
19
- 1.8.6
20
- without 3.6s
21
- with 1.25s
22
-
23
-
24
- rails app, running a unit test file
25
-
26
- 1.8.6
27
- without:
28
- 23s
29
- with:
30
- 14s
31
-
32
- rails app, running $ script/console "puts 333"
33
-
34
- 1.9.1
35
- without:
36
- 20s
37
- with:
38
- 10s
39
-
40
- 1.8.6
41
- without:
42
- 9s
43
- with:
44
- 6s
45
-
46
- running "rake -T"
47
-
48
- 1.9.1
49
- without: 3.75s
50
- with: 1.5s
51
-
52
- 1.8.6
53
- without: 1.37s
54
- with: 1.25s
55
-
56
- Note: in reality what we should do is fix core so that it doesn't have such awful I/O time in windows. There may be some gross inefficiency in there. For now, this is a work-around.
57
-
58
- == How to use in Rails ==
59
-
60
- You can either install the gem, then add a
61
-
62
- require 'rubygems'
63
- require 'faster_require'
64
-
65
- in your config/environment.rb, or (the best way is as follows):
66
-
67
- Unpack it somewhere, like lib
68
- $ cd my_rails_app/lib
69
- $ gem unpack faster_require
70
-
71
- Now add this line to your config/environment.rb:
72
-
73
- require File.dirname(__FILE__) + "/../lib/faster_require-0.7.0/lib/faster_require" # faster speeds all around...make sure to update it to whatever version number you fetched.
74
-
75
- add it *before* this other (existing) line:
76
-
77
- require File.join(File.dirname(__FILE__), 'boot')
78
-
79
- Now it will speedup loading rubygems and everything. Happiness. (NB that setting it this will also run in production mode code, so be careful here, though it does work for me in production).
80
-
81
- == clearing cache ==
82
-
83
- If you use bundler to change bundled gems, you'll want to run the command $ faster_require --clear-cache
84
- so that it will pick up the new load paths. Also if you moves files around to new paths, you may want to do the same.
85
- As you install any new gems, it should clear the paths automatically for you.
86
-
87
- == How to use generally ==
88
-
89
- You can install it to be used "always" (well, for anything that loads rubygems, at least, via something like the following):
90
-
91
- $ gem which rubygems
92
- d:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems.rb
93
-
94
- $ gem which faster_require
95
- d:/Ruby192/lib/ruby/gems/1.9.1/gems/faster_require-0.6.0/lib/faster_require.rb
96
-
97
- Now edit that rubygems.rb file, and add a require line to the top of it like this:
98
-
99
- require 'd:/Ruby192/lib/ruby/gems/1.9.1/gems/faster_require-0.6.0/lib/faster_require.rb'
100
-
101
- update the path for your own, obviously. You'll also have to change that added line if
102
- you ever install a newer version of faster_require gem, or if you update your version of rubygems,
103
- as the rubygems.rb file will be wiped clean at that point.
104
-
1
+ A little utility to make
2
+
3
+ require 'xxx'
4
+
5
+ take much less time. As in much less. Well, on windows at least. And to speedup how long it takes things to load in windows, like rails apps.
6
+
7
+ Well, mostly on windows--on linux it's a speedup of only 0.41 to 0.45s, or so. [1]
8
+
9
+ If you've ever wondered why ruby feels slow on doze...sometimes it's just the startup time. This really helps.
10
+
11
+ Benchmarks:
12
+
13
+ loading a (blank) rspec file:
14
+
15
+ 1.9.1
16
+ without 3.20s
17
+ with 0.34s (10x improvement)
18
+
19
+ 1.8.6
20
+ without 3.6s
21
+ with 1.25s
22
+
23
+
24
+ rails app, running a unit test
25
+
26
+ 1.8.6
27
+ without:
28
+ 23s
29
+ with:
30
+ 14s
31
+
32
+ rails app, running $ script/console "puts 333"
33
+
34
+ 1.9.1
35
+ without:
36
+ 20s
37
+ with:
38
+ 10s
39
+
40
+ 1.8.6
41
+ without:
42
+ 9s
43
+ with:
44
+ 6s
45
+
46
+ running "rake -T" somewhere
47
+
48
+ 1.9.1
49
+ without: 3.75s
50
+ with: 1.5s
51
+
52
+ 1.8.6
53
+ without: 1.37s
54
+ with: 1.25s
55
+
56
+ Note: in reality what we should do is fix core so that it doesn't have such awful load time in windows. There may be some inefficiency in there. For now, this is a work-around that helps.
57
+
58
+ Also it helps with SSD's even, on windows, as it avoids some cpu used at require time.
59
+
60
+ == How to use ==
61
+
62
+ In general, you can either use it by installing the gem, then adding
63
+ require 'rubygems'
64
+ require 'faster_require'
65
+ to the top of your script.
66
+
67
+ However this doesn't speedup the loading of rubygems, so you can do this to get best performance:
68
+
69
+ G:>gem which faster_require
70
+ C:/installs/Ruby187/lib/ruby/gems/1.8/gems/faster_require-0.7.4/lib/faster_require.rb
71
+
72
+ now before doing require rubygems in your script, do this:
73
+
74
+ require 'C:/installs/Ruby187/lib/ruby/gems/1.8/gems/faster_require-0.7.4/lib/faster_require.rb'
75
+
76
+ Then rubygems load will be cached too. Faster.
77
+
78
+ == How to use in Rails ==
79
+
80
+ One way is to install the gem, then add a
81
+
82
+ require 'rubygems'
83
+ require 'faster_require'
84
+
85
+ in your config/environment.rb, or (the better way is as follows):
86
+
87
+ Unpack it somewhere, like lib
88
+
89
+ $ cd my_rails_app/lib
90
+ $ gem unpack faster_require
91
+
92
+ Now add this line to your config/environment.rb:
93
+
94
+ require File.dirname(__FILE__) + "/../lib/faster_require-0.7.0/lib/faster_require" # faster speeds all around...make sure to update it to whatever version number you fetched though.
95
+
96
+ add that *before* this other (pre-existing) line:
97
+
98
+ require File.join(File.dirname(__FILE__), 'boot')
99
+
100
+ Now faster_require will speedup loading rubygems and everything railsy. Happiness. (NB that setting it this will also run in production mode code, so be careful here, though it does work for me fine for production).
101
+
102
+ Ping me if it's still too slow.
103
+
104
+ == Clearing the cache ==
105
+
106
+ If you use bundler to change bundled gems, you'll want to run the command $ faster_require --clear-cache
107
+ so that it will pick up any new load paths. Also if you moves files around to new directories, you may want to do the same.
108
+ As you install any new gems, it should clear the paths automatically for you.
109
+
110
+
111
+ == How to use generally/globally ==
112
+
113
+ You can install it to be used "always" (well, for anything that loads rubygems, at least, which is most things, via something like the following):
114
+
115
+ $ gem which rubygems
116
+ d:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems.rb
117
+
118
+ $ gem which faster_require
119
+ d:/Ruby192/lib/ruby/gems/1.9.1/gems/faster_require-0.6.0/lib/faster_require.rb
120
+
121
+ Now edit that rubygems.rb file, and add a require line to the top of it like this:
122
+
123
+ require 'd:/Ruby192/lib/ruby/gems/1.9.1/gems/faster_require-0.6.0/lib/faster_require.rb'
124
+
125
+ update the path for your own, obviously. You'll also have to change that added line if
126
+ you ever install a newer version of faster_require gem, or if you update your version of rubygems,
127
+ as the rubygems.rb file will be wiped clean at that point.
128
+
129
+ == See also ==
130
+
131
+ Spork can help speedup rails tests. I "should" work well when used in conjunction with faster_require, as well.
132
+
133
+
105
134
  Enjoy.
data/Rakefile CHANGED
@@ -1,5 +1,7 @@
1
- require 'rubygems' if RUBY_VERSION < "1.9'"
2
-
1
+ require 'rubygems' if RUBY_VERSION < "1.9'"
2
+
3
+ ENV['PATH'] = 'C:\Program Files\Git\bin;' + ENV['PATH']
4
+
3
5
  begin
4
6
  require 'psych' # sigh
5
7
  rescue ::LoadError
data/TODO CHANGED
@@ -1,6 +1,7 @@
1
- advertise if quiet for a week after 3/10/11
1
+ advertise more everywhere 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
5
  running rails seems to still have some redundancies in there [?]
6
- "does it slow us down"
6
+ "does it slow us down"
7
+ issues
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.4
1
+ 0.8.0
@@ -1,47 +1,87 @@
1
1
 
2
+ # check for double load...because we're afraid to load twice, since we override require et al
3
+
2
4
  if(defined?($already_using_faster_require))
3
- p 'warning: faster_require double load expected?' if $FAST_REQUIRE_DEBUG
5
+ p 'warning: faster_require double load--expected?' if $FAST_REQUIRE_DEBUG
4
6
  local_version = File.read(File.dirname(__FILE__) + "/../VERSION")
5
- raise 'mismatched faster_require version' unless local_version == FastRequire::VERSION
7
+ raise "mismatched faster_require versions! #{local_version} != #{FastRequire::VERSION}" unless local_version == FastRequire::VERSION
6
8
  else
7
9
  $already_using_faster_require = true
8
10
 
9
- # now load it...
10
11
 
11
- require 'rbconfig' # maybe could cache this one, too?
12
+
13
+ require 'rbconfig' # maybe could cache this one's, too? probably not...
12
14
 
13
15
  module FastRequire
14
- $FAST_REQUIRE_DEBUG ||= $DEBUG # can set via $DEBUG, or on its own.
16
+
17
+ $FAST_REQUIRE_DEBUG ||= $DEBUG # can set this via $DEBUG, or on its own previously
18
+
15
19
  VERSION = File.read(File.dirname(__FILE__) + "/../VERSION")
20
+
21
+ def self.sanitize filename
22
+ filename.gsub(/[\/:]/, '_')
23
+ end
24
+
25
+ if RUBY_VERSION >= '1.9.0'
26
+ # appears 1.9.x has inconsistent string hashes...so roll our own...
27
+ def self.string_array_cruddy_hash strings
28
+ # we only call this method once, so overflowing to a bignum is ok
29
+ hash = 1;
30
+ for string in strings
31
+ hash = hash * 31
32
+ string.each_byte{|b|
33
+ hash += b
34
+ }
35
+ end
36
+ hash # probably a Bignum (sigh)
37
+ end
38
+
39
+ else
40
+
41
+ def self.string_array_cruddy_hash strings
42
+ strings.hash
43
+ end
44
+
45
+ end
46
+
16
47
  def self.setup
17
48
  begin
18
49
  @@dir = File.expand_path('~/.ruby_faster_require_cache')
19
- rescue ArgumentError => e # like couldn't find HOME environment or the like
50
+ rescue ArgumentError => e # couldn't find HOME environment or the like
20
51
  whoami = `whoami`.strip
21
- if File.directory?(home = "/home/#{whoami}") # assume writable :P
52
+ if File.directory?(home = "/home/#{whoami}")
22
53
  @@dir = home + '/.ruby_faster_require_cache'
23
54
  else
24
- raise e
55
+ raise e.to_s + " and couldnt infer it from whoami"
25
56
  end
26
57
  end
27
58
 
28
- Dir.mkdir @@dir unless File.directory?(@@dir)
59
+ unless File.directory?(@@dir)
60
+ Dir.mkdir @@dir
61
+ raise 'unable to create user dir for faster_require ' + @@dir unless File.directory?(@@dir)
62
+ end
29
63
 
30
- parts = [File.basename($0), RUBY_VERSION, RUBY_PLATFORM, File.basename(Dir.pwd), Dir.pwd, File.dirname($0), File.expand_path(File.dirname($0))].map{|part| sanitize(part)}
31
- loc_name = (parts.map{|part| part[0..5]} + parts).join('-')[0..75] # try to be unique, but short...
32
- @@loc = @@dir + '/' + loc_name
33
- end
64
+ config = RbConfig::CONFIG
65
+
66
+ # try to be a unique, but not too long, filename, for restrictions on filename length in doze
67
+ ruby_bin_name = config['bindir'] + config['ruby_install_name'] # needed if you have two rubies, same box, same ruby description [version, patch number]
68
+ parts = [File.basename($0), RUBY_DESCRIPTION, RUBY_VERSION, File.basename(Dir.pwd), Dir.pwd, File.dirname($0), File.expand_path(File.dirname($0)), ruby_bin_name]
69
+ sanitized_parts = parts.map{|part| sanitize(part)}
34
70
 
35
- def self.sanitize filename
36
- filename.gsub(/[\/:]/, '_')
71
+ full_parts_hash = string_array_cruddy_hash(parts).to_s
72
+
73
+ loc_name = (sanitized_parts.map{|part| part[0..5] + (part[-5..-1] || '')}).join('-') + '-' + full_parts_hash + '.marsh'
74
+
75
+ @@loc = @@dir + '/' + loc_name
76
+ @@loc
37
77
  end
38
78
 
39
- FastRequire.setup
40
-
41
79
  def self.load filename
42
- @@require_locs = Marshal.restore( File.open(filename, 'rb') {|f| f.read}) rescue {}
80
+ @@require_locs = Marshal.restore( File.open(filename, 'rb') {|f| f.read} )
43
81
  end
44
-
82
+
83
+ FastRequire.setup
84
+
45
85
  if File.exist?(@@loc)
46
86
  FastRequire.load @@loc
47
87
  else
@@ -105,16 +145,10 @@ module FastRequire
105
145
  @@already_loaded[File.expand_path(__FILE__)] = true # this file itself isn't in loaded features, yet, but very soon will be..
106
146
  # a special case--I hope...
107
147
 
108
- # also disallow re- $0
109
- @@require_locs[$0] = File.expand_path($0) # so when we run into it on a require, we will skip it...
148
+ # also disallow re-loading $0
149
+ @@require_locs[$0] = File.expand_path($0) # so when we run into $0 on a freak require, we will skip it...
110
150
  @@already_loaded[File.expand_path($0)] = true
111
-
112
- # XXXX within a very long depth to require fast_require,
113
- # require 'a' => 'b' => 'c' => 'd' & fast_require
114
- # then
115
- # => 'b.rb'
116
- # it works always
117
-
151
+
118
152
  def self.already_loaded
119
153
  @@already_loaded
120
154
  end
@@ -126,6 +160,10 @@ module FastRequire
126
160
  def self.dir
127
161
  @@dir
128
162
  end
163
+
164
+ def self.loc
165
+ @@loc
166
+ end
129
167
 
130
168
  at_exit {
131
169
  FastRequire.default_save
@@ -141,9 +179,14 @@ module FastRequire
141
179
 
142
180
  def self.clear_all!
143
181
  require 'fileutils'
144
- FileUtils.rm_rf @@dir if File.exist? @@dir
182
+ success = false
183
+ if File.exist? @@dir
184
+ FileUtils.rm_rf @@dir
185
+ success = true
186
+ end
145
187
  @@require_locs.clear
146
188
  setup
189
+ success
147
190
  end
148
191
 
149
192
  private
@@ -195,7 +238,7 @@ module FastRequire
195
238
  # $LOADED_FEATURES << relative_full_path.gsub('.rb', '') # don't think you need this one
196
239
 
197
240
  # load(known_loc, false) # too slow
198
- contents = File.open(known_loc, 'rb') {|f| f.read}
241
+ contents = File.open(known_loc, 'rb') {|f| f.read} # only costs 0.34/10 s...
199
242
  if contents =~ /require_relative/ # =~ is faster than .include? it appears
200
243
  load(known_loc, false) # slow, but dependent on a ruby core bug: http://redmine.ruby-lang.org/issues/4487
201
244
  else
@@ -293,11 +336,6 @@ module Kernel
293
336
 
294
337
  end
295
338
 
296
- # unused?
297
- # def remove_method method
298
- # p 'in mine2'
299
- # end
300
-
301
339
  # similarly overwrite this one...I guess...1.9.x...rubygems uses this as its default...I think...
302
340
  alias :original_non_cached_require :gem_original_require
303
341
  alias :gem_original_require :require_cached
@@ -307,5 +345,4 @@ module Kernel
307
345
  end
308
346
  end
309
347
 
310
-
311
348
  end
@@ -1,5 +1,8 @@
1
1
  Gem.post_install { |gem_installer_instance|
2
2
  require 'faster_require'
3
- FastRequire.clear_all!
4
- puts 'cleared faster_require caches due to new gem install...'
3
+ if FastRequire.clear_all!
4
+ puts 'cleared faster_require caches due to new gem install...'
5
+ else
6
+ puts '(faster_require had no cache to clear/reset)'
7
+ end
5
8
  }
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/../../lib/faster_require.rb"
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../lib/faster_require.rb")
2
2
  require 'rubygems'
3
3
  require 'rspec'
4
4
  a = RSpec
@@ -1,6 +1,5 @@
1
- # different rubygems orders
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../lib/faster_require.rb")
2
2
  require 'rubygems'
3
- require File.dirname(__FILE__) + "/../../lib/faster_require.rb"
4
3
  require 'rspec'
5
4
  a = RSpec
6
5
  p 'success'
@@ -132,7 +132,7 @@ describe "requires faster!" do
132
132
  end
133
133
 
134
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|
135
- it "should not double load gems #{filename}" do
135
+ it "should not double load gems #{@ruby} -v files/#{filename}" do
136
136
  3.times {
137
137
  a = `#{@ruby} -v files/#{filename} 2>&1`
138
138
  a.should_not match('already initialized')
@@ -146,7 +146,7 @@ describe "requires faster!" do
146
146
  it "should be ok if you require itself twice" do
147
147
  Dir.chdir('files') do
148
148
  3.times { assert system(@ruby + 'attempt_double_load.rb') }
149
- assert `#{@ruby + 'attempt_double_load.rb'}` =~ /double load expected/
149
+ assert `#{@ruby + 'attempt_double_load.rb'}` =~ /double load--expected\?/
150
150
  end
151
151
  end
152
152
 
@@ -185,9 +185,10 @@ describe "requires faster!" do
185
185
  end
186
186
  end
187
187
 
188
- it "should be able to infer .so files like socket.so" #do
189
- # ruby "files/socket_load.rb" # LODO reproduce failure
188
+ # was there some failure like
189
+ # stringio or enumerator.so?
190
+ it "should be able to infer .so files" #do
191
+ # ruby "files/socket_load.rb" # LODO reproduce failure?
190
192
  # end
191
193
 
192
-
193
194
  end
data/todo CHANGED
@@ -1,6 +1,7 @@
1
- advertise if quiet for a week after 3/10/11
1
+ advertise more everywhere 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
5
  running rails seems to still have some redundancies in there [?]
6
- "does it slow us down"
6
+ "does it slow us down"
7
+ issues
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: 11
5
- prerelease: false
4
+ hash: 63
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 7
9
- - 4
10
- version: 0.7.4
8
+ - 8
9
+ - 0
10
+ version: 0.8.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Roger Pack
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-10 00:00:00 -07:00
18
+ date: 2011-04-15 00:00:00 -06:00
19
19
  default_executable: faster_require
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -183,18 +183,13 @@ files:
183
183
  - spec/spec.fast_require.rb
184
184
  - todo
185
185
  - TODO
186
- - spec/eval_me1.rb
187
- - spec/eval_me2.rb
188
- - spec/files/a.rb
189
- - spec/temp/slow.rb
190
- - spec/temp/yo.rb
191
186
  has_rdoc: true
192
187
  homepage: http://github.com/rdp/faster_require
193
188
  licenses: []
194
189
 
195
190
  post_install_message:
196
- rdoc_options:
197
- - --charset=UTF-8
191
+ rdoc_options: []
192
+
198
193
  require_paths:
199
194
  - lib
200
195
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -218,18 +213,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
218
213
  requirements: []
219
214
 
220
215
  rubyforge_project:
221
- rubygems_version: 1.3.7
216
+ rubygems_version: 1.5.2
222
217
  signing_key:
223
218
  specification_version: 3
224
219
  summary: Speed library loading in Ruby
225
220
  test_files:
226
- - spec/eval_me1.rb
227
- - spec/eval_me2.rb
228
- - spec/files/a.rb
221
+ - spec/files/a_requires_b.rb
229
222
  - spec/files/active_support_no_double_load.rb
230
223
  - spec/files/attempt_double_load.rb
231
224
  - spec/files/attempt_double_load_wrong_version.rb
232
- - spec/files/a_requires_b.rb
233
225
  - spec/files/b.rb
234
226
  - spec/files/c.rb
235
227
  - spec/files/d.rb
@@ -242,15 +234,13 @@ test_files:
242
234
  - spec/files/load_various_gems.rb
243
235
  - spec/files/load_various_gems2.rb
244
236
  - spec/files/non_dot_rb.rb
245
- - spec/files/requires_itself.rb
246
237
  - spec/files/require_facets.rb
247
238
  - spec/files/require_full_path.rb
248
239
  - spec/files/require_non_dot_rb_fails.rb
249
240
  - spec/files/require_twice_in_dir_pwd.rb
241
+ - spec/files/requires_itself.rb
250
242
  - spec/files/should_put_modules_in_right_place.rb
251
243
  - spec/files/slow.rb
252
244
  - spec/files/socket_load.rb
253
245
  - spec/files/time_just_loading_rubygems.rb
254
246
  - spec/spec.fast_require.rb
255
- - spec/temp/slow.rb
256
- - spec/temp/yo.rb
@@ -1 +0,0 @@
1
- eval(File.read('eval_me2.rb'), binding, File.expand_path('./eval_me2.rb'))
@@ -1 +0,0 @@
1
- require_relative 'eval_me1.rb'
File without changes
@@ -1,9 +0,0 @@
1
- slow = true
2
- file_name = File.expand_path('./yo.rb')
3
- File.open(file_name, 'w') do |f| f.write '33333'; end
4
-
5
- if !slow
6
- 1000.times { eval File.read(file_name) } # ascii mode
7
- else
8
- 1000.times { load file_name } # ascii mode
9
- end
@@ -1,10 +0,0 @@
1
- 33333
2
- 33333
3
- 33333
4
- 33333
5
- 33333
6
- 33333
7
- 33333
8
- 33333
9
- 33333
10
- 33333