bootscale 0.2.2 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c56e07c9b3e01042644446a19d693a986849686
4
- data.tar.gz: e835a0d4b87daa8f9af529a3a7190d870393ba48
3
+ metadata.gz: 4ddc3940d5c39be4fafd2a7c813ba49fa4ec5a8a
4
+ data.tar.gz: 3df41db20b0aa76c75ba21b54b91be29851ca090
5
5
  SHA512:
6
- metadata.gz: fe838b7b940db0d03c89bdeeb3aa2f48ec75de672322f04c5d7d8856f3b63c143806d63201eda1bb41477272c74a282ca9768d574758a8f24d584b8c965c22c1
7
- data.tar.gz: 151eb990affe67d0edfa39689193b7f0794830d48a04e0a610c9d51326b494066c8f314267d7e21170e51267ec6d4cd5162840eec613ab851aac5b18a38deace
6
+ metadata.gz: ac9d2cef90836d14e9b05fbd6d965cc1d9c945898c5d7f6d7f96ce2a704be74961448b208768f0803f800150121b66592f7f2c40aca39e4303db68764b81382e
7
+ data.tar.gz: 62b77423f58c73c43bf72e30de7e4fb3950cfd87c04b6c6e75fdf2f29be428b42ac2c4c84a290b3a43b81b463b516b5cd9f86de5035955b7cfb7f75bb8e7ea79
data/README.md CHANGED
@@ -3,8 +3,7 @@
3
3
  Speedup applications boot by caching require calls.
4
4
 
5
5
  Speed gain depends on your number of gems. Under 100 gems you likely won't see the difference,
6
- but for bigger applications (300+ gems) it can make the application boot up to 30% faster.
7
-
6
+ but for bigger applications it can save 1 to 2 seconds of boot time per 100 gems in the Gemfile.
8
7
 
9
8
  ## Installation
10
9
 
@@ -17,8 +16,7 @@ Then you need to add right after `require 'bundler/setup'`:
17
16
 
18
17
  ```ruby
19
18
  require 'bundler/setup'
20
- require 'bootscale'
21
- Bootscale.setup(cache_directory: 'tmp/bootscale')
19
+ require 'bootscale/setup'
22
20
  ```
23
21
 
24
22
  If your application is a Rails application, you will find this in `config/boot.rb`.
@@ -39,6 +37,10 @@ module MyApp
39
37
  end
