From: Akira Matsuda Date: 2013-08-18T07:50:46+09:00 Subject: [ruby-core:56710] Re: [ruby-trunk - Feature #8781] Use require_relative() instead of require() if possible --001a11c373e4df622804e42c8aa0 Content-Type: text/plain; charset=ISO-8859-1 FYI: For those of you who wants to estimate how a "real use case" looks like, here I made tons of `require_relative`s on Rails https://github.com/amatsuda/rails/compare/require_relative Here I replaced all `require`s to `require_relative`. I confirmed it actually works, and as Ko1 said, we confirmed that it's not at all faster than the current `require` version, because Bundler already made require faster in a different way. > Yes. I think it's fine, I just don't want to use it. Are there no more > ways to speed up `require`? 1. Use Bundler 2. Avoid scanning through all installed gems before falling back to the original_require: https://github.com/ruby/ruby/blob/c106d19/lib/rubygems/core_ext/kernel_require.rb#L41 This is the reason every require call performs significantly slower than require_relative. 3. Reduce number of installed gems in your box... On Sun, Aug 18, 2013 at 5:58 AM, Aaron Patterson wrote: > On Sat, Aug 17, 2013 at 09:00:34PM +0900, Nobuyoshi Nakada wrote: > > (13/08/17 13:13), Aaron Patterson wrote: > > > First, it *is* a real use case (as in, people actually use it in *real* > > > projects): > > > > > > [aaron@higgins ruby (trunk)]$ git grep require_relative | grep '\.\.' > | wc -l > > > 45 > > > [aaron@higgins ruby (trunk)]$ > > > > It's only in test directory, and almost is test/ruby/envutil.rb. > > > > I agree that require_relative fits something but may not other. > > That example tells us that envutil.rb shouldn't be bound in test/ruby. > > > > > Again, "foo.rb" is completely independent of the filesystem. The files > > > it depends on did not change, so it did not have to change. > > > > > > I am uncertain how to make the coupling between "require_relative" and > > > the filesystem more clear than this. > > > > But I don't think your point enough to prohibit to use require_relative. > > I don't think it should be prohibited. I am pointing out why I don't > use it (namely LOAD_PATH hacking). > > > Why move a file but not edit it? > > I am using "file moving" as a way to demonstrate how `require_relative` > couples your file to its location on the file system. `require` does > not have this coupling. > > > An author can use it when one thinks it is useful, it's the author's > choice. > > This proposal is just a proposal, but not mandatory. > > Yes. I think it's fine, I just don't want to use it. Are there no more > ways to speed up `require`? > > -- > Aaron Patterson > http://tenderlovemaking.com/ > -- Akira Matsuda --001a11c373e4df622804e42c8aa0 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
FYI: For those of you who wants to estimate how a "re= al use case" looks like, here I made tons of `require_relative`s on Ra= ils = https://github.com/amatsuda/rails/compare/require_relative
Here I replaced all `require`s to `require_relative`.
I confirmed= it actually works, and as Ko1 said, we confirmed that it's not at all = faster than the current `require` version, because Bundler already made req= uire faster in a different way.

> Yes. =A0I think it's fine, I just don't wa= nt to use it. =A0Are there no more
> ways to speed up `require`?
<= div class=3D"">

1. Use Bundler

2. Avoid scanning through all installe= d gems before falling back to the original_require:=A0This is the reason every require call performs s= ignificantly slower than require_relative.
3. Reduce number of installed gems in = your box...

On Sun, Aug 18, 2013 at 5:58 AM, Aaron Patte= rson <tenderlove@ruby-lang.org> wrote:
On Sat, Aug 17, 2013 at 09:00:34PM +0900, Nobuyoshi Nakad= a wrote:
> (13/08/17 13:13), Aaron Patterson wrote:
> > First, it *is* a real use case (as in, people actually use it in = *real*
> > projects):
> >
> > [aaron@higgins ruby (trunk)]$ git grep require_relative | grep &#= 39;\.\.' | wc -l
> > =A0 =A0 =A0 45
> > [aaron@higgins ruby (trunk)]$
>
> It's only in test directory, and almost is test/ruby/envutil.rb. >
> I agree that require_relative fits something but may not other.
> That example tells us that envutil.rb shouldn't be bound in test/r= uby.
>
> > Again, "foo.rb" is completely independent of the filesy= stem. =A0The files
> > it depends on did not change, so it did not have to change.
> >
> > I am uncertain how to make the coupling between "require_rel= ative" and
> > the filesystem more clear than this.
>
> But I don't think your point enough to prohibit to use require_rel= ative.

I don't think it should be prohibited. =A0I am pointing out why I= don't
use it (namely LOAD_PATH hacking).

> Why move a file but not edit it?

I am using "file moving" as a way to demonstrate how `requi= re_relative`
couples your file to its location on the file system. =A0`require` does
not have this coupling.

> An author can use it when one thinks it is useful, it's the author= 's choice.
> This proposal is just a proposal, but not mandatory.

Yes. =A0I think it's fine, I just don't want to use it. =A0Ar= e there no more
ways to speed up `require`?

--
Aaron Patterson
http://tenderlov= emaking.com/



--
=
Akira Matsuda&l= t;ronnie@dio.jp><= /div>
--001a11c373e4df622804e42c8aa0--