Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

On first incoming request in production mode, eliminates some closure…

…s we

don't have to keep but access frequently.

Without patch:

    request   concurrency   req/s    failures
    ==========================================
    1000      1             1058     0
    1000      11            1181     0
    1000      21            1265     0
    1000      31            1258     0
    1000      41            1079     0
    1000      51            1211     0
    1000      61            1239     0
    1000      71            1232     0
    1000      81            1234     0
    1000      91            1149     0

With patch:

    request   concurrency   req/s    failures
    ==========================================
    1000      1             1142     0
    1000      11            1501     0
    1000      21            1385     0
    1000      31            1779     0
    1000      41            1404     0
    1000      51            1685     0
    1000      61            1764     0
    1000      72            1371     0
    1000      81            1333     0
    1000      91            1374     0
  • Loading branch information...
commit f092e5ad599951215ba9a10d3252b53ef33b2adf 1 parent 088fe7e
@rkh rkh authored
Showing with 16 additions and 0 deletions.
  1. +16 −0 lib/sinatra/base.rb
View
16 lib/sinatra/base.rb
@@ -563,6 +563,7 @@ def call(env)
attr_accessor :env, :request, :response, :params
def call!(env) # :nodoc:
+ settings.freeze_settings!
@env = env
@request = Request.new(env)
@response = Response.new
@@ -1197,6 +1198,19 @@ def call(env)
synchronize { prototype.call(env) }
end
+ @@freezable_settings = [
+ :raise_errors, :dump_errors, :show_exceptions, :root, :views,
+ :reload_templates, :public, :static ]
+
+ # eliminates some closures we don't have to keep but access frequently
+ def freeze_settings! # :nodoc:
+ return if @froze_settings or !freeze_settings?
+ @froze_settings = true
+ @@freezable_settings.each do |name|
+ set name, __send__(name)
+ end
+ end
+
private
def detect_rack_handler
servers = Array(server)
@@ -1291,6 +1305,8 @@ def force_encoding(*) end
reset!
+ # intentionally activating freeze_settings in test mode
+ set :freeze_settings, Proc.new { !development? }
set :environment, (ENV['RACK_ENV'] || :development).to_sym
set :raise_errors, Proc.new { test? }
set :dump_errors, Proc.new { !test? }
Please sign in to comment.
Something went wrong with that request. Please try again.