Skip to content

Commit 5a2cea2

Browse files
committed
Fix hot-path raising in ActionDispatch::Static
Using File.stat where a file does not exist raises an exception. Since ActionDispatch::Static does this: def call(env) @file_handler.attempt(env) || @app.call(env) end ... this means that around 8 exceptions are raised and rescued on each request which is passed to the application. This change improves latency by ~.14 milliseconds on all applications. Partial revert of rails#37265
1 parent ba4fde3 commit 5a2cea2

File tree

1 file changed

+2
-5
lines changed
  • actionpack/lib/action_dispatch/middleware

1 file changed

+2
-5
lines changed

actionpack/lib/action_dispatch/middleware/static.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,8 @@ def try_precompressed_files(filepath, headers, accept_encoding:)
137137
end
138138

139139
def file_readable?(path)
140-
file_stat = File.stat(File.join(@root, path.b))
141-
rescue SystemCallError
142-
false
143-
else
144-
file_stat.file? && file_stat.readable?
140+
file_path = File.join(@root, path.b)
141+
File.file?(file_path) && File.readable?(file_path)
145142
end
146143

147144
def compressible?(content_type)

0 commit comments

Comments
 (0)