The above takes 2.5 to 3 seconds on my machine, but just removing $LOAD_PATH << 'relative-path' make it complete in 50ms.
It's such a stark difference that I think it is a bug, and it cause Zeitwerk, a very popular gem, to be way slower than it should
when the load path contains relative paths.
I dug more into this today, based on @nobu's review. autoload? isn't the only thing slowed down in such case.
Perhaps we should try to emit a performance warning when a relative path or non-string object is appended to $LOAD_PATH. That would at least make it easier to notice this issue.
The problem of course is that $LOAD_PATH is just a regular array, so there isn't a clean hook where to check for this.
Right, that's just broken code. It would consider files under lib in $PWD for require which is wrong.
Perhaps we should try to emit a performance warning when a relative path or non-string object is appended to $LOAD_PATH. That would at least make it easier to notice this issue.
The problem of course is that $LOAD_PATH is just a regular array, so there isn't a clean hook where to check for this.
Maybe just warn on require or so, i.e. when noticing the path is relative, if it's too hard to notice when it's added?
I think there is also a cache for the expanded load path, maybe that could be a reasonable place to check.
It wouldn't immediately point at the culprit, but printing the $LOADED_FEATURES should help find it (maybe there should be a CLI flag/ENV var to print files as they are loaded, TruffleRuby has that).