|
| 1 | +commit 6c6b5199a4bb18d09b1da255b5c8bd549b03dc42 |
| 2 | +Author: Josh Cooper < [email protected]> |
| 3 | +Date: Wed Jan 24 22:31:57 2024 +0000 |
| 4 | + |
| 5 | + Revert "merge revision(s) 1f115f141dd17f75049a5e17107906c5bcc372e1:" |
| 6 | + |
| 7 | + This reverts commit 5baf94f9131fb45d50c8c408e007a138ced46606. |
| 8 | + |
| 9 | + Commit 79a4484a072e9769b603e7b4fbdb15b1d7eccb15 resulted in many more calls to |
| 10 | + `rb_realpath` when trying to load a file. |
| 11 | + |
| 12 | + Commit 8346d1630b8193eef1ec9dd537b16de74afdc2e8 added a cache to fix that. |
| 13 | + It was reverted in commit 1c7624469880bcb964be09a49e4907873f45b026. |
| 14 | + |
| 15 | + Commit 788b03d5ba82fd8b35ce1fe2618ce6bacc648333 added a second fix. |
| 16 | + It was reverted in e777064e4b064fd77aca65c123f1919433f6732d. |
| 17 | + |
| 18 | + Commit 5baf94f9131fb45d50c8c408e007a138ced46606 added a third fix and released in 3.2.3. |
| 19 | + The change does reduce the number of file I/O syscalls on RHEL 8: |
| 20 | + |
| 21 | + puppet-agent 8.4.0 puppet-agent 8.4.0 |
| 22 | + ruby 3.2.2 w/o patches ruby 3.2.3 w/o patches |
| 23 | + calls errors calls errors |
| 24 | + |
| 25 | + puppet --version 57996 5955 34511 6069 |
| 26 | + |
| 27 | + puppet apply -e "" 455006 18845 55159 19089 |
| 28 | + |
| 29 | + In both scenarios, the number of file syscalls dropped from: |
| 30 | + |
| 31 | + 57996 -> 34511 (59.5%) |
| 32 | + 455006 -> 55159 (12.1%) |
| 33 | + |
| 34 | + And the time to apply an empty catalog dropped from 1.908 seconds to 1.435 seconds. |
| 35 | + |
| 36 | + However, platforms like Windows don't HAVE_REALPATH. Instead ruby emulates it |
| 37 | + by walking each ancestor directory. So revert the third attempt to speed up the |
| 38 | + feature index and realpath cache so that we can revert 79a4484a072e9769b603e7b4fbdb15b1d7eccb15 |
| 39 | + |
| 40 | +diff --git a/load.c b/load.c |
| 41 | +index b2e5e962c8..f0219fcf50 100644 |
| 42 | +--- a/load.c |
| 43 | ++++ b/load.c |
| 44 | +@@ -163,12 +163,6 @@ get_loaded_features_realpaths(rb_vm_t *vm) |
| 45 | + return vm->loaded_features_realpaths; |
| 46 | + } |
| 47 | + |
| 48 | +-static VALUE |
| 49 | +-get_loaded_features_realpath_map(rb_vm_t *vm) |
| 50 | +-{ |
| 51 | +- return vm->loaded_features_realpath_map; |
| 52 | +-} |
| 53 | +- |
| 54 | + static VALUE |
| 55 | + get_LOADED_FEATURES(ID _x, VALUE *_y) |
| 56 | + { |
| 57 | +@@ -367,10 +361,7 @@ get_loaded_features_index(rb_vm_t *vm) |
| 58 | + st_foreach(vm->loaded_features_index, loaded_features_index_clear_i, 0); |
| 59 | + |
| 60 | + VALUE realpaths = vm->loaded_features_realpaths; |
| 61 | +- VALUE realpath_map = vm->loaded_features_realpath_map; |
| 62 | +- VALUE previous_realpath_map = rb_hash_dup(realpath_map); |
| 63 | + rb_hash_clear(realpaths); |
| 64 | +- rb_hash_clear(realpath_map); |
| 65 | + features = vm->loaded_features; |
| 66 | + for (i = 0; i < RARRAY_LEN(features); i++) { |
| 67 | + VALUE entry, as_str; |
| 68 | +@@ -387,14 +378,9 @@ get_loaded_features_index(rb_vm_t *vm) |
| 69 | + long j = RARRAY_LEN(features); |
| 70 | + for (i = 0; i < j; i++) { |
| 71 | + VALUE as_str = rb_ary_entry(features, i); |
| 72 | +- VALUE realpath = rb_hash_aref(previous_realpath_map, as_str); |
| 73 | +- if (NIL_P(realpath)) { |
| 74 | +- realpath = rb_check_realpath(Qnil, as_str, NULL); |
| 75 | +- if (NIL_P(realpath)) realpath = as_str; |
| 76 | +- realpath = rb_fstring(realpath); |
| 77 | +- } |
| 78 | +- rb_hash_aset(realpaths, realpath, Qtrue); |
| 79 | +- rb_hash_aset(realpath_map, as_str, realpath); |
| 80 | ++ VALUE realpath = rb_check_realpath(Qnil, as_str, NULL); |
| 81 | ++ if (NIL_P(realpath)) realpath = as_str; |
| 82 | ++ rb_hash_aset(realpaths, rb_fstring(realpath), Qtrue); |
| 83 | + } |
| 84 | + } |
| 85 | + return vm->loaded_features_index; |
| 86 | +@@ -1176,7 +1162,6 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa |
| 87 | + volatile VALUE saved_path; |
| 88 | + volatile VALUE realpath = 0; |
| 89 | + VALUE realpaths = get_loaded_features_realpaths(th->vm); |
| 90 | +- VALUE realpath_map = get_loaded_features_realpath_map(th->vm); |
| 91 | + volatile bool reset_ext_config = false; |
| 92 | + struct rb_ext_config prev_ext_config; |
| 93 | + |
| 94 | +@@ -1267,9 +1252,7 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa |
| 95 | + rb_provide_feature(th2->vm, path); |
| 96 | + VALUE real = realpath; |
| 97 | + if (real) { |
| 98 | +- real = rb_fstring(real); |
| 99 | +- rb_hash_aset(realpaths, real, Qtrue); |
| 100 | +- rb_hash_aset(realpath_map, path, real); |
| 101 | ++ rb_hash_aset(realpaths, rb_fstring(real), Qtrue); |
| 102 | + } |
| 103 | + } |
| 104 | + ec->errinfo = saved.errinfo; |
| 105 | +@@ -1498,8 +1481,6 @@ Init_load(void) |
| 106 | + vm->loaded_features_index = st_init_numtable(); |
| 107 | + vm->loaded_features_realpaths = rb_hash_new(); |
| 108 | + rb_obj_hide(vm->loaded_features_realpaths); |
| 109 | +- vm->loaded_features_realpath_map = rb_hash_new(); |
| 110 | +- rb_obj_hide(vm->loaded_features_realpath_map); |
| 111 | + |
| 112 | + rb_define_global_function("load", rb_f_load, -1); |
| 113 | + rb_define_global_function("require", rb_f_require, 1); |
| 114 | +diff --git a/vm.c b/vm.c |
| 115 | +index de43d022c0..d009a5f64a 100644 |
| 116 | +--- a/vm.c |
| 117 | ++++ b/vm.c |
| 118 | +@@ -2703,7 +2703,6 @@ rb_vm_update_references(void *ptr) |
| 119 | + vm->loaded_features = rb_gc_location(vm->loaded_features); |
| 120 | + vm->loaded_features_snapshot = rb_gc_location(vm->loaded_features_snapshot); |
| 121 | + vm->loaded_features_realpaths = rb_gc_location(vm->loaded_features_realpaths); |
| 122 | +- vm->loaded_features_realpath_map = rb_gc_location(vm->loaded_features_realpath_map); |
| 123 | + vm->top_self = rb_gc_location(vm->top_self); |
| 124 | + vm->orig_progname = rb_gc_location(vm->orig_progname); |
| 125 | + |
| 126 | +@@ -2795,7 +2794,6 @@ rb_vm_mark(void *ptr) |
| 127 | + rb_gc_mark_movable(vm->loaded_features); |
| 128 | + rb_gc_mark_movable(vm->loaded_features_snapshot); |
| 129 | + rb_gc_mark_movable(vm->loaded_features_realpaths); |
| 130 | +- rb_gc_mark_movable(vm->loaded_features_realpath_map); |
| 131 | + rb_gc_mark_movable(vm->top_self); |
| 132 | + rb_gc_mark_movable(vm->orig_progname); |
| 133 | + RUBY_MARK_MOVABLE_UNLESS_NULL(vm->coverages); |
| 134 | +diff --git a/vm_core.h b/vm_core.h |
| 135 | +index b6adeadd87..d86fdbaecd 100644 |
| 136 | +--- a/vm_core.h |
| 137 | ++++ b/vm_core.h |
| 138 | +@@ -680,7 +680,6 @@ typedef struct rb_vm_struct { |
| 139 | + VALUE loaded_features; |
| 140 | + VALUE loaded_features_snapshot; |
| 141 | + VALUE loaded_features_realpaths; |
| 142 | +- VALUE loaded_features_realpath_map; |
| 143 | + struct st_table *loaded_features_index; |
| 144 | + struct st_table *loading_table; |
| 145 | + #if EXTSTATIC |
0 commit comments