From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#72977: 28.2; DOS in Shell-script mode Date: Wed, 04 Sep 2024 08:53:55 -0400 Message-ID: References: <861q227yl3.fsf@gnu.org> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24431"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 72977@debbugs.gnu.org, Chris Moore To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 04 14:55:23 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1slpXe-00069H-Qf for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 04 Sep 2024 14:55:23 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1slpXJ-0001aF-3e; Wed, 04 Sep 2024 08:55:01 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1slpXH-0001VB-Mr for bug-gnu-emacs@gnu.org; Wed, 04 Sep 2024 08:54:59 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1slpXH-0003ue-Ee for bug-gnu-emacs@gnu.org; Wed, 04 Sep 2024 08:54:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=G7mGV5qLMQFgn0XAl5UmjQ2+eiDKqVLKyVX3nIEO1c0=; b=s97iWC6KDJdweyZs96i1FJF8/QGBxPK8bw9Cnck0JFwBKirpxBxQokbTIiJi6Q3VsexUSZA4sYFQMC9VkWk+jnItYJMg60ikKPAc7QIdfM9XUNh+R5KW97aeE0gsgJfsNmuWrZf1eQGEk5RK9Mqk0InfHiRBteGThJxOVUOUlVBCnmA/WUZejyG6Ny9fRw6HSDk1JpWd0fluxuh7l+BdHMdyu/BjqDFpH52SDzLW+MORsi/uTF6oRmhj6Ec34T7Wze5Ui14Eed5r1Y/yXFONCA+IFLamdpVP4qWVJM3MK9+js8qmriMYs0qBR4XW4YhSkpnHV+8F7hU3XMfu7R7eyQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1slpYI-0000Qw-1q for bug-gnu-emacs@gnu.org; Wed, 04 Sep 2024 08:56:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 04 Sep 2024 12:56:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72977 X-GNU-PR-Package: emacs Original-Received: via spool by 72977-submit@debbugs.gnu.org id=B72977.17254545151590 (code B ref 72977); Wed, 04 Sep 2024 12:56:01 +0000 Original-Received: (at 72977) by debbugs.gnu.org; 4 Sep 2024 12:55:15 +0000 Original-Received: from localhost ([127.0.0.1]:33828 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1slpXW-0000PY-Nr for submit@debbugs.gnu.org; Wed, 04 Sep 2024 08:55:15 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:54261) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1slpXU-0000PK-BJ for 72977@debbugs.gnu.org; Wed, 04 Sep 2024 08:55:12 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id E89C8100045; Wed, 4 Sep 2024 08:54:00 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1725454439; bh=0KpblTbbwZvb4uzO1LCulnTKKcjrD2qaJFQ7oyHw8j4=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=o1yhmHgqN8+sK/U2I7H4ny8CAmuogxYvyPtnAltoKLro4R916f+Qu56MApkOLXNNK XRaQSQS9y7GwDg0BohykVlvFCslTzW2ab9IlVTFEIg5vxbu2MLmoFFxODKK/xYEYqp gBA3H/eFcGoDqEikS4Hh4o4vtY0Xke/9QcwUm+HhP8b6EfMlEqPtZYF0qzxUIGD6/F gIe/bbZFTsEyNpMAH8ita9alpTi3nBU6/+/VdsKoQ6gocTEbL+J1hYIv5slWQ3KrfK pzg800tNnLvaUk/tkrNwVwDu7PvHHPDyeU/v2mD023PsaguoTjVh6VRF9ubJHJqxZS JyYiM8k1OIjyw== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 968A7100035; Wed, 4 Sep 2024 08:53:59 -0400 (EDT) Original-Received: from asado (169.183.173.62.cust.ip.kpnqwest.it [62.173.183.169]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id BE72812031C; Wed, 4 Sep 2024 08:53:58 -0400 (EDT) In-Reply-To: <861q227yl3.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 02 Sep 2024 20:30:16 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:291197 Archived-At: >> echo in in in in in in in in in in in in in in in in in in in in in in i= n in in in in in in in >>=20 >> 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% - # > 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=B2) 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