Skip to content

Commit d4a1a27

Browse files
committed
rb_feature_p: skip get_expanded_load_path for absolute paths
Ref: fxn/zeitwerk#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`.
1 parent dd86371 commit d4a1a27

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

load.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ rb_feature_p(rb_vm_t *vm, const char *feature, const char *ext, int rb, int expa
597597

598598
loading_tbl = get_loading_table(vm);
599599
f = 0;
600-
if (!expanded) {
600+
if (!expanded && !rb_is_absolute_path(feature)) {
601601
struct loaded_feature_searching fs;
602602
fs.name = feature;
603603
fs.len = len;

0 commit comments

Comments
 (0)