Package: emacs;
Reported by: Yikai Zhao <yikai <at> z1k.dev>
Date: Sat, 12 Oct 2024 08:03:01 UTC
Severity: normal
Found in version 30.0.91
Done: Stefan Monnier <monnier <at> iro.umontreal.ca>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 73766 in the body.
You can then email your comments to 73766 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
View this report as an mbox folder, status mbox, maintainer mbox
bug-gnu-emacs <at> gnu.org
:bug#73766
; Package emacs
.
(Sat, 12 Oct 2024 08:03:02 GMT) Full text and rfc822 format available.Yikai Zhao <yikai <at> z1k.dev>
:bug-gnu-emacs <at> gnu.org
.
(Sat, 12 Oct 2024 08:03:02 GMT) Full text and rfc822 format available.Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
From: Yikai Zhao <yikai <at> z1k.dev> To: bug-gnu-emacs <at> gnu.org Subject: 30.0.91; (documentation 'pcase) can take several seconds Date: Sat, 12 Oct 2024 16:02:04 +0800
When `lsp-mode` is loaded, `(documentation 'pcase)` can take several seconds to complete. 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. In my case, N is about ~400 (defined in lsp-protocols.el) and M is about ~100 (I think it's a normal case?). This is especially problematic since the `documentation` method can be invoked by eldoc, which affects the responsiveness during editing. -- Here's my profiler result: 2713 86% - timer-event-handler 2713 86% - apply 2707 86% - #<native-comp-function F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_12> 2707 86% - eldoc-print-current-symbol-info 2707 86% - eldoc--invoke-strategy 2707 86% - eldoc-documentation-default 2707 86% - #<native-comp-function F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_17> 2707 86% - elisp-eldoc-funcall 2707 86% - elisp-get-fnsym-args-string 2707 86% - documentation 2707 86% - pcase--make-docstring 2606 82% - help-fns-short-filename 2598 82% - file-relative-name 335 10% file-remote-p 27 0% string-prefix-p -- In GNU Emacs 30.0.91 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.30, cairo version 1.15.10) of 2024-09-12 built on 8afcf8f014b8 Repository revision: 9a1c76bf7ff49d886cc8e1a3f360d71e62544802 Repository branch: HEAD Windowing system distributor 'The X.Org Foundation', version 11.0.12101004 System Description: Ubuntu 22.04.5 LTS Configured using: 'configure --prefix=/work/dist/AppDir --disable-locallisppath --with-native-compilation=aot --with-json --with-threads --with-sqlite3 --with-tree-sitter --with-dbus --with-xml2 --with-modules --with-libgmp --with-gpm --with-lcms2 --with-mps --with-x --without-pgtk --without-gconf --with-x-toolkit=gtk3 --with-xft --without-tiff --without-imagemagick --with-gif --with-png --with-rsvg --with-webp --with-harfbuzz --with-cairo --with-libotf --without-m17n-flt --with-jpeg emacs_cv_jpeglib=/usr/lib/x86_64-linux-gnu/libjpeg.a CPPFLAGS=-I/work/dist/AppDir/include LDFLAGS=-L/work/dist/AppDir/lib' Configured features: CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG LCMS2 LIBOTF LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB Important settings: value of $EMACSDATA: /tmp/.mount_emacsXLI1Nd/share/emacs/30.0.91/etc value of $EMACSDOC: /tmp/.mount_emacsXLI1Nd/share/emacs/30.0.91/etc value of $EMACSLOADPATH: /tmp/.mount_emacsXLI1Nd/share/emacs/30.0.91/lisp value of $EMACSPATH: /tmp/.mount_emacsXLI1Nd/libexec/emacs/30.0.91/x86_64-pc-linux-gnu value of $LC_MONETARY: en_US.UTF-8 value of $LC_NUMERIC: en_US.UTF-8 value of $LC_TIME: en_US.UTF-8 value of $LANG: en_US.UTF-8 value of $XMODIFIERS: @im=fcitx locale-coding-system: utf-8-unix Major mode: ELisp/l Minor modes in effect: sudo-edit-indicator-mode: t evil-vimish-fold-mode: t vimish-fold-mode: t diff-hl-mode: t projectile-mode: t flycheck-posframe-mode: t flycheck-mode: t ligature-mode: t whitespace-mode: t electric-pair-mode: t hl-todo-mode: t dtrt-indent-mode: t windmove-mode: t tempel-abbrev-mode: t company-mode: t global-git-commit-mode: t magit-auto-revert-mode: t hl-line-mode: t display-line-numbers-mode: t recentf-mode: t pixel-scroll-precision-mode: t server-mode: t winner-mode: t global-auto-revert-mode: t save-place-mode: t vertico-mode: t which-key-mode: t global-evil-visualstar-mode: t evil-visualstar-mode: t evil-snipe-override-mode: t evil-snipe-override-local-mode: t evil-owl-mode: t global-evil-surround-mode: t evil-surround-mode: t evil-commentary-mode: t evil-mode: t evil-local-mode: t override-global-mode: t tooltip-mode: t global-eldoc-mode: t eldoc-mode: t show-paren-mode: t electric-indent-mode: t mouse-wheel-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t minibuffer-regexp-mode: t transient-mark-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t Load-path shadows: /home/yikai/.emacs.d/lib/which-key/which-key hides /tmp/.mount_emacsXLI1Nd/share/emacs/30.0.91/lisp/which-key /home/yikai/.emacs.d/lib/transient/lisp/transient hides /tmp/.mount_emacsXLI1Nd/share/emacs/30.0.91/lisp/transient /home/yikai/.emacs.d/lib/editorconfig/editorconfig hides /tmp/.mount_emacsXLI1Nd/share/emacs/30.0.91/lisp/editorconfig /home/yikai/.emacs.d/lib/editorconfig/editorconfig-tools hides /tmp/.mount_emacsXLI1Nd/share/emacs/30.0.91/lisp/editorconfig-tools /home/yikai/.emacs.d/lib/editorconfig/editorconfig-fnmatch hides /tmp/.mount_emacsXLI1Nd/share/emacs/30.0.91/lisp/editorconfig-fnmatch /home/yikai/.emacs.d/lib/editorconfig/editorconfig-core hides /tmp/.mount_emacsXLI1Nd/share/emacs/30.0.91/lisp/editorconfig-core /home/yikai/.emacs.d/lib/editorconfig/editorconfig-core-handle hides /tmp/.mount_emacsXLI1Nd/share/emacs/30.0.91/lisp/editorconfig-core-handle /home/yikai/.emacs.d/lib/editorconfig/editorconfig-conf-mode hides /tmp/.mount_emacsXLI1Nd/share/emacs/30.0.91/lisp/editorconfig-conf-mode /home/yikai/.emacs.d/lib/use-package/bind-key hides /tmp/.mount_emacsXLI1Nd/share/emacs/30.0.91/lisp/bind-key /home/yikai/.emacs.d/lib/use-package/use-package hides /tmp/.mount_emacsXLI1Nd/share/emacs/30.0.91/lisp/use-package/use-package /home/yikai/.emacs.d/lib/use-package/use-package-lint hides /tmp/.mount_emacsXLI1Nd/share/emacs/30.0.91/lisp/use-package/use-package-lint /home/yikai/.emacs.d/lib/use-package/use-package-jump hides /tmp/.mount_emacsXLI1Nd/share/emacs/30.0.91/lisp/use-package/use-package-jump /home/yikai/.emacs.d/lib/use-package/use-package-ensure hides /tmp/.mount_emacsXLI1Nd/share/emacs/30.0.91/lisp/use-package/use-package-ensure /home/yikai/.emacs.d/lib/use-package/use-package-ensure-system-package hides /tmp/.mount_emacsXLI1Nd/share/emacs/30.0.91/lisp/use-package/use-package-ensure-system-package /home/yikai/.emacs.d/lib/use-package/use-package-diminish hides /tmp/.mount_emacsXLI1Nd/share/emacs/30.0.91/lisp/use-package/use-package-diminish /home/yikai/.emacs.d/lib/use-package/use-package-delight hides /tmp/.mount_emacsXLI1Nd/share/emacs/30.0.91/lisp/use-package/use-package-delight /home/yikai/.emacs.d/lib/use-package/use-package-core hides /tmp/.mount_emacsXLI1Nd/share/emacs/30.0.91/lisp/use-package/use-package-core /home/yikai/.emacs.d/lib/use-package/use-package-bind-key hides /tmp/.mount_emacsXLI1Nd/share/emacs/30.0.91/lisp/use-package/use-package-bind-key /home/yikai/.emacs.d/lib/compat/compat hides /tmp/.mount_emacsXLI1Nd/share/emacs/30.0.91/lisp/emacs-lisp/compat Features: (shadow sort mail-extr emacsbug tramp-cmds loadhist doctor devdocs-browser evil-collection-profiler profiler consult-xref evil-collection-shortdoc shortdoc cus-start tabify descr-text evil-collection-view view jka-compr evil-collection-woman woman evil-collection-man man goto-addr magit-extras cl-print printing ps-print ps-print-loaddefs lpr help-fns vc-hg vc-bzr vc-src vc-sccs vc-svn vc-cvs vc-rcs evil-collection-vc-git vc-git bug-reference magit-bookmark evil-collection-magit magit-submodule magit-blame magit-stash magit-reflog magit-bisect magit-push magit-pull magit-fetch magit-clone magit-remote magit-commit magit-sequence magit-notes magit-worktree magit-tag magit-merge magit-branch magit-reset magit-files magit-refs magit-status magit evil-collection-package-menu package url-handlers evil-collection-magit-repos magit-repos magit-apply magit-wip magit-log jinja2-mode tramp-cache time-stamp bpftrace-mode expand-region yaml-mode-expansions text-mode-expansions cc-mode-expansions python-el-fgallina-expansions js-mode-expansions html-mode-expansions css-mode-expansions er-basic-expansions expand-region-core expand-region-custom pr-review-search css-mode sgml-mode facemenu evil-collection-eww eww mm-url evil-collection-gnus gnus nnheader range typescript-ts-mode sudo-edit ebuild-mode skeleton autoinsert lsp-haskell haskell-mode haskell-cabal haskell-utils haskell-font-lock haskell-indentation haskell-string haskell-sort-imports haskell-lexeme haskell-align-imports haskell-complete-module haskell-ghc-support flymake-proc evil-collection-flymake flymake etags fileloop generator dabbrev haskell-customize lsp-pyright lsp-mode lsp-protocol spinner lv inline ht evil-vimish-fold vimish-fold f s git-gutter-fringe fringe-helper git-gutter evil-collection-diff-hl diff-hl evil-collection-log-view log-view evil-collection-vc-dir vc-dir ewoc vc vc-dispatcher projectile evil-collection-grep grep ibuf-ext evil-collection-ibuffer ibuffer ibuffer-loaddefs flycheck-posframe posframe flycheck-google-cpplint evil-collection-flycheck flycheck ligature whitespace elec-pair hl-todo dtrt-indent company-keywords company-dabbrev-code company-dabbrev company-files make-mode evil-collection-sh-script sh-script executable evil-collection-cmake-mode cmake-mode rst js c-ts-common evil-collection-yaml-mode yaml-mode vertico-directory windmove tempel company-abbrev company-emoji company-emoji-list company-capf company orderless bazel evil-collection-xref xref which-func testcover evil-collection-edebug edebug evil-collection-debug debug backtrace evil-collection-python python treesit project evil-collection-imenu imenu ffap protobuf-mode cc-mode cc-fonts cc-guess cc-menus cc-cmds jsonnet-mode smie conf-mode url-queue textsec uni-scripts idna-mapping ucs-normalize uni-confusable textsec-check pr-review pr-review-render shr pixel-fill kinsoku url-file svg dom pr-review-action magit-diff smerge-mode diff evil-collection-diff-mode diff-mode track-changes git-commit evil-collection-log-edit log-edit message sendmail yank-media evil-collection-dired dired dired-loaddefs rfc822 mml mml-sec evil-collection-epa epa derived epg rfc6068 epg-config gnus-util mm-decode mm-bodies mm-encode mailabbrev gmm-utils mailheader pcvs-util add-log magit-core magit-autorevert magit-margin magit-transient magit-process with-editor magit-mode transient browse-url benchmark magit-git magit-base crm pr-review-input evil-collection-markdown-mode markdown-mode evil-collection-outline noutline outline mule-util pulse mail-utils network-stream url-cache hl-line display-line-numbers pr-review-notification pr-review-listview pr-review-api ghub-graphql treepy gsexp ghub url-http mail-parse rfc2231 rfc2047 rfc2045 mm-util ietf-drums mail-prsvr url-gw nsm url-auth url url-proxy url-privacy url-expand url-methods url-history url-cookie url-domsuf url-util mailcap let-alist gnutls puny pr-review-common evil-collection-magit-section magit-section dash recentf tree-widget wid-edit evil-collection-consult consult cursor-sensor time pixel-scroll cua-base auth-source-pass url-parse url-vars server fcitx dbus xml winner evil-collection-vterm vterm evil-collection-bookmark bookmark pp face-remap evil-collection-compile compile text-property-search evil-collection-term term disp-table ehelp find-func vterm-module term/xterm xterm cc-styles cc-align cc-engine cc-vars cc-defs google-c-style midnight diary-lib diary-loaddefs evil-collection-calendar cal-menu calendar cal-loaddefs autorevert filenotify saveplace tramp-sh tramp trampver tramp-integration files-x tramp-message tramp-compat xdg shell pcomplete evil-collection-comint comint ansi-osc parse-time iso8601 time-date auth-source eieio eieio-core password-cache json map ansi-color tramp-loaddefs cus-load evil-collection-vertico vertico compat solarized-light-theme solarized-theme solarized solarized-faces color evil-collection-which-key which-key fringe-scale switch-buffer-functions evil-visualstar evil-snipe evil-owl format-spec evil-surround evil-commentary evil-commentary-integration evil-collection-tabulated-list evil-collection-tab-bar evil-collection-simple evil-collection-replace evil-collection-process-menu evil-collection-kmacro evil-collection-info evil-collection-indent evil-collection-help evil-collection-elisp-mode evil-collection-eldoc evil-collection-buff-menu evil-collection annalist evil evil-integration evil-maps evil-commands evil-digraphs reveal evil-jumps evil-command-window evil-types evil-search evil-ex evil-macros evil-repeat evil-states evil-core advice evil-common thingatpt rect evil-vars ring edmacro kmacro byte-opt delight comp-run use-package use-package-ensure use-package-delight use-package-diminish use-package-bind-key bind-key easy-mmode use-package-core yaml-mode-autoloads xonsh-mode-autoloads with-editor-autoloads which-key-autoloads wgrep-autoloads vterm-autoloads vimrc-mode-autoloads vimish-fold-autoloads vertico-autoloads use-package-autoloads treesit-auto-autoloads treepy-autoloads transient-autoloads tempel-autoloads switch-buffer-functions-autoloads suggest-autoloads sudo-edit-autoloads spinner-autoloads solarized-theme-autoloads s-autoloads rust-mode-autoloads rg-autoloads rainbow-mode-autoloads pydoc-autoloads protobuf-mode-autoloads projectile-autoloads pr-review-autoloads posframe-autoloads popup-autoloads pkg-info-autoloads php-mode-autoloads package-lint-autoloads org2elcomment-autoloads org-tree-slide-autoloads orderless-autoloads markdown-mode-autoloads magit-autoloads lv-autoloads lua-mode-autoloads lsp-pyright-autoloads lsp-mode-autoloads lsp-haskell-autoloads loop-autoloads llama-autoloads ligature-autoloads kotlin-mode-autoloads just-mode-autoloads jsonnet-mode-autoloads jinja2-mode-autoloads ht-autoloads hl-todo-autoloads haskell-mode-autoloads groovy-mode-autoloads gptel-autoloads goto-chg-autoloads google-c-style-autoloads go-mode-autoloads gn-mode-autoloads git-link-autoloads git-gutter-fringe-autoloads git-gutter-autoloads ghub-autoloads fringe-helper-autoloads flycheck-posframe-autoloads flycheck-package-autoloads flycheck-google-cpplint-autoloads flycheck-autoloads fish-mode-autoloads fcitx-autoloads f-autoloads explain-pause-mode-autoloads expand-region-autoloads exec-path-from-shell-autoloads evil-visualstar-autoloads evil-vimish-fold-autoloads evil-surround-autoloads evil-snipe-autoloads evil-owl-autoloads evil-commentary-autoloads evil-collection-autoloads evil-autoloads epl-autoloads epkg-autoloads embark-autoloads emacsql-autoloads emacs-fringe-scale-autoloads editorconfig-autoloads ebuild-mode-autoloads dumb-jump-autoloads dtrt-indent-autoloads dockerfile-mode-autoloads diff-hl-autoloads devdocs-browser-autoloads delight-autoloads dash-autoloads cuda-mode-autoloads copilot-autoloads consult-flycheck-autoloads consult-autoloads compat-autoloads company-emoji-autoloads company-autoloads codeium-autoloads cl-macs cmake-mode-autoloads closql-autoloads bpftrace-mode-autoloads borg-autoloads bazel-autoloads avy-autoloads annalist-autoloads add-node-modules-path-autoloads borg loaddefs-gen generate-lisp-file lisp-mnt radix-tree pcase info comp cl-seq comp-cstr cl-extra help-mode comp-common warnings icons subr-x rx gv cl-loaddefs cl-lib bytecomp byte-compile rmc iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win term/common-win x-dnd touch-screen tool-bar dnd fontset image regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic indonesian philippine cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese composite emoji-zwj charscript charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp files window text-properties overlay sha1 md5 base64 format env code-pages mule custom widget keymap hashtable-print-readable backquote threads dbusbind inotify lcms2 dynamic-setting system-font-setting font-render-setting cairo gtk x-toolkit xinput2 x multi-tty move-toolbar make-network-process native-compile emacs) Memory information: ((conses 16 1185831 1011558) (symbols 48 67125 23) (strings 32 316477 39434) (string-bytes 1 10307989) (vectors 16 123279) (vector-slots 8 2358285 658163) (floats 8 1093 15048) (intervals 56 31071 5410) (buffers 992 56))
bug-gnu-emacs <at> gnu.org
:bug#73766
; Package emacs
.
(Sat, 12 Oct 2024 09:23:02 GMT) Full text and rfc822 format available.Message #8 received at 73766 <at> debbugs.gnu.org (full text, mbox):
From: Eli Zaretskii <eliz <at> gnu.org> To: Yikai Zhao <yikai <at> z1k.dev>, Stefan Monnier <monnier <at> iro.umontreal.ca>, João Távora <joaotavora <at> gmail.com> Cc: 73766 <at> debbugs.gnu.org Subject: Re: bug#73766: 30.0.91; (documentation 'pcase) can take several seconds Date: Sat, 12 Oct 2024 12:22:13 +0300
> From: Yikai Zhao <yikai <at> z1k.dev> > Date: Sat, 12 Oct 2024 16:02:04 +0800 > > When `lsp-mode` is loaded, `(documentation 'pcase)` can take several > seconds to complete. > > 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. > > In my case, N is about ~400 (defined in lsp-protocols.el) and M is about > ~100 (I think it's a normal case?). > > This is especially problematic since the `documentation` method can be > invoked by eldoc, which affects the responsiveness during editing. > > -- > > Here's my profiler result: > > 2713 86% - timer-event-handler > 2713 86% - apply > 2707 86% - #<native-comp-function > F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_12> > 2707 86% - eldoc-print-current-symbol-info > 2707 86% - eldoc--invoke-strategy > 2707 86% - eldoc-documentation-default > 2707 86% - #<native-comp-function > F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_17> > 2707 86% - elisp-eldoc-funcall > 2707 86% - elisp-get-fnsym-args-string > 2707 86% - documentation > 2707 86% - pcase--make-docstring > 2606 82% - help-fns-short-filename > 2598 82% - file-relative-name > 335 10% file-remote-p > 27 0% string-prefix-p Adding Stefan and João, in case they have some comments or suggestions.
bug-gnu-emacs <at> gnu.org
:bug#73766
; Package emacs
.
(Sat, 12 Oct 2024 16:41:04 GMT) Full text and rfc822 format available.Message #11 received at 73766 <at> debbugs.gnu.org (full text, mbox):
From: Stefan Monnier <monnier <at> iro.umontreal.ca> To: Eli Zaretskii <eliz <at> gnu.org> Cc: 73766 <at> debbugs.gnu.org, Yikai Zhao <yikai <at> z1k.dev>, João Távora <joaotavora <at> gmail.com> Subject: Re: bug#73766: 30.0.91; (documentation 'pcase) can take several seconds Date: Sat, 12 Oct 2024 12:39:38 -0400
[Message part 1 (text/plain, inline)]
>> 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? Stefan
[shortenfile.patch (text/x-diff, inline)]
diff --git a/lisp/help-fns.el b/lisp/help-fns.el index 3f64b2e126f..3e0973c25ee 100644 --- a/lisp/help-fns.el +++ b/lisp/help-fns.el @@ -1090,17 +1090,38 @@ help-fns--mention-shortdoc-groups (fill-region-as-paragraph (point-min) (point-max)) (goto-char (point-max)))))) +(require 'radix-tree) + +(defconst help-fns--radix-trees + (make-hash-table :weakness 'key :test #'equal)) + +(defun help-fns--radix-tree (dirs) + (with-memoization (gethash dirs help-fns--radix-trees) + (let ((rt radix-tree-empty)) + (dolist (d dirs) + (let ((d (abbreviate-file-name + (file-name-as-directory (expand-file-name d))))) + (setq rt (radix-tree-insert rt d t)))) + rt))) + (defun help-fns-short-filename (filename) - (let* ((abbrev (abbreviate-file-name filename)) - (short abbrev)) - (dolist (dir load-path) - (let ((rel (file-relative-name filename dir))) - (if (< (length rel) (length short)) - (setq short rel))) - (let ((rel (file-relative-name abbrev dir))) - (if (< (length rel) (length short)) - (setq short rel)))) - short)) + (let* ((short (abbreviate-file-name (expand-file-name filename))) + (dir (file-name-directory short)) + (nondir (file-name-nondirectory short)) + (rt (help-fns--radix-tree load-path)) + (prefixes (radix-tree-prefixes rt dir))) + (if (not prefixes) + ;; The file is not inside the `load-path'. + ;; FIXME: We used to try and shorten it with "../". + ;; (dolist (dir load-path) + ;; (let ((rel (file-relative-name filename dir))) + ;; (if (< (length rel) (length short)) + ;; (setq short rel))) + ;; (let ((rel (file-relative-name abbrev dir))) + ;; (if (< (length rel) (length short)) + ;; (setq short rel)))) + short + (file-relative-name short (caar prefixes))))) (defun help-fns--analyze-function (function) ;; FIXME: Document/explain the differences between FUNCTION,
bug-gnu-emacs <at> gnu.org
:bug#73766
; Package emacs
.
(Sun, 13 Oct 2024 14:12:01 GMT) Full text and rfc822 format available.Message #14 received at 73766 <at> debbugs.gnu.org (full text, mbox):
From: Yikai Zhao <yikai <at> z1k.dev> To: Stefan Monnier <monnier <at> iro.umontreal.ca> Cc: Eli Zaretskii <eliz <at> gnu.org>, 73766 <at> debbugs.gnu.org, João Távora <joaotavora <at> gmail.com> Subject: Re: bug#73766: 30.0.91; (documentation 'pcase) can take several seconds Date: Sun, 13 Oct 2024 22:10:24 +0800
On Sun, Oct 13, 2024 at 12:39 AM Stefan Monnier <monnier <at> iro.umontreal.ca> wrote: > > >> 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? Hello, 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 However it's still slower than last stable version: - 29.4 version: 0.02s Yikai
bug-gnu-emacs <at> gnu.org
:bug#73766
; Package emacs
.
(Thu, 17 Oct 2024 17:23:02 GMT) Full text and rfc822 format available.Message #17 received at 73766 <at> debbugs.gnu.org (full text, mbox):
From: Stefan Monnier <monnier <at> iro.umontreal.ca> To: Yikai Zhao <yikai <at> z1k.dev> Cc: Eli Zaretskii <eliz <at> gnu.org>, 73766 <at> debbugs.gnu.org, João Távora <joaotavora <at> gmail.com> Subject: Re: bug#73766: 30.0.91; (documentation 'pcase) can take several seconds Date: Thu, 17 Oct 2024 13:22:00 -0400
>> >> 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 <at> 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
bug-gnu-emacs <at> gnu.org
:bug#73766
; Package emacs
.
(Fri, 18 Oct 2024 01:24:02 GMT) Full text and rfc822 format available.Message #20 received at 73766 <at> debbugs.gnu.org (full text, mbox):
From: Stefan Monnier <monnier <at> iro.umontreal.ca> To: Yikai Zhao <yikai <at> z1k.dev> Cc: Eli Zaretskii <eliz <at> gnu.org>, 73766 <at> debbugs.gnu.org, João Távora <joaotavora <at> gmail.com> Subject: Re: bug#73766: 30.0.91; (documentation 'pcase) can take several seconds Date: Thu, 17 Oct 2024 21:22:58 -0400
> Wli, this is a non-trivial chunk of code and it's used more often than ^^^ Eli Boy, my typing is getting worse by the day. Sometimes I wonder is my brain is turning to mush. At least for the above blunder, `e` is right next to `w` on my keyboard, so there is some kind of "logic" to it. Stefan
bug-gnu-emacs <at> gnu.org
:bug#73766
; Package emacs
.
(Fri, 18 Oct 2024 05:59:02 GMT) Full text and rfc822 format available.Message #23 received at 73766 <at> debbugs.gnu.org (full text, mbox):
From: Eli Zaretskii <eliz <at> gnu.org> To: Stefan Monnier <monnier <at> iro.umontreal.ca> Cc: 73766 <at> debbugs.gnu.org, yikai <at> z1k.dev, joaotavora <at> gmail.com Subject: Re: bug#73766: 30.0.91; (documentation 'pcase) can take several seconds Date: Fri, 18 Oct 2024 08:57:32 +0300
> From: Stefan Monnier <monnier <at> iro.umontreal.ca> > Cc: Eli Zaretskii <eliz <at> gnu.org>, João Távora > <joaotavora <at> gmail.com>, > 73766 <at> debbugs.gnu.org > Date: Thu, 17 Oct 2024 21:22:58 -0400 > > > Wli, this is a non-trivial chunk of code and it's used more often than > ^^^ > Eli > > Boy, my typing is getting worse by the day. Sometimes I wonder is my > brain is turning to mush. At least for the above blunder, `e` is right > next to `w` on my keyboard, so there is some kind of "logic" to it. Your simple cypher was successfully decoded here ;-)
bug-gnu-emacs <at> gnu.org
:bug#73766
; Package emacs
.
(Fri, 18 Oct 2024 07:10:02 GMT) Full text and rfc822 format available.Message #26 received at 73766 <at> debbugs.gnu.org (full text, mbox):
From: Eli Zaretskii <eliz <at> gnu.org> To: Stefan Monnier <monnier <at> iro.umontreal.ca> Cc: 73766 <at> debbugs.gnu.org, yikai <at> z1k.dev, joaotavora <at> gmail.com Subject: Re: bug#73766: 30.0.91; (documentation 'pcase) can take several seconds Date: Fri, 18 Oct 2024 10:08:41 +0300
> From: Stefan Monnier <monnier <at> iro.umontreal.ca> > Cc: Eli Zaretskii <eliz <at> gnu.org>, João Távora > <joaotavora <at> gmail.com>, > 73766 <at> debbugs.gnu.org > Date: Thu, 17 Oct 2024 13:22:00 -0400 > > Eli, 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 <at> 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 "'.")))) I'd prefer the last alternative for emacs-30, but then you say: > 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. Does it mean that this slowdown of eldoc was also caused by commit 052c2ce0284c5193c9d6768a45a9b3508af51230, and if so, does the patch you've shown previously (and which you consider not safe enough for emacs-30) solve the eldoc slowdown as well?
bug-gnu-emacs <at> gnu.org
:bug#73766
; Package emacs
.
(Fri, 18 Oct 2024 17:06:01 GMT) Full text and rfc822 format available.Message #29 received at 73766 <at> debbugs.gnu.org (full text, mbox):
From: Stefan Monnier <monnier <at> iro.umontreal.ca> To: Eli Zaretskii <eliz <at> gnu.org> Cc: 73766 <at> debbugs.gnu.org, yikai <at> z1k.dev, joaotavora <at> gmail.com Subject: Re: bug#73766: 30.0.91; (documentation 'pcase) can take several seconds Date: Fri, 18 Oct 2024 13:04:54 -0400
>> 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 "'.")))) > > I'd prefer the last alternative for emacs-30, but then you say: Thanks, will do. >> 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. > Does it mean that this slowdown of eldoc was also caused by commit > 052c2ce0284c5193c9d6768a45a9b3508af51230, and if so, does the patch > you've shown previously (and which you consider not safe enough for > emacs-30) solve the eldoc slowdown as well? What I meant is that the 4s slowdown affects both `C-h f` and eldoc, and that the patch I sent which reduces it to 0.12s is IMO sufficient for the `C-h f` case but may still make Emacs feel occasionally a bit sluggish when eldoc hits this 0.12s. Stefan
bug-gnu-emacs <at> gnu.org
:bug#73766
; Package emacs
.
(Fri, 18 Oct 2024 18:36:01 GMT) Full text and rfc822 format available.Message #32 received at 73766 <at> debbugs.gnu.org (full text, mbox):
From: Eli Zaretskii <eliz <at> gnu.org> To: Stefan Monnier <monnier <at> iro.umontreal.ca> Cc: 73766 <at> debbugs.gnu.org, yikai <at> z1k.dev, joaotavora <at> gmail.com Subject: Re: bug#73766: 30.0.91; (documentation 'pcase) can take several seconds Date: Fri, 18 Oct 2024 21:35:05 +0300
> From: Stefan Monnier <monnier <at> iro.umontreal.ca> > Cc: yikai <at> z1k.dev, joaotavora <at> gmail.com, 73766 <at> debbugs.gnu.org > Date: Fri, 18 Oct 2024 13:04:54 -0400 > > > I'd prefer the last alternative for emacs-30, but then you say: > > Thanks, will do. > > >> 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. > > Does it mean that this slowdown of eldoc was also caused by commit > > 052c2ce0284c5193c9d6768a45a9b3508af51230, and if so, does the patch > > you've shown previously (and which you consider not safe enough for > > emacs-30) solve the eldoc slowdown as well? > > What I meant is that the 4s slowdown affects both `C-h f` and eldoc, > and that the patch I sent which reduces it to 0.12s is IMO sufficient > for the `C-h f` case but may still make Emacs feel occasionally a bit > sluggish when eldoc hits this 0.12s. If the slowdown of eldoc is significant, maybe we will be better with reverting the change which introduced the regression on emacs-30, and then solving on master with your more thorough fix.
bug-gnu-emacs <at> gnu.org
:bug#73766
; Package emacs
.
(Fri, 18 Oct 2024 20:44:02 GMT) Full text and rfc822 format available.Message #35 received at 73766 <at> debbugs.gnu.org (full text, mbox):
From: Stefan Monnier <monnier <at> iro.umontreal.ca> To: Eli Zaretskii <eliz <at> gnu.org> Cc: 73766 <at> debbugs.gnu.org, yikai <at> z1k.dev, joaotavora <at> gmail.com Subject: Re: bug#73766: 30.0.91; (documentation 'pcase) can take several seconds Date: Fri, 18 Oct 2024 16:42:32 -0400
>> >> 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. >> > Does it mean that this slowdown of eldoc was also caused by commit >> > 052c2ce0284c5193c9d6768a45a9b3508af51230, and if so, does the patch >> > you've shown previously (and which you consider not safe enough for >> > emacs-30) solve the eldoc slowdown as well? >> >> What I meant is that the 4s slowdown affects both `C-h f` and eldoc, >> and that the patch I sent which reduces it to 0.12s is IMO sufficient >> for the `C-h f` case but may still make Emacs feel occasionally a bit >> sluggish when eldoc hits this 0.12s. > > If the slowdown of eldoc is significant, maybe we will be better with > reverting the change which introduced the regression on emacs-30, > and then solving on master with your more thorough fix. The "quickfix" I installed on `emacs-30` should not suffer from a significant slowdown, no, so I think we're good for `emacs-30`. The "better" fix I installed on `master`, may still cause a bit of sluggishness with eldoc, OTOH. I think the "right" fix for that is to extend `documentation` or `C-h f` such that the `pcase` doc can distinguish between the (quick to generate) doc about `pcase` itself and the table of Pcase patterns defined with `pcase-defmacro` which is appended to the end of the `pcase` doc (and which can take a bit of time to generate but is not needed for eldoc). It would also be good to be able to show the table in a kind of abbreviated form (one line per Pcase pattern) with a way to unfold/refold specific patterns' doc. The same applies to the list of methods displayed in the doc of generic functions and in the doc of types. Stefan
bug-gnu-emacs <at> gnu.org
:bug#73766
; Package emacs
.
(Sun, 27 Oct 2024 10:50:02 GMT) Full text and rfc822 format available.Message #38 received at 73766 <at> debbugs.gnu.org (full text, mbox):
From: Eli Zaretskii <eliz <at> gnu.org> To: Stefan Monnier <monnier <at> iro.umontreal.ca> Cc: 73766 <at> debbugs.gnu.org, yikai <at> z1k.dev, joaotavora <at> gmail.com Subject: Re: bug#73766: 30.0.91; (documentation 'pcase) can take several seconds Date: Sun, 27 Oct 2024 12:48:29 +0200
> From: Stefan Monnier <monnier <at> iro.umontreal.ca> > Cc: yikai <at> z1k.dev, joaotavora <at> gmail.com, 73766 <at> debbugs.gnu.org > Date: Fri, 18 Oct 2024 16:42:32 -0400 > > The "quickfix" I installed on `emacs-30` should not suffer from > a significant slowdown, no, so I think we're good for `emacs-30`. > > The "better" fix I installed on `master`, may still cause a bit of > sluggishness with eldoc, OTOH. > > I think the "right" fix for that is to extend `documentation` or `C-h f` > such that the `pcase` doc can distinguish between the (quick to > generate) doc about `pcase` itself and the table of Pcase patterns > defined with `pcase-defmacro` which is appended to the end of the > `pcase` doc (and which can take a bit of time to generate but is not > needed for eldoc). > > It would also be good to be able to show the table in a kind of > abbreviated form (one line per Pcase pattern) with a way to > unfold/refold specific patterns' doc. > > The same applies to the list of methods displayed in the doc of generic > functions and in the doc of types. Should we now close this bug?
Stefan Monnier <monnier <at> iro.umontreal.ca>
:Yikai Zhao <yikai <at> z1k.dev>
:Message #43 received at 73766-done <at> debbugs.gnu.org (full text, mbox):
From: Stefan Monnier <monnier <at> iro.umontreal.ca> To: Eli Zaretskii <eliz <at> gnu.org> Cc: 73766-done <at> debbugs.gnu.org, yikai <at> z1k.dev, joaotavora <at> gmail.com Subject: Re: bug#73766: 30.0.91; (documentation 'pcase) can take several seconds Date: Sun, 27 Oct 2024 10:28:39 -0400
> Should we now close this bug? Yes! Stefan
Debbugs Internal Request <help-debbugs <at> gnu.org>
to internal_control <at> debbugs.gnu.org
.
(Mon, 25 Nov 2024 12:24:11 GMT) Full text and rfc822 format available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.