summaryrefslogtreecommitdiff
path: root/gem_prelude.rb
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2021-06-30 13:50:19 -0700
committerJeremy Evans <code@jeremyevans.net>2021-09-18 07:05:23 -0900
commitddb85c5d2bdf75a83eb163856508691a7436b446 (patch)
tree020e81c62e9f6b6f2f8fe058dbbb1f5238decf08 /gem_prelude.rb
parent1b300789ffc5fda1fcb534d0611ffdb7731e5b9d (diff)
downloadruby-ddb85c5d2bdf75a83eb163856508691a7436b446.tar.gz
Do not load file with same realpath twice when requiring
This fixes issues with paths being loaded twice in certain cases when symlinks are used. It took me multiple attempts to get this working. My original attempt tried to convert paths to realpaths before adding them to $LOADED_FEATURES. Unfortunately, this doesn't work well with the loaded feature index, which is based off load paths and not realpaths. While I was able to get require working, I'm fairly sure the loaded feature index was not being used as expected, which would have significant performance implications. Additionally, I was never able to get that approach working with autoload when autoloading a non-realpath file. It also broke some specs. This takes a more conservative approach. Directly before loading the file, if the file with the same realpath has been required, the loading of the file is skipped. The realpaths are stored as fstrings in a hidden hash. When rebuilding the loaded feature index, the hash of realpaths is also rebuilt. I'm guessing this makes rebuilding process slower, but I don think that is a hot path. In general, modifying loaded features is only done when reloading, and that tends to be in non-production environments. Change test_require_with_loaded_features_pop test to use 30 threads and 300 iterations, instead of 4 threads and 1000 iterations. I saw only sporadic failures with 4/1000, but consistent failures 30/300 threads. These failures were due to the fact that the concurrent deletions from $LOADED_FEATURES in other threads can result in rb_ary_entry returning nil when rebuilding the loaded features index. To avoid concurrency issues when rebuilding the loaded features index, the building of the index itself is left alone, and afterwards, a separate loop is done on a copy of the loaded feature snapshot in order to rebuild the realpaths hash. Fixes [Bug #17885]
Diffstat (limited to 'gem_prelude.rb')
0 files changed, 0 insertions, 0 deletions