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#63622: lisp/progmodes/python.el: performance regression introduced by multiline font-lock Date: Sun, 21 May 2023 11:16:13 -0400 Message-ID: References: <83zg5yqkr1.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="10978"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Tom Gillespie , Eli Zaretskii , 63622@debbugs.gnu.org To: kobarity Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun May 21 17:18:25 2023 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 1q0kpF-0002ez-3p for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 21 May 2023 17:18:25 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q0kot-0007pY-FG; Sun, 21 May 2023 11:18:03 -0400 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 1q0kos-0007ot-A1 for bug-gnu-emacs@gnu.org; Sun, 21 May 2023 11:18:02 -0400 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 1q0kos-0008RC-2I for bug-gnu-emacs@gnu.org; Sun, 21 May 2023 11:18:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q0kor-0008Mj-U9 for bug-gnu-emacs@gnu.org; Sun, 21 May 2023 11:18:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 21 May 2023 15:18:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63622 X-GNU-PR-Package: emacs Original-Received: via spool by 63622-submit@debbugs.gnu.org id=B63622.168468225032120 (code B ref 63622); Sun, 21 May 2023 15:18:01 +0000 Original-Received: (at 63622) by debbugs.gnu.org; 21 May 2023 15:17:30 +0000 Original-Received: from localhost ([127.0.0.1]:60978 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q0koM-0008M0-4J for submit@debbugs.gnu.org; Sun, 21 May 2023 11:17:30 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:39657) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q0knE-0008KN-Ul for 63622@debbugs.gnu.org; Sun, 21 May 2023 11:17:28 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 4027180AFC; Sun, 21 May 2023 11:16:15 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id CF02180677; Sun, 21 May 2023 11:16:13 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1684682173; bh=Ibof+W5+SBqviJmmxzZhw52IVoOfC8RhC44NT5vZ1qw=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=TwFFKXZcXlKU8OsY0oWOQSL66/A09WzbwOKUch3W27XqUCltlMfb9No5IfU8kntgA T+OIHg48e4mbda55bJu32pu4bNdORdn8E0Z039SN+VwK2bRAeLpoltYzubqUaVEo3O y2KZMk8Ad85dOUiBe3DF+neskQGrzsWMqHg9V7Op9vM0u5txiMpD77/fH4OKI/OV8C ymAcPzMHRcTt3Yw3aIj+qfFCe3uX3lreWZVjxh+O6Yddrw8DhYUG7W/QWrJ/223N16 Se8n6OFsngbcglP5W3oq0h+UgdOjrJuEcJaSkiAUzczFuAjxVCcVrb0DZRw8UsREjV YYaVsgyYjRcxA== Original-Received: from pastel (unknown [45.72.217.176]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 9F16E1203EF; Sun, 21 May 2023 11:16:13 -0400 (EDT) In-Reply-To: (kobarity@gmail.com's message of "Sun, 21 May 2023 18:31:50 +0900") 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:262109 Archived-At: > I agree. It seems to me that it is not python-font-lock-extend-region > itself that is slow, but rather font-lock's processing of the area > extended by it. So one workaround would be to limit the number of > lines to be extended, as in the attached patch. If this limit is > exceeded, the area or the entire buffer must be font-locked manually > later. What do you think of this idea? FWIW, I recommend against using `font-lock-extend-after-change-region-function`. E.g. in a case like `python-font-lock-assignment-statement-multiline-1`, the current code may misfontify code because jit-lock may decide to first call font-lock on a chunk that goes until: [ a, b and will call again font-lock later to fontify the rest: ] # ( 1, 2 ) and this can happen with no buffer modification at all (e.g. on the initial fontification of a buffer). You can use `font-lock-extend-region-functions` instead (which performs the region-extension right before fontifying a chunk) to avoid this problem. [ It won't help with the current performance issue, tho. ] `font-lock-extend-after-change-region-function` can also be costly when a command makes many changes (since `font-lock-extend-after-change-region-function` is called for every such change rather than once at the end). `font-lock-extend-region-functions` tends to be better behaved in this respect (it's called once per chunk, and there's usually only a single chunk (re)fontified per command, even after a command that makes many changes), One more thing: Tom mentioned a suspicion that the performance issue may have to do with interaction with `syntax-ppss`. This is odd, because `syntax-ppss` and `syntax-propertize` should not be affected by font-lock. Stefan