From 04c7fc37ab4fb2fbaa1b4a2570871713cf9d1319 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 16 Sep 2009 16:56:22 -0700 Subject: Avoid freezing objects that don't benefit from it This gives applications more rope to play with in case they have any reasons for changing some values of the default constants. Freezing strings for Hash assignments still speeds up MRI, so we'll keep on doing that for now (and as long as MRI supports frozen strings, I expect them to always be faster for Hashes though I'd be very happy to be proven wrong...) --- lib/unicorn.rb | 2 +- lib/unicorn/app/exec_cgi.rb | 2 +- lib/unicorn/app/old_rails/static.rb | 2 +- lib/unicorn/cgi_wrapper.rb | 2 +- lib/unicorn/const.rb | 12 ++++++------ lib/unicorn/http_request.rb | 8 ++++---- lib/unicorn/http_response.rb | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/lib/unicorn.rb b/lib/unicorn.rb index bcf5c3b..4cc5c2d 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -285,7 +285,7 @@ module Unicorn # list of signals we care about and trap in master. QUEUE_SIGS = [ :WINCH, :QUIT, :INT, :TERM, :USR1, :USR2, :HUP, - :TTIN, :TTOU ].freeze + :TTIN, :TTOU ] # defer a signal for later processing in #join (master process) def trap_deferred(signal) diff --git a/lib/unicorn/app/exec_cgi.rb b/lib/unicorn/app/exec_cgi.rb index ff52d0c..4f9216b 100644 --- a/lib/unicorn/app/exec_cgi.rb +++ b/lib/unicorn/app/exec_cgi.rb @@ -26,7 +26,7 @@ module Unicorn::App SERVER_PORT SERVER_PROTOCOL SERVER_SOFTWARE - ).map { |x| x.freeze }.freeze # frozen strings are faster for Hash lookups + ).map { |x| x.freeze } # frozen strings are faster for Hash assignments # Intializes the app, example of usage in a config.ru # map "/cgit" do diff --git a/lib/unicorn/app/old_rails/static.rb b/lib/unicorn/app/old_rails/static.rb index a1f3b6b..1a78a23 100644 --- a/lib/unicorn/app/old_rails/static.rb +++ b/lib/unicorn/app/old_rails/static.rb @@ -20,7 +20,7 @@ # with Unicorn and you should see a decent speed boost (but not as # fast as if you use a static server like nginx). class Unicorn::App::OldRails::Static < Struct.new(:app, :root, :file_server) - FILE_METHODS = { 'GET' => true, 'HEAD' => true }.freeze + FILE_METHODS = { 'GET' => true, 'HEAD' => true } REQUEST_METHOD = 'REQUEST_METHOD'.freeze REQUEST_URI = 'REQUEST_URI'.freeze PATH_INFO = 'PATH_INFO'.freeze diff --git a/lib/unicorn/cgi_wrapper.rb b/lib/unicorn/cgi_wrapper.rb index 07ed979..64848b4 100644 --- a/lib/unicorn/cgi_wrapper.rb +++ b/lib/unicorn/cgi_wrapper.rb @@ -46,7 +46,7 @@ class Unicorn::CGIWrapper < ::CGI 'language' => 'Content-Language'.freeze, 'expires' => 'Expires'.freeze, 'length' => CONTENT_LENGTH, - }.freeze + } # Takes an a Rackable environment, plus any additional CGI.new # arguments These are used internally to create a wrapper around the diff --git a/lib/unicorn/const.rb b/lib/unicorn/const.rb index bda6e46..b7a3690 100644 --- a/lib/unicorn/const.rb +++ b/lib/unicorn/const.rb @@ -7,11 +7,11 @@ module Unicorn # gave about a 3% to 10% performance improvement over using the strings directly. # Symbols did not really improve things much compared to constants. module Const - UNICORN_VERSION="0.91.0".freeze + UNICORN_VERSION="0.91.0" - DEFAULT_HOST = "0.0.0.0".freeze # default TCP listen host address - DEFAULT_PORT = "8080".freeze # default TCP listen port - DEFAULT_LISTEN = "#{DEFAULT_HOST}:#{DEFAULT_PORT}".freeze + DEFAULT_HOST = "0.0.0.0" # default TCP listen host address + DEFAULT_PORT = "8080" # default TCP listen port + DEFAULT_LISTEN = "#{DEFAULT_HOST}:#{DEFAULT_PORT}" # The basic max request size we'll try to read. CHUNK_SIZE=(16 * 1024) @@ -24,8 +24,8 @@ module Unicorn MAX_BODY=MAX_HEADER # common errors we'll send back - ERROR_400_RESPONSE = "HTTP/1.1 400 Bad Request\r\n\r\n".freeze - ERROR_500_RESPONSE = "HTTP/1.1 500 Internal Server Error\r\n\r\n".freeze + ERROR_400_RESPONSE = "HTTP/1.1 400 Bad Request\r\n\r\n" + ERROR_500_RESPONSE = "HTTP/1.1 500 Internal Server Error\r\n\r\n" EXPECT_100_RESPONSE = "HTTP/1.1 100 Continue\r\n\r\n" # A frozen format for this is about 15% faster diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb index 400a63e..2d191d7 100644 --- a/lib/unicorn/http_request.rb +++ b/lib/unicorn/http_request.rb @@ -12,15 +12,15 @@ module Unicorn "rack.multiprocess" => true, "rack.multithread" => false, "rack.run_once" => false, - "rack.version" => [1, 0].freeze, - "SCRIPT_NAME" => "".freeze, + "rack.version" => [1, 0], + "SCRIPT_NAME" => "", # this is not in the Rack spec, but some apps may rely on it - "SERVER_SOFTWARE" => "Unicorn #{Const::UNICORN_VERSION}".freeze + "SERVER_SOFTWARE" => "Unicorn #{Const::UNICORN_VERSION}" } NULL_IO = StringIO.new(Z) - LOCALHOST = '127.0.0.1'.freeze + LOCALHOST = '127.0.0.1' # Being explicitly single-threaded, we have certain advantages in # not having to worry about variables being clobbered :) diff --git a/lib/unicorn/http_response.rb b/lib/unicorn/http_response.rb index 0d05b2c..f226ef3 100644 --- a/lib/unicorn/http_response.rb +++ b/lib/unicorn/http_response.rb @@ -32,7 +32,7 @@ module Unicorn # Rack does not set/require a Date: header. We always override the # Connection: and Date: headers no matter what (if anything) our # Rack application sent us. - SKIP = { 'connection' => true, 'date' => true, 'status' => true }.freeze + SKIP = { 'connection' => true, 'date' => true, 'status' => true } OUT = [] # :nodoc def self.write_header(socket, status, headers) -- cgit v1.2.3-24-ge0c7