fast_require 0.0.0
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 +0 -0
- data/Rakefile +11 -0
- data/TODO.LIST +8 -0
- data/VERSION +1 -0
- data/lib/fast_require.rb +63 -0
- data/spec/files/a_requires_b.rb +1 -0
- data/spec/files/b.rb +6 -0
- data/spec/files/c.rb +5 -0
- data/spec/files/fast.rb +3 -0
- data/spec/files/slow.rb +3 -0
- data/spec/spec.fast_require.rb +95 -0
- metadata +89 -0
data/README
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'jeweler'
|
2
|
+
Jeweler::Tasks.new do |s|
|
3
|
+
s.name = "fast_require"
|
4
|
+
s.summary = "A tool designed to speedup library loading in Ruby by caching library locations"
|
5
|
+
s.email = "rogerdpack@gmail.com"
|
6
|
+
s.homepage = "http://github.com/rdp/fast_ruby_require"
|
7
|
+
s.authors = ["Roger Pack"]
|
8
|
+
s.add_development_dependency 'rspec'
|
9
|
+
s.add_development_dependency 'sane'
|
10
|
+
# s.add_dependency
|
11
|
+
end
|
data/TODO.LIST
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
irb(main):001:0> $LOADED_FEATURES << 'abc.rb'
|
2
|
+
=> ["enumerator.so", "E:/installs/ruby191p376/lib/ruby/1.9.1/i386-mingw32/enc/encdb.so", "E:/installs/ruby191p376/lib/ruby/1.9.1/i386-mingw32/enc/trans/transdb.so", "E:/installs/ruby191p376/lib/ruby/1.9.1/i386-mingw32/enc/iso_8859_1.so", "E:/installs/ruby191p376/lib/ruby/1.9.1/rubygems.rb", "E:/installs/ruby191p376/lib/ruby/gems/1.9.1/gems/faster_rubygems-0.1.0/lib/faster_rubygems.rb", "E:/installs/ruby191p376/lib/ruby/gems/1.9.1/gems/faster_rubygems-0.1.0/lib/ubygemsf.rb", "E:/installs/ruby191p376/lib/ruby/1.9.1/i386-mingw32/rbconfig.rb", "E:/installs/ruby191p376/lib/ruby/gems/1.9.1/gems/backtracer-0.7.2/lib/shared.rb", "E:/installs/ruby191p376/lib/ruby/gems/1.9.1/gems/backtracer-0.7.2/lib/backtracer.rb", "E:/installs/ruby191p376/lib/ruby/1.9.1/e2mmap.rb", "E:/installs/ruby191p376/lib/ruby/1.9.1/irb/init.rb", "E:/installs/ruby191p376/lib/ruby/1.9.1/irb/workspace.rb", "E:/installs/ruby191p376/lib/ruby/1.9.1/irb/context.rb", "E:/installs/ruby191p376/lib/ruby/1.9.1/irb/extend-command.rb", "E:/installs/ruby191p376/lib/ruby/1.9.1/irb/output-method.rb", "E:/installs/ruby191p376/lib/ruby/1.9.1/irb/notifier.rb", "E:/installs/ruby191p376/lib/ruby/1.9.1/irb/slex.rb", "E:/installs/ruby191p376/lib/ruby/1.9.1/irb/ruby-token.rb", "E:/installs/ruby191p376/lib/ruby/1.9.1/irb/ruby-lex.rb", "E:/installs/ruby191p376/lib/ruby/1.9.1/irb/src_encoding.rb", "E:/installs/ruby191p376/lib/ruby/1.9.1/irb/magic-file.rb", "E:/installs/ruby191p376/lib/ruby/1.9.1/i386-mingw32/enc/euc_jp.so", "E:/installs/ruby191p376/lib/ruby/1.9.1/i386-mingw32/enc/shift_jis.so", "E:/installs/ruby191p376/lib/ruby/1.9.1/i386-mingw32/etc.so", "E:/installs/ruby191p376/lib/ruby/1.9.1/i386-mingw32/dl.so", "E:/installs/ruby191p376/lib/ruby/site_ruby/1.9.1/rbreadline.rb", "E:/installs/ruby191p376/lib/ruby/site_ruby/1.9.1/readline.rb", "E:/installs/ruby191p376/lib/ruby/1.9.1/irb/input-method.rb", "E:/installs/ruby191p376/lib/ruby/1.9.1/irb/locale.rb", "E:/installs/ruby191p376/lib/ruby/1.9.1/irb.rb", "abc.rb"]
|
3
|
+
irb(main):002:0> require 'abc'
|
4
|
+
=> false
|
5
|
+
|
6
|
+
this could be optimized more for 1.9
|
7
|
+
|
8
|
+
Also, could loaded_features be made into a hash for much faster comparison?
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/lib/fast_require.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
module FastRequire
|
2
|
+
|
3
|
+
@@loc = File.expand_path('~/.ruby_fast_require_location')
|
4
|
+
if File.exist? (@@loc)
|
5
|
+
@@require_locs = Marshal.restore( File.open(@@loc, 'rb') {|f| f.read})
|
6
|
+
else
|
7
|
+
@@require_locs = {}
|
8
|
+
end
|
9
|
+
@@already_loaded = {}
|
10
|
+
$LOADED_FEATURES.each{|loaded| @@already_loaded[loaded] = true}
|
11
|
+
|
12
|
+
at_exit {
|
13
|
+
FastRequire.save
|
14
|
+
}
|
15
|
+
|
16
|
+
def self.save
|
17
|
+
File.open(@@loc, 'wb'){|f| f.write Marshal.dump(@@require_locs)}
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.clear!
|
21
|
+
require 'fileutils'
|
22
|
+
FileUtils.rm @@loc if File.exist? @@loc
|
23
|
+
@@require_locs.clear
|
24
|
+
end
|
25
|
+
|
26
|
+
def require_cached lib
|
27
|
+
if a = @@require_locs[lib]
|
28
|
+
return if @@already_loaded[a]
|
29
|
+
@@already_loaded[a] = true
|
30
|
+
if a =~ /.so$/
|
31
|
+
puts 'doing original require on full path' if $DEBUG
|
32
|
+
original_non_cached_require a # not much we can do there...too bad...
|
33
|
+
else
|
34
|
+
puts 'doing eval on ' + lib + '=>' + a if $DEBUG
|
35
|
+
eval(File.open(a, 'rb') {|f| f.read}, TOPLEVEL_BINDING, a) # note the b here--this means it's reading .rb files as binary, which *typically* works--if it breaks re-save the offending file in binary mode...
|
36
|
+
$LOADED_FEATURES << a
|
37
|
+
end
|
38
|
+
else
|
39
|
+
old = $LOADED_FEATURES.dup
|
40
|
+
if(original_non_cached_require lib)
|
41
|
+
new = $LOADED_FEATURES - old
|
42
|
+
@@require_locs[lib] = new.last
|
43
|
+
puts 'found new loc:' + lib + '=>' + @@require_locs[lib] if $DEBUG
|
44
|
+
@@already_loaded[@@require_locs[lib]] = true
|
45
|
+
end# how could this fail, though...
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
module Kernel
|
52
|
+
|
53
|
+
if(defined?(@already_using_fast_require))
|
54
|
+
raise 'cant require it twice...'
|
55
|
+
else
|
56
|
+
@already_using_fast_require = true
|
57
|
+
end
|
58
|
+
|
59
|
+
include FastRequire
|
60
|
+
# overwrite require...
|
61
|
+
alias :original_non_cached_require :require
|
62
|
+
alias :require :require_cached
|
63
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'b'
|
data/spec/files/b.rb
ADDED
data/spec/files/c.rb
ADDED
data/spec/files/fast.rb
ADDED
data/spec/files/slow.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'faster_rubygems' if RUBY_VERSION < '1.9'
|
2
|
+
require_relative '../lib/fast_require'
|
3
|
+
require 'sane'
|
4
|
+
require 'spec/autorun'
|
5
|
+
require 'benchmark'
|
6
|
+
require 'spec/adapters/mock_frameworks/rspec'
|
7
|
+
#require 'ruby-debug'
|
8
|
+
|
9
|
+
#assert !defined?(FastRequire) # so that we can loadup our unit tests sanely, using the old way LOL.
|
10
|
+
require_relative '../lib/fast_require'
|
11
|
+
|
12
|
+
describe "faster requires" do
|
13
|
+
|
14
|
+
def with_file(filename = 'test')
|
15
|
+
FileUtils.touch filename + '.rb'
|
16
|
+
yield
|
17
|
+
FileUtils.rm filename + '.rb'
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should be able to go one deep" do
|
21
|
+
Dir.chdir('files') do
|
22
|
+
assert require 'c'
|
23
|
+
assert !(require 'c')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should be able to go two deep, and once only" do
|
28
|
+
Dir.chdir('files') do
|
29
|
+
assert(require 'a_requires_b')
|
30
|
+
assert !(require 'a_requires_b')
|
31
|
+
assert !(require 'a_requires_b')
|
32
|
+
$b.should == 1
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should be faster" do
|
37
|
+
Dir.chdir('files') do
|
38
|
+
#slow = Benchmark.realtime { system("#{OS.ruby_bin} slow.rb")}
|
39
|
+
#Benchmark.realtime { system("#{OS.ruby_bin} fast.rb")} # warmup
|
40
|
+
#fast = Benchmark.realtime { system("#{OS.ruby_bin} fast.rb")}
|
41
|
+
#pps 'fast', fast, 'slow', slow
|
42
|
+
#assert fast*2 < slow
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should not save if it hasn't changed"
|
47
|
+
it "should cache when requires have already been done instead of calling require on them again"
|
48
|
+
it "should know which requires are currently active and avoid calling require on them again"
|
49
|
+
|
50
|
+
it "should have different based on $0"
|
51
|
+
|
52
|
+
|
53
|
+
it "should do two of the same requires" do
|
54
|
+
with_file('test') do
|
55
|
+
assert(require 'test')
|
56
|
+
assert(!(require 'test'))
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
before do # each
|
61
|
+
#FastRequire.clear!
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
it "should require files still" do
|
66
|
+
with_file('file1') { require 'file1'}
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should require .so files still" do
|
70
|
+
# ruby-prof gem
|
71
|
+
2.times { require 'ruby_prof' } # .so
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should add them to $LOADED_FEATURES" do
|
75
|
+
with_file('file2') {require 'file2'}
|
76
|
+
assert ($LOADED_FEATURES.grep(/file2.rb/)).length > 0
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should work with and without rubygems, esp. in 1.8" do
|
80
|
+
# run these tests in 1.8...hmm...
|
81
|
+
# maybe with and
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should have a faster require method--faster, my friend, faster!"
|
85
|
+
|
86
|
+
it "should save a file" do
|
87
|
+
#FastRequire.clear!
|
88
|
+
loc = File.expand_path('~/.ruby_fast_require_location')
|
89
|
+
assert !File.exist?(loc)
|
90
|
+
FastRequire.save
|
91
|
+
assert File.exist?(loc)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should override the gem method"
|
95
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fast_require
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Roger Pack
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-18 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: sane
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
description:
|
36
|
+
email: rogerdpack@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README
|
43
|
+
files:
|
44
|
+
- README
|
45
|
+
- Rakefile
|
46
|
+
- TODO.LIST
|
47
|
+
- VERSION
|
48
|
+
- lib/fast_require.rb
|
49
|
+
- spec/files/a_requires_b.rb
|
50
|
+
- spec/files/b.rb
|
51
|
+
- spec/files/c.rb
|
52
|
+
- spec/files/fast.rb
|
53
|
+
- spec/files/slow.rb
|
54
|
+
- spec/spec.fast_require.rb
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://github.com/rdp/fast_ruby_require
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options:
|
61
|
+
- --charset=UTF-8
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
version:
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: "0"
|
75
|
+
version:
|
76
|
+
requirements: []
|
77
|
+
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.3.5
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: A tool designed to speedup library loading in Ruby by caching library locations
|
83
|
+
test_files:
|
84
|
+
- spec/files/a_requires_b.rb
|
85
|
+
- spec/files/b.rb
|
86
|
+
- spec/files/c.rb
|
87
|
+
- spec/files/fast.rb
|
88
|
+
- spec/files/slow.rb
|
89
|
+
- spec/spec.fast_require.rb
|