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#74281: 30.0.91; font-lock mode hangs on scrolling large Scheme file Date: Thu, 14 Nov 2024 11:56:37 -0500 Message-ID: References: <8734k0cs1u.fsf@subvertising.org> <86zfm2jjbo.fsf@gnu.org> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15057"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Divya Ranjan , 74281@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 14 17:57:51 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 1tBdAE-0003lb-VS for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 14 Nov 2024 17:57:51 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tBd9V-0008Nc-69; Thu, 14 Nov 2024 11: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 1tBd9T-0008N4-2x for bug-gnu-emacs@gnu.org; Thu, 14 Nov 2024 11:57: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 1tBd9S-0002ZN-RD for bug-gnu-emacs@gnu.org; Thu, 14 Nov 2024 11:57:02 -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:Date:References:In-Reply-To:From:To:Subject; bh=4sfpTWwUfzgCE2cOvDMahAkQs7YXQKZZKRPFpwCbwjM=; b=F9YPqOLIUKvzTsJjbierjjp9EfaCn1AxbdWZMe3JCci7RRSNS0ABokqb6Fbn543qEuHb0ZuJ/dBWiwaoHyj66eSt/PJoZSA/vFEp4dzCSYAo1c1+6n139PVpCbH0NF6jPqDC8s5zrHyQ4X/5iMey+zY3VJcfMMQr+2bv2oJbHvzzQ1oEZ/oyA2qkQyy53gjcB50agdF5MVDur7BFsd+TqL8i6O7fyfBpfUaXFal5CQjhi9BuJZiStlrTkle9jPKCk+WwlijutMM1mfOK1FtcK9upky1yV8gOIEhQp3ZI7OZE21DuWl0qJQ/g35OpLxfWV6EQb1XDNL0qYgh0CxJyIw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tBd9S-0000V8-Fm for bug-gnu-emacs@gnu.org; Thu, 14 Nov 2024 11:57:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 14 Nov 2024 16:57:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74281 X-GNU-PR-Package: emacs Original-Received: via spool by 74281-submit@debbugs.gnu.org id=B74281.17316034101902 (code B ref 74281); Thu, 14 Nov 2024 16:57:02 +0000 Original-Received: (at 74281) by debbugs.gnu.org; 14 Nov 2024 16:56:50 +0000 Original-Received: from localhost ([127.0.0.1]:46958 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tBd9F-0000Uc-Fe for submit@debbugs.gnu.org; Thu, 14 Nov 2024 11:56:49 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:28047) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tBd9D-0000UP-Eq for 74281@debbugs.gnu.org; Thu, 14 Nov 2024 11:56:47 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id CD622442683; Thu, 14 Nov 2024 11:56:40 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1731603398; bh=CbRluiu7+NL/Q4JBkBzwru81PRrb98wKdD+hnloKwik=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=KBZUupxYomdOgZoNJKpIhz4DSh2QIaW3zHGm8ourFnRUyVGIPIwVTRrpPQ71xjP68 0gb4nvppLGnBvWBFu4oBIGkL1IFP1T0BSuEWOMNzxQBUGI2D4s9llCrPo6MZ601QL7 kPsi0izQWfFhzDynjKy5CF0aJyvufZlp48N8TVMD2Q8IZUbOCjf1Af+A2ecsXtlcwk JeTMKJJBawIAp9GxI3jaqxhfINJTQgiTka6eMt0xwlKQSGYwAy8LK6qVGliniGmPn6 aAL7wlKnf3KXQTuiA4If4j+h+X4Sd8k7p/fJH8Xm2yPQoA32mPxiwolytH4pJwk/RM WBhbPOqyHygdw== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 86A09442629; Thu, 14 Nov 2024 11:56:38 -0500 (EST) Original-Received: from alfajor (modemcable005.21-80-70.mc.videotron.ca [70.80.21.5]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 651291201CF; Thu, 14 Nov 2024 11:56:38 -0500 (EST) In-Reply-To: <86zfm2jjbo.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 14 Nov 2024 10:44:27 +0200") 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:295346 Archived-At: > Stefan, what tools do we have to investigate slowness related to > parse-partial-sexp? Or maybe you have suggestions for how to speed up > font-lock in this case? Hmm... `parse-partial-sexp` is normally expected to be fast, unless it has to scan a lot of text. > 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 (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 affects PPSS, ;; then we can't use `syntax-ppss' since that would pollute ;; and be polluted by its cache. (parse-partial-sexp (point-min) start))) so the origin of the slowdown would be the (?#. "w 14") in the setting below in `scheme.el`: (setq font-lock-defaults '((scheme-font-lock-keywords scheme-font-lock-keywords-1 scheme-font-lock-keywords-2) nil t (("+-*/.<>=!?$%_&~^:" . "w") (?#. "w 14")) beginning-of-defun (font-lock-mark-block-function . mark-defun))) 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 this (?#. "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. So, we could solve it by improving the code that sets `font-lock--syntax-table-affects-ppss`, as in the patch below. Stefan diff --git a/lisp/font-lock.el b/lisp/font-lock.el index 203131bfd5a..f6299920c0a 100644 --- a/lisp/font-lock.el +++ b/lisp/font-lock.el @@ -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)) ;"." "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)) ;"." "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-syntax-function', ;; but that was removed in 25.1, so if it's a cons cell, we assume that ;; it's part of the variable alist.