faster_gem_script 0.3.0 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +30 -26
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/bin/faster_gem_script +2 -1
- data/lib/faster_gem_scripts.rb +14 -16
- data/lib/rubygems_plugin.rb +24 -0
- data/spec/spec.faster_gem_scripts.rb +1 -1
- metadata +5 -7
- data/bin/yo_bin_location +0 -0
- data/lib/rubygems_plugin.rb.disabled +0 -18
data/README
CHANGED
@@ -1,49 +1,53 @@
|
|
1
|
-
|
2
|
-
This is a utility to speedup gem scripts quite a bit (especially for windows users), by avoiding expensive rubygems calls.
|
1
|
+
This is a utility to speedup gem executable scripts quite a bit (especially for windows users), by avoiding expensive rubygems calls.
|
3
2
|
|
4
3
|
Background:
|
5
4
|
|
6
5
|
By default rubygems runs a
|
7
6
|
|
8
|
-
require rubygems
|
9
|
-
...
|
10
|
-
load Gem.bin_path(...)
|
11
7
|
|
12
|
-
|
8
|
+
require rubygems
|
9
|
+
...
|
10
|
+
load Gem.bin_path(name)
|
13
11
|
|
14
|
-
|
12
|
+
in every gem's auto-generated startup (ex: bin/ruby-prof script).
|
15
13
|
|
16
|
-
|
14
|
+
This is great if you have a complex gem that requires specific version of its dependencies, etc.
|
17
15
|
|
18
|
-
|
16
|
+
However, this template loads full rubygems (even in 1.9), which results in an extra slowdown.
|
17
|
+
In windows, for example, this take an extra 2s, EVERY TIME, at startup.
|
19
18
|
|
20
|
-
|
19
|
+
This can be alleviated, however.
|
21
20
|
|
22
|
-
|
21
|
+
In my box 2s went down to 0.37s (1.9.1 mingw). In linux it can startup a bit faster, too (from 0.3 to 0.16s).
|
23
22
|
|
24
|
-
This gem provides a utility to replace the auto-generated startup script with one that caches the
|
23
|
+
This gem provides a utility to replace the auto-generated startup script with one that caches the
|
24
|
+
Gem.bin_path result so that the second/third/fourth times it starts up using a cached value.
|
25
25
|
|
26
|
-
|
26
|
+
In 1.9, this allows it to avoid loading full rubygems.
|
27
|
+
In 1.8, it relies on the "faster_rubygems" gem, which also avoids loading full rubygems.
|
27
28
|
|
28
29
|
How to use it:
|
29
30
|
|
30
|
-
# install
|
31
|
-
|
32
|
-
# install a gem pre-req--necessary because of a bug in rubygems
|
33
|
-
C:> gem install os
|
34
|
-
# install the optimizer
|
31
|
+
# install the gem
|
35
32
|
C:> gem install faster_gem_scripts
|
36
|
-
#
|
37
|
-
C:> faster_gem_script c:\ruby18\bin\
|
33
|
+
# now use it to optimize an existing gem, ex:
|
34
|
+
C:> faster_gem_script c:\ruby18\bin\redcar
|
35
|
+
|
36
|
+
If you want an easy way to discover the gem paths (and are on windows),
|
37
|
+
you can checkout the whichr gem (http://github.com/rdp/whichr).
|
38
|
+
|
39
|
+
Other caveat: if your gem has any "complex dependencies" ,like it uses things like
|
38
40
|
|
39
|
-
|
41
|
+
gem 'some_other_dependency', '= 1.1.9' # somewhere inside it
|
40
42
|
|
41
|
-
|
43
|
+
then this system won't help, because it will be forced to load full rubygems at that point.
|
42
44
|
|
43
|
-
|
45
|
+
You can find out by running it once. If it fails then reinstall the gem in question to get back to its original functionality.
|
44
46
|
|
45
|
-
|
47
|
+
Current problems:
|
46
48
|
|
47
|
-
|
49
|
+
Currently it only works for executables named the same thing as their gem is, ex:
|
50
|
+
redcar's bin/redcar works
|
51
|
+
redcar's bin/cucumber does not.
|
48
52
|
|
49
|
-
|
53
|
+
Try it out and see. If it fails then reinstall the gem in question to get back to its original functionality.
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
data/bin/faster_gem_script
CHANGED
@@ -2,8 +2,9 @@
|
|
2
2
|
require 'faster_gem_scripts'
|
3
3
|
if ARGV.length == 1
|
4
4
|
FasterGemScripts.overwrite ARGV[0]
|
5
|
+
puts 'clearing caches because of new gem install'
|
5
6
|
else
|
6
7
|
puts 'syntax: script_name_to_optimize (clears caches either way)'
|
7
8
|
end
|
9
|
+
FasterGemScripts.clear_caches!
|
8
10
|
|
9
|
-
FasterGemScripts.clear_caches!
|
data/lib/faster_gem_scripts.rb
CHANGED
@@ -1,27 +1,25 @@
|
|
1
|
+
require 'sane'
|
1
2
|
|
2
3
|
class FasterGemScripts
|
4
|
+
|
3
5
|
def self.overwrite full_path
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
contents_should_be = File.read File.dirname(__FILE__) + '/template'
|
7
|
+
if File.file?(full_path)
|
8
|
+
puts 'faster_gem_scripts: optimizing ' + full_path + '...'
|
9
|
+
File.open(full_path, 'wb') do |f| f.write(contents_should_be); end
|
10
|
+
bin_loc = full_path + '_bin_location'
|
11
|
+
File.delete(bin_loc) if File.exist?(bin_loc)
|
12
|
+
else
|
13
|
+
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)"
|
14
|
+
end
|
13
15
|
end
|
14
16
|
|
15
17
|
def self.clear_caches!
|
16
|
-
|
17
|
-
bin_dir = Gem.ruby.split('/')[0..-2].join('/') # strip off ruby.exe
|
18
|
-
require 'ruby-debug'
|
19
|
-
# debugger
|
18
|
+
bin_dir = File.dirname(OS.ruby_bin)
|
20
19
|
Dir[bin_dir + '/*_bin_location'].each{|file|
|
21
|
-
puts 'faster_gem_scripts clearing cached file ' + file
|
20
|
+
puts 'faster_gem_scripts clearing previously cached file ' + file
|
22
21
|
File.delete file
|
23
|
-
|
24
|
-
|
22
|
+
}
|
25
23
|
end
|
26
24
|
|
27
25
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Gem.post_install { |gem_installer_instance|
|
2
|
+
puts 'clearing faster_gem script because of install'
|
3
|
+
require 'faster_gem_scripts'
|
4
|
+
FasterGemScripts.clear_caches!
|
5
|
+
|
6
|
+
|
7
|
+
# all = gem_installer_instance.spec.files.select{|file| file =~ /^bin/ }
|
8
|
+
# bin_dir = Gem.ruby.split('/')[0..-3].join('/')
|
9
|
+
# if all.length > 0
|
10
|
+
# FasterGemScripts.clear_caches!
|
11
|
+
# all.each{|script_name|
|
12
|
+
# name = bin_dir + '/' + script_name
|
13
|
+
# FasterGemScripts.overwrite name
|
14
|
+
# }
|
15
|
+
# end
|
16
|
+
}
|
17
|
+
|
18
|
+
Gem.post_uninstall { |gem_installer_instance|
|
19
|
+
if (gem_installer_instance.spec.files.select{|file| file =~ /^bin/ }.length > 0)
|
20
|
+
puts 'clearing faster_gem script because of uninstall'
|
21
|
+
require 'faster_gem_scripts'
|
22
|
+
FasterGemScripts.clear_caches!
|
23
|
+
end
|
24
|
+
}
|
@@ -25,7 +25,7 @@ describe "rewriter" do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should clear olds on request" do
|
28
|
-
old_file = File.dirname(OS.ruby_bin) + '/yo_bin_location'
|
28
|
+
old_file = File.dirname(OS.ruby_bin) + '/yo_bin_location'
|
29
29
|
FileUtils.touch old_file
|
30
30
|
ARGV << 'yoyo'
|
31
31
|
load __dir__ + '/../bin/faster_gem_script'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faster_gem_script
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 2
|
10
|
+
version: 0.3.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Roger Pack
|
@@ -16,7 +16,7 @@ bindir: bin
|
|
16
16
|
cert_chain: []
|
17
17
|
|
18
18
|
date: 2010-06-07 00:00:00 -06:00
|
19
|
-
default_executable:
|
19
|
+
default_executable: faster_gem_script
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: sane
|
@@ -66,7 +66,6 @@ description:
|
|
66
66
|
email: rogerdpack@gmail.com
|
67
67
|
executables:
|
68
68
|
- faster_gem_script
|
69
|
-
- yo_bin_location
|
70
69
|
extensions:
|
71
70
|
- ext/mkrf_conf.rb
|
72
71
|
extra_rdoc_files:
|
@@ -78,10 +77,9 @@ files:
|
|
78
77
|
- bin/faster_gem_script
|
79
78
|
- ext/mkrf_conf.rb
|
80
79
|
- lib/faster_gem_scripts.rb
|
81
|
-
- lib/rubygems_plugin.rb
|
80
|
+
- lib/rubygems_plugin.rb
|
82
81
|
- lib/template
|
83
82
|
- spec/spec.faster_gem_scripts.rb
|
84
|
-
- bin/yo_bin_location
|
85
83
|
has_rdoc: true
|
86
84
|
homepage: http://github.com/rdp/faster_gem_scripts
|
87
85
|
licenses: []
|
data/bin/yo_bin_location
DELETED
File without changes
|
@@ -1,18 +0,0 @@
|
|
1
|
-
Gem.post_install { |gem_installer_instance|
|
2
|
-
require 'faster_gem_scripts'
|
3
|
-
all = gem_installer_instance.spec.files.select{|file| file =~ /^bin/ }
|
4
|
-
bin_dir = Gem.ruby.split('/')[0..-3].join('/')
|
5
|
-
if all.length > 0
|
6
|
-
FasterGemScripts.clear_caches!
|
7
|
-
all.each{|script_name|
|
8
|
-
name = bin_dir + '/' + script_name
|
9
|
-
FasterGemScripts.overwrite name
|
10
|
-
}
|
11
|
-
end
|
12
|
-
}
|
13
|
-
|
14
|
-
Gem.post_uninstall { |gem_installer_instance|
|
15
|
-
require 'faster_gem_scripts'
|
16
|
-
require 'sane'
|
17
|
-
FasterGemScripts.clear_caches! if (gem_installer_instance.spec.files.select{|file| file =~ /^bin/ }.length > 0)
|
18
|
-
}
|