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: Sat, 23 Jul 2022 18:43:09 +0300 Message-ID: <835yjnj0mq.fsf@gnu.org> References: <837d46mjen.fsf@gnu.org> <174616cd5c33bfc14b1f@heytings.org> <837d44jr4p.fsf@gnu.org> <83bktghrn0.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12718"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 56682@debbugs.gnu.org, gregory@heytings.org, monnier@iro.umontreal.ca To: Gerd =?UTF-8?Q?M=C3=B6llmann?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jul 23 17:44:23 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 1oFHIl-00034p-DX for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 23 Jul 2022 17:44:23 +0200 Original-Received: from localhost ([::1]:36970 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oFHIk-0004AZ-0D for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 23 Jul 2022 11:44:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53828) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFHIQ-00049r-Ip for bug-gnu-emacs@gnu.org; Sat, 23 Jul 2022 11:44:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:56344) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oFHIQ-0000sk-AK for bug-gnu-emacs@gnu.org; Sat, 23 Jul 2022 11:44:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oFHIP-0008OC-VL for bug-gnu-emacs@gnu.org; Sat, 23 Jul 2022 11:44:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 23 Jul 2022 15:44: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.165859100132171 (code B ref 56682); Sat, 23 Jul 2022 15:44:01 +0000 Original-Received: (at 56682) by debbugs.gnu.org; 23 Jul 2022 15:43:21 +0000 Original-Received: from localhost ([127.0.0.1]:46092 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oFHHk-0008Mo-Ke for submit@debbugs.gnu.org; Sat, 23 Jul 2022 11:43:20 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:40852) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oFHHi-0008MS-QX for 56682@debbugs.gnu.org; Sat, 23 Jul 2022 11:43:19 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:40838) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFHHb-0000Yb-SV; Sat, 23 Jul 2022 11:43:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=285Z45GpjTp9l57gl4Kv+c1Sbr1CtQFX+eZvCPHJESE=; b=FxsX3P9bcURslVYLEEyL 4m1pkoTlxez7vogJ83+BnsDfNil93UROV8nlmIVe7fxk3FFWbMDC3AfZw4LjDNW0QDcE5pCVJxElC nBOy5ZiyAcIER8LsO7Ss6Ip7qxYAyBgiNssM5OkAKe3rMHHlV1UIJhZgoea0y2tHXBfFF4ELkL7qm /Q95vEd4euX9nnLWn8SEy8XIaJ3ySQcKFj0oaQpoq0OfI0vTVURIUVBR0QpeC5rzN+g3gpYY/f2oz iVjYHwh6qohITMFu3S9nYk6bd0lo1w4sCy90134AF7+nA0tqMNwdhElG6mdljY4HzaVGGk6e0ffVS n5jcYGVNGJc/GQ==; Original-Received: from [87.69.77.57] (port=2354 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 1oFHHb-0002J3-Bi; Sat, 23 Jul 2022 11:43:11 -0400 In-Reply-To: (message from Gerd =?UTF-8?Q?M=C3=B6llmann?= on Sat, 23 Jul 2022 16:33:28 +0200) 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:237760 Archived-At: > From: Gerd Möllmann > Cc: 56682@debbugs.gnu.org, gregory@heytings.org, monnier@iro.umontreal.ca > Date: Sat, 23 Jul 2022 16:33:28 +0200 > > Gerd Möllmann writes: > > > Eli Zaretskii writes: > > > >> And I've found a serious sink of CPU cycles under truncate-lines, and > >> installed a fix on the feature branch. Gerd, if you have time to > >> eyeball the fix and comment on it, I'd appreciate. It's commit > >> 350e97d on the branch. (I can post a more detailed explanation of > >> what I did and why, if that would help, because the code and the > >> functions it calls are somewhat tricky.) > > > > I'll look at it and come back. > > modified src/xdisp.c > @@ -7153,10 +7153,10 @@ forward_to_next_line_start (struct it *it, bool *skipped_p, > || ((pos = Fnext_single_property_change (make_fixnum (start), > Qdisplay, Qnil, > make_fixnum (limit)), > - NILP (pos)) > + (NILP (pos) || XFIXNAT (pos) == limit)) > && next_overlay_change (start) == ZV)) > { > - if (!it->bidi_p) > + if (!it->bidi_p || !bidi_it_prev) > { > IT_CHARPOS (*it) = limit; > IT_BYTEPOS (*it) = bytepos; > > I understand the first diff, which makes a lot of sense Thanks, this was the main part. From what I see, this code never really worked correctly, since Emacs 21, because Fnext_single_property_change can never return nil when called like that. IOW, we never took the shortcut there, and probably didn't notice it because 500-character lines are rare. > but I'm afraid I don't know enough about bidi to be of any help. The idea is that since the value of BIDI_IT_PREV is never used by the caller when ON_NEWLINE_P is zero, we don't need to compute it when ON_NEWLINE_P is zero, something that would have precluded us from taking the shortcut. Not taking the shortcut is very expensive when we have very long lines, of course. Btw, one quirk of the code in forward_to_next_line_start (which took me some time to take in and convince myself it's okay) is that it returns non-zero when it didn't find any new newlines till ZV. This is not very clean, but I guess we don't care in that case, since the iterator will be moved to ZV, and from there there's not much we need to do...