all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Yikai Zhao <yikai@z1k.dev>
Cc: "Eli Zaretskii" <eliz@gnu.org>,
	73766@debbugs.gnu.org, "João Távora" <joaotavora@gmail.com>
Subject: bug#73766: 30.0.91; (documentation 'pcase) can take several seconds
Date: Thu, 17 Oct 2024 13:22:00 -0400	[thread overview]
Message-ID: <jwv8qummzdu.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <CANMyjpgmECc9wek+F5uecVRMaweSZhTBADBZTff-Ce=LyqnjSg@mail.gmail.com> (Yikai Zhao's message of "Sun, 13 Oct 2024 22:10:24 +0800")

>> >> Apparently, it would iterate over all defined pcase macros (N), and for
>> >> each of those, `help-fns-short-filename` would iterate over all items in
>> >> `load-path` (M). Total time complexity is N*M.
>> > Adding Stefan and João, in case they have some comments or
>> > suggestions.
>> How 'bout a patch like the one below?
> I tried this patch and can confirm it improves the performance.
> Here's the result of (benchmark-run (documentation 'pcase)):
> - master: 4s
> - master with this patch: 0.12s

Thanks 🙂

Wli, this is a non-trivial chunk of code and it's used more often than
just to get the docstring of `pcase`, so I'm clearly not obviously safe
for `emacs-30`.

Here are some options I can think of:

- Install it `emacs-30` anyway.
- Revert on `emacs-30` the change that introduced the slowdown:

    commit 052c2ce0284c5193c9d6768a45a9b3508af51230
    Author: Stefan Monnier <monnier@iro.umontreal.ca>
    Date:   Sun Feb 11 17:43:37 2024 -0500

        (pcase): Add buttons to the macros' defs in the docstring of `pcase`

        * lisp/emacs-lisp/pcase.el (pcase--find-macro-def-regexp): New var.
        (find-function-regexp-alist): Add entry for `pcase-macro`s.
        (help-fns--signature): Move declaration to where we know it is valid.
        (pcase--make-docstring): Add buttons to jump to the definition
        of Pcase macros.

- Install on `emacs-30` a simpler and more focused change, which should
  work acceptably in most cases, such as:

    diff --git a/lisp/emacs-lisp/pcase.el b/lisp/emacs-lisp/pcase.el
    index 5a7f3995311..811d42793cd 100644
    --- a/lisp/emacs-lisp/pcase.el
    +++ b/lisp/emacs-lisp/pcase.el
    @@ -214,7 +214,7 @@ pcase--make-docstring
                   (save-excursion
                     (forward-char -1)
                     (insert (format-message "  in `"))
    -                (help-insert-xref-button (help-fns-short-filename filename)
    +                (help-insert-xref-button (file-name-nondirectory filename)
                                              'help-function-def symbol filename
                                              'pcase-macro)
                     (insert (format-message "'."))))

> However it's still slower than last stable version:
> - 29.4 version: 0.02s

Slower than 29.4 is expected because it gives more information (the
file name, as a hyperlink).
I think for `C-h o` this plenty fast.

There's still a remaining performance issue for things like
`eldoc-mode`, admittedly where we'd really want it to be instantaneous,
but I think this should be fixed by making `eldoc` call `documentation`
in a special way to skips those useless computations (eldoc just wants
a "short doc" anyway).  This affects other functions using the
`function-documentation` property in a similar way.


        Stefan






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

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-12  8:02 bug#73766: 30.0.91; (documentation 'pcase) can take several seconds Yikai Zhao
2024-10-12  9:22 ` Eli Zaretskii
2024-10-12 16:39   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-13 14:10     ` Yikai Zhao
2024-10-17 17:22       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-10-18  1:22         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-18  5:57           ` Eli Zaretskii
2024-10-18  7:08         ` Eli Zaretskii
2024-10-18 17:04           ` 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

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

  git send-email \
    --in-reply-to=jwv8qummzdu.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=73766@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=joaotavora@gmail.com \
    --cc=monnier@iro.umontreal.ca \
    --cc=yikai@z1k.dev \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.