unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* [PATCH] use require_relative to reduce syscalls at startup
@ 2015-02-05 18:01 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-02-05 18:01 UTC (permalink / raw)
  To: unicorn-public

require_relative appeared in Ruby 1.9.2 to speed up load times by
avoiding needless open() syscalls.  This has no effect if you're using
RUBYLIB or the '-I' option when running ruby(1), but avoids searching
paths in other gems.

This does not affect unicorn greatly as unicorn does not activate many
gems, but still leads to reducing ~45 syscalls during startup.
---
 lib/unicorn.rb       | 16 +++++-----------
 lib/unicorn/const.rb |  2 +-
 2 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/lib/unicorn.rb b/lib/unicorn.rb
index cfa1656..dd02761 100644
--- a/lib/unicorn.rb
+++ b/lib/unicorn.rb
@@ -104,14 +104,8 @@ module Unicorn
   # :startdoc:
 end
 # :enddoc:
-require 'unicorn/const'
-require 'unicorn/socket_helper'
-require 'unicorn/stream_input'
-require 'unicorn/tee_input'
-require 'unicorn/http_request'
-require 'unicorn/configurator'
-require 'unicorn/tmpio'
-require 'unicorn/util'
-require 'unicorn/http_response'
-require 'unicorn/worker'
-require 'unicorn/http_server'
+
+%w(const socket_helper stream_input tee_input http_request configurator
+   tmpio util http_response worker http_server).each do |s|
+  require_relative "unicorn/#{s}"
+end
diff --git a/lib/unicorn/const.rb b/lib/unicorn/const.rb
index 51d7394..26fa62b 100644
--- a/lib/unicorn/const.rb
+++ b/lib/unicorn/const.rb
@@ -41,4 +41,4 @@ module Unicorn::Const
 
   # :startdoc:
 end
-require 'unicorn/version'
+require_relative 'version'
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-02-05 18:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-05 18:01 [PATCH] use require_relative to reduce syscalls at startup Eric Wong

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/unicorn.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).