Current check uses File.mtime, then a check for symlink?, in which case it uses File.lstat:
compile_time < File.mtime(file_name) ||
(File.symlink?(file_name) && (compile_time < File.lstat(file_name).mtime))
This incurs two system calls at best, and three system calls if the file is indeed a symlink: mtime calls fstat(), whereas File.symlink? uses lstat(), making the duplicate call to lstat() unnecessary.
This patch reverses the logic so that lstat() is always called once; if the file is a symlink (as indicated in the stat mode flags), one additional stat() call is made to find the modification time of the endpoint. This optimizes for the common case where a template is a regular file.
The patch also aliases the compilation time lookup to avoid a duplicate hash access.