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 04:05:57 +0300 Message-ID: <17c0d4df-78f5-76f4-784d-5c9d52eb7fa0@yandex.ru> 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> <2f7eeea3-6ba9-d2c2-1fb9-dd40d2de2002@yandex.ru> <8c7321f2f368e8dd096d@heytings.org> <56a688f6-6c93-8b67-895c-2c41f563fc93@yandex.ru> <83sfmg2mkv.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="5976"; 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 Tue Aug 02 03:07:25 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 1oIgNY-0001Oq-OU for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 02 Aug 2022 03:07:24 +0200 Original-Received: from localhost ([::1]:38848 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIgNW-0008Ip-PF for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 01 Aug 2022 21:07:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41800) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIgNC-0008IS-Uc for bug-gnu-emacs@gnu.org; Mon, 01 Aug 2022 21:07:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:52146) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oIgNC-0000g9-Kq for bug-gnu-emacs@gnu.org; Mon, 01 Aug 2022 21:07:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oIgNC-00057Y-GI for bug-gnu-emacs@gnu.org; Mon, 01 Aug 2022 21:07: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: Tue, 02 Aug 2022 01:07: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.165940237019601 (code B ref 56682); Tue, 02 Aug 2022 01:07:02 +0000 Original-Received: (at 56682) by debbugs.gnu.org; 2 Aug 2022 01:06:10 +0000 Original-Received: from localhost ([127.0.0.1]:41895 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oIgML-000565-WB for submit@debbugs.gnu.org; Mon, 01 Aug 2022 21:06:10 -0400 Original-Received: from mail-wr1-f48.google.com ([209.85.221.48]:36636) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oIgMH-00055R-3R for 56682@debbugs.gnu.org; Mon, 01 Aug 2022 21:06:08 -0400 Original-Received: by mail-wr1-f48.google.com with SMTP id j7so16022834wrh.3 for <56682@debbugs.gnu.org>; Mon, 01 Aug 2022 18:06:05 -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=z3ZwYDQzL1pylH7ZwKNGRSF0U9R/jxKtAqOETuDU8lY=; b=b5MxowsL+F15xyTiFFxCD19sJWQaORHeOMYdu9gYgnldVRcCJWVtmv79OANFsvlANs WRqqpG+LDV/gkva6IhlQ20NP6bZbU1K2jpHPQ5zavCeAhX1pR8XfP5aGcLFazFuzVUJx ZMT5FYfTT2Ib8tL4Ax2QHvv5FBB03m0EMpTrW2zqX7cKEQzhB60yis4u6hJm8RYUlgzx KTgs0C7fInXom4kE8FWecOHnvZzC2Q/KtX7FAvd5IewbL/GOmVallm7cWwYn3V9Ixl6e FfDuML1c4o3Aw7G/DATWmSK7Sarcf++lRBC92S9B/KlvM1OQJ9eAVYZnMN0mTewVKM9K R6jA== 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=z3ZwYDQzL1pylH7ZwKNGRSF0U9R/jxKtAqOETuDU8lY=; b=L2FnMjFvO94Ld6uGbsLs6RGPG5k3cdYVk5rhX+DWUIjjQwuYuG2BCuHbw2LIHWZsf7 HCXXWC02l+8GHIKcxRqy+Vs4T7VWQkf1g9yhT8T624GIHzZk/EHcE03PIG3NEmeyCAFD t292TkXSbl8a5XeOEZJVpcibBwePPc7kaDoZPMI2KA+4LSrdCd1y9u35JBJwTeEcnw+J VhXikj5xtPm/43gZB6VWAd4fEtPqO9BkWyoPQ6WGp/p5AlcntwtdNOrf3wqXtyHsCTax vel2dR6RyKyBeHyV77tTsIlK5+tAlszMV6VN2A3bLLsgiYNjjzene9sH9o1aAlrt6/Pg +5tw== X-Gm-Message-State: ACgBeo11csqYeBljksJwUG362dyzcNwbzedMFQrMOqiXAQNhxyl/Faez +qxRNTUuHEesH4YkQE5oodw= X-Google-Smtp-Source: AA6agR5w7yUBHBO1LEEXs07MviNPCe+pL4SRMwyW89ZZXVJFrKRcHTvFR/lQHkgaNrIkYUFJMNvFGQ== X-Received: by 2002:a5d:5581:0:b0:20f:fc51:7754 with SMTP id i1-20020a5d5581000000b0020ffc517754mr12074232wrv.413.1659402359199; Mon, 01 Aug 2022 18:05:59 -0700 (PDT) Original-Received: from [192.168.0.6] ([46.251.119.176]) by smtp.googlemail.com with ESMTPSA id o1-20020a5d6841000000b0021f0ff1bc6csm11430718wrw.41.2022.08.01.18.05.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 01 Aug 2022 18:05:58 -0700 (PDT) Content-Language: en-US In-Reply-To: <83sfmg2mkv.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:238479 Archived-At: On 01.08.2022 15:08, Eli Zaretskii wrote: >> Date: Mon, 1 Aug 2022 04:23:21 +0300 >> Cc: 56682@debbugs.gnu.org, Eli Zaretskii , >> Stefan Monnier >> From: Dmitry Gutov >> >> IIUC this state of affairs is caused by your chosen approach to speeding >> up font-lock (hard narrowing while it is called), which makes the >> initial call to syntax-ppss happen inside that narrowing as well. >> >> The alternative being that font-lock would call syntax-ppss right away >> with no restriction, but then only apply highlighting to limited parts >> of the buffer. > > AFAIU, this seems to assume that highlighting is much faster than > syntax-ppss. Is that a given? If not, I don't think I understand how > this could help. I don't have the concrete numbers at hand, but from experience I'd say: - syntax-ppss over the whole buffer is fast-ish. But it takes O(N) time of course, and the bigger the buffer is, the longer it'll take. Not much we can do about it. - font-lock has to do more work, so over the whole buffer it will take an order of a magnitude more time than syntax-ppss. Further: - syntax-ppss is also important for correctness: for commands to understand whether the point is inside a string, comments, etc. So it's better to avoid applying narrowing when calling it. Unless you're in a multiple-major-modes situation. - font-lock calls syntax-ppss. So ideally font-lock is either called with undo-able narrowing, or is simply passed a range of positions, and shouldn't fontify too far from them. The latter seems to be the case already (if you open xdisp.c and press M->, only top and bottom of the buffer are fontified), with the caveat that font-lock always tries to backtrack to BOL when fontifying the current hunk. Which makes sense, of course, but could be tweaked for long lines to avoid re-fontifying the whole buffer again and again. IOW, IIUC the fix for font-lock performance could be better implemented inside font-lock itself, as long as all the info about whether the current line is "long" is available to Lisp.