gem_bench 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gem_bench.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Peter Boling
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,120 @@
1
+ # GemBench
2
+
3
+ Gem: "Put me in coach!"
4
+ You: ❨╯°□°❩╯︵┻━┻
5
+
6
+ `gem_bench` is the super easy way to trim down app load times by keeping your worst players on the bench.
7
+
8
+ It is a fact of RubyGems that many of them do not need to be loaded by your app at boot time.
9
+ It is a fact of Bundler that you don't know which ones need to be 'required' while staring at the Gemfile.
10
+ It is a fact of Heroku that you only have 60 precious seconds to get your app loaded before ❨╯°□°❩╯︵┻━┻
11
+
12
+ This gem helps by telling you which gems are being loaded during app boot that don't need to be.
13
+
14
+ ## Installation
15
+
16
+ You **DO NOT** need to add this gem to your project.
17
+
18
+ ### Option 1
19
+
20
+ Just install it, and require it in your`irb`/`console` session when you want to use it.
21
+
22
+ $ gem install gem_bench
23
+
24
+
25
+ ### Option 2
26
+
27
+ If you decide to include it in your project: add this line to your Gemfile in the development group:
28
+
29
+ gem 'gem_bench', :require => false, :group => :development
30
+
31
+ And then execute:
32
+
33
+ $ bundle
34
+
35
+
36
+ ## Usage
37
+
38
+ Fire up ab `irb` session or a `rails console` and then:
39
+
40
+ >> require 'gem_bench'
41
+ => true
42
+ >> team = GemBench.check(true) # true => print output, false => just returns a GemBench::Team object you can inspect.
43
+
44
+ Here is an example `irb` session where I have installed only `gem_bench`, `rails`, and `bundler`. For the first run I don't require any gems besides `gem_bench`.
45
+
46
+ ∴ irb
47
+ >> require 'gem_bench'
48
+ => true
49
+ >> team = GemBench.check(true) # true => print output, false => just returns a GemBench::Team object you can inspect.
50
+ [GemBench] will search for gems in ["/Users/pboling/.rvm/gems/ruby-1.9.3-head@foss/gems", "/Users/pboling/.rvm/gems/ruby-1.9.3-head@global/gems", "/Users/pboling/.rvm/gems/ruby-1.9.3-head@foss/bundler/gems"]
51
+ [GemBench] detected 0 loaded gems (2 will be skipped by GemBench)
52
+ [GemBench] Found no gems to load at boot.
53
+ [GemBench] 0 gems to skip require in Gemfile (require => false):
54
+ => #<GemBench::Team:0x007fd4451207c0 @paths=["/Users/pboling/.rvm/gems/ruby-1.9.3-head@foss/gems", "/Users/pboling/.rvm/gems/ruby-1.9.3-head@global/gems", "/Users/pboling/.rvm/gems/ruby-1.9.3-head@foss/bundler/gems"], @excluded=[["bundler", "1.2.3"], ["gem_bench", "0.0.1"]], @all=[], @starters=[], @benchers=[], @verbose=true>
55
+
56
+ For the second run I require rails, and now I can see which rails dependencies are not required at boot time:
57
+
58
+ >> require 'rails'
59
+ => true
60
+ >> team = GemBench.check(true)
61
+ [GemBench] will search for gems in ["/Users/pboling/.rvm/gems/ruby-1.9.3-head@foss/gems", "/Users/pboling/.rvm/gems/ruby-1.9.3-head@global/gems", "/Users/pboling/.rvm/gems/ruby-1.9.3-head@foss/bundler/gems"]
62
+ [GemBench] detected 14 loaded gems (2 will be skipped by GemBench)
63
+ You might want to verify that activesupport v3.2.13 really has a Railtie (or Rails::Engine). Check here:
64
+ ["/Users/pboling/.rvm/gems/ruby-1.9.3-head@foss/gems/activesupport-3.2.11/lib/active_support/i18n_railtie.rb", 146]
65
+ You might want to verify that actionpack v3.2.13 really has a Railtie (or Rails::Engine). Check here:
66
+ ["/Users/pboling/.rvm/gems/ruby-1.9.3-head@foss/gems/actionpack-3.2.11/lib/action_controller/railtie.rb", 248]
67
+ You might want to verify that railties v3.2.13 really has a Railtie (or Rails::Engine). Check here:
68
+ ["/Users/pboling/.rvm/gems/ruby-1.9.3-head@foss/gems/railties-3.2.11/lib/rails/application/configuration.rb", 245]
69
+ [GemBench] 3 gems to load at boot:
70
+ [GemBench] If you want to check for false positives, the files to check for Railties and Engines are listed above:
71
+ gem 'activesupport', '~> 3.2.13'
72
+ gem 'actionpack', '~> 3.2.13'
73
+ gem 'railties', '~> 3.2.13'
74
+ [GemBench] 11 gems to skip require in Gemfile (require => false):
75
+ gem 'i18n', :require => false, '~> 0.6.1'
76
+ gem 'builder', :require => false, '~> 3.0.4'
77
+ gem 'activemodel', :require => false, '~> 3.2.13'
78
+ gem 'rack-cache', :require => false, '~> 1.2'
79
+ gem 'rack', :require => false, '~> 1.4.5'
80
+ gem 'rack-test', :require => false, '~> 0.6.2'
81
+ gem 'journey', :require => false, '~> 1.0.4'
82
+ gem 'hike', :require => false, '~> 1.2.1'
83
+ gem 'tilt', :require => false, '~> 1.3.3'
84
+ gem 'sprockets', :require => false, '~> 2.2.2'
85
+ gem 'erubis', :require => false, '~> 2.7.0'
86
+
87
+ See that? Lots of those gems that rails brings don't need to be required when your app boots!
88
+
89
+ ## Contributing
90
+
91
+ 1. Fork it
92
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
93
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
94
+ 4. Push to the branch (`git push origin my-new-feature`)
95
+ 5. Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
96
+ 6. Create new Pull Request
97
+
98
+ ## Versioning
99
+
100
+ This library aims to adhere to [Semantic Versioning 2.0.0][semver].
101
+ Violations of this scheme should be reported as bugs. Specifically,
102
+ if a minor or patch version is released that breaks backward
103
+ compatibility, a new version should be immediately released that
104
+ restores compatibility. Breaking changes to the public API will
105
+ only be introduced with new major versions.
106
+
107
+ As a result of this policy, you can (and should) specify a
108
+ dependency on this gem using the [Pessimistic Version Constraint][pvc] with two digits of precision.
109
+
110
+ For example:
111
+
112
+ spec.add_dependency 'gem_bench', '~> 0.0'
113
+
114
+ [semver]: http://semver.org/
115
+ [pvc]: http://docs.rubygems.org/read/chapter/16#page74
116
+
117
+ ## Legal
118
+
119
+ * MIT License
120
+ * Copyright (c) 2013 [Peter H. Boling](http://www.railsbling.com), and Acquaintable [http://acquaintable.com/]
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/gem_bench.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gem_bench/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "gem_bench"
8
+ gem.version = GemBench::VERSION
9
+ gem.authors = ["Peter Boling"]
10
+ gem.email = ["peter.boling@gmail.com"]
11
+ gem.description = %q{trim down app load times by keeping your worst players on the bench}
12
+ gem.summary = %q{Gem: "Put me in coach"
13
+ You: ❨╯°□°❩╯︵┻━┻}
14
+ gem.homepage = "http://github.com/acquaintable/gem_bench"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_runtime_dependency(%q<bundler>, ["> 1.2"])
22
+ gem.add_development_dependency( 'gem-release' )
23
+
24
+ end
@@ -0,0 +1,49 @@
1
+ module GemBench
2
+ class Player
3
+
4
+ DO_NOT_SCAN = []
5
+
6
+ attr_accessor :name, :version, :state, :stats
7
+
8
+ def initialize(options = {})
9
+ @name = options[:name]
10
+ @version = options[:version]
11
+ @state = nil
12
+ @stats = []
13
+ end
14
+
15
+ def path_glob
16
+ "#{self.name}*/lib/**/*.rb"
17
+ end
18
+
19
+ def set_starter(file_path)
20
+ scan = begin
21
+ if DO_NOT_SCAN.include? self.name
22
+ false
23
+ else
24
+ File.read(file_path) =~ /Rails::Engine|Rails::Railtie/
25
+ end
26
+ end
27
+ self.stats << [file_path,scan] if scan
28
+ self.state = !!scan ?
29
+ 'starter' :
30
+ 'bench'
31
+ end
32
+
33
+ def starter?
34
+ self.state == 'starter'
35
+ end
36
+
37
+ def to_s
38
+ "#{self.name} v#{self.version}"
39
+ end
40
+
41
+ def how
42
+ case state
43
+ when 'starter' then "gem '#{self.name}', '~> #{self.version}'"
44
+ when 'bench' then "gem '#{self.name}', :require => false, '~> #{self.version}'"
45
+ else "I'm not sure where I am."
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,84 @@
1
+ module GemBench
2
+ class Team
3
+
4
+ EXCLUDE = ['bundler','gem_bench']
5
+
6
+ attr_accessor :paths, :all, :excluded, :starters, :benchers, :verbose
7
+
8
+ def initialize(verbose = false)
9
+ #>> Bundler.install_path
10
+ #=> #<Pathname:/Users/pboling/.rvm/gems/ruby-1.9.3-head@foss/bundler/gems>
11
+ #>> Bundler.bundle_path
12
+ #=> #<Pathname:/Users/pboling/.rvm/gems/ruby-1.9.3-head@foss>
13
+ possibles = [Bundler.rubygems.gem_dir, Bundler.rubygems.gem_path]
14
+ @paths = possibles.flatten.compact.uniq.map {|x| x.to_s }.reject { |p| p.empty? }.map {|x| "#{x}/gems" }
15
+ self.paths << "#{Bundler.install_path}"
16
+ self.paths << "#{Bundler.bundle_path}/gems"
17
+ self.paths.uniq!
18
+ puts "[GemBench] will search for gems in #{self.paths.inspect}"
19
+ # Gem.loaded_specs are the gems that have been loaded / required.
20
+ # Among these there may be some that did not need to be.
21
+ totes = Gem.loaded_specs.values.map {|x| [x.name, x.version.to_s] }
22
+ @excluded, @all = totes.partition {|x| EXCLUDE.include?(x[0]) }
23
+ puts "[GemBench] detected #{self.all.length} loaded gems (#{self.excluded.length} will be skipped by GemBench)"
24
+ @starters = []
25
+ @benchers = []
26
+ @verbose = verbose
27
+ self.check_all
28
+ self.print if self.verbose
29
+ end
30
+
31
+ def print
32
+ string = ''
33
+ if self.starters.empty?
34
+ string << "[GemBench] Found no gems to load at boot.\n"
35
+ else
36
+ self.starters.each do |starter|
37
+ string << "You might want to verify that #{starter} really has a Railtie (or Rails::Engine). Check here:\n"
38
+ starter.stats.each do |stat|
39
+ string << "\t#{stat}\n"
40
+ end
41
+ end
42
+ string << "[GemBench] #{self.starters.length} gems to load at boot:\n"
43
+ string << "[GemBench] If you want to check for false positives, the files to check for Railties and Engines are listed above:\n"
44
+ self.starters.each do |starter|
45
+ string << "\t#{starter.how}\n"
46
+ end
47
+ end
48
+ string << "[GemBench] #{self.benchers.length} gems to skip require in Gemfile (require => false):\n"
49
+ self.benchers.each do |starter|
50
+ string << "\t#{starter.how}\n"
51
+ end
52
+ puts string
53
+ end
54
+
55
+ def check_all
56
+ self.all.each do |player_data|
57
+ player = GemBench::Player.new({name: player_data[0], version: player_data[1]})
58
+ self.check(player)
59
+ self.add_to_roster(player)
60
+ end
61
+ end
62
+
63
+ def check(player)
64
+ self.paths.each do |path|
65
+ glob_path = "#{path}/#{player.path_glob}"
66
+ file_paths = Dir.glob("#{glob_path}")
67
+ puts "[GemBench] checking #{player} at #{glob_path} (#{file_paths.length} files)" if self.verbose == 'extra'
68
+ file_paths.each do |file_path|
69
+ player.set_starter(file_path)
70
+ return if player.starter?
71
+ end
72
+ end
73
+ end
74
+
75
+ def add_to_roster(player)
76
+ if player.starter?
77
+ self.starters << player
78
+ else
79
+ self.benchers << player
80
+ end
81
+ end
82
+
83
+ end
84
+ end
@@ -0,0 +1,3 @@
1
+ module GemBench
2
+ VERSION = "0.0.1"
3
+ end
data/lib/gem_bench.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'bundler' # This gem utilizes bundler as a tool.
2
+ require 'gem_bench/version'
3
+ require 'gem_bench/team'
4
+ require 'gem_bench/player'
5
+
6
+ module GemBench
7
+
8
+ class << self
9
+ attr_accessor :roster
10
+ def check(verbose = false)
11
+ @roster = GemBench::Team.new(verbose)
12
+ end
13
+ end
14
+
15
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem_bench
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Peter Boling
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>'
20
+ - !ruby/object:Gem::Version
21
+ version: '1.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>'
28
+ - !ruby/object:Gem::Version
29
+ version: '1.2'
30
+ - !ruby/object:Gem::Dependency
31
+ name: gem-release
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: trim down app load times by keeping your worst players on the bench
47
+ email:
48
+ - peter.boling@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - gem_bench.gemspec
59
+ - lib/gem_bench.rb
60
+ - lib/gem_bench/player.rb
61
+ - lib/gem_bench/team.rb
62
+ - lib/gem_bench/version.rb
63
+ homepage: http://github.com/acquaintable/gem_bench
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 1.8.24
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: ! 'Gem: "Put me in coach" You: ❨╯°□°❩╯︵┻━┻'
87
+ test_files: []