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: Tue, 26 Jul 2022 20:46:24 +0300 Message-ID: <831qu7daxb.fsf@gnu.org> References: <837d46mjen.fsf@gnu.org> <174616cd5c33bfc14b1f@heytings.org> <837d44jr4p.fsf@gnu.org> <83bktghrn0.fsf@gnu.org> <8a3eaeef010995a5da8d@heytings.org> <837d40ds09.fsf@gnu.org> <83zggwcby5.fsf@gnu.org> <83o7xccagi.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1109"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 56682@debbugs.gnu.org, monnier@iro.umontreal.ca To: gregory@heytings.org, gerd.moellmann@gmail.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jul 26 19:47:26 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 1oGOeT-000AeT-KL for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 26 Jul 2022 19:47:25 +0200 Original-Received: from localhost ([::1]:50474 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oGOeS-00084B-Jt for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 26 Jul 2022 13:47:24 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56892) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGOe6-00083y-JN for bug-gnu-emacs@gnu.org; Tue, 26 Jul 2022 13:47:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36345) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oGOe6-0004FC-AC for bug-gnu-emacs@gnu.org; Tue, 26 Jul 2022 13:47:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oGOe6-0001HF-4b for bug-gnu-emacs@gnu.org; Tue, 26 Jul 2022 13:47: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: Tue, 26 Jul 2022 17:47: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.16588575904850 (code B ref 56682); Tue, 26 Jul 2022 17:47:02 +0000 Original-Received: (at 56682) by debbugs.gnu.org; 26 Jul 2022 17:46:30 +0000 Original-Received: from localhost ([127.0.0.1]:54327 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oGOdZ-0001GA-KF for submit@debbugs.gnu.org; Tue, 26 Jul 2022 13:46:30 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:43828) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oGOdW-0001Fq-Qv for 56682@debbugs.gnu.org; Tue, 26 Jul 2022 13:46:28 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:43100) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGOdR-00045n-0x; Tue, 26 Jul 2022 13:46:21 -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=p5aAxZKMS3AEwn0B4wGTOqtqxDqO0Kfj8lFzuDi7Hjc=; b=KTR0YAHlysaX Fng6IOO/DVKVXhpHulMCcj3TklnnfcgaklA4WDjxEG/51Ky8Wi/mQfR5S22667+XgkaRyLz9FBnMZ jf7s3v3w+2kI1LH/hEFVwTVoItYyoJFqnlpeG9yMdBZTFsSbfLqFT0DROkhzlXST2Uqg/SeOM6hEI dSVKwPYYPN9vVbjO6PxtwNsk9Qxt+3n6UocQy2zkMIzLtxjQDRbKLXFJxI2Vwjor4/rh72olzgmMS JPz5I6dUgO93nNfTN+fMzhkabtaBGIJn9BhDpDNKkHvj/METDviEXpSf07WxtAnuMq2rm33jslaI3 /5qRRX3HNMf7JFPFABKXhg==; Original-Received: from [87.69.77.57] (port=1209 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 1oGOdQ-00011R-3Q; Tue, 26 Jul 2022 13:46:20 -0400 In-Reply-To: <83o7xccagi.fsf@gnu.org> (message from Eli Zaretskii on Tue, 26 Jul 2022 15:41:49 +0300) 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:237983 Archived-At: > Cc: gerd.moellmann@gmail.com, 56682@debbugs.gnu.org, monnier@iro.umontreal.ca > Date: Tue, 26 Jul 2022 15:41:49 +0300 > From: Eli Zaretskii > > > I just tried again, and on my machine with an optimized build C-s > takes 220 seconds to finish (and cannot be interrupted). That's what I > > call "hang". With 350e97d78e, C-s > what I call "slow" (without truncate-lines C-s > OK, I will take a look soon. That change makes us use a branch of > code that AFAIU was never used since it was written, so some kind of > trouble can be expected. Heh, it's a case of "better is worse". There's nothing wrong with the change in commit 350e97d78e: it does indeed make redisplay of long-and-truncated lines significantly faster. And that speedup is what's causing the problem: because the initial redisplay of the buffer, before the results of C-s are displayed, is much faster, the lazy-highlighting starts very soon, and it inserts thousands of overlays into the buffer (because it by default highlights all the matches till window-end, which is EOB in this case). And once it inserts enough overlays, we are dead in the water: the shortcut in forward_to_next_line_start can no longer be taken, and we instead iterate the slow way, one character at a time, all the way to EOB, and on top of that need on the way to examine every one of the overlays inserted by lazy-highlighting. If I revert commit 350e97d78e, redisplay of long-and-truncated lines becomes much slower, but because of that, lazy-highlighting doesn't have time to highlight anything before you hit C-s for repeated search, and thus there are no overlays in the buffer, and on the average the responses are faster. I tried to limit the lazy-highlighting by long-line-threshold, but the speedup due to that is not significant enough (because even a single overlay in the long line disables the shortcut in forward_to_next_line_start). Only limiting lazy-highlight-initial-delay to, say, 1 sec and lazy-highlight-max-at-a-time to a small number (like 2 or 5) makes the problem go away because lazy-highlighting doesn't have enough time to highlight too much. And even then once you go deep enough into the file, the problem comes back. At this point, I think the only way to produce reasonable performance from C-s in this case is to turn off lazy-highlighting when lines are truncated and the buffer has long lines. Which means we need to expose the value of long_line_optimizations_p to Lisp, via an accessor function. I already have one other use for this: "C-x =", which attempts to report the column of the character, something that is very slow in a long-and-truncated line. And I think we will see more cases where Lisp code needs to know about this in order to adapt itself to long lines. Comments?