all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#72977: 28.2; DOS in Shell-script mode
@ 2024-09-02 15:35 Chris Moore
  2024-09-02 17:30 ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: Chris Moore @ 2024-09-02 15:35 UTC (permalink / raw)
  To: 72977

[-- Attachment #1: Type: text/plain, Size: 5097 bytes --]

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))

[-- Attachment #2: Type: text/html, Size: 5731 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#72977: 28.2; DOS in Shell-script mode
  2024-09-02 15:35 bug#72977: 28.2; DOS in Shell-script mode Chris Moore
@ 2024-09-02 17:30 ` Eli Zaretskii
  2024-09-04 12:53   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 3+ messages in thread
From: Eli Zaretskii @ 2024-09-02 17:30 UTC (permalink / raw)
  To: Chris Moore, Stefan Monnier; +Cc: 72977

> From: Chris Moore <christopher.ian.moore@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





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#72977: 28.2; DOS in Shell-script mode
  2024-09-02 17:30 ` Eli Zaretskii
@ 2024-09-04 12:53   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-09-04 12:53 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 72977, Chris Moore

>> 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






^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-09-04 12:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-02 15:35 bug#72977: 28.2; DOS in Shell-script mode Chris Moore
2024-09-02 17:30 ` Eli Zaretskii
2024-09-04 12:53   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

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.