New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10X speed improvements for AS::Dependencies.loadable_constants_for_path #21411

Merged
merged 1 commit into from Aug 28, 2015

Conversation

Projects
None yet
2 participants
@byroot
Member

byroot commented Aug 28, 2015

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

cc @rafaelfranca

@@ -421,13 +421,13 @@ def loadable_constants_for_path(path, bases = autoload_paths)
bases.each do |root|
expanded_root = File.expand_path(root)
next unless %r{\A#{Regexp.escape(expanded_root)}(/|\\)} =~ expanded_path

This comment has been minimized.

@byroot

byroot Aug 28, 2015

Member

I assume the \\ was for Windows support. But then nesting[0] == ?/ was kinda breaking it. Not sure what to do here, but I can test for both.

@byroot

byroot Aug 28, 2015

Member

I assume the \\ was for Windows support. But then nesting[0] == ?/ was kinda breaking it. Not sure what to do here, but I can test for both.

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
@byroot

This comment has been minimized.

Show comment
Hide comment
@byroot

byroot Aug 28, 2015

Member

After fixing the test failure it's slightly slower, still about 9 times faster than current implementation though:

Calculating -------------------------------------
             patched   792.000  i/100ms
-------------------------------------------------
             patched      9.664k (±19.9%) i/s -     44.352k
Member

byroot commented Aug 28, 2015

After fixing the test failure it's slightly slower, still about 9 times faster than current implementation though:

Calculating -------------------------------------
             patched   792.000  i/100ms
-------------------------------------------------
             patched      9.664k (±19.9%) i/s -     44.352k

@byroot byroot referenced this pull request Aug 28, 2015

Closed

Bootscale/activesupport? #26

@rafaelfranca rafaelfranca reopened this Aug 28, 2015

rafaelfranca added a commit that referenced this pull request Aug 28, 2015

Merge pull request #21411 from byroot/perf-improvement-in-dependencie…
…s-loadable-constants

10X speed improvements for AS::Dependencies.loadable_constants_for_path

@rafaelfranca rafaelfranca merged commit 1abbd3e into rails:master Aug 28, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment