faster_rubygems 0.6.4 → 0.9.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.
data/README CHANGED
@@ -1,78 +1,75 @@
1
- A helper to dramatically speedup the time it takes to load rubygems.
1
+ A helper gem to dramatically speedup the time it takes to startup a ruby script.
2
2
 
3
- i.e. it makes it so that "require 'rubygems'" no longer has to sap valuable time from your life.
3
+ i.e. it makes it so that requiring rubygems no longer takes as long.
4
4
 
5
- Speed difference (windows box, lots of gem):
5
+ Speed difference (a demo gem script, ruby 1.8 windows mingw):
6
6
 
7
- $ time ruby examples/require_rubygems_normal.rb
8
- real 0m1.109s
7
+ normal rubygems:
9
8
 
10
- $ time ruby examples/require_fast_start.rb
11
- real 0m0.500s
9
+ $ timer ruby whichr
10
+ 0.83
12
11
 
13
- Yea! Finally ruby script startup times that don't spend forever just reloading gem specs every single time...
12
+ with faster_rubygems:
14
13
 
15
- It acts about the same as gem_prelude (prelude is 1.9 only currently) -- adds the paths of the highest version of each gem into your load path so they're ready to be required.
14
+ $ timer ruby whichr
15
+ 0.19
16
16
 
17
- It is also good for 1.9 makes script startup faster. To use it with 1.9 do an
18
- $ export RUBYOPTS=-rfaster_rubygems
17
+ Yea!
19
18
 
20
- somewhere.
19
+ It acts as a beefed up version of gem_prelude (prelude is 1.9 only currently), but only adds load paths on demand.
21
20
 
22
- == installation ==
23
-
24
- $ gem install faster_rubygems
25
-
26
- == usage ==
21
+ It makes even more of a difference when used with 1.9:
27
22
 
28
- require 'faster_rubygems' at the top of your script.
23
+ normal rubygems:
29
24
 
30
- Or
25
+ $ timer ruby whichr
26
+ 3.8s
31
27
 
32
- 1.9:
33
- $ export RUBYOPTS=-rfaster_rubygems
28
+ with faster_rubygems:
34
29
 
35
- 1.8:
36
- you can install it to be used by default thus:
37
-
38
- >> require 'rubygems'
39
- >> require 'faster_rubygems/install' # installs faster_rubygems to be use in place of normal rubygems when you do a "require 'rubygems'"
30
+ $ timer ruby whichr
31
+ 0.24s
40
32
 
41
- # later, to revert back to normal, should you so desire:
42
- >> require 'rubygems'
43
- >> require 'faster_rubygems/uninstall'
33
+ == installation ==
44
34
 
45
- If all else fails in this process (it typically works fine), you can reinstall normal rubygems by running setup.rb from within its package.
35
+ $ gem install faster_rubygems
46
36
 
47
- == More Speed Comparisons ==
37
+ 1.9
38
+ :
39
+ $ export RUBYOPT=-rfaster_rubygems --disable-gems
48
40
 
49
- For those interested, speed difference example on linux (250 gems):
41
+ 1.8:
50
42
 
51
- $ time ruby examples/require_rubygems_normal.rb
52
- ruby examples/require_rubygems_normal.rb 0.57s user 0.05s system 85% cpu 0.726 total
43
+ you currently have to install to override normal rubygems by doing the following (in an irb session):
53
44
 
54
- $ time ruby examples/require_fast_start.rb
55
- ruby examples/require_fast_start.rb 0.04s user 0.02s system 46% cpu 0.121 total
45
+ >> require 'rubygems'
46
+ >> require 'faster_rubygems/override' # installs faster_rubygems to be use in place of normal rubygems when you do a "require 'rubygems'" so you don't have to worry about anything
56
47
 
