From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#56682: Fix the long lines font locking related slowdowns Date: Tue, 2 Aug 2022 17:53:36 +0300 Message-ID: References: <837d46mjen.fsf@gnu.org> <8a3eaeef01be5bfaa5ef@heytings.org> <05388e8d8812bfa3695d@heytings.org> <83v8rf5894.fsf@gnu.org> <65cb7c73fd4a999cca00@heytings.org> <8c7321f2f3400a5db9be@heytings.org> <8c7321f2f388e5343475@heytings.org> <6ea376f6-d503-06d8-6d83-50c52b695394@yandex.ru> <8c7321f2f3ac52bfee4b@heytings.org> <8c7321f2f3ec1ef81af9@heytings.org> <02e83b0e-1b5c-fe75-6e59-1f8ddff82d37@yandex.ru> <96f28fd8-6744-1925-0631-0095099362dd@yandex.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2049"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Cc: 56682@debbugs.gnu.org, Eli Zaretskii , Stefan Monnier To: Gregory Heytings Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Aug 02 16:54:12 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 1oItHe-0000IU-Rc for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 02 Aug 2022 16:54:10 +0200 Original-Received: from localhost ([::1]:45946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oItHd-0002WU-Lm for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 02 Aug 2022 10:54:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oItHW-0002Ux-2q for bug-gnu-emacs@gnu.org; Tue, 02 Aug 2022 10:54:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54947) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oItHV-00040e-Pb for bug-gnu-emacs@gnu.org; Tue, 02 Aug 2022 10:54:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oItHV-0000Mk-JE for bug-gnu-emacs@gnu.org; Tue, 02 Aug 2022 10:54:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 02 Aug 2022 14:54:01 +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.16594520271383 (code B ref 56682); Tue, 02 Aug 2022 14:54:01 +0000 Original-Received: (at 56682) by debbugs.gnu.org; 2 Aug 2022 14:53:47 +0000 Original-Received: from localhost ([127.0.0.1]:44696 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oItHG-0000ME-Pe for submit@debbugs.gnu.org; Tue, 02 Aug 2022 10:53:47 -0400 Original-Received: from mail-wm1-f46.google.com ([209.85.128.46]:56044) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oItHE-0000M0-DG for 56682@debbugs.gnu.org; Tue, 02 Aug 2022 10:53:45 -0400 Original-Received: by mail-wm1-f46.google.com with SMTP id b6so7332691wmq.5 for <56682@debbugs.gnu.org>; Tue, 02 Aug 2022 07:53:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=fnpKwtRWHU8+9sbwqwzTvcV8m1XbpvAY9NvqwXViK8g=; b=eN6+0yCIfmdWdE/zFdy0+DOtxWQ12UiddTwPYGSYWefVs5d9XCxgOzDXrINuFR7HKw htfeUmrP8l2AF48Hcdr4ZseVwMPPVq90HXNJxJHnvD6UFi3nXbnO4QAOrcxPdjKH/HpC vB67xPrGOEvKzxYJbp4ujKAebFsdIzEPikz6jMMxCmLwIQSd9iRCLqrFBeeUJePGk/Jr MrnUZF4Fey9iSDwN+cYLCFKJSh2vEyOsFEuf2pH1TxVqNC6B4qLoFWK5CRXOQ0SlVEcI nMN0D3ubpXcOPsHplFwRrtpc0YCeVRfZrQCWz3pp6OJMLo9HP9O9o3YgNVgFZ0ZKuQwv GvJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:message-id:date:mime-version:user-agent :subject:content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=fnpKwtRWHU8+9sbwqwzTvcV8m1XbpvAY9NvqwXViK8g=; b=lEnTpbT27IKGchreEzkLkyvd72XNMxpI789w6yPN3xg9IZLYTFfdKx9J+vRikKUb/V QJUmqSpeQAu+atHi3N/Ecz25CqoGWOxR7tpKSEtP/Fv5GWSpKr30Gj3X69voR5A0ysuW YGhla+SRATKvJ14uUd7ZK9wKdju4vdceS+zzNCLtrPEACW40nrctNminBtve22sQQXH+ k3enqHiAymC6nopOlw4JtT0XCyY1LwcwBxbXxR0o0bOQt0+GqZaIFUW1EaavgVKvssE3 g+F6NqaeoWMsVRr7MICVoW85MeykFX2aZBrzfki0t7VfGth0DOyZ5LfdtEP03D5Z8P7+ g9bw== X-Gm-Message-State: AJIora+TM9D+1wN16M+cZDW1lCqk6ejMMWcf7G7s176TsJJ9L9ZH3lda mWs+vKKjBxDho9a6rRmvw6k= X-Google-Smtp-Source: AGRyM1v+8V7YY0XJ9e5LaeglmvM95SZrE81RxONAHCgXnALvmFdacNq9m2DXXLE4y39HxOCCqEq9aw== X-Received: by 2002:a05:600c:ad2:b0:3a3:181e:e228 with SMTP id c18-20020a05600c0ad200b003a3181ee228mr15059974wmr.139.1659452018416; Tue, 02 Aug 2022 07:53:38 -0700 (PDT) Original-Received: from [192.168.0.215] (buscust41-118.static.cytanet.com.cy. [212.31.107.118]) by smtp.googlemail.com with ESMTPSA id b17-20020a05600c4e1100b003a331c6bffdsm19252372wmq.47.2022.08.02.07.53.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 Aug 2022 07:53:38 -0700 (PDT) Content-Language: en-US In-Reply-To: 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:238560 Archived-At: On 01.08.2022 14:01, Gregory Heytings wrote: > >>> No, it happens when the buffer is opened.  Given the importance that >>> you and Stefan seem to give to that function, it is, with the patch I >>> sent in my previous post, called once on the whole buffer (without >>> any narrowing) when the file is opened. >> >> But if the buffer is not scrolled to the end, shouldn't it be called >> with a position that's close to the beginning? >> >> That shouldn't force the full buffer scan, meaning this call should >> complete quickly. >> > > I'm trying to reconcile two conflicting constraints. > > It is necessary to add a locked narrowing around fontification-functions > and pre/post-command-hook to ensure that Emacs remains responsive. Perhaps tweaking the value of syntax-wholeline-max could have a similar enough effect? > At the same time, you and Stefan tell me that syntax-ppss does an > important job and will not do it correctly with such a locked narrowing, > IOW, that at least syntax-ppss should be called without a locked > narrowing.  But you also tell me that its result is cached so that a > full buffer scan isn't necessary anymore when it has happened at least > once. > > So what I'm suggesting is to do a full buffer scan immediately, when the > file is opened, without any narrowing.  If that happens, later calls to > syntax-ppss inside fontification-functions and pre/post-command-hook > will use the cached result of the initial scan, and will do their job > correctly even with a locked narrowing. syntax-ppss has two caches: one for the widened buffer (when point-min equals to 1), and another for narrowings. The latter cache is always cleared when point-min changes. The latter cache works okay-ish for multiple-major-mode scenario, but if redisplay narrows with different limits, that would blow cache often. And if the whole chunk is big enough (i.e. bigger than the average distance between the cached syntax-ppss positions), that could actually result in syntax-ppss working slower than it could. > Unless I misunderstand something, I think (and my tests seem to confirm) > that that would be a workable solution, provided that the initial scan > is reasonably fast, that is, at least six times faster than it is now. I'm afraid this approach is too blunt to be a solution.