Issue #10902 has been updated by Aman Gupta.


Having a hard time coming up with a clean patch here. The following works but it's pretty hacky.

~~~ diff
diff --git a/load.c b/load.c
index fa225fa..68d15e7 100644
--- a/load.c
+++ b/load.c
@@ -952,6 +952,9 @@ rb_require_safe(VALUE fname, int safe)
     } volatile saved;
     char *volatile ftptr = 0;

+    if (strcmp(RSTRING_PTR(fname), "enumerator") == 0)
+	return Qfalse;
+
     if (RUBY_DTRACE_REQUIRE_ENTRY_ENABLED()) {
 	RUBY_DTRACE_REQUIRE_ENTRY(StringValuePtr(fname),
 				  rb_sourcefile(),
~~~

----------------------------------------
Bug #10902: require("enumerator") scans LOAD_PATH 2x on every invocation
https://bugs.ruby-lang.org/issues/10902#change-51702

* Author: Aman Gupta
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.1.5
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
On every invocation of `require "enumerator"` (for example during boot when many gems require it), the VM will scan the load path twice: once for enumerator.rb and again for enumerator.so. Of course, no file is found because enumerator is now shipped within the VM by default.

~~~
$ ruby -e' p $LOADED_FEATURES[0] '
"enumerator.so"

$ ruby -e' p $LOAD_PATH.size '
8

$ strace -e trace=open ruby -e' 1.times{ require "enumerator" } ' 2>&1 | grep enumerator.rb | wc -l
8

$ strace -e trace=open ruby -e' 1.times{ require "enumerator" } ' 2>&1 | grep enumerator.so | wc -l
8

$ strace -e trace=open ruby -e' 10.times{ require "enumerator" } ' 2>&1 | grep enumerator.so | wc -l
80

$ strace -e trace=open ruby -e' 100.times{ require "enumerator" } ' 2>&1 | grep enumerator.so | wc -l
800
~~~

In enumerator.c, we call `rb_provide("enumerator.so")` which adds it to $LOADED_FEATURES. This means `require "enumerator.so"` can be optimized, but most libraries do not include the .so extension when requiring enumerator.



-- 
https://bugs.ruby-lang.org/