From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#56682: Fix the long lines font locking related slowdowns Date: Fri, 05 Aug 2022 21:14:53 +0300 Message-ID: <83h72qzheq.fsf@gnu.org> References: <837d46mjen.fsf@gnu.org> <8a3eaeef01be5bfaa5ef@heytings.org> <05388e8d8812bfa3695d@heytings.org> <83v8rf5894.fsf@gnu.org> <65cb7c73fd4a999cca00@heytings.org> <8c7321f2f3400a5db9be@heytings.org> <8c7321f2f388e5343475@heytings.org> <8c7321f2f36494299e61@heytings.org> <83v8rc2n1h.fsf@gnu.org> <64084296-1953-8ef8-5938-adfb6fb9b43f@yandex.ru> <83r11uzs8n.fsf@gnu.org> <14845631-c2ef-8371-8606-c858092e3192@yandex.ru> <83mtcizov2.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30327"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 56682@debbugs.gnu.org, gregory@heytings.org, monnier@iro.umontreal.ca To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Aug 05 20:16:36 2022 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 1oK1sA-0007gs-IB for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 05 Aug 2022 20:16:34 +0200 Original-Received: from localhost ([::1]:33850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oK1s9-0005Gt-AS for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 05 Aug 2022 14:16:33 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45264) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oK1re-0005Gi-MB for bug-gnu-emacs@gnu.org; Fri, 05 Aug 2022 14:16:06 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42552) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oK1re-00062S-AC for bug-gnu-emacs@gnu.org; Fri, 05 Aug 2022 14:16:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oK1re-00068c-3N for bug-gnu-emacs@gnu.org; Fri, 05 Aug 2022 14:16:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 05 Aug 2022 18:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56682 X-GNU-PR-Package: emacs Original-Received: via spool by 56682-submit@debbugs.gnu.org id=B56682.165972330323513 (code B ref 56682); Fri, 05 Aug 2022 18:16:02 +0000 Original-Received: (at 56682) by debbugs.gnu.org; 5 Aug 2022 18:15:03 +0000 Original-Received: from localhost ([127.0.0.1]:60531 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oK1qg-000678-7y for submit@debbugs.gnu.org; Fri, 05 Aug 2022 14:15:03 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:60298) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oK1qe-00066K-Fc for 56682@debbugs.gnu.org; Fri, 05 Aug 2022 14:15:01 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:42912) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oK1qY-0005Zd-8v; Fri, 05 Aug 2022 14:14:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=h+Na5t9TNhptVxy4u7ke5LrlTKPUm/wgJfEZuu+cCa0=; b=N0pCOMZu+I9e 3nkz3YpM1Oz13C5iITNnAy2W8GatcmJNQM7JGm6MsaW1vX8iZvoY4XXek1akBhsjZTtBd8syCSRjz c/j4YzLMBtgAUZd+l4NRy4b2Mklb1CS7HfmfH2VEU5mE850Rv7zi/T3cbNpb45zTJ8+aqmjXSorF9 B63ais497oRJUO6fdQmorqARD3jky/n7RCDlH3p1HMK8LaDRk0Ue4QsMQ1oAnWoPh+dLUzOLpIL// 2BAXNFo5EXkpaiM26G/Y7cPiPV3aqutHi6/YnRtPQbYcctPquj6MhYWy23P1PwFQ7wmyfAroCOG3t gHy2Xw2tXKJ2CencKG6qCQ==; Original-Received: from [87.69.77.57] (port=1062 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oK1qX-0005hV-PO; Fri, 05 Aug 2022 14:14:54 -0400 In-Reply-To: (message from Dmitry Gutov on Fri, 5 Aug 2022 21:02:35 +0300) 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" Xref: news.gmane.io gmane.emacs.bugs:238936 Archived-At: > Date: Fri, 5 Aug 2022 21:02:35 +0300 > Cc: 56682@debbugs.gnu.org, gregory@heytings.org, monnier@iro.umontreal.ca > From: Dmitry Gutov > > > How is (parse-partial-sexp 1 (point-max)) related to the issue at > > hand? > > Or perhaps I should answer this way: > > We move to near EOB. > fontification-functions are called. > > jit-lock > calls > (font-lock-fontify-region point-near-buffer-end (point-max)) > which calls > font-lock-fontify-syntactically-region > which calls both > (syntax-propertize (point-max)) > and > (syntax-ppss point-near-buffer-end) -> and it calls parse-partial-sexp > > syntax-propertize will also likely call syntax-ppss itself, probably > through the major mode's syntax-propertize-function. But if > syntax-propertize-function is nil, parse-partial-sexp gets called > anyway, over the whole buffer, which makes it the main workload in > fontifying near EOB. > > Now, if syntax-propertize-function is non-nil, parse-partial-sexp will > also call it, and it adds its overhead (sometimes a multiple of p-p-s), > which also scales linearly with the length of the buffer. > > So if one can demonstrate that (parse-partial-sexp (point-min) > (point-max)) takes about the same time as it takes to fontify the last > screen-ful of a buffer, then that says that everything else that > jit-lock does to fontify, is negligible, time-wise. So you have demonstrated that, if visiting a file and moving inside it calls parse-partial-sexp to scan the entire buffer, then this could be some, perhaps a large, part of the slowdown. First, we need to establish that indeed parse-partial-sexp is called in that manner in the relevant major modes (not just one of them), or by font-lock itself regardless of the mode. Second, we need to establish that indeed this takes a large portion of the time in the slow operations. Not just one particular operation, but most or all of them. And after that, we may have some food for thought.