ruby/internal
Eric Wong 35136e1e9c reuse open(2) from rb_file_load_ok on POSIX-like system
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.
2023-02-26 20:39:41 +00:00
..
array.h Add Data class implementation: Simple immutable value object 2022-09-30 18:23:19 +09:00
basic_operators.h Use a BOP for Hash#default 2022-12-17 14:51:49 -08:00
bignum.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
bits.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
class.h Move `attached_object` into `rb_classext_struct` 2023-02-16 08:14:44 +01:00
cmdlineopt.h YJIT: Lazily enable YJIT after prelude (#6597) 2022-10-24 12:20:44 -04:00
compar.h Introduce BOP_CMP for optimized comparison 2022-12-06 12:37:23 -08:00
compile.h Fix incorrect line numbers in GC hook 2023-02-24 14:10:09 -05:00
compilers.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
complex.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
cont.h Introduce `Fiber#storage` for inheritable fiber-scoped variables. (#6612) 2022-12-01 23:00:33 +13:00
dir.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
enc.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
encoding.h parenthesize to macro 2022-12-02 01:31:27 +09:00
enum.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
enumerator.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
error.h suppress GCC's -Wsuggest-attribute=format 2021-09-10 20:00:06 +09:00
eval.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
file.h reuse open(2) from rb_file_load_ok on POSIX-like system 2023-02-26 20:39:41 +00:00
fixnum.h Fix rb_fix_mul_fix on OpenBSD/mips64 2022-07-03 09:42:44 -07:00
gc.h Merge gc.h and internal/gc.h 2023-02-09 10:32:29 -05:00
hash.h Implement ObjectSpace::WeakKeyMap basic allocator 2023-02-23 16:01:57 +01:00
imemo.h use correct svar even if env is escaped 2023-02-10 17:55:25 +09:00
inits.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
io.h Move some function declaration to internal/io.h 2021-09-28 18:08:08 +13:00
load.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
loadpath.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
math.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
missing.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
numeric.h Use `roomof` macro for rounding up divisions 2022-10-14 19:23:25 +09:00
object.h Revert "Revert "This commit implements the Object Shapes technique in CRuby."" 2022-10-11 08:40:56 -07:00
parse.h reuse open(2) from rb_file_load_ok on POSIX-like system 2023-02-26 20:39:41 +00:00
proc.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
process.h Don't redefine RB_OBJ_WRITE 2023-01-18 08:49:32 -05:00
ractor.h internal/ractor.h: Added 2022-03-30 16:50:46 +09:00
random.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
range.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
rational.h Don't redefine RB_OBJ_WRITE 2023-01-18 08:49:32 -05:00
re.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
sanitizers.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
serial.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
signal.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
static_assert.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
string.h Use shared flags of the type 2022-11-02 11:03:21 -04:00
struct.h Don't redefine RB_OBJ_WRITE 2023-01-18 08:49:32 -05:00
symbol.h Ensure _id2ref finds symbols with the correct type 2022-07-20 10:38:44 -07:00
thread.h Only emit circular dependency warning for owned thread shields 2023-02-08 09:50:00 +01:00
time.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
transcode.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
util.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00
variable.h Copying GC support for EXIVAR 2023-01-31 09:24:26 -05:00
vm.h Remove unused class serial 2022-10-21 14:56:48 -07:00
warnings.h internal/*.h: skip doxygen 2021-09-10 20:00:06 +09:00