From 70c976bdd85bb8515fea01d6ad6074ef472fc2e0 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 14 Nov 2015 02:47:24 +0000 Subject: reduce constant lookup dependencies Unicorn 5 removes some constants we were using, and constant lookups + inline caching are waste of time anyways on newer Rubies with the opt_str_freeze bytecode instruction. This may reduce performance for folks on older Rubies (probably not noticeable); but improves performance for folks on newer Rubies. --- lib/rainbows/event_machine/client.rb | 12 ++++++------ lib/rainbows/event_machine/try_defer.rb | 5 +---- 2 files changed, 7 insertions(+), 10 deletions(-) (limited to 'lib/rainbows/event_machine') diff --git a/lib/rainbows/event_machine/client.rb b/lib/rainbows/event_machine/client.rb index 9871c09..7fb88f6 100644 --- a/lib/rainbows/event_machine/client.rb +++ b/lib/rainbows/event_machine/client.rb @@ -23,7 +23,7 @@ class Rainbows::EventMachine::Client < EM::Connection end EM.next_tick { receive_data(nil) } unless @buf.empty? else - on_read(data || Z) if (@buf.size > 0) || data + on_read(data || ''.freeze) if (@buf.size > 0) || data end end @@ -34,10 +34,10 @@ class Rainbows::EventMachine::Client < EM::Connection def app_call input set_comm_inactivity_timeout 0 - @env[RACK_INPUT] = input - @env[REMOTE_ADDR] = @_io.kgio_addr - @env[ASYNC_CALLBACK] = method(:write_async_response) - @env[ASYNC_CLOSE] = EM::DefaultDeferrable.new + @env['rack.input'] = input + @env['REMOTE_ADDR'] = @_io.kgio_addr + @env['async.callback'] = method(:write_async_response) + @env['async.close'] = EM::DefaultDeferrable.new @hp.hijack_setup(@env, @_io) status, headers, body = catch(:async) { APP.call(@env.merge!(RACK_DEFAULTS)) @@ -117,7 +117,7 @@ class Rainbows::EventMachine::Client < EM::Connection def unbind return if @hp.hijacked? - async_close = @env[ASYNC_CLOSE] and async_close.succeed + async_close = @env['async.close'] and async_close.succeed @deferred.respond_to?(:fail) and @deferred.fail begin @_io.close diff --git a/lib/rainbows/event_machine/try_defer.rb b/lib/rainbows/event_machine/try_defer.rb index 615adae..778f3d0 100644 --- a/lib/rainbows/event_machine/try_defer.rb +++ b/lib/rainbows/event_machine/try_defer.rb @@ -10,9 +10,6 @@ # See http://brainspl.at/articles/2008/04/18/deferred-requests-with-merb-ebb-and-thin # for more information. class Rainbows::EventMachine::TryDefer - # shortcuts - ASYNC_CALLBACK = Rainbows::EvCore::ASYNC_CALLBACK # :nodoc: - def initialize(app) # :nodoc: # the entire app becomes multithreaded, even the root (non-deferred) # thread since any thread can share processes with others @@ -22,7 +19,7 @@ class Rainbows::EventMachine::TryDefer def call(env) # :nodoc: if @app.deferred?(env) - EM.defer(proc { catch(:async) { @app.call(env) } }, env[ASYNC_CALLBACK]) + EM.defer(proc { catch(:async) { @app.call(env) } }, env['async.callback']) # all of the async/deferred stuff breaks Rack::Lint :< nil else -- cgit v1.2.3-24-ge0c7