From 20c66dbf1ebd0ca993e7a79c9d0d833d747df358 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 14 Mar 2017 19:18:55 +0000 Subject: http_request: reduce insn size for check_client_connection Unlike constants and instance variables, class variable access is not optimized in the mainline Ruby VM. Use a constant instead, to take advantage of inline constant caching. This further reduces runtime instruction size by avoiding a branch by allocating the Raindrops::TCP_Info object up front. This reduces the method size by roughly 300 bytes on 64-bit. --- lib/unicorn/http_request.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb index c08097c..9010007 100644 --- a/lib/unicorn/http_request.rb +++ b/lib/unicorn/http_request.rb @@ -106,12 +106,13 @@ class Unicorn::HttpParser end if defined?(Raindrops::TCP_Info) + TCPI = Raindrops::TCP_Info.allocate + def check_client_connection(socket) # :nodoc: if Unicorn::TCPClient === socket - @@tcp_info ||= Raindrops::TCP_Info.new(socket) - @@tcp_info.get!(socket) + # Raindrops::TCP_Info#get!, #state (reads struct tcp_info#tcpi_state) raise Errno::EPIPE, "client closed connection".freeze, - EMPTY_ARRAY if closed_state?(@@tcp_info.state) + EMPTY_ARRAY if closed_state?(TCPI.get!(socket).state) else write_http_header(socket) end -- cgit v1.2.3-24-ge0c7