bootscale 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d7cebced958f11c9be28bed53c94d90a051fc374
4
+ data.tar.gz: 14597c1da5e6bd2650dff3f53725c4169e9ba18e
5
+ SHA512:
6
+ metadata.gz: 173f3e377dbff8eb4cd036daf341196a3f09f4c0a1c3ae0a461cd8d57deaac6ea43b594f79eb351e84e2410a805fd7d67919a92810e78f4879b8077bbab84e68
7
+ data.tar.gz: bd0a0ad17b6b55db54c32fba1181d45e2e4734dc22799e50d350fd7b7cb69dae0a2b1c22fd50b6b85667256797f5a0087c6103683a86efb5d005671393dd5ef6
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'bundler'
6
+ gem 'rake'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Jean Boussier
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,48 @@
1
+ # Bootscale
2
+
3
+ Speedup applications boot by caching require calls
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'bootscale', require: false
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Then you need to add `require 'bootscale'` right after `require 'bundler/setup'`.
18
+ If your application is a Rails application, you will find this in `config/boot.rb`.
19
+
20
+ ### Important
21
+
22
+ You must regenerate the cache everytime `$LOAD_PATH` is modified by calling `Bootscale.regenerate`.
23
+
24
+ For Rails apps it means adding an initializer in `config/application.rb`:
25
+
26
+ ```ruby
27
+ module MyApp
28
+ class Application < Rails::Application
29
+ initializer :regenerate_require_cache, after: :set_load_path do
30
+ Bootscale.regenerate
31
+ end
32
+ end
33
+ end
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ Just install it that's all!
39
+
40
+ ## How much faster is it?
41
+
42
+ It totally depends on your number of gems. Under 100 gems you likely won't see the difference,
43
+ but for bigger applications (300+ gems) it can make the application boot up to 30% faster.
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/byroot/bootscale.
48
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bootscale"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/bootscale.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bootscale/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'bootscale'
8
+ spec.version = Bootscale::VERSION
9
+ spec.authors = ['Jean Boussier']
10
+ spec.email = ['jean.boussier@gmail.com']
11
+
12
+ spec.summary = %q{Speedup applications boot by caching require calls}
13
+ spec.description = %q{Inspired by Aaron Patterson's talk on the subject}
14
+ spec.homepage = "https://github.com/byroot/bootscale"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+ spec.required_ruby_version = '>= 1.9.3'
21
+ end
data/lib/bootscale.rb ADDED
@@ -0,0 +1,21 @@
1
+ require_relative 'bootscale/version'
2
+ require_relative 'bootscale/entry'
3
+ require_relative 'bootscale/cache'
4
+
5
+ module Bootscale
6
+ class << self
7
+ def [](path)
8
+ cache[path.to_s] || path
9
+ end
10
+
11
+ def regenerate
12
+ cache.regenerate
13
+ end
14
+
15
+ def cache
16
+ @cache ||= Cache.new
17
+ end
18
+ end
19
+ end
20
+
21
+ require_relative 'bootscale/setup'
@@ -0,0 +1,25 @@
1
+ require 'benchmark'
2
+
3
+ module Bootscale
4
+ class Cache
5
+ attr_reader :entries
6
+
7
+ def initialize
8
+ @entries = {}
9
+ regenerate
10
+ end
11
+
12
+ def [](path)
13
+ if path.end_with?(DOT_RB) || path.end_with?(DOT_SO)
14
+ @cache[path]
15
+ else
16
+ @cache["#{path}#{DOT_RB}"] || @cache["#{path}#{DOT_SO}"]
17
+ end
18
+ end
19
+
20
+ def regenerate
21
+ ordered_entries = $LOAD_PATH.map { |path| entries.fetch(path) { Entry.new(path) } }
22
+ @cache = Hash[ordered_entries.reverse.flat_map(&:features)]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,37 @@
1
+ module Bootscale
2
+ DL_EXTENSIONS = [
3
+ RbConfig::CONFIG['DLEXT'],
4
+ RbConfig::CONFIG['DLEXT2'],
5
+ ].reject(&:empty?).map { |ext| ".#{ext}"}
6
+
7
+ DOT_SO = '.so'.freeze
8
+ DOT_RB = '.rb'.freeze
9
+
10
+ class Entry
11
+ FEATURE_FILES = "**/*{#{DOT_RB},#{DL_EXTENSIONS.join(',')}}"
12
+ NORMALIZE_NATIVE_EXTENSIONS = !DL_EXTENSIONS.include?(DOT_SO)
13
+ ALTERNATIVE_NATIVE_EXTENSIONS_PATTERN = /\.(o|bundle|dylib)\z/
14
+
15
+ attr_reader :path, :features
16
+
17
+ def initialize(path)
18
+ @path = path
19
+ @path_prefix = path.end_with?('/'.freeze) ? path : "#{path}/"
20
+ @features = list_features
21
+ end
22
+
23
+ private
24
+
25
+ def list_features
26
+ Dir[File.join(path, FEATURE_FILES)].map do |absolute_path|
27
+ relative_path = absolute_path.sub(@path_prefix, ''.freeze)
28
+
29
+ if NORMALIZE_NATIVE_EXTENSIONS
30
+ relative_path.sub!(ALTERNATIVE_NATIVE_EXTENSIONS_PATTERN, DOT_SO)
31
+ end
32
+
33
+ [relative_path, absolute_path]
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,26 @@
1
+ module Kernel
2
+ def require_with_cache(path)
3
+ require_without_cache(Bootscale[path])
4
+ end
5
+
6
+ alias_method :require_without_cache, :require
7
+ alias_method :require, :require_with_cache
8
+ end
9
+
10
+ class << Kernel
11
+ def require_with_cache(path)
12
+ require_without_cache(Bootscale[path])
13
+ end
14
+
15
+ alias_method :require_without_cache, :require
16
+ alias_method :require, :require_with_cache
17
+ end
18
+
19
+ class Module
20
+ def autoload_with_cache(const, path)
21
+ autoload_without_cache(const, Bootscale[path])
22
+ end
23
+
24
+ alias_method :autoload_without_cache, :autoload
25
+ alias_method :autoload, :autoload_with_cache
26
+ end
@@ -0,0 +1,3 @@
1
+ module Bootscale
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bootscale
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jean Boussier
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-23 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Inspired by Aaron Patterson's talk on the subject
14
+ email:
15
+ - jean.boussier@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - Gemfile
22
+ - LICENSE.txt
23
+ - README.md
24
+ - Rakefile
25
+ - bin/console
26
+ - bin/setup
27
+ - bootscale.gemspec
28
+ - lib/bootscale.rb
29
+ - lib/bootscale/cache.rb
30
+ - lib/bootscale/entry.rb
31
+ - lib/bootscale/setup.rb
32
+ - lib/bootscale/version.rb
33
+ homepage: https://github.com/byroot/bootscale
34
+ licenses: []
35
+ metadata: {}
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 1.9.3
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 2.4.6
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: Speedup applications boot by caching require calls
56
+ test_files: []