ActionController caching small String#split optimization #5570

Merged
merged 1 commit into from Mar 25, 2012

Conversation

Projects
None yet
3 participants
Contributor

avakhov commented Mar 24, 2012

It's a little bit better to split on 2 parts.

require 'benchmark'

n = 50000
Benchmark.bm(7) do |x|
  x.report("rails:") { n.times {"http://rubyonrails.org/documentation".split(%r{://}).last } }
  x.report("my:") { n.times { "http://rubyonrails.org/documentation".split(%r{://}, 2).last } }
end

on my laptop:

              user     system      total        real
rails:    0.170000   0.000000   0.170000 (  0.171520)
my:       0.090000   0.000000   0.090000 (  0.096497)
actionpack/lib/action_controller/caching/actions.rb
@@ -170,14 +170,14 @@ def initialize(controller, options = {}, infer_extension = true)
options.reverse_merge!(:format => @extension) if options.is_a?(Hash)
end
- path = controller.url_for(options).split(%r{://}).last
+ path = controller.url_for(options).split(%r{://}, 2).last
@lest

lest Mar 24, 2012

Contributor

Regular expression could be replaced with a string:

path = controller.url_for(options).split('://', 2).last
Contributor

avakhov commented Mar 24, 2012

Changed regexp to string and rebased.

jeremy added a commit that referenced this pull request Mar 25, 2012

Merge pull request #5570 from avakhov/ac-caching-split
ActionController caching small String#split optimization

@jeremy jeremy merged commit 64ccb59 into rails:master Mar 25, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment