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: Fri, 1 Nov 2024 07:18:11 +0000	[thread overview]
Message-ID: <CABCREdq_cFqeqDSVLOeFtt+u_5c12db+eAgfVuAHsN5rGSZNUA@mail.gmail.com> (raw)
In-Reply-To: <jwvsescwe1d.fsf-monnier+emacs@gnu.org>

On Thu, Oct 31, 2024 at 3:04 PM Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>
> >> 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.
>
> No, but if `package.el` adds elements to `load-hints` and then in your
> init file you add more elements to `load-path`, the `load-hints` may end
> up taking precedence over the new elements of `load-path` in some cases
> and thus change which file shadows which.

Yes, introducing this new variable will increase the complexity to the end user.

> > 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.
>
> You're not "supposed" to look at the representation of the radix tree,
> indeed (unless you're working on `radix-tree.el`, of course).
> Feel free to ask for help using it.
>
> > The `load-hints' in the list are easy to understand / maintain by the
> > end user.
>
> I don't think we need to burden end users with load hints.
>
> >> 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'.
>
> Here's the idea: the `<PKG>-autoloads.el` file can registers the longest
> common prefix of all the `.el` files for its own `load-path` entry, with
> say:
>
>     (load-prefix-register <DIR> <PREFIX>)
>
> where we'd define this function along the lines of
>
>     (defconst load-prefix-directories (make-hash-table :test 'equal))
>       "Set of entries from `load-path` for which we have prefix info.")
>
>     (defconst load-prefix-map radix-tree-empty
>       "Table associating file prefixes to directories.")
>
>     (defun load-prefix-register (dir prefix)
>       (puthash dir t load-prefix-directories)
>       (let ((dirs (radix-tree-lookup load-prefix-map prefix)))
>         (unless (member dir dirs)
>           (setq load-prefix-map (radix-tree-insert load-prefix-map prefix
>                                                    (cons dir dirs))))))
>
>     (defun load-prefix-trim-load-path (file)
>       "Return a trimmed `load-path` to use for FILE."
>       (if (file-name-directory file)
>           ;; If there's a `/` in FILE, fallback on the safe default.
>           load-path
>         (let* ((prefixes (radix-tree-prefixes load-prefix-map file))
>                (dirs (apply #'append (mapcar #'cdr prefixes))))
>           ;; Remove from `load-path` the entries which can't possibly
>           ;; have FILE because their prefixes doesn't match.
>           (cl-remove-if (lambda (dir)
>                           (and (gethash dir load-prefix-directories)
>                                (not (member dir dirs))))
>                         load-path))))
>
> and then `load` can use `load-prefix-trim-load-path` to iterate on
> a much shorter `load-path`.
>
> I'm not completely sure if it's a good idea, tho: I'd really prefer
> a solution that doesn't require any change to any package management
> code, which instead uses a cache (updated/filled automatically) of all
> the files found in all the `load-path` directories.

If that, we have to track the file/path changes in each entry of
load-path, it may not be possible for all the supported OSs.

> >> Is that with or without using `package-quickstart`?
> > The `package-quickstart' does not help in this scenario,
>
> AFAICT your scenario includes Emacs startup with packages installed, so
> `package-quickstart' can definitely make a difference.  But maybe you're
> right that it will affect both cases equally.

I had tried the package-quickstart, it does NOT help on windows, like
after load the quickstart.el, it will add all the packages directories
into the load-path, the load-path may have ~300 entries, then a simple
"(require 'org)" will trigger the emacs walk on the load-path one by
one to try open (org.so, org.so.gz, org.elc, org.elc.gz, org.el,
org.el.gz) for 6 times, while the org actually is on the bottom of
load-path, so the emacs tried near 1800 (300x6) times to load one org
file (its depends need similar counts), on windows systems, it's very
slow.

> >> 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.
> > The `load-hints` just put the matched paths on the top of `load-path`,
> > still following the `load-path' mechanism, and won't affect any other
> > features (Or someone already has some code to adjust the `load-path'
> > orders, can just ignore the `load-hints', everything work like before,
> > no break changes).
>
> But if FOO is in one dir and FOO.el is in another dir, adding entries
> to the load path can change which file we end up loading.

Yeh, that may happen, and the end user will get confused.





  reply	other threads:[~2024-11-01  7:18 UTC|newest]

Thread overview: 24+ 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
2024-10-31 15:04                                           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-01  7:18                                             ` Lin Sun [this message]
2024-11-01  7:49                                               ` Lin Sun
2024-11-01  8:17                                                 ` Eli Zaretskii
2024-11-01 13:11                                               ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-01 16:56                                                 ` Lin Sun
2024-11-01 17:08                                                   ` Eli Zaretskii
2024-11-01 17:58                                                     ` Lin Sun
2024-11-01 18:15                                                       ` Lin Sun
2024-11-01 19:17                                                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
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=CABCREdq_cFqeqDSVLOeFtt+u_5c12db+eAgfVuAHsN5rGSZNUA@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).