From: "k0kubun (Takashi Kokubun) via ruby-core" Date: 2023-02-27T17:29:52+00:00 Subject: [ruby-core:112620] [Ruby master Feature#19465] [PATCH] reuse open(2) from rb_file_load_ok on POSIX-like system Issue #19465 has been updated by k0kubun (Takashi Kokubun). Status changed from Closed to Assigned Assignee set to normalperson (Eric Wong) Since there has been no action since @hsbt reported it, I temporarily reverted the commit at commit:526111290b2e01e798f436dfe4acc3bf10c6bbd1. Please have a look at the failure and re-push it once the issue is resolved. Thank you! ---------------------------------------- Feature #19465: [PATCH] reuse open(2) from rb_file_load_ok on POSIX-like system https://bugs.ruby-lang.org/issues/19465#change-102068 * Author: normalperson (Eric Wong) * Status: Assigned * Priority: Normal * Assignee: normalperson (Eric Wong) ---------------------------------------- ``` When loading Ruby source files, we can save the result of successful opens as open(2)/openat(2) are a fairly expensive syscalls. This also avoids a time-of-check-to-time-of-use (TOCTTOU) problem. This reduces open(2) syscalls during `require'; but should be most apparent when users have a small $LOAD_PATH. Users with large $LOAD_PATH will benefit less since there'll be more open(2) failures due to ENOENT. With `strace -c -e openat ruby -e exit' under Linux, this results in a ~14% reduction of openat(2) syscalls (glibc uses openat(2) to implement open(2)). % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 0.00 0.000000 0 296 110 openat 0.00 0.000000 0 254 110 openat Additionally, the introduction of `struct ruby_file_load_state' may make future optimizations more apparent. This change cannot benefit binary (.so) loading since the dlopen(3) API requires a filename and I'm not aware of an alternative that takes a pre-existing FD. In typical situations, Ruby source files outnumber the mount of .so files. I've only tested this lightly on small apps since I don't have large codebases to test on. However, I think organizing various on-stack variables into `struct ruby_file_load_state' can be beneficial if we end up using io-uring on Linux. ``` ---Files-------------------------------- 0001-reuse-open-2-from-rb_file_load_ok-on-POSIX-like-syst.patch (15.2 KB) -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/