57
- Note also that a few non conforming gems require the use of require 'rubygems' no matter what (they're pretty rare, though--you probably won't run into them, and I'm not aware of any).
48
+ # later, to revert this override, back to normal rubygems, should you so desire, do the following:
49
+ >> require 'rubygems'
50
+ >> require 'faster_rubygems/unoverride'
58
51
 
52
+ If all else fails in this process (it has typically worked fine), you can
53
+ reinstall normal rubygems by downloading its package (.tgz) and running ruby setup.rb within it.
59
54
 
60
- == Experimental ==
55
+ After installation, usage is automatic.
61
56
 
62
- If you want to be more aggressive you can try loading it with its cousin, faster_require:
63
57
 
64
- $ gem install faster_require
58
+ To regenerate cache files (should never be necessary, but if you for some reason think yours are stale) do
59
+ >> require 'rubygems'
60
+ >> require 'faster_rubygems/create_cache_for_all'
65
61
 
66
- Now use it by default:
67
-
68
- 1.9: $ export RUBYOPTS=-rfaster_rubygems_with_faster_require_too
69
- 1.8: >> require 'faster_rubygems/install_with_faster_require_too' # installs faster_rubygems, as above, but also loads faster_require along with it.
62
+ Note that it still loads full rubygems when it necessary (like when installing gems). This is also automatic.
63
+ Most of the credit for this goes to gem prelude.
70
64
 
71
65
  == Related projects ==
72
66
 
67
+ rubygems (of course)
73
68
  http://github.com/fabien/minigems/tree/master
74
- 1.9's gem_prelude.rb
69
+ 1.9's gem_prelude
75
70
  http://www.ruby-forum.com/topic/191673
71
+ the Builder gem
72
+
73
+ Source/feedback:
76
74
 
77
- Source/contact:
78
- http://www.github.com/rdp/faster_rubygems
75
+ http://www.github.com/rdp/faster_rubygems
data/Rakefile CHANGED
@@ -7,12 +7,7 @@ require 'jeweler'
7
7
 
8
8
  s.post_install_message = "
9
9
 
10
- installed! 1.9 use -> require 'faster_rubygems'
11
-
12
- 1.8: use require 'faster_rubygems' or install as the default thus:
13
-
14
- >> require 'rubygems'
15
- >> require 'faster_rubygems/install'
10
+ faster_rubygems installed! see the readme for post-install instructions: http://github.com/rdp/faster_rubygems
16
11
 
17
12
  "
18
13
  s.add_development_dependency 'test-unit', '=1.2.3'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.4
1
+ 0.9.2
data/benchmarks.txt ADDED
@@ -0,0 +1,71 @@
1
+ whichr whichr benchmarks (best time seen):
2
+
3
+ mingw 1.8
4
+
5
+ normal rubygems
6
+ 0.77
7
+
8
+ faster_rubygems with cache
9
+ 0.14
10
+
11
+ faster_rubygems without cache:
12
+ 0.20
13
+
14
+ mingw 1.9
15
+
16
+ normal rubygems:
17
+ 3.79
18
+
19
+ faster_rubygems with cache:
20
+ 0.19
21
+
22
+ faster_rubygems without cache:
23
+ 0.50
24
+
25
+ jruby, faster_rubygems with "full load path"
26
+
27
+ faster_rubygems without cache:
28
+ 1.15
29
+
30
+ faster_rubygems with cache:
31
+ 1.11
32
+
33
+ normal rubygems:
34
+ 2.31
35
+
36
+
37
+
38
+ rails 3 [ $ ruby script\rails runner -e production "puts 3" ]
39
+
40
+ unfortunately with rails 3 currently it loads "full rubygems" no matter what, which is the thing we were trying to avoid.
41
+
42
+ 1.9
43
+ faster_rubygems with cache[RUBYOPT=-rfaster_rubygems --disable-gems]:
44
+ 11.26
45
+
46
+ faster_rubygems without cache [RUBYOPT=-rfaster_rubygems]:
47
+ 13.73
48
+
49
+ normal rubygems (with gem prelude [straight ruby]):
50
+ 13.88
51
+
52
+ normal rubygems (ruby --disable-gems):
53
+ 10.41
54
+
55
+ rails 2.3.8 [ $ ruby script\runner -e production "puts 3" ]
56
+
57
+ 1.9
58
+ faster_rubygems with cache[RUBYOPT=-rfaster_rubygems --disable-gems]:
59
+ 12.4
60
+
61
+
62
+
63
+
64
+ lacking:
65
+ rails benchmarks, faster_require for everybody...
66
+
67
+ TODO:
68
+ jruby spawning itself was *so slow* it seemed (timer.rb)
69
+
70
+ only regenerate appropriate cache files after gem installs...
71
+ only cache lib filenames, not spec files, et al...
data/ext/mkrf_conf.rb CHANGED
@@ -2,8 +2,11 @@ require 'rubygems'
2
2
 
3
3
  # do some ruby stuff...
4
4
 
5
- puts File.dirname(__FILE__)
6
- load File.expand_path(File.dirname(__FILE__)) + "/../internalize.rb" # install this gem locally
5
+ load File.expand_path(File.dirname(__FILE__)) + "/../internalize.rb" # install this gem locally...
6
+
7
+ # create as many as possible at install time ...
8
+
9
+ require File.dirname(__FILE__) + "/../lib/faster_rubygems/create_cache_for_all.rb"
7
10
 
8
11
  f = File.open(File.join(File.dirname(__FILE__), "Rakefile"), "w") # create dummy rakefile to indicate success
9
12
  f.write("task :default\n")
data/internalize.rb CHANGED
@@ -2,9 +2,12 @@ require 'fileutils'
2
2
  require 'rbconfig'
3
3
 
4
4
  Dir.chdir File.dirname(__FILE__) + '/lib' do
5
- for file in Dir['*.rb'] do
6
- FileUtils.cp file, Config::CONFIG['sitelibdir'] + '/' + file
5
+ for file in Dir['*'] do
6
+ next if file =~ /rubygems_plugin/ # don't want to copy that one over
7
+ new_file = Config::CONFIG['sitelibdir'] + '/' + file
8
+ FileUtils.rm_rf new_file if File.exist?(new_file)
9
+ FileUtils.cp_r file, new_file
7
10
  end
8
11
  end
9
12
 
10
- puts 'Installed--thank you for trying out -- require \'faster_rubygems\''
13
+ puts 'Installed--thank you for trying out faster_rubygems' # they never see this message tho...
@@ -0,0 +1,2 @@
1
+ require File.dirname(__FILE__) + "/prelude_create_cache"
2
+ Gem.create_cache_for_all!
@@ -6,7 +6,7 @@
6
6
  require 'fileutils'
7
7
  old = rubygems_path
8
8
  new = old + ".bak.rb"
9
- raise 'cannot install twice--please run uninstall first' if File.exist?(new)
9
+ raise 'cannot install twice--please run unoverride first' if File.exist?(new)
10
10
  FileUtils.cp old, new
11
11
  File.open(old, 'w') do |f|
12
12
  f.write "require 'faster_rubygems'\n"
@@ -0,0 +1,29 @@
1
+ TOPLEVEL_BINDING = binding unless defined?(TOPLEVEL_BINDING)
2
+
3
+ def repl(scope = TOPLEVEL_BINDING)
4
+ Repl.start(scope)
5
+ end
6
+
7
+ module Repl
8
+ def self.start(scope = TOPLEVEL_BINDING)
9
+ quitstr = ['quit', 'exit', '']
10
+ while true
11
+ stack = eval("caller[3..-1]", scope)
12
+ print "\n#{stack.first}\n" if stack and not stack.empty?
13
+ print 'rb> '
14
+ input = gets.strip rescue 'quit'
15
+ break if quitstr.include?(input)
16
+ puts "=> #{
17
+ begin
18
+ eval(input, scope).inspect
19
+ rescue LoadError => le
20
+ puts le.inspect
21
+ rescue SyntaxError => se
22
+ puts se.inspect
23
+ rescue => e
24
+ puts e.inspect
25
+ end
26
+ }"
27
+ end
28
+ end
29
+ end
@@ -10,7 +10,7 @@
10
10
  # * Should not expect Encoding.default_internal.
