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.devel Subject: Re: treesitter local parser: huge slowdown and memory usage in a long file Date: Tue, 13 Feb 2024 00:08:33 -0800 Message-ID: <47F1243E-0515-418D-96B9-4D3FE3CC4BBC@gmail.com> References: <5991618.MhkbZ0Pkbq@fedora> <93F7DE13-0EC7-4A17-89B1-E07C99C6347B@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) 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="20981"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Vincenzo Pupillo , "Ergus via Emacs development discussions." , Eli Zaretskii To: Dmitry Gutov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Feb 13 09:09:49 2024 Return-path: Envelope-to: ged-emacs-devel@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 1rZnrQ-0005H1-PH for ged-emacs-devel@m.gmane-mx.org; Tue, 13 Feb 2024 09:09:48 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rZnqW-00073S-Bw; Tue, 13 Feb 2024 03:08:52 -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 1rZnqV-00072h-4q for emacs-devel@gnu.org; Tue, 13 Feb 2024 03:08:51 -0500 Original-Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rZnqT-0008Ux-FO; Tue, 13 Feb 2024 03:08:50 -0500 Original-Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1d932f6ccfaso28207135ad.1; Tue, 13 Feb 2024 00:08:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707811727; x=1708416527; darn=gnu.org; 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=iJD1ubAJakB9IpJFCLZfRDO7/2uMjf1QW0qrnbkRK9w=; b=G4uTGVeCjSAuCcJBXxH5jHS58fibeLD/STtdxEROJ5vNnQRK40UOhgmFEUCJry7wGk e669wQ/Uws9RZ6wG0Bc/2UpZX2+xC51v+BORmh31kJ3yVqSvCxvBUR3NUNGHESVDiCbr VVDQSWgJp9HQjAhUr7WXsjI3Z6mdUck+6zCiNDJaH+abz9Ak/z92yeV++GXINJfpo5qD GTBPGmu/EPWohKHxOgh31QPuqofkhnRr7l7qynIj0JFfG2lkaBLYdpn70OnJw85dncY8 ND2b15IAfUZsvBIPR1Hok0hXEBT5hrax+8tUtTrCgDnc3fqQoSeXRRSlfngcn/PL/Mof 2oZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707811727; x=1708416527; 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=iJD1ubAJakB9IpJFCLZfRDO7/2uMjf1QW0qrnbkRK9w=; b=dNwq//yUfpwEwOfRq7uzbHT7IRQcl83UAyQ0aCNlucw7qWkVwjZ2yzdDR/DN0UJJBk RHzQB9e//N3H557lIx7RVO+BE1kI8ZXnmIa/t1uUz5Lwg6of4HYA3JpRUK3igmifaVId ohTI8gW1N3ekaAhdkHhfWgMhcoRGJAzVbTtRUuckVdY4heS3UecA3GOCdQmO5zDgd3Hk q6KLwHlYcs2xnRrxW+/QseHCyytLZnRAbAWtFnb4BgYinmUH+yTWtHkabzJR2baOXN+b cn6E2zrpnBa96XBSCmFgG9PaknVq2yjHWGN88TJtNCJ9/WodRfs0feUhq2A+mhwB0z9D 3Gvw== X-Forwarded-Encrypted: i=1; AJvYcCV+Up9MgK+Uz7DnLLIqdYeWaScb/dUKFWs1QlORW5PymteOoZ8RZoKuZx0bfbW9mpacYNskv/ANjLkrXEUZYseHSLSlkXE4pH1IZkLdE5WM02k= X-Gm-Message-State: AOJu0YzoUBbcodV+/NZZJoEVEEgChx9sN+S7sJiL8IvEROAXfuL45ELv 9oIpFzbADrycVwtLtij5alAbORLpEQrp57SbkpYjKRXKYc0IscI/ X-Google-Smtp-Source: AGHT+IH6+6or2cKgE23lnRuR6KTwM4HmMD8w7b2X0fHwFDNxcwDZL1f8bHP0cxJ/zjokeg791FSY0g== X-Received: by 2002:a17:903:110f:b0:1d8:a93f:a5b2 with SMTP id n15-20020a170903110f00b001d8a93fa5b2mr9992389plh.12.1707811726901; Tue, 13 Feb 2024 00:08:46 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCW8x1K/UwyspkCoLG2XH6FBLVRVRnQl5h53vX2/XVFsQf/ooJjXw1fDDeZl8Ov74etT5ISLm/1BPt5MPVz/bjwUZE31SfxIYfvOzVTh08mrK30= Original-Received: from smtpclient.apple (172-117-161-177.res.spectrum.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id h12-20020a170902f2cc00b001da0a698095sm552102plc.282.2024.02.13.00.08.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Feb 2024 00:08:46 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.3731.700.6) Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=casouri@gmail.com; helo=mail-pl1-x62f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:316166 Archived-At: > On Feb 12, 2024, at 4:50 PM, Dmitry Gutov wrote: >=20 > On 12/02/2024 06:16, Yuan Fu wrote: >> Thanks, the culprit is the call to treesit-update-ranges in >> treesit--pre-redisplay, where we don=E2=80=99t pass it any specific = range, so it >> updates the range for the whole buffer. Eli, is there any way to get = a >> rough estimate the range that redisplay is refreshing? Do you think >> something like this would work? >=20 > If we don't update the ranges outside of some interval surrounding the = window, what does that mean for correctness? If the place of update and the embedded code currently in view belong to = the same node in the host language, then when we update ranges for the = current window-visible range, the whole node=E2=80=99s range is updated. = So at least for this node, the range is correct. If the place of update and the embedded code currently in view belong to = different nodes in the host language, then when we update ranges for the = current window-visible range, only the visible node=E2=80=99s range is = updated.=20 >=20 > Perhaps the mode has a syntax-propertize-function which behaves = differently (as it should) depending on the language at point. Or = different ranges have different syntax tables, something like that. >=20 > If the ranges, after some edit (perhaps a programmatic one, performed = far from the visible area), are kept not update somewhere around the = beginning of the buffer, do we not risk confusing the syntax-ppss = parser, for example? That can happen, yes.=20 >=20 > Come to think of it, take treesit-indent: it only updates the ranges = for the current line. But the line's indentation usually depends on the = previous buffer positions, doesn't it? The range passed to treesit-update-ranges act as an intercepting = range=E2=80=94we capture nodes that intercepts with the range and use = them to update ranges. If the line to be indented is in an embedded = language block, the whole block will be captured and it=E2=80=99s range = will be given to the embedded language parser. We haven=E2=80=99t have any problem so far mainly because most embedded = code blocks are local, and it=E2=80=99s rare for some edit to take = place far from the visible portion which affects ranges and user expects = that edit to affect the current visible range. I don=E2=80=99t have any great idea for a better way to update ranges = right now. Let me think about that. In the meantime, I=E2=80=99ll push a = temporary fix so V=E2=80=99s original problem can be solved. Yuan=