sprockets: Performance regression while requiring lots of files
Hi guys,
I’m following rails/sprockets-rails#225 and I would like to share with you a performance regression I’m experiencing after moving from sprocket-rails 2.1.3
to 3.0
or master
.
It turns out that the issue is not in sprocket-rails
but rather in the underlying sprockets
since most of the time is spent resolving asset paths (cc @eileencodes).
Here is what I’m seeing on my personal app (ruby-prof output):
Measure Mode: wall_time
Thread ID: 70253745167340
Fiber ID: 70253756137300
Total: 1.518107
Sort by: self_time
%self total self wait child calls name
19.84 0.302 0.301 0.000 0.000 1368 <Module::Marshal>#load_without_autoloading
5.71 0.087 0.087 0.000 0.000 143 Zlib::Inflate#inflate
4.60 0.070 0.070 0.000 0.000 1339 <Class::File>#utime
4.22 0.074 0.064 0.000 0.010 1908 Sprockets::URIUtils#join_file_uri
3.72 0.448 0.056 0.000 0.392 1339 Sprockets::EncodingUtils#unmarshaled_deflated
3.58 0.054 0.054 0.000 0.000 21137 String#scan
2.48 0.222 0.038 0.000 0.184 20937 Sprockets::Resolve#parse_path_extnames
2.16 0.033 0.033 0.000 0.000 4095 <Class::File>#exist?
2.03 0.031 0.031 0.000 0.000 2 SQLite3::Statement#step
1.77 0.055 0.027 0.000 0.029 20939 Array#reverse_each
1.75 0.048 0.027 0.000 0.021 302 Array#include?
1.74 0.028 0.026 0.000 0.002 7471 *String#gsub
1.63 0.025 0.025 0.000 0.000 1370 File#initialize
1.46 0.022 0.022 0.000 0.000 120894 String#==
1.42 0.052 0.022 0.000 0.031 1831 Sprockets::DigestUtils#digest
1.38 0.021 0.021 0.000 0.000 21201 <Class::File>#basename
1.32 0.020 0.020 0.000 0.000 20 <Class::Dir>#[]
1.29 0.020 0.020 0.000 0.000 3203 Regexp#===
1.28 0.161 0.019 0.000 0.141 20937 Sprockets::PathUtils#match_path_extname
And here is a small project reproducing the issue: redox/perf_regression_sprockets. In that application a page that took 20ms to be rendered using sprockets-rails 2.1.3
now takes 60ms with the latest master
branch.
Any chance it could be related to the “compat” resolving layer? Let me know if I can help!
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 37 (14 by maintainers)
Commits related to this issue
- Short circuit entry check The method `match_path_extname` is expensive. We know that if the name of the file on disk does not start with the same basename that we're looking for then it won't matter ... — committed to rails/sprockets by schneems 8 years ago
- Short circuit entry check The method `match_path_extname` is expensive. We know that if the name of the file on disk does not start with the same basename that we're looking for then it won't matter ... — committed to rails/sprockets by schneems 8 years ago
- Short circuit entry check The method `match_path_extname` is expensive. We know that if the name of the file on disk does not start with the same basename that we're looking for then it won't matter ... — committed to rails/sprockets by schneems 8 years ago
Alright I did some digging and here’s my derailed stackprof of slow methods
before
after
So my app is faster with the older sprockets: (from flame graph info of page load)
before
after
It looks like way more sprocket method calls are being done and the app is spending more time in it.