11
11
  # * Locale encoding is available.
12
12
  if defined?(Gem) then
13
-
13
+ start = Time.now if $VERBOSE
14
14
  require 'rbconfig'
15
15
  # :stopdoc:
16
16
 
@@ -142,6 +142,7 @@ if defined?(Gem) then
142
142
  @loaded_full_rubygems_library = false
143
143
 
144
144
  def self.load_full_rubygems_library
145
+ puts 'faster_rubygems: loading full rubygems',caller if $VERBOSE
145
146
  if $DEBUG || $VERBOSE
146
147
  $stderr.puts 'warning, loading full rubygems'
147
148
  end
@@ -167,7 +168,7 @@ if defined?(Gem) then
167
168
  require 'rubygems'
168
169
  begin
169
170
  require 'rubygems.rb.bak' # just in case
170
- rescue LoadError
171
+ rescue ::LoadError
171
172
  # ok
172
173
  end
173
174
  end
@@ -196,13 +197,48 @@ if defined?(Gem) then
196
197
  GemPaths = {}
197
198
  GemVersions = {}
198
199
 
200
+ GemsActivated = {}
199
201
  def push_gem_version_on_load_path(gem_name, *version_requirements)
200
202
  if version_requirements.empty?
201
- unless GemPaths.has_key?(gem_name) then
203
+ unless path = GemPaths[(gem_name)] then
204
+ puts "Could not find RubyGem #{gem_name} (>= 0)\n" if $VERBOSE || $DEBUG
202
205
  raise Gem::LoadError, "Could not find RubyGem #{gem_name} (>= 0)\n"
203
206
  end
