GNU bug report logs - #72977
28.2; DOS in Shell-script mode

Previous Next

Package: emacs;

Reported by: Chris Moore <christopher.ian.moore <at> gmail.com>

Date: Mon, 2 Sep 2024 16:27:04 UTC

Severity: normal

Found in version 28.2

To reply to this bug, email your comments to 72977 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#72977; Package emacs. (Mon, 02 Sep 2024 16:27:04 GMT) Full text and rfc822 format available.

Acknowledgement sent to Chris Moore <christopher.ian.moore <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 02 Sep 2024 16:27:05 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Chris Moore <christopher.ian.moore <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 28.2; DOS in Shell-script mode
Date: Mon, 2 Sep 2024 12:35:18 -0300
[Message part 1 (text/plain, inline)]
I've been seeing Emacs hang up repeatedly for no apparent reason recently
while editing shell scripts. I spent the time to isolate the issue. It
turns out that I can reproduce the issue by opening a new shell script file
and typing the word "in" 20 or 30 times on a single line:

$ emacs -Q
C-x C-f /tmp/x.sh
echo in in in in in in in in in in in in in in in in in in in in in in in
in in in in in in in

After about 20 'in's, things slow down noticeably, and I can't get to 30
without it hanging.

I fixed the issue by replacing "in" with "'in'" in my script.


In GNU Emacs 28.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.38,
cairo version 1.16.0)
 of 2024-06-25, modified by Debian built on x86-conova-01
System Description: Debian GNU/Linux 12 (bookworm)

Configured using:
 'configure --build x86_64-linux-gnu --prefix=/usr
 --sharedstatedir=/var/lib --libexecdir=/usr/libexec
 --localstatedir=/var/lib --infodir=/usr/share/info
 --mandir=/usr/share/man --with-libsystemd --with-pop=yes
 --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/28.2/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/28.2/site-lisp:/usr/share/emacs/site-lisp
 --with-sound=alsa --without-gconf --with-mailutils
 --with-native-compilation --build x86_64-linux-gnu --prefix=/usr
 --sharedstatedir=/var/lib --libexecdir=/usr/libexec
 --localstatedir=/var/lib --infodir=/usr/share/info
 --mandir=/usr/share/man --with-libsystemd --with-pop=yes
 --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/28.2/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/28.2/site-lisp:/usr/share/emacs/site-lisp
 --with-sound=alsa --without-gconf --with-mailutils
 --with-native-compilation --with-cairo --with-x=yes
 --with-x-toolkit=gtk3 --with-toolkit-scroll-bars 'CFLAGS=-g -O2
 -ffile-prefix-map=/build/reproducible-path/emacs-28.2+1=.
-fstack-protector-strong
 -Wformat -Werror=format-security -Wall' 'CPPFLAGS=-Wdate-time
 -D_FORTIFY_SOURCE=2' LDFLAGS=-Wl,-z,relro'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES
NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF
TOOLKIT_SCROLL_BARS X11 XDBE XIM XPM GTK3 ZLIB

Important settings:
  value of $LANG: en_CA.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Shell-script

Minor modes in effect:
  sh-electric-here-document-mode: t
  display-time-mode: t
  global-so-long-mode: t
  shell-dirtrack-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny rfc822 mml mml-sec epa
