Skip to content

Commit 1c76244

Browse files
committed
Revert "Ruby 3.2 - Speed up rebuilding the loaded feature index and realpath cache (#8023)"
This reverts commit 8346d16. It seems break CI on MinGW. https://github.com/ruby/ruby/actions/runs/5698775895/job/15447455988
1 parent 8346d16 commit 1c76244

File tree

3 files changed

+6
-44
lines changed

3 files changed

+6
-44
lines changed

load.c

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,6 @@ get_loaded_features_realpaths(rb_vm_t *vm)
163163
return vm->loaded_features_realpaths;
164164
}
165165

166-
static VALUE
167-
get_loaded_features_realpath_map(rb_vm_t *vm)
168-
{
169-
return vm->loaded_features_realpath_map;
170-
}
171-
172166
static VALUE
173167
get_LOADED_FEATURES(ID _x, VALUE *_y)
174168
{
@@ -367,10 +361,7 @@ get_loaded_features_index(rb_vm_t *vm)
367361
st_foreach(vm->loaded_features_index, loaded_features_index_clear_i, 0);
368362

369363
VALUE realpaths = vm->loaded_features_realpaths;
370-
VALUE realpath_map = vm->loaded_features_realpath_map;
371-
VALUE previous_realpath_map = rb_hash_dup(realpath_map);
372364
rb_hash_clear(realpaths);
373-
rb_hash_clear(realpath_map);
374365
features = vm->loaded_features;
375366
for (i = 0; i < RARRAY_LEN(features); i++) {
376367
VALUE entry, as_str;
@@ -387,14 +378,9 @@ get_loaded_features_index(rb_vm_t *vm)
387378
long j = RARRAY_LEN(features);
388379
for (i = 0; i < j; i++) {
389380
VALUE as_str = rb_ary_entry(features, i);
390-
VALUE realpath = rb_hash_aref(previous_realpath_map, as_str);
391-
if (NIL_P(realpath)) {
392-
realpath = rb_check_realpath(Qnil, as_str, NULL);
393-
if (NIL_P(realpath)) realpath = as_str;
394-
realpath = rb_fstring(realpath);
395-
}
396-
rb_hash_aset(realpaths, realpath, Qtrue);
397-
rb_hash_aset(realpath_map, as_str, realpath);
381+
VALUE realpath = rb_check_realpath(Qnil, as_str, NULL);
382+
if (NIL_P(realpath)) realpath = as_str;
383+
rb_hash_aset(realpaths, rb_fstring(realpath), Qtrue);
398384
}
399385
}
400386
return vm->loaded_features_index;
@@ -689,19 +675,6 @@ rb_provide(const char *feature)
689675

690676
NORETURN(static void load_failed(VALUE));
691677

692-
static inline VALUE
693-
realpath_internal_cached(VALUE hash, VALUE path)
694-
{
695-
VALUE ret = rb_hash_aref(hash, path);
696-
if(RTEST(ret)) {
697-
return ret;
698-
}
699-
700-
VALUE realpath = rb_realpath_internal(Qnil, path, 1);
701-
rb_hash_aset(hash, rb_fstring(path), rb_fstring(realpath));
702-
return realpath;
703-
}
704-
705678
static inline void
706679
load_iseq_eval(rb_execution_context_t *ec, VALUE fname)
707680
{
@@ -714,12 +687,8 @@ load_iseq_eval(rb_execution_context_t *ec, VALUE fname)
714687
VALUE parser = rb_parser_new();
715688
rb_parser_set_context(parser, NULL, FALSE);
716689
ast = (rb_ast_t *)rb_parser_load_file(parser, fname);
717-
718-
rb_thread_t *th = rb_ec_thread_ptr(ec);
719-
VALUE realpath_map = get_loaded_features_realpath_map(th->vm);
720-
721690
iseq = rb_iseq_new_top(&ast->body, rb_fstring_lit("<top (required)>"),
722-
fname, realpath_internal_cached(realpath_map, fname), NULL);
691+
fname, rb_realpath_internal(Qnil, fname, 1), NULL);
723692
rb_ast_dispose(ast);
724693
rb_vm_pop_frame(ec);
725694
RB_GC_GUARD(v);
@@ -1192,7 +1161,6 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa
11921161
volatile VALUE saved_path;
11931162
volatile VALUE realpath = 0;
11941163
VALUE realpaths = get_loaded_features_realpaths(th->vm);
1195-
VALUE realpath_map = get_loaded_features_realpath_map(th->vm);
11961164
volatile bool reset_ext_config = false;
11971165
struct rb_ext_config prev_ext_config;
11981166

@@ -1226,7 +1194,7 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa
12261194
}
12271195
#endif
12281196
else if (RTEST(rb_hash_aref(realpaths,
1229-
realpath = realpath_internal_cached(realpath_map, path)))) {
1197+
realpath = rb_realpath_internal(Qnil, path, 1)))) {
12301198
result = 0;
12311199
}
12321200
else {
@@ -1284,8 +1252,7 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa
12841252
rb_provide_feature(th2->vm, path);
12851253
VALUE real = realpath;
12861254
if (real) {
1287-
real = rb_fstring(real);
1288-
rb_hash_aset(realpaths, real, Qtrue);
1255+
rb_hash_aset(realpaths, rb_fstring(real), Qtrue);
12891256
}
12901257
}
12911258
ec->errinfo = saved.errinfo;
@@ -1506,8 +1473,6 @@ Init_load(void)
15061473
vm->loaded_features_index = st_init_numtable();
15071474
vm->loaded_features_realpaths = rb_hash_new();
15081475
rb_obj_hide(vm->loaded_features_realpaths);
1509-
vm->loaded_features_realpath_map = rb_hash_new();
1510-
rb_obj_hide(vm->loaded_features_realpath_map);
15111476

15121477
rb_define_global_function("load", rb_f_load, -1);
15131478
rb_define_global_function("require", rb_f_require, 1);

vm.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2703,7 +2703,6 @@ rb_vm_update_references(void *ptr)
27032703
vm->loaded_features = rb_gc_location(vm->loaded_features);
27042704
vm->loaded_features_snapshot = rb_gc_location(vm->loaded_features_snapshot);
27052705
vm->loaded_features_realpaths = rb_gc_location(vm->loaded_features_realpaths);
2706-
vm->loaded_features_realpath_map = rb_gc_location(vm->loaded_features_realpath_map);
27072706
vm->top_self = rb_gc_location(vm->top_self);
27082707
vm->orig_progname = rb_gc_location(vm->orig_progname);
27092708

@@ -2795,7 +2794,6 @@ rb_vm_mark(void *ptr)
27952794
rb_gc_mark_movable(vm->loaded_features);
27962795
rb_gc_mark_movable(vm->loaded_features_snapshot);
27972796
rb_gc_mark_movable(vm->loaded_features_realpaths);
2798-
rb_gc_mark_movable(vm->loaded_features_realpath_map);
27992797
rb_gc_mark_movable(vm->top_self);
28002798
rb_gc_mark_movable(vm->orig_progname);
28012799
RUBY_MARK_MOVABLE_UNLESS_NULL(vm->coverages);

vm_core.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,6 @@ typedef struct rb_vm_struct {
680680
VALUE loaded_features;
681681
VALUE loaded_features_snapshot;
682682
VALUE loaded_features_realpaths;
683-
VALUE loaded_features_realpath_map;
684683
struct st_table *loaded_features_index;
685684
struct st_table *loading_table;
686685
#if EXTSTATIC

0 commit comments

Comments
 (0)