204
-
205
- # highest version gems already active
207
+ # highest version gems *not* already active
208
+ if !ALL_CACHES.empty?
209
+ # then we are using the caches, and the stuff isn't preloaded yet
210
+ # copied and pasted...
211
+ require_paths = []
212
+ if GemsActivated[gem_name]
213
+ return false
214
+ else
215
+ GemsActivated[gem_name] = true
216
+ end
217
+ if File.exist?(file = File.join(path, ".require_paths")) then
218
+ paths = File.read(file).split.map do |require_path|
219
+ File.join path, require_path
220
+ end
221
+
222
+ require_paths.concat paths
223
+ else
224
+ # bin shouldn't be necessary...
225
+ # require_paths << file if File.exist?(file = File.join(path, "bin"))
226
+ require_paths << file if File.exist?(file = File.join(path, "lib"))
227
+ end
228
+
229
+ # "tag" the first require_path inserted into the $LOAD_PATH to enable
230
+ # indexing correctly with rubygems proper when it inserts an explicitly
231
+ # gem version
232
+ unless require_paths.empty? then
233
+ require_paths.first.instance_variable_set(:@gem_prelude_index, true)
234
+ end
235
+ # gem directories must come after -I and ENV['RUBYLIB']
236
+ # TODO puts $:.index{|e|e.instance_variable_defined?(:@gem_prelude_index)}
237
+ # $:[$:.index{|e|e.instance_variable_defined?(:@gem_prelude_index)}||-1,0] = require_paths
238
+ $:[0,0] = require_paths
239
+ return true
240
+ end
241
+ # normal flow when not using caches--it's already on the path
206
242
  return false
207
243
  else
208
244
  if version_requirements.length > 1 then
@@ -212,6 +248,11 @@ if defined?(Gem) then
212
248
 
213
249
  requirement, version = version_requirements[0].split
214
250
  requirement.strip!
251
+ # accomodate for gem 'xxx', '2.3.8'
252
+ if !version
253
+ version = requirement
254
+ requirement = '='
255
+ end
215
256
 
216
257
  if loaded_version = GemVersions[gem_name] then
217
258
  case requirement
@@ -237,7 +278,7 @@ if defined?(Gem) then
237
278
  numbers
238
279
  end
239
280
 
240
- def push_all_highest_version_gems_on_load_path
281
+ def calculate_all_highest_version_gems load_them_into_the_require_path
241
282
  Gem.path.each do |path|
242
283
  gems_directory = File.join(path, "gems")
243
284
 
@@ -257,6 +298,9 @@ if defined?(Gem) then
257
298
  end
258
299
  end
259
300
 
301
+ return unless load_them_into_the_require_path
302
+
303
+ # load them into $: now
260
304
  require_paths = []
261
305
 
262
306
  GemPaths.each_value do |path|
@@ -267,7 +311,8 @@ if defined?(Gem) then
267
311
 
268
312
  require_paths.concat paths
269
313
  else
270
- require_paths << file if File.exist?(file = File.join(path, "bin"))
314
+ # bin shouldn't be necessary...
315
+ # require_paths << file if File.exist?(file = File.join(path, "bin"))
271
316
  require_paths << file if File.exist?(file = File.join(path, "lib"))
272
317
  end
273
318
  end
@@ -281,8 +326,9 @@ if defined?(Gem) then
281
326
  # gem directories must come after -I and ENV['RUBYLIB']
282
327
  $:[$:.find{|e|e.instance_variable_defined?(:@gem_prelude_index)}||-1,0] = require_paths
283
328
  end
284
-
329
+
285
330
  def const_missing(constant)
331
+ puts 'gem_prelude: const missing', constant if $VERBOSE || $DEBUG
286
332
  QuickLoader.load_full_rubygems_library
287
333
 
288
334
  if Gem.const_defined?(constant) then
@@ -297,20 +343,45 @@ if defined?(Gem) then
297
343
  super unless Gem.respond_to?(method)
298
344
  Gem.send(method, *args, &block)
299
345
  end
346
+
347
+ # if the gem dir doesn't exist, don't count it against us
348
+ ALL_CACHES = Gem.path.select{|path| File.exist?(path)}.map{|path|
349
+ cache_name = path + '/.faster_rubygems_cache'
350
+ if File.exist?(cache_name)
351
+ File.open(cache_name, 'rb') do |f|
352
+ [path, Marshal.load(f)]
353
+ end
354
+ else
355
+ $stderr.puts 'faster_rubygems: a cache file does not exist! reverting to full load path ' + cache_name
356
+ nil
357
+ end
358
+ }
359
+
360
+ # we will use a clear cache as an indication of "non success" loading caches
361
+ ALL_CACHES.clear if ALL_CACHES.index(nil)
362
+
300
363
  end
301
364
 
302
365
  extend QuickLoader
303
366
 
304
367
  end
305
368
 
369
+
306
370
  begin
307
- Gem.push_all_highest_version_gems_on_load_path
308
- Gem::QuickLoader.fake_rubygems_as_loaded
371
+ if !Gem::QuickLoader::ALL_CACHES.empty?
372
+ puts 'faster_rubygems using caches', Gem::QuickLoader::ALL_CACHES.map{|fn, contents| fn} if $VERBOSE
373
+ Gem.calculate_all_highest_version_gems false
374
+ # use cached load instead of loading lib paths into the load path here
375
+ require File.expand_path(File.dirname(__FILE__)) + "/prelude_cached_load"
376
+ else
377
+ puts 'faster_rubygems not using caches!' if $VERBOSE
378
+ Gem.calculate_all_highest_version_gems true
379
+ end
380
+ Gem::QuickLoader.fake_rubygems_as_loaded # won't be needing that regardless
309
381
  rescue Exception => e
