From 6f685e106c47c755c930a1597271265149b5cb4e Mon Sep 17 00:00:00 2001 From: k0kubun Date: Fri, 26 May 2017 13:49:35 +0000 Subject: erb.rb: Generate static string with opt_str_uminus to skip object allocation for static string. We can't always enable frozen_string_literal pragma because we can't freeze string literals embedded by user for backward compatibility. So we need to use fstring for each static string. Since adding ".freeze" to string literals in #content_dump is slow on compiling, I used unary "-" operator instead. benchmark/bm_app_erb_render.rb: Added rendering-only benchmark to test rendering performance on production environment. This benchmark is created to reproduce the behavior on Sinatra (Tilt). Thus it doesn't use ERB#result to skip parsing compiled code. It doesn't use ERB#def_method too to regard `title` and `content` as local variables. If we use #def_method, `title` and `content` needs to be method call. I wanted to avoid it. This patch's benchmark results is: * Before app_erb_render 1.250 app_erb 0.704 * After app_erb_render 1.066 app_erb 0.686 This patch optimizes rendering performance (app_erb_render) without spoiling (total of rendering +) compiling performance (app_erb). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58905 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/erb.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/erb.rb b/lib/erb.rb index cb7dbaf286..cecab2fceb 100644 --- a/lib/erb.rb +++ b/lib/erb.rb @@ -589,7 +589,7 @@ class ERB end def add_put_cmd(out, content) - out.push("#{@put_cmd} #{content_dump(content)}") + out.push("#{@put_cmd} -#{content_dump(content)}") end def add_insert_cmd(out, content) -- cgit v1.2.3