Issue #20177 has been reported by palkan (Vladimir Dementyev).
----------------------------------------
Feature #20177: Optimized $LOADED_FEATURES.include?
https://bugs.ruby-lang.org/issues/20177
* Author: palkan (Vladimir Dementyev)
* Status: Open
* Priority: Normal
----------------------------------------
I'd like to propose adding the optimized `$LOADED_FEATURES.include?` (not the one
provided by the Array class) for faster feature checks in large codebases (when there are
thousands of entries in the features list). I hit this problem while working on
[
require-hooks](https://github.com/ruby-next/require-hooks#results).
We can use the internal `vm->loaded_features_realpaths` Hash to achieve faster lookups
(it's used by MRI's `require / load` mechanism).
Alternatively to overriding the `#include?` method, we can introduce a custom API similar
to how `$LOAD_PATH.resolve_feature_path` has been introduced (e.g.,
`$LOADED_FEATURES.feature_loaded?(path)`); but since the behaviour is similar to
`Array#include?`, I'd suggest re-using it (and stay backward compatible).
--
https://bugs.ruby-lang.org/