Bazel has a stateful server component that caches information about the build graph and source files in memory. As you said, this allows it to check mtimes first to avoid re-computing hashes for source files.
Bazel can also read source file hashes from the filesystem if the filesystem supports it.