From ead3bbc2405ad1df2228c44133ee1c6574ef5973 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Thu, 13 Feb 2025 21:09:41 -0800 Subject: [PATCH] merge revision(s) d4a1a2780c39bc648496ac92fc6e6ce2eb38ab47: [Backport #21032] rb_feature_p: skip `get_expanded_load_path` for absolute paths Ref: https://github.com/fxn/zeitwerk/pull/308 ```ruby require 'benchmark' $LOAD_PATH << 'relative-path' autoload :FOO, '/tmp/foo.rb' puts Benchmark.realtime { 500_000.times do Object.autoload?(:FOO) end } ``` The above script takes 2.5 seconds on `master`, and only 50ms on this branch. When we're looking for a feature with an absolute path, we don't need to call the expensive `get_expanded_load_path`. --- load.c | 2 +- version.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/load.c b/load.c index 68ee9d86ef..4ccd2ed20f 100644 --- a/load.c +++ b/load.c @@ -597,7 +597,7 @@ rb_feature_p(rb_vm_t *vm, const char *feature, const char *ext, int rb, int expa loading_tbl = get_loading_table(vm); f = 0; - if (!expanded) { + if (!expanded && !rb_is_absolute_path(feature)) { struct loaded_feature_searching fs; fs.name = feature; fs.len = len; diff --git a/version.h b/version.h index ce08b11d47..f97a24982c 100644 --- a/version.h +++ b/version.h @@ -11,7 +11,7 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 1 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 19 +#define RUBY_PATCHLEVEL 20 #include "ruby/version.h" #include "ruby/internal/abi.h"