310
382
  puts "Error loading gem paths on load path in gem_prelude"
311
383
  puts e
312
384
  puts e.backtrace.join("\n")
313
385
  end
314
-
315
- end
316
-
386
+ puts "faster_rubygems total load time:" + (Time.now - start).to_s if $VERBOSE
387
+ end
File without changes
@@ -1,7 +1,7 @@
1
1
  module Gem
2
2
 
3
3
  module QuickLoader
4
- def bin_path(gem_name, exec_name = null, *version_requirements)
4
+ def bin_path(gem_name, exec_name = nil, *version_requirements)
5
5
  unless GemPaths.has_key?(gem_name) then
6
6
  raise Gem::LoadError, "Could not find RubyGem #{gem_name} (>= 0)\n"
7
7
  end
@@ -44,7 +44,7 @@ module Gem
44
44
  bin_path(gem_name, exec_name, *version_requirements)
45
45
  end
46
46
 
47
- # 1.9.1 doesn't have this...
47
+ # 1.9.1's gem_prelude doesn't have this for some reason...
48
48
  def integers_for(gem_version)
49
49
  numbers = gem_version.split(".").collect {|n| n.to_i}
50
50
  numbers.pop while numbers.last == 0
@@ -0,0 +1,46 @@
1
+ module Gem
2
+ module QuickLoader
3
+ module PreludeRequire
4
+ def require_prelude lib
5
+ begin
6
+ require_pre_prelude lib
7
+ rescue ::LoadError => e
8
+ if Gem.push_all_gems_that_might_match_and_reload_files(lib, e)
9
+ require_pre_prelude lib
10
+ else
11
+ # re-raise
12
+ raise e
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ def push_all_gems_that_might_match_and_reload_files lib, error
19
+ sub_lib = lib.gsub("\\", '/').split('/')[-1].split('.')[0]
20
+ success = false
21
+ raise if ALL_CACHES.empty? # should never be empty...
22
+ ALL_CACHES.each{|path, gem_list|
23
+ for gem_name, long_file_list in gem_list
24
+ if idx = long_file_list.index(sub_lib)
25
+ puts 'activating' + gem_name + sub_lib.to_s if $DEBUG
26
+ if gem(gem_name)
27
+ puts 'gem activated ' + gem_name + ' ' + sub_lib + ' ' + long_file_list[idx] if $VERBOSE || $DEBUG
28
+ success = true
29
+ end
30
+ puts 'done activeating' + gem_name + sub_lib if $DEBUG
31
+ end
32
+
33
+ end
34
+ }
35
+ success
36
+ end
37
+
38
+ end
39
+ end
40
+
41
+ module Kernel
42
+ include Gem::QuickLoader::PreludeRequire
43
+ alias :require_pre_prelude :require
44
+ alias :require :require_prelude
45
+ end
46
+
@@ -0,0 +1,59 @@
1
+ require File.dirname(__FILE__) + "/prelude_bin_path" # Gem.integers_for, for 1.9.1
2
+
3
+ module Gem
4
+ module QuickLoader
5
+ def create_cache gems_paths
6
+ puts 'faster_rubygems: creating caches'
7
+ gems_paths.each do |path|
8
+ gem_versions = {}
9
+ gem_paths = {}
10
+ gems_directory = File.join(path, "gems")
11
+ if File.exist?(gems_directory) then
12
+ Dir.entries(gems_directory).each do |gem_directory_name|
13
+ next if gem_directory_name == "." || gem_directory_name == ".."
14
+
15
+ next unless gem_name = gem_directory_name[/(.*)-(.*)/, 1]
16
+ new_version = integers_for($2)
17
+ current_version = gem_versions[gem_name]
18
+
19
+ if !current_version or (current_version <=> new_version) < 0 then
20
+ gem_versions[gem_name] = new_version
21
+ gem_paths[gem_name] = File.join(gems_directory, gem_directory_name)
22
+ end
23
+ end
24
+ end
25
+ gem_paths_with_contents = {}
26
+ # strip out directories, and the gem-d.d.d prefix
27
+ gem_paths.each{|k, v|
28
+
29
+ gem_paths_with_contents[k] = Dir[v + '/**/*.{rb,so,bundle}'].select{|f|
30
+ !File.directory? f
31
+ }.map{ |full_name|
32
+ full_name.sub(v + '/', '')
33
+ full_name.split('/')[-1].split('.')[0] # just a of a.b.c.rb, for now
34
+ }
35
+ }
36
+
37
+ cache_path = path + '/.faster_rubygems_cache'
38
+ puts '.'
39
+ $stdout.flush
40
+ # accomodate for those not running as sudo...
41
+ if File.writable? path
42
+ File.open(cache_path, 'wb') do |f|
43
+ f.write Marshal.dump(gem_paths_with_contents)
44
+ end
45
+ else
46
+ $stderr.puts "warning, unable to write cache to:" + cache_path
47
+ end
48
+ end
49
+
50
+ end
51
+
52
+ def create_cache_for_all!
53
+ puts 'recreating all faster_rubygems caches'
54
+ create_cache Gem.path
55
+ end
56
+
57
+ end
58
+ extend QuickLoader
59
+ end
File without changes
@@ -1,21 +1,25 @@
1
1
  # :stopdoc:
