summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2023-04-12 12:33:16 -0700
committerJeremy Evans <code@jeremyevans.net>2023-04-13 20:22:36 -0700
commit1f115f141dd17f75049a5e17107906c5bcc372e1 (patch)
treeee97dfc4e85959cf84b8cb2e048e21fcc9e8b784 /vm.c
parent6beb755d810082ea3f557f54c687bc752a11cc7b (diff)
downloadruby-1f115f141dd17f75049a5e17107906c5bcc372e1.tar.gz
Speed up rebuilding the loaded feature index
Rebuilding the loaded feature index slowed down with the bug fix for #17885 in 79a4484a072e9769b603e7b4fbdb15b1d7eccb15. The slowdown was extreme if realpath emulation was used, but even when not emulated, it could be about 10x slower. This adds loaded_features_realpath_map to rb_vm_struct. This is a hidden hash mapping loaded feature paths to realpaths. When rebuilding the loaded feature index, look at this hash to get cached realpath values, and skip calling rb_check_realpath if a cached value is found. Fixes [Bug #19246]
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/vm.c b/vm.c
index 27d57a3b24..dfb535d01e 100644
--- a/vm.c
+++ b/vm.c
@@ -2699,6 +2699,7 @@ rb_vm_update_references(void *ptr)
vm->loaded_features = rb_gc_location(vm->loaded_features);
vm->loaded_features_snapshot = rb_gc_location(vm->loaded_features_snapshot);
vm->loaded_features_realpaths = rb_gc_location(vm->loaded_features_realpaths);
+ vm->loaded_features_realpath_map = rb_gc_location(vm->loaded_features_realpath_map);
vm->top_self = rb_gc_location(vm->top_self);
vm->orig_progname = rb_gc_location(vm->orig_progname);
@@ -2790,6 +2791,7 @@ rb_vm_mark(void *ptr)
rb_gc_mark_movable(vm->loaded_features);
rb_gc_mark_movable(vm->loaded_features_snapshot);
rb_gc_mark_movable(vm->loaded_features_realpaths);
+ rb_gc_mark_movable(vm->loaded_features_realpath_map);
rb_gc_mark_movable(vm->top_self);
rb_gc_mark_movable(vm->orig_progname);
RUBY_MARK_MOVABLE_UNLESS_NULL(vm->coverages);