PATH Should Be a System Call
Emacs and bash, when starting up, inefficiently search for configuration files by iterating through each directory in the PATH environment variable, checking for the target file's existence one by one. This article explores this inefficient search mechanism, using the strace tool to trace the system calls of Emacs and bash, demonstrating numerous fstatat calls. The author argues that this search should be optimized by the operating system or file system, using a database-like query to directly return matching files instead of iterative attempts. Python's implementation, while relatively more efficient, is also shown to have shortcomings. The author proposes an improved solution: provide the OS with a list of all possible filenames and directories, reducing system calls and network roundtrips.