2
2
 
3
- # don't load it if normal rubygems is already defined
4
- if !defined?(Gem::Dependency)
5
-
6
- if RUBY_VERSION < '1.9.0'
7
3
 
4
+ # don't load it if normal rubygems is already loaded
5
+
6
+ if !defined?(Gem::Dependency)
7
+ if( (RUBY_VERSION < '1.9.0') || !defined?(Gem))
8
8
  # we're either 1.8 or 1.9 with --disable-gems
9
9
  # define it so gem_prelude will execute...
10
10
  module Gem;
11
- end
12
11
 
13
- require File.expand_path(File.dirname(__FILE__)) + "/my_gem_prelude.rb"
12
+ end
13
+ require File.expand_path(File.dirname(__FILE__)) + "/faster_rubygems/my_gem_prelude"
14
+ else
15
+ if RUBY_VERSION >= '1.9.0'
16
+ puts 'warning: faster_rubygems: you loaded gem_prelude already so I cant speed that up' if $VERBOSE
17
+ end
14
18
  end
15
19
 
16
- # both 1.8 and 1.9 want this one always though...
17
- require File.expand_path(File.dirname(__FILE__)) + "/prelude_bin_path"
20
+ # both 1.8 and 1.9 want this one no matter what though though...
21
+ require File.expand_path(File.dirname(__FILE__)) + "/faster_rubygems/prelude_bin_path"
18
22
 
19
23
  else
20
24
  if $VERBOSE || $DEBUG
21
- puts 'warning: faster_rubygems unable to load because normal rubygems already loaded (expected in certain instances, like when running the gem command)'
25
+ puts 'warning: faster_rubygems unable to load because normal rubygems already loaded (which thing is expected in certain instances, like when running the gem command)'
22
26
  end
23
27
  end
24
28
 
@@ -0,0 +1,7 @@
1
+ Gem.post_install { |gem_installer_instance|
2
+ require File.dirname(__FILE__) + "/faster_rubygems/create_cache_for_all"
3
+ }
4
+
5
+ Gem.post_uninstall {
6
+ require File.dirname(__FILE__) + "/faster_rubygems/create_cache_for_all"
7
+ }
@@ -1,4 +1,4 @@
1
1
  require File.dirname(__FILE__) + '/../../lib/faster_rubygems'
2
2
  gem 'test-unit', '= 1.2.3'
3
3
  require 'test/unit/version'
