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 16:43:12 +0300 Message-ID: <83wnbmztzj.fsf@gnu.org> References: <83pmhuft5a.fsf@gnu.org> <05388e8d8836c2e7ef3e@heytings.org> <136c4fe0fcb9ce5181cb@heytings.org> <3d639ea12689d767ba2a@heytings.org> <838ro44fc8.fsf@gnu.org> <3d639ea126d759bddfea@heytings.org> <83y1w42vp4.fsf@gnu.org> <3d639ea12618e6a503af@heytings.org> <83wnbo2uw3.fsf@gnu.org> <3d639ea126e3a4d880b8@heytings.org> <83k07o2izh.fsf@gnu.org> <3d639ea1265c40a07f40@heytings.org> <83h72s2e3o.fsf@gnu.org> <3d639ea126c6b0c6737b@heytings.org> <838ro42b1g.fsf@gnu.org> <3d639ea126db3913202e@heytings.org> <83wnbn264f.fsf@gnu.org> <3d639ea12684115449f8@heytings.org> <83tu6r1b03.fsf@gnu.org> <92da07bd02b96d54dbf4@heytings.org> <835yj62a18.fsf@gnu.org> <92da07bd02f5963a2da4@heytings.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36905"; mail-complaints-to="usenet@ciao.gmane.io" Cc: gerd.moellmann@gmail.com, 56682@debbugs.gnu.org, monnier@iro.umontreal.ca, dgutov@yandex.ru To: Gregory Heytings Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Aug 05 15:44:09 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 1oJxcW-0009SS-NF for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 05 Aug 2022 15:44:08 +0200 Original-Received: from localhost ([::1]:35024 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJxcV-0003mc-RI for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 05 Aug 2022 09:44:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38436) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJxcQ-0003mO-QH for bug-gnu-emacs@gnu.org; Fri, 05 Aug 2022 09:44:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:38761) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oJxcQ-0005PO-Ha for bug-gnu-emacs@gnu.org; Fri, 05 Aug 2022 09:44:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oJxcQ-00028q-E4 for bug-gnu-emacs@gnu.org; Fri, 05 Aug 2022 09:44: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 13:44: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.16597070028178 (code B ref 56682); Fri, 05 Aug 2022 13:44:02 +0000 Original-Received: (at 56682) by debbugs.gnu.org; 5 Aug 2022 13:43:22 +0000 Original-Received: from localhost ([127.0.0.1]:56743 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oJxbm-00027q-29 for submit@debbugs.gnu.org; Fri, 05 Aug 2022 09:43:22 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:53648) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oJxbk-00027d-3e for 56682@debbugs.gnu.org; Fri, 05 Aug 2022 09:43:21 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:37268) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJxbe-0005MW-QN; Fri, 05 Aug 2022 09:43:14 -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=tkL9WL6GazWckNITiJ2saRjqmPET/jwQgQ6iTfFSN40=; b=UApzGxlnfBj4 Fz4NnES3PbA/sELZC9KEjX8jUQSttrjI5IvMxTIhNQnYHlEitueJtvx3+MCLVaVLDlOwgfDvRUpsh 20XixvXHcfPMz/R+KktmQIv0UZnBRH3OseDM6dA+ij9tbuJ2Ljce13IueSisuhmTaXE5ePP2tcAu/ jpgAvVWIW1LwBjTxp2H7QnOjVl2DwZkiYYFCuIEx0C9AoqdRrjFvEAVNTmxO7X/fEfZuUFBgmDDhD V7rihfcPJeyAIh2vapEU3x1JeBZC1LE/6IXlbPgicd6UIYXKrCLCk1DxJqGDnu/Wj4UPjNu5I4+rj bfFGKsWQks6GVconKkMdNA==; Original-Received: from [87.69.77.57] (port=3825 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 1oJxbe-0002ru-A5; Fri, 05 Aug 2022 09:43:14 -0400 In-Reply-To: <92da07bd02f5963a2da4@heytings.org> (message from Gregory Heytings on Fri, 05 Aug 2022 11:50:56 +0000) 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:238915 Archived-At: > Date: Fri, 05 Aug 2022 11:50:56 +0000 > From: Gregory Heytings > cc: gerd.moellmann@gmail.com, 56682@debbugs.gnu.org, monnier@iro.umontreal.ca, > dgutov@yandex.ru > > > There's (at least) one more aspect of this, as long as Text mode is > > being used: Text mode doesn't force bidi-paragraph-direction to be > > left-to-right, whereas all descendants of prog-mode, including js-mode, > > do. Leaving bidi-paragraph-direction at nil means Emacs needs to > > determine the base paragraph direction each time it's about to redisplay > > a window, and that might be expensive, especially in a large buffer > > without any paragraph breaks (by default, an empty line), because that > > is determined by the first strong directional character of the > > paragraph. So for a more fair comparison with Text mode, you should set > > bidi-paragraph-direction to the value left-to-right in text-mode > > buffers. > > Indeed, that seems to be the culprit here, I didn't know that text-mode > was an exception here. Actually, it's the other way around: prog-mode and its descendants are the exception. The default value of bidi-paragraph-direction is nil, but in prog-mode's we _know_ that program source code is written left-to-right, even if some of strings and comments could include R2L text, so we force bidi-paragraph-direction in these modes. > If I set bidi-paragraph-direction to 'left-to-right after visiting > the arabic-small.txt file, Emacs (mis) behaves like it does for the > other Arabic files: it becomes slow, and C-n C-p do not work > correctly anymore. OK, so there's one more subtle issue about bidi, and it definitely affects some of these files: whether the file actually includes both L2R and R2L characters. If all of the characters are L2R or all of them are R2L (the latter is the case with arabic-small.txt), and bidi-paragraph-direction is either nil or left-to-right for L2R text and right-to-left for R2L text, then from the display engine's POV the text is not truly bidirectional, it actually has a single direction. Text that has a single direction doesn't require (expensive) reordering for display, and we have optimizations in place for such situations, to make redisplay faster in those cases, because that is the natural situation with human-readable text: text that is predominantly R2L is relatively rarely mixed with L2R text and is normally displayed in right-to-left paragraphs. By adding the "ar" prefix to the files, you made what was a unidirectional text be bidirectional. The effect on display is dramatic: the first Arabic letter will now be displayed _last_, because the paragraph now has left-to-right direction (the first strong character in it is 'a', a L2R character), and the entire Arabic string that follows needs to be reversed on display. Compare arabic-small.txt with arabic-small.json after setting bidi-paragraph-direction to be right-to-left in the latter, and you should see a similar performance in both. (And watch what happens on display when you change the value of bidi-paragraph-direction in arabic-small.json.)