From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Divya Ranjan via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#74281: 30.0.91; font-lock mode hangs on scrolling large Scheme file Date: Sun, 29 Dec 2024 18:38:17 +0000 Message-ID: <3C3AB452-B954-4A3B-9BAB-20209973E21C@subvertising.org> References: <8734k0cs1u.fsf@subvertising.org> <86zfm2jjbo.fsf@gnu.org> <865xo59hhm.fsf@gnu.org> <8634iqwqtr.fsf@gnu.org> <86msggt66d.fsf@gnu.org> Reply-To: Divya Ranjan Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=----HU5UDVQ9LQSXY1TT2WXEZOJOQQQKYL Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39531"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Thunderbird for Android Cc: monnier@iro.umontreal.ca To: 74281@debbugs.gnu.org, eliz@gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 29 19:39:18 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 1tRyC6-000A7x-2C for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 29 Dec 2024 19:39:18 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tRyBt-0007Jt-TA; Sun, 29 Dec 2024 13:39:06 -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 1tRyBr-0007II-Ch for bug-gnu-emacs@gnu.org; Sun, 29 Dec 2024 13:39:03 -0500 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 1tRyBq-0005UE-Qp for bug-gnu-emacs@gnu.org; Sun, 29 Dec 2024 13:39:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:From:Date:To:Subject; bh=3Rny6seXddC3cq/glHRybR3CdT1x21eJ7ISYjFlaJa0=; b=tE1JF80a0J1H8lX1t1YfMyCVVKdG9FYOcf5gNm2ghHyOXH+WRd7AJ9ndQd87Fhj0VNiL2dRjFWRBrr9W1zPqUTFRuqNouwjQYZdPEkngYD7hofr3UD9zV+Gm3IlVBahGU8lgjLHnlY19OCmpxZar5U01a5TD0zyuYr+mPlAuLfWH3MPd+3iGcmY8PjIoX266gFFwyo01OMYg+ST1zo52dcs+FJY2W4ACtTOslrUlxmq3fOm+mWSn+2iWXboD88kfP1sN4vQX+caKL15HTRSjmicTD3P4bLINLGV+4uLA+ZJEQU7/s66Io1lqwIw57IZ+ftafbp5wMdcSh7rYgGNTxA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tRyBq-0006ju-KR for bug-gnu-emacs@gnu.org; Sun, 29 Dec 2024 13:39:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Divya Ranjan Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 29 Dec 2024 18:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74281 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org, Eli Zaretskii X-Debbugs-Original-Cc: monnier@iro.umontreal.ca, 74281@debbugs.gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.173549752725880 (code B ref -1); Sun, 29 Dec 2024 18:39:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 29 Dec 2024 18:38:47 +0000 Original-Received: from localhost ([127.0.0.1]:56147 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tRyBa-0006jL-8Z for submit@debbugs.gnu.org; Sun, 29 Dec 2024 13:38:46 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:33468) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tRyBX-0006jD-Iy for submit@debbugs.gnu.org; Sun, 29 Dec 2024 13:38:44 -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 1tRyBW-0006xq-O1 for bug-gnu-emacs@gnu.org; Sun, 29 Dec 2024 13:38:43 -0500 Original-Received: from latitanza.investici.org ([82.94.249.234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tRyBU-0005Qw-H0; Sun, 29 Dec 2024 13:38:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=subvertising.org; s=stigmate; t=1735497507; bh=3Rny6seXddC3cq/glHRybR3CdT1x21eJ7ISYjFlaJa0=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=mCQyQWBi0SM7JaCoktres1h++tAdWsgYATUvQJSWQXFQ/ruwIlV3Scl5HE1UhCxAl FYe9jefFvLK+iDaR0OWveIvTXLcH6OYQoOpDI+rGfVpjfGMCJl9J9OqxEOa0bPBns6 HWx0e99nycvPgrzb4VY6yclJ9Hf1PafpY9HdteZI= Original-Received: from mx3.investici.org (unknown [127.0.0.1]) by latitanza.investici.org (Postfix) with ESMTP id 4YLp030HLNzGp3d; Sun, 29 Dec 2024 18:38:27 +0000 (UTC) Original-Received: from [82.94.249.234] (mx3.investici.org [82.94.249.234]) (Authenticated sender: divya@subvertising.org) by localhost (Postfix) with ESMTPSA id 4YLp014FYfzGp3Z; Sun, 29 Dec 2024 18:38:25 +0000 (UTC) In-Reply-To: <86msggt66d.fsf@gnu.org> Received-SPF: pass client-ip=82.94.249.234; envelope-from=divya@subvertising.org; helo=latitanza.investici.org X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:297958 Archived-At: ------HU5UDVQ9LQSXY1TT2WXEZOJOQQQKYL Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Apologies Eli, I missed this thread! On 28 December 2024 11:09:46 GMT, Eli Zaretskii wrote: >Ping! Ping! Ping! Divya, please respond=2E > >> Cc: monnier@iro=2Eumontreal=2Eca, 74281@debbugs=2Egnu=2Eorg >> Date: Sat, 14 Dec 2024 11:34:40 +0200 >> From: Eli Zaretskii >>=20 >> Ping! Ping! Divya, are you there? >>=20 >> > Cc: 74281@debbugs=2Egnu=2Eorg >> > Date: Sat, 30 Nov 2024 11:51:49 +0200 >> > From: Eli Zaretskii >> >=20 >> > Ping! Divya, could you please try Stefan's suggestions and report >> > back? >> >=20 >> > > Cc: Divya Ranjan , 74281@debbugs=2Egnu=2E= org >> > > From: Stefan Monnier >> > > Date: Thu, 14 Nov 2024 11:56:37 -0500 >> > >=20 >> > > > Stefan, what tools do we have to investigate slowness related to >> > > > parse-partial-sexp? Or maybe you have suggestions for how to spe= ed up >> > > > font-lock in this case? >> > >=20 >> > > Hmm=2E=2E=2E `parse-partial-sexp` is normally expected to be fast, = unless it >> > > has to scan a lot of text=2E >> > >=20 >> > > > Here's the profile I get while moving with C-p through the above = file: >> > >=20 >> > > A stab in the dark, but maybe the relevant call is the one in: >> > >=20 >> > > (state (if (or syntax-ppss-table >> > > (not font-lock--syntax-table-affects-ppss)= ) >> > > (syntax-ppss start) >> > > ;; If `syntax-ppss' doesn't have its own syntax-= table and >> > > ;; we have installed our own syntax-table which >> > > ;; differs from the standard one in ways which a= ffects PPSS, >> > > ;; then we can't use `syntax-ppss' since that wo= uld pollute >> > > ;; and be polluted by its cache=2E >> > > (parse-partial-sexp (point-min) start))) >> > >=20 >> > > so the origin of the slowdown would be the (?#=2E "w 14") in the se= tting >> > > below in `scheme=2Eel`: >> > >=20 >> > > (setq font-lock-defaults >> > > '((scheme-font-lock-keywords >> > > scheme-font-lock-keywords-1 scheme-font-lock-keywords-2) >> > > nil t (("+-*/=2E<>=3D!?$%_&~^:" =2E "w") (?#=2E "w 14")) >> > > beginning-of-defun >> > > (font-lock-mark-block-function =2E mark-defun))) >> > >=20 >> > > in which case, setting a `syntax-ppss-table` should fix the problem= , tho >> > > we could also fix it by being more careful: AFAICT the purpose of t= his >> > > (?#=2E "w 14") is only to change the syntax of `#` from "prefix" to= "word" >> > > without changing the comment-related flags, so it shouldn't cause >> > > `font-lock--syntax-table-affects-ppss` to be set=2E >> > > So, we could solve it by improving the code that sets >> > > `font-lock--syntax-table-affects-ppss`, as in the patch below=2E >> > >=20 >> > >=20 >> > > Stefan >> > >=20 >> > >=20 >> > > diff --git a/lisp/font-lock=2Eel b/lisp/font-lock=2Eel >> > > index 203131bfd5a=2E=2Ef6299920c0a 100644 >> > > --- a/lisp/font-lock=2Eel >> > > +++ b/lisp/font-lock=2Eel >> > > @@ -1955,14 +1955,15 @@ font-lock-set-defaults >> > > (dolist (char (if (numberp (car selem)) >> > > (list (car selem)) >> > > (mapcar #'identity (car selem)))) >> > > - (unless (memq (car (aref font-lock-syntax-table char)) >> > > - '(1 2 3)) ;"=2E" "w" "_" >> > > - (setq font-lock--syntax-table-affects-ppss t)) >> > > - (modify-syntax-entry char syntax font-lock-syntax-table) >> > > - (unless (memq (car (aref font-lock-syntax-table char)) >> > > - '(1 2 3)) ;"=2E" "w" "_" >> > > - (setq font-lock--syntax-table-affects-ppss t)) >> > > - )))) >> > > + (let ((old-syntax (aref font-lock-syntax-table char))) >> > > + (modify-syntax-entry char syntax font-lock-syntax-table) >> > > + (let ((new-syntax (aref font-lock-syntax-table char))) >> > > + (unless (and (equal (cdr old-syntax) (cdr new-syntax)) >> > > + (memq (logand (car old-syntax) 255) '(1 2 = 3 6)) >> > > + (memq (logand (car new-syntax) 255) '(1 2 = 3 6)) >> > > + (equal (ash (car old-syntax) -8) >> > > + (ash (car new-syntax) -8))) >> > > + (setq font-lock--syntax-table-affects-ppss t)))))))) >> > > ;; (nth 4 defaults) used to hold `font-lock-beginning-of-syn= tax-function', >> > > ;; but that was removed in 25=2E1, so if it's a cons cell, w= e assume that >> > > ;; it's part of the variable alist=2E >> > >=20 >> > >=20 >> > >=20 >> > >=20 >> > >=20 >> >=20 >> >=20 >> >=20 >> >=20 >>=20 >>=20 >>=20 >>=20 > > > Divya Ranjan, Mathematics, Philosophy and Libre Software ------HU5UDVQ9LQSXY1TT2WXEZOJOQQQKYL Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Apologies Eli, I missed this thr= ead!