4
- raise unless Test::Unit::VERSION == '1.2.3'
4
+ raise 'bad version' unless Test::Unit::VERSION == '1.2.3'
data/spec/reload.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'benchmark'
2
+ puts Benchmark.realtime {
3
+ puts Marshal.load File.open("c:/ruby19/lib/ruby/gems/1.9.1/.faster_rubygems_cache", "rb")
4
+ }
@@ -0,0 +1,121 @@
1
+ require File.dirname(__FILE__) + "/../lib/faster_rubygems"
2
+ require File.dirname(__FILE__) + "/../lib/faster_rubygems/prelude_create_cache"
3
+ require 'sane'
4
+ require 'spec' # rspec 1
5
+ require 'spec/autorun'
6
+ require 'fileutils'
7
+ raise if ENV['RUBYOPT'] # avoid silly testing conflicts
8
+ require 'rbconfig'
9
+
10
+ describe 'can create cache file apropo' do
11
+ before do
12
+ @ruby_ver = RbConfig::CONFIG['ruby_version']
13
+ @gem_dir = 'test_dir/gems/' + @ruby_ver
14
+ @gem_dir_cache = @gem_dir + '/.faster_rubygems_cache'
15
+ clean
16
+ create_gem 'gem1'
17
+ cache!
18
+ end
19
+
20
+ def clean
21
+ FileUtils.rm_rf Dir['test_dir/gems/*']
22
+ FileUtils.rm_rf Dir['test_dir/.faster*']
23
+ FileUtils.rm_rf 'test_file.rb'
24
+ end
25
+
26
+ after do
27
+ clean
28
+ end
29
+
30
+ private
31
+
32
+ def create_gem name, version = '0.0.0'
33
+ new_name = @gem_dir + '/gems/' + name + "-" + version
34
+ FileUtils.mkdir_p new_name + '/lib'
35
+ File.write new_name + '/lib/a_file.rb', name.upcase + '= "abc"'
36
+ end
37
+
38
+ def cache!
39
+ Gem.create_cache [@gem_dir]
40
+ end
41
+
42
+ it 'should be able to create a cache file' do
43
+ assert File.exist?(@gem_dir_cache)
44
+ end
45
+
46
+ it 'should be bigger with more gems' do
47
+ size = File.size(@gem_dir_cache)
48
+ create_gem 'gem2'
49
+ cache!
50
+ size2 = File.size(@gem_dir_cache)
51
+ assert size2 > size
52
+ end
53
+
54
+ it 'should be same size if two versions, same gem' do
55
+ size = File.size(@gem_dir_cache)
56
+ create_gem 'gem1', '0.0.1'
57
+ cache!
58
+ size2 = File.size(@gem_dir_cache)
59
+ assert size2 == size
60
+ end
61
+
62
+ it "should cache the version numbers of gems, too" do
63
+ Marshal.load(File.open(@gem_dir_cache)).to_s.should_not include "0.0.0"
64
+ end
65
+
66
+ it "should create two caches if you pass it two dirs" do
67
+ Dir['**/.faster_rubygems_cache'].length.should == 1
68
+ gem_dir2 = 'test_dir2/gems/' + @ruby_ver
69
+ FileUtils.mkdir_p gem_dir2
70
+ Gem.create_cache [@gem_dir, gem_dir2]
71
+ Dir['**/.faster_rubygems_cache'].length.should == 2
72
+ FileUtils.rm_rf 'test_dir2'
73
+ end
74
+
75
+ def create_file use_gem
76
+ all = <<-EOS
77
+ ENV['GEM_PATH'] = 'test_dir/gems/#{@ruby_ver}'
78
+ require File.dirname(__FILE__) + '/../lib/faster_rubygems'
79
+ #{use_gem ? "gem 'gem1'" : nil}
80
+ require 'a_file'
81
+ unless defined?(GEM1)
82
+ puts 'GEM1 not defined'
83
+ exit 1
84
+ end
85
+ if defined?(Gem::Dependency)
86
+ puts 'Gem::Dependency defined'
87
+ exit 1
88
+ end
89
+ EOS
90
+ File.write 'test_file.rb', all
91
+ if RUBY_VERSION >= '1.9.0'
92
+ assert system(OS.ruby_bin + " --disable-gems test_file.rb")
93
+ else
94
+ assert system(OS.ruby_bin + " test_file.rb")
95
+ end
96
+ end
97
+
98
+ it "should not load full rubygems--load the cache files instead" do
99
+ create_file false
100
+ end
101
+
102
+ it "should work with the gem 'xxx' command" do
103
+ create_file true
104
+ end
105
+
106
+ it "should create the caches on install/uninstall" do
107
+ FileUtils.rm_rf Gem.path[0] + "/.faster_rubygems_cache"
108
+ Gem.create_cache_for_all!
109
+ assert File.exist?(Gem.path[0] + "/.faster_rubygems_cache")
110
+ puts Gem.path[0] + "/.faster_rubygems_cache"
111
+ end
112
+
113
+ it "should not cause a cyclic require that just calls and fails, calls and fails"
114
+
115
+ it "should use that phreaky marker well (set it, et al)"
116
+
117
+ it "should be ok if certain .paths aren't writable"
118
+
119
+ it "should revert to full load of all paths into $: in the case of missing cache files"
120
+
121
+ end
@@ -1,14 +1,10 @@
1
1
  # to test in 1.8.x, make sure to use ruby specname.rb
2
2
  require File.dirname(__FILE__) + "/../lib/faster_rubygems"
3
3
  require 'sane'
4
- require 'rspec' # rspec 2
5
-
6
- begin
7
- require 'spec/autorun'
8
- rescue LoadError
9
- # ok
10
- end
11
- require 'fileutils'
4
+ require 'spec' # rspec 1
5
+ require 'spec/autorun'
6
+ require 'fileutils'
7
+ raise if ENV['RUBYOPT']
12
8
 
13
9
  describe Gem do
14
10
 
@@ -19,7 +15,7 @@ describe Gem do
19
15
  FileUtils.mkdir_p @gem_path
20
16
  end
21
17
 
22
- context "speeding Gem.bin_path the fake sick way" do
18
+ context "speeding Gem.bin_path by inferring" do
23
19
 
24
20
  it "should fake guess the right path instead of loading full rubygems for now" do
25
21
  assert Gem.bin_path('after', 'after', ">= 0") =~ /after.*bin.*after/
@@ -30,6 +26,12 @@ describe Gem do
30
26
 
31
27
  end
32
28
 
