Some quick benchmarks on extracting ActionView from ActionPack. There are performance gains in both development and production envs, but not that significant.
| Requests per second [#/sec] (mean) | |
|---|---|
| irb(main):001:0> s = 92.chr | |
| => "\\" | |
| irb(main):002:0> s.size | |
| => 1 | |
| irb(main):003:0> puts s | |
| \ | |
| => nil | |
| irb(main):004:0> s2 = s + s | |
| => "\\\\" | |
| irb(main):005:0> s2.size |
| class Post < ActiveRecord::Base | |
| has_many :comments | |
| end | |
| class Comments | |
| belongs_to :post | |
| end | |
| Post.first.comments.class # => Array | |
| Kernel.instance_method(:class).bind(Post.first.comments).call # => ActiveRecord::Associations::CollectionProxy |
| diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb | |
| index a8368b6..abe4d71 100644 | |
| --- a/actionpack/lib/action_dispatch/routing/route_set.rb | |
| +++ b/actionpack/lib/action_dispatch/routing/route_set.rb | |
| @@ -500,11 +500,11 @@ module ActionDispatch | |
| end | |
| def recognize_path(path, environment = {}) | |
| - method = (environment[:method] || "GET").to_s.upcase | |
| + environment[:method] = (environment[:method] || "GET").to_s.upcase |
| [43] square » Rails.application.routes.draw do | |
| » get "/foo" => "foo#bar" | |
| » end | |
| => nil | |
| [44] square » Rails.application.routes.routes | |
| => [ | |
| [0] GET /foo(.:format) {:controller=>"foo", :action=>"bar"} | |
| ] | |
| from /Users/lukaszstrzalkowski/Development/rails/actionpack/lib/action_dispatch/routing/route_set.rb:532:in `recognize_path' | |
| [46] square » Rails.application.routes.recognize_path("/foo", :method => :get) |
| class Foobar | |
| def initialize | |
| @data = {} | |
| @lock = Mutex.new | |
| end | |
| def [](key) | |
| @lock do | |
| @data[key.to_s] | |
| end |
| class Foobar | |
| def foo | |
| ... | |
| end | |
| end | |
| class Barfoo < Foobar | |
| def foo | |
| super | |
| # check from where super comes and print "Foobar" |
This is a working draft of proposal. Feel free to comment, express your opinions and suggest alternative solutions.
As a second part of my Google Summer of Code, I planned to introduce View Classes to Action View.
There was ongoing discussion about this and extracting AV from AP (which is done already: rails/rails#11396) here: https://groups.google.com/forum/#!topic/rubyonrails-gsoc/N7uDY_6513I
| class TestController < ActionController::Base | |
| protect_from_forgery | |
| def render_string_hello_world | |
| render "Hello world!" | |
| end | |
| def render_text_hello_world | |
| render :text => "hello world" | |
| end |