On 28 Decemb= er 2024 11:09:46 GMT, Eli Zaretskii <eliz@gnu=2Eorg> wrote:
Ping! Ping! Ping! Divya, please re= spond=2E

Cc: monnier@iro=2Eumontreal=2Eca, 74281@debbugs=2Egnu=2EorgDate: Sat, 14 Dec 2024 11:34:40 +0200
From: Eli Zaretskii <eliz@gnu= =2Eorg>

Ping! Ping! Divya, are you there?

Cc: 74281@debbugs= =2Egnu=2Eorg
Date: Sat, 30 Nov 2024 11:51:49 +0200
From: Eli Zaretski= i <eliz@gnu=2Eorg>

Ping! Divya, could you please try Stefan's= suggestions and report
back?

Cc: Divya Ranjan <divya@subvertisi= ng=2Eorg>, 74281@debbugs=2Egnu=2Eorg
From: Stefan Monnier <monnier= @iro=2Eumontreal=2Eca>
Date: Thu, 14 Nov 2024 11:56:37 -0500

<= /div>
Ste= fan, what tools do we have to investigate slowness related to
parse-part= ial-sexp? Or maybe you have suggestions for how to speed up
font-lock i= n this case?

Hmm=2E=2E=2E `pars= e-partial-sexp` is normally expected to be fast, unless it
has to scan a= lot of text=2E