derived epg rfc6068 epg-config gnus-util rmail rmail-loaddefs time-date
mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils
mailheader sendmail comp comp-cstr warnings cl-extra help-mode rfc2047
rfc2045 ietf-drums mm-util mail-prsvr mail-utils sh-script smie
executable dired-aux term/screen term/xterm xterm cus-edit pp cus-start
wid-edit ido time cus-load wdired dired dired-loaddefs so-long shell
pcomplete rust-utils thingatpt rust-mode rx rust-rustfmt rust-playpen
rust-compile compile text-property-search comint ansi-color ring
rust-cargo finder-inf package browse-url url url-proxy url-privacy
url-expand url-methods url-history url-cookie url-domsuf url-util
mailcap url-handlers url-parse auth-source cl-seq eieio eieio-core
cl-macs eieio-loaddefs password-cache json subr-x map url-vars seq
byte-opt gv bytecomp byte-compile cconv cl-loaddefs cl-lib iso-transl
tooltip eldoc paren electric uniquify ediff-hook vc-hooks
lisp-float-type elisp-mode mwheel term/x-win x-win term/common-win x-dnd
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 cl-generic
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 simple abbrev obarray
cl-preloaded nadvice button loaddefs faces cus-face macroexp files
window text-properties overlay sha1 md5 base64 format env code-pages
mule custom widget hashtable-print-readable backquote threads dbusbind
inotify lcms2 dynamic-setting system-font-setting font-render-setting
cairo move-toolbar gtk x-toolkit x multi-tty make-network-process
native-compile emacs)

Memory information:
((conses 16 199366 8596)
 (symbols 48 13308 1)
 (strings 32 65460 2058)
 (string-bytes 1 1538163)
 (vectors 16 22561)
 (vector-slots 8 424286 17680)
 (floats 8 62 347)
 (intervals 56 1790 178)
 (buffers 992 17))
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#72977; Package emacs. (Mon, 02 Sep 2024 17:34:04 GMT) Full text and rfc822 format available.

Message #8 received at 72977 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Chris Moore <christopher.ian.moore <at> gmail.com>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 72977 <at> debbugs.gnu.org
Subject: Re: bug#72977: 28.2; DOS in Shell-script mode
Date: Mon, 02 Sep 2024 20:30:16 +0300
> From: Chris Moore <christopher.ian.moore <at> gmail.com>
> Date: Mon, 2 Sep 2024 12:35:18 -0300
> 
> I've been seeing Emacs hang up repeatedly for no apparent reason recently while editing shell scripts. I spent
> the time to isolate the issue. It turns out that I can reproduce the issue by opening a new shell script file and
> typing the word "in" 20 or 30 times on a single line:
> 
> $ emacs -Q
> C-x C-f /tmp/x.sh
> echo in in in in in in in in in in in in in in in in in in in in in in in in in in in in in in
> 
> After about 20 'in's, things slow down noticeably, and I can't get to 30 without it hanging.

