Skip to content

Commit

Permalink
Short circuit entry check
Browse files Browse the repository at this point in the history
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 what extensions it's got. This check is pretty fast.

On the example app

https://github.com/nfm/sprockets-3.x-performance-regressions

It reduced asset lookup from 15 seconds to 2.6 seconds. It's still not perfect but it's a 400% + speed increase in the case of looking for an asset in a huge directory.

Related comment #84 (comment)
  • Loading branch information
schneems committed Jun 28, 2016
1 parent 0bb48ff commit fb35173
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions lib/sprockets/path_utils.rb
Expand Up @@ -178,6 +178,7 @@ def match_path_extname(path, extensions)
def find_matching_path_for_extensions(path, basename, extensions)
matches = []
entries(path).each do |entry|
next unless File.basename(entry).start_with?(basename)
extname, value = match_path_extname(entry, extensions)
if basename == entry.chomp(extname)
filename = File.join(path, entry)
Expand Down

0 comments on commit fb35173

Please sign in to comment.