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: Mon, 15 Aug 2022 21:17:23 +0300 Message-ID: References: <92da07bd028e3ede61a6@heytings.org> <47894c57-dd8b-5778-240a-3fa6540e4d37@yandex.ru> <92da07bd02941d5537e9@heytings.org> <5308e3b5-a160-17d7-77ee-b1d00acfa20d@yandex.ru> <92da07bd02a6cc861e1a@heytings.org> <837d3lzv8n.fsf@gnu.org> <2c8d6755-cfe2-6559-3fde-3fa30ffb411e@yandex.ru> <83mtcgy44k.fsf@gnu.org> <83k07jx5jn.fsf@gnu.org> <866e510d-a060-7daa-d002-97861d056fa7@yandex.ru> <1144021660321893@iva5-64778ce1ba26.qloud-c.yandex.net> <12348081660379417@sas2-a098efd00d24.qloud-c.yandex.net> <66bbbb95983414e79637@heytings.org> <83wnb9hadb.fsf@gnu.org> <395454dd-7238-c5d0-e924-2f65a186baa7@yandex.ru> <83r11hh4pm.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16852"; 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, gregory@heytings.org, monnier@iro.umontreal.ca To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Aug 15 20:18:18 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 1oNefH-00041c-I6 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 15 Aug 2022 20:18:15 +0200 Original-Received: from localhost ([::1]:55218 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNefF-0004UD-Qr for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 15 Aug 2022 14:18:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57638) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNef4-0004TI-Hq for bug-gnu-emacs@gnu.org; Mon, 15 Aug 2022 14:18:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54275) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oNef4-0007UZ-98 for bug-gnu-emacs@gnu.org; Mon, 15 Aug 2022 14:18:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oNef4-000305-18 for bug-gnu-emacs@gnu.org; Mon, 15 Aug 2022 14:18:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 15 Aug 2022 18:18: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.166058745411498 (code B ref 56682); Mon, 15 Aug 2022 18:18:01 +0000 Original-Received: (at 56682) by debbugs.gnu.org; 15 Aug 2022 18:17:34 +0000 Original-Received: from localhost ([127.0.0.1]:44024 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oNeeb-0002zN-WD for submit@debbugs.gnu.org; Mon, 15 Aug 2022 14:17:34 -0400 Original-Received: from mail-wr1-f50.google.com ([209.85.221.50]:45856) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oNeeZ-0002z9-JW for 56682@debbugs.gnu.org; Mon, 15 Aug 2022 14:17:32 -0400 Original-Received: by mail-wr1-f50.google.com with SMTP id z16so9936363wrh.12 for <56682@debbugs.gnu.org>; Mon, 15 Aug 2022 11:17:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:from:to:cc; bh=wZR1GipgP2F97/Y+rgT65tCJLc18zqtZ+5fz9Qpfq4A=; b=plB6dyT2is5IV9e0ii1MxqwHnIsGvxLzx4HoVBHzC0wBf5DdTvJ/UNIY/znixEWTC+ Bjkk+e266mymss12LB3j/AFJ+TZyjxOQ8ESiVHj9nPCyRbtdQd5hK1n3tut8IlEFgYtw y+tii+mWbqtCpqupqEISLQVVuabH37LA9xH5I//tIVSr7UkXhc4QCUJN1Q+PMVt2mJH2 BmR3pDVUC6QusTJPoCZwd6af/7ciLjBK7pLVU0crrG/DQBUQaBy2SeA4AHTDQqTDKtaP FjsU31aBXqY7CNVm7MugmSCMBdchSF00+4m072fz3xzI2KNCRc0KRS5YMVAZ013HQfpg pAGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:x-gm-message-state:from:to:cc; bh=wZR1GipgP2F97/Y+rgT65tCJLc18zqtZ+5fz9Qpfq4A=; b=yFApgEsUw2/AGVILiLeA9drCoxjHn5WNSerPHEGPMiVlascuWuhQHcPBGo8zwBQHN3 2M4M3F4U0+ObWWMMOIFl8hd5BXFnFxIXyaBZTwW1mckbTa/VS9cU/A7xgm+mTC0ikaiy a6bdz5cuwRO/Mn/DJBKA/ZCdI+z/EABaSRDq+D7J7XSEDAccs+xnGKNnno5eprefKAyr h8rvCatHarqNtkE3zQECSI2mC77uGXyvV6aDNyylpJY4zHQ3GCg9/es2SwZF7NL6LJSI YQ7kgXZlAjwVnr/OPGZqAPimeSvFlBI7aXVr+H5NUi6GPt/BYPij/JhKIaTITBPaMlem U94Q== X-Gm-Message-State: ACgBeo1bJLeEke6CrD95lBKUGzkkaoUBmUV3+sWiISl6tirOttXdpon7 o+sEzUxXZtc1eFHZTjd9N1E= X-Google-Smtp-Source: AA6agR5v/XoDLVVoCtOKQw7k76BHOvVPFYxXVJ9CLdCG4RIy4Ri0ID8hVn6z+1kv9c2FW+1O/7uiTA== X-Received: by 2002:a5d:688c:0:b0:21f:160d:8859 with SMTP id h12-20020a5d688c000000b0021f160d8859mr9787756wru.711.1660587445723; Mon, 15 Aug 2022 11:17:25 -0700 (PDT) Original-Received: from [192.168.0.6] ([46.251.119.176]) by smtp.googlemail.com with ESMTPSA id y5-20020adfd085000000b0021e6c52c921sm10290053wrh.54.2022.08.15.11.17.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 15 Aug 2022 11:17:25 -0700 (PDT) Content-Language: en-US In-Reply-To: <83r11hh4pm.fsf@gnu.org> 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:239824 Archived-At: On 15.08.2022 19:05, Eli Zaretskii wrote: >> Date: Mon, 15 Aug 2022 18:52:41 +0300 >> Cc: 56682@debbugs.gnu.org, gregory@heytings.org, monnier@iro.umontreal.ca >> From: Dmitry Gutov >> >> On 15.08.2022 17:03, Eli Zaretskii wrote: >> >>> I tested this branch with an unoptimized build and a 416MB file made >>> of 23 copies of dictionary.json, after disabling show-paren-mode. >>> >>> Observations: >>> >>> . With the default value of font-lock-large-files, which allows >>> font-lock to widen as it pleases, the initial M-> in takes 5 min >>> here. That's way too long. On master, this is instantaneous. >>> . Thereafter jumping into various random places inside the file is >>> much faster, but still takes between 1 min and 2.25 min -- again >>> too long, even if I divide by 10 to get an approximation to your >>> faster machine. On master this takes maybe 1 sec, maybe less. >>> . Horizontal and vertical motion commands are as fast (or as slow) >>> as on master, which is not surprising. >>> >>> Bottom line: with the default value of font-lock-large-files, this >>> scales much worse than the master branch -- which again is no >>> surprise. >> >> So we change the default, then? >> >> (setq font-lock-large-files '(narrow . 5000)) > > No, I want a simple variable that just gives the size of the narrowed > region, with nil meaning don't narrow at all. OK. >>> My conclusion is that we do need to prevent uncontrolled >>> widening in fontification-functions, if we want a scalable solution. >> >> Do you mean the widening inside font-lock-fontify-region that's >> controlled by font-lock-dont-widen? > > No, I mean _any_ widening in _any_ function placed on the > fontification-functions hook. > >>> I honestly don't see any reason to explore more sophisticated >>> alternatives for where and how to narrow, until and unless major modes >>> will on their side develop capabilities which will make such >>> complications (both in code, but mainly on the user part) justified. >> >> I'm pretty sure that doing all that in Lisp is a good thing, and would >> be conducive to whatever improvements we might want to add later... > > No, because quite a few packages use jit-lock-register to run stuff > that is not font-lock at all, and I don't want that to slow down > redisplay when long lines are involved. And trying various values of > a variable exposed to Lisp is easy enough. It should also be possible to move the whole invocation of the fontification-functions up to Lisp, and apply the narrowing in the new function that does that. Another reason I chose font-lock-fontify-region, though, is that it's called from different places. It's the common entry point for font-lock. Like, from 'font-lock-ensure', for example (font-lock-turn-on-thing-lock sets font-lock-ensure-function to #'jit-lock-fontify-now). It's called from Org (see all references to org-font-lock-ensure), for instance. mmm-mode calls font-lock-fontify-region directly (sometime we'll change it to use font-lock-ensure instead). Also see htmlfontify-buffer, occur-engine-line, describe-variable, diff-syntax-fontify-props. It's also used in after-change-functions when font-lock-support-mode is not `jit-lock', but that's probably not important. Some of these definitely can be dealing with long lines and/or large files. If font-lock-fontify-region decides the narrowing bounds, it can apply them correctly it each case. I get what you're saying about alternative fontification-functions, though: we have multiple similar hooks: it, then jit-lock-functions, and font-lock-keywords are more or less used for the same purpose. I've never seen fontification-functions contain anything but jit-lock-function, but jit-lock-functions is used by nlinum, for instance. And bug-reference-mode, and goto-address-mode. Perhaps we should ask Stefan's opinion on this. As a practical matter, though, neither goto-addr, nor bug-reference should call syntax-ppss or do anything similarly costly in on long lines/in large files. And nlinum might not appreciate being narrowed. It seems to be working okay without that in my 20 MB XML file. And in 200 MB one too.