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: Eli Zaretskii <eliz@gnu.org>
Cc: 72977@debbugs.gnu.org, Chris Moore <christopher.ian.moore@gmail.com>
Subject: bug#72977: 28.2; DOS in Shell-script mode
Date: Wed, 04 Sep 2024 08:53:55 -0400	[thread overview]
Message-ID: <jwv4j6vy4m3.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <861q227yl3.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 02 Sep 2024 20:30:16 +0300")

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






      reply	other threads:[~2024-09-04 12:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

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=jwv4j6vy4m3.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=72977@debbugs.gnu.org \
    --cc=christopher.ian.moore@gmail.com \
    --cc=eliz@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.