From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.bugs Subject: bug#59738: c-ts-mode is slow with large buffers. Date: Tue, 6 Dec 2022 20:56:13 -0800 Message-ID: <87E351E0-2EE2-434A-9609-86506D2F263D@gmail.com> References: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12707"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 59738@debbugs.gnu.org To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 07 05:57:46 2022 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 1p2mV8-00037i-EN for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 07 Dec 2022 05:57:46 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p2mUT-0001Jv-0B; Tue, 06 Dec 2022 23:57:05 -0500 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 1p2mUR-0001Jn-48 for bug-gnu-emacs@gnu.org; Tue, 06 Dec 2022 23:57:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p2mUQ-00074r-SG for bug-gnu-emacs@gnu.org; Tue, 06 Dec 2022 23:57:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p2mUQ-0006uv-Ib for bug-gnu-emacs@gnu.org; Tue, 06 Dec 2022 23:57:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 07 Dec 2022 04:57:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59738 X-GNU-PR-Package: emacs Original-Received: via spool by 59738-submit@debbugs.gnu.org id=B59738.167038898526580 (code B ref 59738); Wed, 07 Dec 2022 04:57:02 +0000 Original-Received: (at 59738) by debbugs.gnu.org; 7 Dec 2022 04:56:25 +0000 Original-Received: from localhost ([127.0.0.1]:47294 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p2mTo-0006ue-Hh for submit@debbugs.gnu.org; Tue, 06 Dec 2022 23:56:24 -0500 Original-Received: from mail-pf1-f169.google.com ([209.85.210.169]:47002) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p2mTl-0006uY-DQ for 59738@debbugs.gnu.org; Tue, 06 Dec 2022 23:56:22 -0500 Original-Received: by mail-pf1-f169.google.com with SMTP id t18so6183937pfq.13 for <59738@debbugs.gnu.org>; Tue, 06 Dec 2022 20:56:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:from:to:cc:subject:date:message-id :reply-to; bh=lsQoKJP9juE1ukqnMKngHvgaZXsLipb9gGZnN8wLx0c=; b=CQWznrr657r+FvRqCX8J4aVtjPbCQ0JluUHruQSMfaQr20rF6SJyqPg7zRLIlPiniq AIzV1F//aocOHsclfkXjADhgCirV3MYE5mJjEzdh1trX+7qqCNoBrqKDyZdT/A6r2krY rURaB07GO+2hgRin30is/3W/U0QfKEixiHNkJyrJue8osBnGjBHdIlcjWuYFMx+C249t fw+vNrHKGKyCcOggi93Gj7AyrhF3olN/srbj3FCfgr2MGMQiG+xAHhYJR4qM4O7yCvpb Iat+8mYzc2QZ7sDSmstOHSXvtwFAe2ONvQKsXYIbaUiZPtLzXhiNwNZQ+CNLMHOgjwCC GTlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lsQoKJP9juE1ukqnMKngHvgaZXsLipb9gGZnN8wLx0c=; b=K7BWYu5Z+TEvx7FEwCmrSFNNuPVRC9QEo+C71NhLEHUQkUgM7kZ6lTHhjavEfsZNEG irtv90CLjZWeseR/5+uEkTyIpe8l7SL7L83o4gjTt1pKtEJC9ho0wclLsEMsPEyJdXxW cT95FHgBDr3dPNsDc2oZkmVUqncl5bcqDAUk1UjNK4YI3QgJxKlNAh/qWCuydcsvbRxk grHzWO3DI4w/0B/0+/TN7GyWrPyIYMLze6SckE04LdvlZ/ZTIWbQ4+BX/rBcTOtP9TQa qpps90Ov0UpKV8CXTHVtTEHId/WQAuhywMruYdkVRiCvBom/RwiqSpog226QezxHgo5o 719Q== X-Gm-Message-State: ANoB5pmNcH6PgyrZ9xoYlDaKk4PFKZsT9XtMvJIl4e0RCuR7lDTpU4+c 5XvK/G9vmaawVNzs29QfUtFuOVp+LSFykw== X-Google-Smtp-Source: AA0mqf7TvO2t87VxmjomX8jE63o+1Or+AosjVnGUzAJv2WiUku2BA8JaoXSXtoJiOSwBEm/sZJzoTA== X-Received: by 2002:a63:fb11:0:b0:478:e97b:7a1 with SMTP id o17-20020a63fb11000000b00478e97b07a1mr3879166pgh.113.1670388975105; Tue, 06 Dec 2022 20:56:15 -0800 (PST) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id n12-20020a170903110c00b00186a6b63525sm13564068plh.120.2022.12.06.20.56.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Dec 2022 20:56:14 -0800 (PST) X-Mailer: Apple Mail (2.3696.120.41.1.1) 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:250162 Archived-At: Alan Mackenzie writes: > Hello, Emacs. > > In an up to date (2022-11-30) master started as $ emacs --no-desktop: > > The file = .../drivers/gpu/drm/amd/include/asic_reg/dce/dce_12_0_sh_mask.h > in the Linux source tree is 6.8 MB big, consisting of a large number = of > #defines and comments, but nothing else. > > To scroll through it in c-ts-mode takes a little over 26 minutes on my > system. By comparison, in C Mode it takes 31 seconds. There would > appear to be a need for some optimisation in c-ts-mode, here. > > > The file > = https://gitlab.com/wireshark/wireshark/-/raw/master/epan/dissectors/packet= -rrc.c > (see bug #45248) (10 MB) takes 578 seconds to scroll in c-ts-mode. It > scrolls through the first 83% of the buffer rapidly, then chokes on a = big > brace block initialisation. Also, the font-locking fails part way > through this brace block (without any apparent speed up). > > For comparison, the scrolling takes 30 seconds in C Mode. There seems = to > be a need for optimisation of c-ts-mode in this case, too. > > > For completeness, I used M-: (time-scroll) in the following for the > timings: > > (defmacro time-it (&rest forms) > "Time the running of a sequence of forms using `float-time'. > Call like this: \"M-: (time-it (foo ...) (bar ...) ...)\"." > `(let ((start (float-time))) > ,@forms > (- (float-time) start))) > > (defun time-scroll (&optional arg) > (interactive "P") > (message "%s" > (time-it > (condition-case nil > (while t > (if arg (scroll-down) (scroll-up)) > (sit-for 0)) > (error nil))))) Ah, the lovely packet-rrc.c file. We had some discussion of it in bug#59415, basically it contains some syntax that screws tree-sitter up. The block initialization you see makes tree-sitter into erroneously generating a very tall tree: it recognizes all the opening bracket and ignores (almost) all the closing brackets. That causes operations on the tree to be much much slower than it normally is. I added some fix so the rest of the file can be largely unaffected, and reported this problem to tree-sitter-c=E2=80=99s developer (no reply as = of now). There is not much we can do to fix this, and since it=E2=80=99s rare, I = think a user could probably just use c-mode for this kind of files. Yuan