40
38
  ```
41
39
 
40
+ ## Faster cache loading
41
+
42
+ Add the `msgpack` gem and `require 'msgpack'` to gain ~10-30ms of extra load speed by using msgpack.
43
+
42
44
  ## Contributing
43
45
 
44
46
  Bug reports and pull requests are welcome on GitHub at https://github.com/byroot/bootscale.
@@ -0,0 +1,26 @@
1
+ module Kernel
2
+ def require_with_cache(path)
3
+ require_without_cache(Bootscale[path] || 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] || 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] || path)
22
+ end
23
+
24
+ alias_method :autoload_without_cache, :autoload
25
+ alias_method :autoload, :autoload_with_cache
26
+ end
@@ -1,5 +1,4 @@
1
1
  require 'digest/md5'
2
- require 'msgpack'
3
2
 
4
3
  module Bootscale
5
4
  class FileStorage
@@ -9,19 +8,30 @@ module Bootscale
9
8
 
10
9
  def load(load_path)
11
10
  path = cache_path(load_path)
12
- MessagePack.load(File.read(path)) if File.exist?(path)
11
+ Serializer.load(File.read(path)) if File.exist?(path)
13
12
  end
14
13
 
15
14
  def dump(load_path, cache)
16
15
  path = cache_path(load_path)
17
16
  return if File.exist?(path)
18
17
  FileUtils.mkdir_p(File.dirname(path))
19
- File.open(path, 'wb+') { |f| f.write(MessagePack.dump(cache)) }
18
+ File.write(path, Serializer.dump(cache))
20
19
  end
21
20
 
22
- def cache_path(load_path)
23
- hash = Digest::MD5.hexdigest((load_path + [RUBY_VERSION, Bootscale::VERSION, MessagePack::VERSION]).join('|'))
24
- File.join(@directory, "bootscale-#{hash}.msgpack")
21
+ if defined?(MessagePack)
22
+ Serializer = MessagePack
23
+
24
+ def cache_path(load_path)
25
+ hash = Digest::MD5.hexdigest((load_path + [RUBY_VERSION, Bootscale::VERSION, MessagePack::VERSION]).join('|'))
26
+ File.join(@directory, "bootscale-#{hash}.msgpack")
27
+ end
28
+ else
29
+ Serializer = Marshal
30
+
31
+ def cache_path(load_path)
32
+ hash = Digest::MD5.hexdigest((load_path + [RUBY_VERSION, Bootscale::VERSION]).join('|'))
33
+ File.join(@directory, "bootscale-#{hash}.marshal")
34
+ end
25
35
  end
26
36
  end
27
37
  end
@@ -1,26 +1,2 @@
1
- module Kernel
2
- def require_with_cache(path)
3
- require_without_cache(Bootscale[path] || 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] || 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] || path)
22
- end
23
-
24
- alias_method :autoload_without_cache, :autoload
25
- alias_method :autoload, :autoload_with_cache
26
- end
1
+ require 'bootscale'
2
+ Bootscale.setup(cache_directory: 'tmp/bootscale')
@@ -1,3 +1,3 @@
1
1
  module Bootscale
2
- VERSION = '0.2.2'
2
+ VERSION = '0.3.0'
3
3
  end
data/lib/bootscale.rb CHANGED
@@ -18,7 +18,7 @@ module Bootscale
18
18
 
19
19
  def setup(options = {})
20
20
  self.cache_directory = options[:cache_directory]
21
- require_relative 'bootscale/setup'
21
+ require_relative 'bootscale/core_ext'
22
22
  regenerate
23
23
  end
24
24
 
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootscale
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2015-08-24 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: msgpack
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 0.6.2
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 0.6.2
12
+ dependencies: []
27
13
  description: Inspired by Aaron Patterson's talk on the subject
28
14
  email:
29
15
  - jean.boussier@gmail.com
@@ -31,18 +17,11 @@ executables: []
31
17
  extensions: []
32
18
  extra_rdoc_files: []
33
19
  files:
34
- - ".gitignore"
35
- - ".rspec"
36
- - ".travis.yml"
37
- - Gemfile
38
20
  - LICENSE.txt
39
21
  - README.md
40
- - Rakefile
41
- - bin/console
42
- - bin/setup
43
- - bootscale.gemspec
44
22
  - lib/bootscale.rb
45
23
  - lib/bootscale/cache_builder.rb
24
+ - lib/bootscale/core_ext.rb
46
25
  - lib/bootscale/entry.rb
47
26
  - lib/bootscale/file_storage.rb
48
27
  - lib/bootscale/setup.rb
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --require spec_helper
data/.travis.yml DELETED
@@ -1,10 +0,0 @@
1
- language: ruby
2
- sudo: false
3
- rvm:
4
- - '1.9'
5
- - '2.0'
6
- - '2.1'
7
- - '2.2'
8
- - rbx-2
9
- before_install: gem install bundler -v 1.10.6
10
-
data/Gemfile DELETED
@@ -1,18 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- gem 'bundler'
6
- gem 'rake'
7
- gem 'rspec'
8
-
9
- group :dummy do
10
- gem 'rails', '4.2.3'
11
- gem 'sqlite3'
12
- gem 'sass-rails', '~> 5.0'
13
- gem 'uglifier', '>= 1.3.0'
14
- gem 'coffee-rails', '~> 4.1.0'
15
- gem 'jquery-rails'
16
- gem 'turbolinks'
17
- gem 'jbuilder', '~> 2.0'
18
- end
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
data/bin/console DELETED
@@ -1,14 +0,0 @@
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 DELETED
@@ -1,7 +0,0 @@
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 DELETED
@@ -1,23 +0,0 @@
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
-
21
- spec.required_ruby_version = '>= 1.9.3'
22
- spec.add_runtime_dependency 'msgpack', '~> 0.6.2'
23
- end