aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2015-08-27 21:28:54 -0400
committerJean Boussier <jean.boussier@gmail.com>2015-08-27 21:49:04 -0400
commit2e0cd0f371bd8f2bf0908f5f4c8887b6faef0884 (patch)
treed0d911e0a0de208dd1c68f9bb0de6c860b3bf60e /activesupport
parentf642208ae4f2779b9c247eaa02f04491608e4b34 (diff)
downloadrails-2e0cd0f371bd8f2bf0908f5f4c8887b6faef0884.tar.gz
rails-2e0cd0f371bd8f2bf0908f5f4c8887b6faef0884.tar.bz2
rails-2e0cd0f371bd8f2bf0908f5f4c8887b6faef0884.zip
10X speed improvements for AS::Dependencies.loadable_constants_for_path
When the autoload_paths start to grows, this methods is quite a hotspot >> ActiveSupport::Dependencies.autoload_paths.size => 49 >> Benchmark.ips { |x| x.report('baseline') { ActiveSupport::Dependencies.loadable_constants_for_path(File.expand_path('app/models/shop')) }} Calculating ------------------------------------- baseline 90.000 i/100ms ------------------------------------------------- baseline 1.073k (±20.2%) i/s - 4.950k After the patch Calculating ------------------------------------- patched 883.000 i/100ms ------------------------------------------------- patched 11.050k (±19.7%) i/s - 50.331k
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/dependencies.rb10
1 files changed, 5 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index f76ef04f49..8215a3085e 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -421,13 +421,13 @@ module ActiveSupport #:nodoc:
bases.each do |root|
expanded_root = File.expand_path(root)
- next unless %r{\A#{Regexp.escape(expanded_root)}(/|\\)} =~ expanded_path
+ next unless expanded_path.start_with?(expanded_root)
- nesting = expanded_path[(expanded_root.size)..-1]
- nesting = nesting[1..-1] if nesting && nesting[0] == ?/
- next if nesting.blank?
+ root_size = expanded_root.size
+ next if expanded_path[root_size] != ?/.freeze
- paths << nesting.camelize
+ nesting = expanded_path[(root_size + 1)..-1]
+ paths << nesting.camelize unless nesting.blank?
end
paths.uniq!