Issue #5427 has been updated by funny_falcon (Yura Sokolov).


> The proposal is COMPLETELY compatible?

Unlike #5767 , this proposal is slightly incompatible, because it forces some kind
of sort order on LOADED_FEATURES, and this has impact on debugging (one couldn't
know which file were required last). But it allows to disable itself by setting 
environment variable 'RUBY_LOADED_FEATURES_SORTED=0'.

Also, some methods, which could change order of LOADED_FEATURES entries are undefined
at all (reverse!, sort!, shuffle!, rotate!, etc), but there is no one real application call
this methods.

So that, except debugging messages, this proposal fully compatible with any real
application.

Big applications gains about 6% of startup time improvement (whether #5767 applied or not).
Tiny script has neither benefits nor impact from this.

I believe, there could be another way to improve search across LOADED_FEATURES. 
For example, instead of sort LOADED_FEATURES itself by basename of file, there
could be managed hash mapping basename to array of files. But this adds a lot of
complexity.

Yura aka funny_falcon
----------------------------------------
Feature #5427: Not complex patch to improve `require` time (load.c)
https://bugs.ruby-lang.org/issues/5427#change-25525

Author: funny_falcon (Yura Sokolov)
Status: Assigned
Priority: Normal
Assignee: nobu (Nobuyoshi Nakada)
Category: 
Target version: 


Currently `loaded_features` are unsorted, so that `rb_feature_p` ought to iterate over all `loaded_features` to figure: is requested feature loaded?

After this patch `loaded_features` is kept sorted by basename without extension (/usr/lib/ruby/asdf.rb => asdf). When `rb_feature_p` start its check, it goes straight to the first item with matching basename (using binary search) and stops after last.

Methods `$LOADED_FEATURES.<<` and `$LOADED_FEATURES.push` are overriden to keep sort order. `push` accepts only 1 parameter, but it seems that no one pass more to it.

Currently I choose to consider characters of basename in right to left order, but it could be changed, I think.

https://gist.github.com/1272991
https://github.com/ruby/ruby/pull/51


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