Closed
Description
fn main() {
let _ = std::fs::read("test.rs");
}
gives the following strace
output:
[...]
openat(AT_FDCWD, "test.rs", O_RDONLY|O_CLOEXEC) = 3
statx(0, NULL, AT_STATX_SYNC_AS_STAT, STATX_ALL, NULL) = -1 EFAULT (Ongeldig adres)
statx(3, "", AT_STATX_SYNC_AS_STAT|AT_EMPTY_PATH, STATX_ALL, {stx_mask=STATX_ALL|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=52, ...}) = 0
lseek(3, 0, SEEK_CUR) = 0
read(3, "fn main() {\n let _ = std::fs:"..., 52) = 52
read(3, "", 32) = 0
close(3) = 0
[...]
The lseek
call is unnecessary as we know for a fact that we are at the start of the file and thus the result is always 0. It accounts for about 14% of the time when stracing. This is likely inflated due to syscall overhead when using strace, but still it may be a good idea to remove this syscall.