The profile is below.  Maybe Stefan (CC'ed) has some comments or
suggestions.

       36361  58% - timer-event-handler
       36361  58%  - apply
       36361  58%   - show-paren-function
       36361  58%    - #<advice 1DA>
       36361  58%     - apply
       36361  58%      - smie--matching-block-data
       36359  58%       - smie--opener/closer-at-point
       36068  57%        - sh-smie-sh-forward-token
       23841  38%         - sh-smie--sh-keyword-p
       23841  38%          - sh-smie--sh-keyword-in/do-p
       23841  38%           - sh-smie-sh-backward-token
       23837  38%            - sh-smie--sh-keyword-p
       23837  38%             - sh-smie--sh-keyword-in/do-p
       23837  38%              - sh-smie-sh-backward-token
       23805  38%               - sh-smie--sh-keyword-p
       23801  38%                - sh-smie--sh-keyword-in/do-p
       23793  38%                 - sh-smie-sh-backward-token
       23685  38%                  - sh-smie--sh-keyword-p
       23681  38%                   - sh-smie--sh-keyword-in/do-p
       23665  37%                    - sh-smie-sh-backward-token
       23425  37%                     - sh-smie--sh-keyword-p
       23409  37%                      - sh-smie--sh-keyword-in/do-p
       23349  37%                       - sh-smie-sh-backward-token
       13623  21%                          looking-back
        6152   9%                          sh-smie--default-backward-token
        3368   5%                        - sh-smie--sh-keyword-p
        1655   2%                           sh-smie--sh-keyword-in/do-p
          28   0%                         assoc
         136   0%                       looking-back
          44   0%                       sh-smie--default-backward-token
           8   0%                      assoc
          64   0%                    looking-back
          20   0%                    sh-smie--default-backward-token
           4   0%                   assoc
          16   0%                 sh-smie--default-backward-token
           8   0%                 looking-back
           4   0%              sh-smie--default-backward-token
       12227  19%         - sh-smie--newline-semi-p
       12227  19%          - sh-smie-sh-backward-token
       12227  19%           - sh-smie--sh-keyword-p
       12227  19%            - sh-smie--sh-keyword-in/do-p
       12227  19%             - sh-smie-sh-backward-token
       12227  19%              - sh-smie--sh-keyword-p
       12227  19%               - sh-smie--sh-keyword-in/do-p
       12227  19%                - sh-smie-sh-backward-token
       12223  19%                 - sh-smie--sh-keyword-p
       12223  19%                  - sh-smie--sh-keyword-in/do-p
       12223  19%                   - sh-smie-sh-backward-token
       12203  19%                    - sh-smie--sh-keyword-p
       12203  19%                     - sh-smie--sh-keyword-in/do-p
       12199  19%                      - sh-smie-sh-backward-token
       12143  19%                       - sh-smie--sh-keyword-p
       12143  19%                        - sh-smie--sh-keyword-in/do-p
       10012  16%                           sh-smie-sh-backward-token
        2119   3%                           assoc
          36   0%                         looking-back
 [...]
       25633  41%   Automatic GC




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#72977; Package emacs. (Wed, 04 Sep 2024 12:56:02 GMT) Full text and rfc822 format available.

Message #11 received at 72977 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 72977 <at> debbugs.gnu.org, Chris Moore <christopher.ian.moore <at> gmail.com>
Subject: Re: bug#72977: 28.2; DOS in Shell-script mode
Date: Wed, 04 Sep 2024 08:53:55 -0400
>> echo in in in in in in in in in in in in in in in in in in in in in in in in in in in in in in
>> 
>> After about 20 'in's, things slow down noticeably, and I can't get to 30 without it hanging.
>
> The profile is below.  Maybe Stefan (CC'ed) has some comments or
> suggestions.
>
>        36361  58% - timer-event-handler
>        36361  58%  - apply
>        36361  58%   - show-paren-function
>        36361  58%    - #<advice 1DA>
>        36361  58%     - apply
>        36361  58%      - smie--matching-block-data
>        36359  58%       - smie--opener/closer-at-point
>        36068  57%        - sh-smie-sh-forward-token
>        23841  38%         - sh-smie--sh-keyword-p
>        23841  38%          - sh-smie--sh-keyword-in/do-p
>        23841  38%           - sh-smie-sh-backward-token
>        23837  38%            - sh-smie--sh-keyword-p
>        23837  38%             - sh-smie--sh-keyword-in/do-p
>        23837  38%              - sh-smie-sh-backward-token
>        23805  38%               - sh-smie--sh-keyword-p
>        23801  38%                - sh-smie--sh-keyword-in/do-p
>        23793  38%                 - sh-smie-sh-backward-token
>        23685  38%                  - sh-smie--sh-keyword-p
[...]

Hmm... indeed, in order to decide whether a given `in` is a keyword
rather than just some command's argument, we need to look back, so we
probably have an O(N²) situation here, where we walk backward over all
the `in`s in order to decide whether the last one is a keyword.  Then we
do the same starting from the "last but one" (because the check for
keyword-p was only made to decide how to skip that last token), etc...

In theory we could do it more efficiently by integrating better the
keyword-p check and the navigation to the beginning of a command, but it
requires a different structure than the one we're using.

Another solution is to use a cache (which could simply memoize the
output of `sh-smie--sh-keyword-p`) which we could flush from
`after-change-functions`.

Yet another (more ad-hoc) approach might be to try and keep track of the
nesting, and let `sh-smie--sh-keyword-p` return nil when we reach
a nesting of say 2 (at least for `in` I can't think of a piece of code
where the 3rd (or subsequent) `in` can be a keyword).


        Stefan





This bug report was last modified 289 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.