Here's the profile I get while moving with C-p through= the above file:

A stab in the = dark, but maybe the relevant call is the one in:

(state (i= f (or syntax-ppss-table
(not font-lock--syntax-= table-affects-ppss))
(syntax-ppss start)
= ;; If `syntax-ppss' doesn't have its own syntax-table and
= ;; we have installed our own syntax-table which
= ;; differs from the standard one in ways which affects PPSS, ;; then we can't use `syntax-ppss' since that would pol= lute
;; and be polluted by its cache=2E
= (parse-partial-sexp (point-min) start)))

so the origin of t= he slowdown would be the (?#=2E "w 14") in the setting
below in `scheme= =2Eel`:

(setq font-lock-defaults
'((scheme-font-lock-ke= ywords
scheme-font-lock-keywords-1 scheme-font-lock-keywords-= 2)
nil t (("+-*/=2E<>=3D!?$%_&~^:" =2E "w") (?#=2E "= w 14"))
beginning-of-defun
(font-lock-mark-block-= function =2E mark-defun)))

in which case, setting a `syntax-ppss-tab= le` should fix the problem, tho
we could also fix it by being more caref= ul: AFAICT the purpose of this
(?#=2E "w 14") is only to change the synt= ax of `#` from "prefix" to "word"
without changing the comment-related f= lags, so it shouldn't cause
`font-lock--syntax-table-affects-ppss` to be= set=2E
So, we could solve it by improving the code that sets
`font-l= ock--syntax-table-affects-ppss`, as in the patch below=2E


= Stefan


diff --git a/lisp/font-lock=2Eel b/lisp/font-lock=2Eel<= br>index 203131bfd5a=2E=2Ef6299920c0a 100644
--- a/lisp/font-lock=2Eel+++ b/lisp/font-lock=2Eel
@@ -1955,14 +1955,15 @@ font-lock-set-defaul= ts
(dolist (char (if (numberp (car selem))
(list (car= selem))
(mapcar #'identity (car selem))))
- (unless (m= emq (car (aref font-lock-syntax-table char))
- '(1 2= 3)) ;"=2E" "w" "_"
- (setq font-lock--syntax-table-affects-p= pss t))
- (modify-syntax-entry char syntax font-lock-syntax-table)=
- (unless (memq (car (aref font-lock-syntax-table char))
- = '(1 2 3)) ;"=2E" "w" "_"
- (setq font-lock--= syntax-table-affects-ppss t))
- ))))
+ (let ((old-syntax = (aref font-lock-syntax-table char)))
+ (modify-syntax-entry char= syntax font-lock-syntax-table)
+ (let ((new-syntax (aref font-l= ock-syntax-table char)))
+ (unless (and (equal (cdr old-syntax= ) (cdr new-syntax))
+ (memq (logand (car old-synt= ax) 255) '(1 2 3 6))
+ (memq (logand (car new-syn= tax) 255) '(1 2 3 6))
+ (equal (ash (car old-synt= ax) -8)
+ (ash (car new-syntax) -8)))
+= (setq font-lock--syntax-table-affects-ppss t))))))))
= ;; (nth 4 defaults) used to hold `font-lock-beginning-of-syntax-function',=
;; but that was removed in 25=2E1, so if it's a cons cell, we as= sume that
;; it's part of the variable alist=2E












<= br>

Divya Ranjan, M= athematics, Philosophy and Libre Software
------HU5UDVQ9LQSXY1TT2WXEZOJOQQQKYL--