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: Wed, 7 Dec 2022 16:40:15 -0800 Message-ID: <3A956C88-F81D-4DED-B020-178291D405D9@gmail.com> References: <87E351E0-2EE2-434A-9609-86506D2F263D@gmail.com> <83edtb3z6t.fsf@gnu.org> 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="8522"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Alan Mackenzie , 59738@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 08 01:41:25 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 1p34yb-000212-J6 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 08 Dec 2022 01:41:25 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p34yG-0006b2-F9; Wed, 07 Dec 2022 19:41:04 -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 1p34yE-0006ap-MM for bug-gnu-emacs@gnu.org; Wed, 07 Dec 2022 19:41:02 -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 1p34yE-00051U-4D for bug-gnu-emacs@gnu.org; Wed, 07 Dec 2022 19:41:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p34yD-0005AN-Vz for bug-gnu-emacs@gnu.org; Wed, 07 Dec 2022 19:41:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 08 Dec 2022 00:41:01 +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.167046002719845 (code B ref 59738); Thu, 08 Dec 2022 00:41:01 +0000 Original-Received: (at 59738) by debbugs.gnu.org; 8 Dec 2022 00:40:27 +0000 Original-Received: from localhost ([127.0.0.1]:53154 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p34xf-0005A1-7I for submit@debbugs.gnu.org; Wed, 07 Dec 2022 19:40:27 -0500 Original-Received: from mail-pl1-f170.google.com ([209.85.214.170]:35394) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p34xb-00059u-GW for 59738@debbugs.gnu.org; Wed, 07 Dec 2022 19:40:26 -0500 Original-Received: by mail-pl1-f170.google.com with SMTP id y4so22431plb.2 for <59738@debbugs.gnu.org>; Wed, 07 Dec 2022 16:40:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=r9fQZbnvMZSx1RRIF8nSYStGdWmI5ZUL7TONDnkQNdc=; b=WcED9CBUQZOOCSnjnyiBIHRFoluhf87xK6MEeFKmip2ojQ/e/+4ijgeqGGkyT/wYXb YOatJnFDE8urx/w959jhaZkQC+c0fyolc8uIEajCNkW8UbySAEIJCJPXFS3MfTiNnNON oeejaQmCXiFpGKGuFqHwHWfoJ9aIyi2ejWmSV8u1/PILNcWUrZYNdmekOW7J3UVZDX6z nyDPoj0rL2rXWiolhS/JaB46/pWmjowFdrKM6IiyjbZdaWxrkpRUP6tHnuYXcx81n5kl 1+9xn99y+Xo0rFf77GSJMBGJdWH3XUfePhFdbewDRunwZZpA9G8AFkt9M3owSXmCaTOC dRqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r9fQZbnvMZSx1RRIF8nSYStGdWmI5ZUL7TONDnkQNdc=; b=o2rFWBSCDOByHXI+LL5p1NbzCPYNMyreiXafU3b1Cc2lbB/8lFp4m6SxPaoAGmRBEk 4pKqhD2LNHidyJZIu57Y69BkHHowKZVruXnOHMXS6V7lP0L4TtucYnPtAPSdUZ3azRib eikw576FvZ/Hl2O+pFnxOU+T7RHfUS5+m+hxcEL8uHS94XAe58NCvNgFDbrJZR3x2+Cz 3pVMPOFfiGHDjJGKYI8dqEK6ssCBrBpwUDoMh5YWS048e1swBh9M3K7syeuBHAfSIqxL To/XDOcAo2HoE3CtglOY85saXZ6nb+tUJbiFNtbVkFwrBKS17HVqWKs96jp5BhoWUYcb nGZA== X-Gm-Message-State: ANoB5pnW0rJKIA924CUN4cmx5yz6bVC7hFQnlvYHibeOYPrruqhuLlgB vE4UTGuXTdGOGr4MMS/zpjAhrImABMcR1g== X-Google-Smtp-Source: AA0mqf6PRQR6+ihjPrt1bPfcwj9FHdHAmDzIPcvW3f921iuD6t/Wi90mJyX/BO6QbhWfqhFYkIlfvw== X-Received: by 2002:a05:6a21:e211:b0:a7:8781:5a7d with SMTP id by17-20020a056a21e21100b000a787815a7dmr1333325pzc.60.1670460017587; Wed, 07 Dec 2022 16:40:17 -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 r12-20020aa7962c000000b005758d26fbf7sm8900971pfg.58.2022.12.07.16.40.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Dec 2022 16:40:17 -0800 (PST) In-Reply-To: <83edtb3z6t.fsf@gnu.org> 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:250230 Archived-At: > On Dec 7, 2022, at 9:23 AM, Eli Zaretskii wrote: >=20 >> Cc: 59738@debbugs.gnu.org >> From: Yuan Fu >> Date: Tue, 6 Dec 2022 20:56:13 -0800 >>=20 >>=20 >> Alan Mackenzie writes: >>=20 >>> Hello, Emacs. >>>=20 >>> In an up to date (2022-11-30) master started as $ emacs = --no-desktop: >>>=20 >>> 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. >>>=20 >>> 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. >>> [...] >> Ah, the lovely packet-rrc.c file. >=20 > No, this is a different file, dce_12_0_sh_mask.h. It is a header file > which only has preprocessor #define lines. I'm puzzled why this > presents such a great difficulty for tree-sitter. Could you take a > look what happens with that file? >=20 >> 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. >=20 > Right, but with a long series of #define lines there should be no > parse tree at all=E2=80=A6 Ok, I think I know why. At the beginning of the file there is this line #ifndef _dce_12_0_SH_MASK_HEADER So it=E2=80=99s parsed into a preproc_ifdef node, which contains every = #define directive in the file as its immediate child. Now you have this = node with a tons of immediate children. And querying this node in = font-lock is very slow, even with a limited range. I think for the query = result to be accurate, tree-sitter has to query the whole node without = considering the range, then throw away matches that are not in the = range.=20 Anyway, I activated my backup backup plan, which goes down the parse = tree to find a sufficiently small node to query. Now scrolling the = header file is fast as other files. Yuan