unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Lin Sun <sunlin7.mail@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Eli Zaretskii <eliz@gnu.org>,
	acorallo@gnu.org, 41646@debbugs.gnu.org, stefankangas@gmail.com,
	monnier@gnu.org
Subject: bug#41646: Startup in Windows is very slow when load-path contains many
Date: Mon, 21 Oct 2024 17:11:17 +0000	[thread overview]
Message-ID: <CABCREdrcS+vQ4J_GTkAyM3CCf6APL5DhAUgY=G5ccA9Xtag+Jw@mail.gmail.com> (raw)
In-Reply-To: <jwvmsix4ld1.fsf-monnier+emacs@gnu.org>

On Mon, Oct 21, 2024 at 2:34 PM Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>
> > The `load-hints` can reduce searching attempts by putting the matched
> > paths on the top of `load-path`, it won't break the original
> > load-path; and the patch for the `package.el` will put the installed
> > files into the `load-hints`.
>
> The downside is that it can break existing setups for users who use
> `package.el` but also modify their `load-path` "by hand" in the
> init file, and it doesn't help users who don't use `package.el`.

The `load-hints' do nothing with its default value nil.

The package manager can use the `load-hints' or ignore it. The
"package.el" is emacs builtin package manager, can support or ignore
the `load-hints' by setting `package-enable-load-hints` to t or nil.
Other package managers can continue without any change, or do some
work to get performance benefits by supporting the `load-hints'.

> Note also that your `load-hints` could grow large, so scanning it could
> take a significant amount of time.  Maybe it would make sense to turn it
> into a hash table for those entries that don't use the "*" special
> thingy (and maybe use a radix-tree for those entries using the "*"
> special thingy)?

The `load-hints` could grow as the `load-path', or larger than the
`load-path', but it should not be too much.

For the hash table, it can not support the '*', or the hash-table
requires every file to have an entry explicitly, which costs a lot on
building the table.

I had checked the radix-tree at the beginning, it's not user-friendly,
or it's not easy to dump the radix tree for an end user to understand
which is obviously matching the entry or not.

The `load-hints' in the list are easy to understand / maintain by the end user.

> But your prefix idea makes me think maybe we can aim for a significantly
> smaller table, where we basically record only one entry per
> package/directory, like for "~/.emacs.d/elpa/helm-core-VERSION/" we just
> record "helm" because all the `.el` files share the "helm" prefix.
> I.e. keep for each dir the corresponding longest-common-prefix.
> If we're careful to consider only those files with a `.el` suffix, then
> I think we can reduce the hint to such a longest-common-prefix.  I.e. an
> info which doesn't say just "you can find FOO* files here" but "you can
> find *only* FOO* files here".

I had searched all 200+ packages in my test env, most of the packages
use their feature name as the prefix, only 11 packages have
exceptions. But I didn't understand how it works toward the
`load-hints'.

> Then we should be able to create quickly (so it can be recomputed on the
> fly whenever `load-path` changes) a radix-tree that maps a relative
> file name to the list of directories from `load-path` where it is
> worthwhile to look (by filtering out those dirs whose
> longest-common-prefix doesn't match).  We'd only do it for MUST_SUFFIX
> is specified, of course.
>
> > 1. On my local linux test env, disable load-hints on the package.el,
> > the test cli spends 6.327s; and enable load-hints then it spends
> > 5.392s.
> >
> > 2. On my local Windows test env, disable load-hints on the package.el,
> > the test cli spends 11.769s, and enable load-hints then it spends
> > 7.279s.
>
> Is that with or without using `package-quickstart`?

The `package-quickstart' does not help in this scenario, the key point
is the `load-path` count will times the read attempt.
A simple "(require 'X)" will lead the emacs walks through the
`load-path' to attempt opening the "X.so, X.so.gz, X.elc, X.elc.gz,
X.el, X.el.gz" one by one, if the `load-path' has 200 entries, emacs
will try search 200x6=1200 times for the worst case.

The `load-hints` will help put the matched path to the top of
`load-path` then emacs can find the X on the top entries of
`load-path' then returns shortly.

> BTW, in your patch, you change `locate-file-internal` which seems wrong,
> since that function is not specific to loading ELisp files, it's also
> used for $MANPATH, $PATH, and things like that.
>
> Similarly, I wasn't able to convince myself that your patch does the
> right thing when `require` or `load` is used such that MUST_SUFFIX is
> not specified.

I'm going to search the cases carefully. Thank you for all the
comments, appreciate it.





  reply	other threads:[~2024-10-21 17:11 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CABCREdrcJL1xfhB4NFW-WWRDd2ucMj_rVRTGZw1FqLHJHJFaQg@mail.gmail.com>
     [not found] ` <86jzedy84g.fsf@gnu.org>
     [not found]   ` <CABCREdq4JXaJbQwsS9=MWEzYnOAr2CZCCvg6pjjyNEgZO-MZrg@mail.gmail.com>
     [not found]     ` <CABCREdosvZSGgwrU8bvVtCzK+P0aX3ACCeTDqQXyg+6xhFXzkw@mail.gmail.com>
     [not found]       ` <86r08luqsq.fsf@gnu.org>
     [not found]         ` <CABCREdqtUisaCsV4=-nc7wNJ3P5Z_43yPXrYH1ZwWPGOQuptsw@mail.gmail.com>
     [not found]           ` <86frp1unvu.fsf@gnu.org>
     [not found]             ` <CABCREdp2Ug_wgnj=w=bS-XiYESp6D4Cr4aE2G2wBHTwAttZ=9Q@mail.gmail.com>
     [not found]               ` <86y12stv24.fsf@gnu.org>
     [not found]                 ` <CABCREdogicz4OKd0ORAtD_u2Q9HdLSt+DFs9pTqUQ1gcWGFdYg@mail.gmail.com>
2024-10-13  9:50                   ` bug#41646: Startup in Windows is very slow when load-path contains many Stefan Kangas
2024-10-13 10:43                     ` Eli Zaretskii
2024-10-13 14:47                       ` Lin Sun
2024-10-13 15:24                         ` Eli Zaretskii
2024-10-13 15:43                           ` Lin Sun
2024-10-13 15:56                             ` Eli Zaretskii
2024-10-13 16:03                               ` Lin Sun
2024-10-13 16:39                                 ` Eli Zaretskii
2024-10-16  7:51                                   ` Lin Sun
2024-10-21  4:09                                     ` Lin Sun
2024-10-21 14:34                                       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-21 17:11                                         ` Lin Sun [this message]
2024-10-21 19:53                                         ` Lin Sun
2024-10-13 15:51                     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CABCREdrcS+vQ4J_GTkAyM3CCf6APL5DhAUgY=G5ccA9Xtag+Jw@mail.gmail.com' \
    --to=sunlin7.mail@gmail.com \
    --cc=41646@debbugs.gnu.org \
    --cc=acorallo@gnu.org \
    --cc=eliz@gnu.org \
    --cc=monnier@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=stefankangas@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).