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: Sat, 28 Dec 2024 10:03:29 -0500 Message-ID: References: <8734k0cs1u.fsf@subvertising.org> <86zfm2jjbo.fsf@gnu.org> <865xo59hhm.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="31359"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: divya@subvertising.org, 74281@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 28 16:04:15 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 1tRYMQ-0007w7-Tf for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 28 Dec 2024 16:04:15 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tRYMF-0006mw-Nl; Sat, 28 Dec 2024 10:04:03 -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 1tRYME-0006mm-R4 for bug-gnu-emacs@gnu.org; Sat, 28 Dec 2024 10:04:02 -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 1tRYME-00008j-1O for bug-gnu-emacs@gnu.org; Sat, 28 Dec 2024 10:04: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=6cHyqiBlY3sIIohO6Edjm/JrMG0YyZp0wuojzJfnIiU=; b=QThOXAMT69ve38dz8k/bNAm44aEE4UfFAuF7Zge+I0RfzzlV6icUIickICWx6cj8+34z8y823G7hI+GNw0srvIhf7i73DTKefYVgSsWQd87AU7Ic/F57MjrQProS6o0f8+htgiaFpfgzuAiKBh1Pxxh5UOwRU/idfczx7AP9A+UaRXVS/r8dWtNnZE3K97FtOrjHKbd1em0SUN5uIqhSRnQd4VqmWKR8IY7x6kOWdab1XF/wWnN8pmQTjX/UlsQz9norEOUM8NE6QQJXr/HJXAQ8KSd2nfWg06OiyKXwuDYRD+t0LSyXPIuETOTva6NitU1Yr6Z5zcgO+ZAd0cEJPw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tRYMD-0001bx-S3 for bug-gnu-emacs@gnu.org; Sat, 28 Dec 2024 10:04:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 28 Dec 2024 15:04:01 +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.17353982196154 (code B ref 74281); Sat, 28 Dec 2024 15:04:01 +0000 Original-Received: (at 74281) by debbugs.gnu.org; 28 Dec 2024 15:03:39 +0000 Original-Received: from localhost ([127.0.0.1]:52279 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tRYLr-0001bB-5C for submit@debbugs.gnu.org; Sat, 28 Dec 2024 10:03:39 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:59936) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tRYLo-0001ax-Ro for 74281@debbugs.gnu.org; Sat, 28 Dec 2024 10:03:37 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 6FEBA8089D; Sat, 28 Dec 2024 10:03:31 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1735398210; bh=/ObhJ4SThutXZY+OAK7fPxEhtOQGfT3zwOi38le7mQU=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=YRHUrQOofmlEmMxxjppOzuLk/P27A5l9RfpQXZhay2DOj/tPni5ny+avUv6WV/x+o 7jWWPZnTeX1L2rdPumxsAuDoClou3NGdM7hjb76HID2mUDENHQk27dYI0Bk1bZAKBX tlivJkk6yQLlS+/GAlFyrFtXPtThg0QTimBCuiluDbtSzW3S2uAnGYK0hGn40V3qH0 n+a2d1hUVqkXyYldk/RlUpoohlAZfXMifJGwtyEAJ3sbNwlAD4G8J7YD9v/KspuWNf qbFLFtuTb+USGkoUQsM0s42Nyk6tyqkW6SxoMhLNpuiY0uGhmLea0cxusNkssGmtYa G7Y6vQJbgjTEQ== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 5D0848029E; Sat, 28 Dec 2024 10:03:30 -0500 (EST) Original-Received: from pastel (104-195-225-43.cpe.teksavvy.com [104.195.225.43]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 2AD39120478; Sat, 28 Dec 2024 10:03:30 -0500 (EST) In-Reply-To: <865xo59hhm.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 30 Nov 2024 11:51:49 +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:297909 Archived-At: > Ping! Divya, could you please try Stefan's suggestions and report > back? FWIW, I think the change is an improvement in any case, so we could install it. Since it's in a "core" file, it might be too risky for `emacs-30`, so I'm thinking of installing it in `master`, WDYT? Stefan >> Cc: Divya Ranjan , 74281@debbugs.gnu.org >> From: Stefan Monnier >> Date: Thu, 14 Nov 2024 11:56:37 -0500 >> >> > 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. >> >> >> >> >>