faster_gem_script 0.1.2 → 0.1.4

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,41 +1,49 @@
1
- Example:
2
-
3
- # install it
4
- C:\> gem install faster_gem_script
5
-
6
- # install something to optimize
7
-
8
- C:\> gem install whichr
9
-
10
- C:\>whichr whichr
11
- higher in the list is executed first
12
- C:\installs\ruby19_mingw\bin\whichr.bat
13
-
14
- C:\>faster_gem_script C:\installs\ruby19_mingw\bin\whichr
15
-
16
- # now run it twice
17
-
18
-
19
-
20
- C:\> timer whichr whichr
21
- higher in the list is executed first
22
- C:\installs\ruby19_mingw\bin\whichr.bat
23
-
24
- 2.484375
25
-
26
- C:\dev\ruby\faster_gem_script>timer whichr whichr
27
- higher in the list is executed first
28
- C:\installs\ruby19_mingw\bin\whichr.bat
29
-
30
- 0.40625
31
-
32
- Yea much faster now.
33
-
34
- You can revert back to the original performance, too.
35
-
36
- C:\> gem install whichr
37
- C:\> timer whichr whichr
38
- higher in the list is executed first
39
- C:\installs\ruby19_mingw\bin\whichr.bat
40
-
41
- 2.5625
1
+ <<<<<<< HEAD
2
+ This is a utility to speedup gem scripts quite a bit (especially for windows users), by avoiding expensive rubygems calls.
3
+
4
+ Background:
5
+
6
+ By default rubygems runs a
7
+
8
+ require rubygems
9
+ ...
10
+ load Gem.bin_path(...)
11
+
12
+ in every gem's auto-generated startup script (ex: the ruby-prof gem has a ruby-prof command--it runs the above before running that command).
13
+
14
+ This is great if you have a complex gem that requires specific version of its dependencies, etc.
15
+
16
+ However, these calls result in an extra slowdown--especially in windows it can take up to an extra 2s, EVERY TIME, at startup.
17
+
18
+ This can be alleviated, however, with this gem.
19
+
20
+ In my box 2s went down to 0.37s (1.9.1 mingw). In linux it can speedup a tidge, too (from 0.3 to 0.16s).
21
+
22
+ How it does it:
23
+
24
+ This gem provides a utility to replace the auto-generated startup script with one that caches the bin_path location so that the second/third/fourth times it starts up almost instantly.
25
+
26
+ This works in 1.9 because of gem_prelude (which makes loading rubygems at times unnecessary), and of the "faster_rubygems" gem for 1.8.x, which is essentially gem_prelude for 1.8.
27
+
28
+ How to use it:
29
+
30
+ # install a gem that has a command line executable, like ruby-prof
31
+
32
+ # install a gem pre-req--necessary because of a bug in rubygems
33
+ C:> gem install os
34
+ # install the optimizer
35
+ C:> gem install faster_gem_scripts
36
+ # this next line will change based on your ruby location
37
+ C:> faster_gem_script c:\ruby18\bin\whichr
38
+
39
+ If you want an easier way to discover the path for your commands (and are on windows), you can checkout the whichr gem (http://github.com/rdp/whichr).
40
+
41
+ Caveat: If you update a gem after using this, you'll need to run it again so that it will be sure to cache the location of the latest version of the gem.
42
+
43
+ Other caveat: if your gem has any "complex dependencies" (like it uses the gem command like
44
+
45
+ gem 'some_other_dependency', '= 1.1.9'
46
+
47
+ then this system won't work for you. Try it out to see.
48
+
49
+ You can find out by running it once. If it fails then reinstall the gem to get back to its original functionality.
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'jeweler'
2
+ Jeweler::Tasks.new do |gemspec|
3
+ gemspec.name = "faster_gem_script"
4
+ gemspec.summary = "A utility to make ruby \"command line scripts\" run much faster by using gem prelude instead of full rubygems"
5
+ gemspec.email = "rogerdpack@gmail.com"
6
+ gemspec.homepage = "http://github.com/rdp/faster_gem_scripts"
7
+ gemspec.authors = ["Roger Pack"]
8
+ gemspec.add_dependency('sane', '>= 0.17.0')
9
+ gemspec.add_dependency('fast_require')
10
+ gemspec.add_development_dependency('rspec')
11
+ # don't need faster_rubygems here, as we auto install it
12
+ gemspec.extensions = 'ext/mkrf_conf.rb'
13
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.4
@@ -1,8 +1,8 @@
1
- require 'sane'
2
- require_relative '../lib/faster_gem_scripts'
3
- if ARGV.length == 0 || ARGV[0] == '-h' || ARGV[0] == '--help'
4
- puts "syntax: gem binary, like bin/abc (no .rb)"
5
- exit
6
- end
7
-
8
- FasterGemScripts.overwrite ARGV[0]
1
+ #!/usr/bin/env ruby
2
+ require 'faster_gem_scripts'
3
+ if ARGV.length == 0
4
+ puts 'syntax: script_name_to_optimize'
5
+ else
6
+ FasterGemScripts.overwrite ARGV[0]
7
+ end
8
+
data/ext/mkrf_conf.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'rubygems/command.rb'
3
+ require 'rubygems/dependency_installer.rb'
4
+ begin
5
+ Gem::Command.build_args = ARGV
6
+ rescue NoMethodError
7
+ end
8
+ inst = Gem::DependencyInstaller.new
9
+ begin
10
+ if RUBY_VERSION < "1.9" # need the helper
11
+ inst.install "faster_rubygems"
12
+ end
13
+ rescue
14
+ exit(1)
15
+ end
16
+
17
+ f = File.open(File.join(File.dirname(__FILE__), "Rakefile"), "w") # create dummy rakefile to indicate success
18
+ f.write("task :default\n")
19
+ f.close
@@ -3,9 +3,24 @@ require 'sane'
3
3
  class FasterGemScripts
4
4
  def self.overwrite full_path
5
5
  contents_should_be = File.read __dir__ + '/template'
6
- File.write(full_path, contents_should_be)
7
- bin_loc = full_path + '_bin_location'
8
- File.delete(bin_loc) if File.exist?(bin_loc)
6
+ if File.file?(full_path)
7
+ puts 'faster_gem_scripts: optimizing ' + full_path + '...'
8
+ File.write(full_path, contents_should_be)
9
+ bin_loc = full_path + '_bin_location'
10
+ File.delete(bin_loc) if File.exist?(bin_loc)
11
+ else
12
+ puts "unable to find the binary:" + full_path + " you may want to find it and overwrite it yourself using C:\>faster_gem_script file_name (no .bat)"
13
+ end
14
+ end
15
+
16
+ def self.clear_caches!
17
+ # I only know about one type...
18
+ bin_dir = OS.ruby_bin.split('/')[0..-2].join('/') # strip off ruby.exe
19
+ Dir[bin_dir = '/*_bin_location'].each{|file|
20
+ puts 'deleting'
21
+ File.delete file
22
+ }
23
+
9
24
  end
10
25
 
11
26
  end
@@ -0,0 +1,18 @@
1
+ Gem.post_install { |gem_installer_instance|
2
+ require 'os'
3
+ require 'faster_gem_scripts'
4
+ all = gem_installer_instance.spec.files.select{|file| file.start_with? "bin" }
5
+ bin_dir = OS.ruby_bin.split('/')[0..-3].join('/')
6
+ if all.length > 0
7
+ FasterGemScripts.clear_caches!
8
+ all.each{|script_name|
9
+ name = bin_dir + '/' + script_name
10
+ FasterGemScripts.overwrite name
11
+ }
12
+ end
13
+ }
14
+
15
+ Gem.post_uninstall {
16
+ require 'faster_gem_scripts'
17
+ FasterGemScripts.clear_caches! if (gem_installer_instance.spec.files.select{|file| file.start_with? "bin" }.length > 0)
18
+ }
data/lib/template CHANGED
@@ -1,7 +1,7 @@
1
1
  gem_name = File.basename(__FILE__)
2
2
 
3
3
  if ARGV.first =~ /^_(.*)_$/
4
- # special version of the gem--we'll need full rubygems for this
4
+ # special version of the gem--we'll need full rubygems for this...
5
5
  require 'rubygems'
6
6
  if Gem::Version.correct? $1 then
7
7
  version = $1
@@ -14,14 +14,16 @@ end
14
14
 
15
15
  cached = File.dirname(__FILE__) + "/#{gem_name}_bin_location"
16
16
 
17
- # if we haven't cached its location yet...
17
+ # if we haven't cached its location yet...
18
18
  unless File.exist? cached
19
19
  File.open(cached, 'w') do |f|
20
+ # then setup the cache
21
+ puts 'faster_gem_script cacheing bin location (1st time only) ' + __FILE__
20
22
  require 'rubygems'
21
23
  f.write Gem.bin_path(gem_name, gem_name, ">= 0")
22
24
  end
23
25
  end
24
26
 
25
27
  require 'faster_rubygems' if RUBY_VERSION < '1.9' # gem prelude equivalent
26
-
27
- load File.read(cached)
28
+ require 'fast_require' # happiness
29
+ load File.read(cached)
@@ -1,11 +1,14 @@
1
+ require 'faster_rubygems' if RUBY_VERSION < '1.9'
1
2
  require 'sane'
2
- require_rel '../lib/faster_gem_scripts'
3
+ require_relative '../lib/faster_gem_scripts'
3
4
  require 'spec/autorun'
5
+ require 'fileutils'
4
6
 
5
- describe "rewriter" do
7
+ describe "faster rubygems" do
6
8
 
7
9
  def setup
8
10
  File.delete 'abc' if File.exist?('abc')
11
+ FileUtils.touch 'abc'
9
12
  FasterGemScripts.overwrite 'abc'
10
13
  end
11
14
 
@@ -15,11 +18,15 @@ describe "rewriter" do
15
18
  assert new_contents.contain?("faster_rubygems")
16
19
  end
17
20
 
18
- it "should nuke the cache on write" do
21
+ it "should nuke the old cache on re-write" do
19
22
  require 'fileutils'
20
23
  FileUtils.touch 'abc_bin_location'
21
24
  setup
22
25
  assert !File.exist?('abc_bin_location')
23
26
  end
27
+
28
+ it "should overwrite on gem install"
29
+
30
+
24
31
 
25
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faster_gem_script
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roger Pack
@@ -9,13 +9,23 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-27 00:00:00 -07:00
12
+ date: 2010-01-29 00:00:00 -07:00
13
13
  default_executable: faster_gem_script
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sane
17
17
  type: :runtime
18
18
  version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.17.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: fast_require
27
+ type: :runtime
28
+ version_requirement:
19
29
  version_requirements: !ruby/object:Gem::Requirement
20
30
  requirements:
21
31
  - - ">="
@@ -36,14 +46,20 @@ description:
36
46
  email: rogerdpack@gmail.com
37
47
  executables:
38
48
  - faster_gem_script
39
- extensions: []
40
-
49
+ extensions:
50
+ - ext/mkrf_conf.rb
41
51
  extra_rdoc_files:
42
52
  - README
43
53
  files:
54
+ - README
55
+ - Rakefile
56
+ - VERSION
57
+ - bin/faster_gem_script
58
+ - ext/mkrf_conf.rb
44
59
  - lib/faster_gem_scripts.rb
60
+ - lib/rubygems_plugin.rb
45
61
  - lib/template
46
- - README
62
+ - spec/spec.faster_gem_scripts.rb
47
63
  has_rdoc: true
48
64
  homepage: http://github.com/rdp/faster_gem_scripts
49
65
  licenses: []
@@ -73,4 +89,4 @@ signing_key:
73
89
  specification_version: 3
74
90
  summary: A utility to make ruby "command line scripts" run much faster by using gem prelude instead of full rubygems
75
91
  test_files:
76
- - spec/spec.rb
92
+ - spec/spec.faster_gem_scripts.rb