29
+ it "should pass test files" do
30
+ Dir['files/*'].each{|f|
31
+ raise f unless system(OS.ruby_bin + " #{f}")
32
+ }
33
+ end
34
+
33
35
  context "gem xxx" do
34
36
  it "should allow you to load 'older' gem versions somehow, like maybe cacheing" # lower prio
35
37
  end
@@ -0,0 +1,2 @@
1
+ handle gem 'rails', '2.3.8'
2
+ it uses find instead of index for $:
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faster_rubygems
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 63
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 6
9
- - 4
10
- version: 0.6.4
8
+ - 9
9
+ - 2
10
+ version: 0.9.2
11
11
  platform: ruby
12
12
  authors: []
13
13
 
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-22 00:00:00 -06:00
18
+ date: 2010-06-24 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -92,25 +92,30 @@ files:
92
92
  - README
93
93
  - Rakefile
94
94
  - VERSION
95
- - examples/require_fast_start.rb
96
- - examples/require_rubygems_normal.rb
95
+ - benchmarks.txt
97
96
  - ext/mkrf_conf.rb
98
97
  - internalize.rb
99
98
  - lib/faster_rubygems.rb
100
- - lib/faster_rubygems/install.rb
99
+ - lib/faster_rubygems/create_cache_for_all.rb
101
100
  - lib/faster_rubygems/install_helper.rb
102
101
  - lib/faster_rubygems/install_with_faster_require_too.rb
103
- - lib/faster_rubygems/uninstall.rb
102
+ - lib/faster_rubygems/ir_session.rb
103
+ - lib/faster_rubygems/my_defaults.rb
104
+ - lib/faster_rubygems/my_gem_prelude.rb
105
+ - lib/faster_rubygems/override.rb
106
+ - lib/faster_rubygems/prelude_bin_path.rb
107
+ - lib/faster_rubygems/prelude_cached_load.rb
108
+ - lib/faster_rubygems/prelude_create_cache.rb
109
+ - lib/faster_rubygems/unoverride.rb
104
110
  - lib/faster_rubygems_with_faster_require_too.rb
105
- - lib/frubygems.rb
106
- - lib/my_defaults.rb
107
- - lib/my_gem_prelude.rb
108
- - lib/prelude_bin_path.rb
111
+ - lib/rubygems_plugin.rb
109
112
  - spec/files/test_gem.rb
110
113
  - spec/files/test_gem_const.rb
111
114
  - spec/files/test_gem_func.rb
115
+ - spec/spec.can_create_cache_file.rb
112
116
  - spec/spec.faster_rubygems.rb
113
- - spec/test.spec.rb
117
+ - things_prelude_needs.txt
118
+ - spec/reload.rb
114
119
  has_rdoc: true
115
120
  homepage:
116
121
  licenses: []
@@ -118,12 +123,7 @@ licenses: []
118
123
  post_install_message: |+
119
124
 
120
125
 
121
- installed! 1.9 use -> require 'faster_rubygems'
122
-
123
- 1.8: use require 'faster_rubygems' or install as the default thus:
124
-
125
- >> require 'rubygems'
126
- >> require 'faster_rubygems/install'
126
+ faster_rubygems installed! see the readme for post-install instructions: http://github.com/rdp/faster_rubygems
127
127
 
128
128
  rdoc_options:
129
129
  - --charset=UTF-8
@@ -158,7 +158,6 @@ test_files:
158
158
  - spec/files/test_gem.rb
159
159
  - spec/files/test_gem_const.rb
160
160
  - spec/files/test_gem_func.rb
161
+ - spec/reload.rb
162
+ - spec/spec.can_create_cache_file.rb
161
163
  - spec/spec.faster_rubygems.rb
162
- - spec/test.spec.rb
163
- - examples/require_fast_start.rb
164
- - examples/require_rubygems_normal.rb
@@ -1,7 +0,0 @@
1
- require 'benchmark'
2
- puts Benchmark.realtime {
3
- require File.dirname(__FILE__) + '/../lib/faster_rubygems'
4
- gem 'ruby-prof'
5
- Gem.bin_path 'ruby-prof'
6
- require 'ruby-prof' # load a gem
7
- }
@@ -1,7 +0,0 @@
1
- require 'benchmark'
2
- puts Benchmark.realtime {
3
- require 'rubygems'
4
- gem 'ruby-prof'
5
- Gem.bin_path('ruby-prof')
6
- require 'ruby-prof' # load a gem
7
- }
data/lib/frubygems.rb DELETED
@@ -1 +0,0 @@
1
- require 'faster_rubygems'
data/spec/test.spec.rb DELETED
@@ -1,9 +0,0 @@
1
- #require "spec/autorun"
2
- require "spec"
3
- require "spec/rake/spectask"
4
- RAILS_ENV = 'test'
5
-
6
- namespace :go do
7
- describe "yoyo" do
8
- end
9
- end