From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Gregory Heytings Newsgroups: gmane.emacs.bugs Subject: bug#56682: Fix the long lines font locking related slowdowns Date: Sat, 30 Jul 2022 18:13:18 +0000 Message-ID: <65cb7c73fd159efe32af@heytings.org> References: <8a3eaeef010995a5da8d@heytings.org> <837d40ds09.fsf@gnu.org> <83zggwcby5.fsf@gnu.org> <83o7xccagi.fsf@gnu.org> <831qu7daxb.fsf@gnu.org> <83sfmnb7yg.fsf@gnu.org> <837d3ybh5z.fsf@gnu.org> <136c4fe0fc74196714aa@heytings.org> <83pmhp89ov.fsf@gnu.org> <136c4fe0fc39573addc9@heytings.org> <83k07x8738.fsf@gnu.org> <136c4fe0fcdf00ef9a11@heytings.org> <83h73183r7.fsf@gnu.org> <136c4fe0fc0fceb0d752@heytings.org> <838roc8ka7.fsf@gnu.org> <83tu706obt.fsf@gnu.org> <83h7306ifa.fsf@gnu.org> <83edy37pul.fsf@gnu.org> <83pmhn55sk.fsf@gnu.org> <65cb7c73fdc753518d35@heytings.org> <83fsii68o3.fsf@gnu.org> <65cb7c73fdf6704d19d5@heytings.org> <835yje62vz.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19602"; mail-complaints-to="usenet@ciao.gmane.io" Cc: gerd.moellmann@gmail.com, 56682@debbugs.gnu.org, larsi@gnus.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 Sat Jul 30 20:14:11 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 1oHqyY-0004wX-Vi for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 30 Jul 2022 20:14:11 +0200 Original-Received: from localhost ([::1]:48100 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oHqyX-0002x3-Bd for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 30 Jul 2022 14:14:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47866) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oHqyQ-0002vL-K6 for bug-gnu-emacs@gnu.org; Sat, 30 Jul 2022 14:14:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45984) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oHqyQ-000186-Aj for bug-gnu-emacs@gnu.org; Sat, 30 Jul 2022 14:14:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oHqyQ-00082M-58 for bug-gnu-emacs@gnu.org; Sat, 30 Jul 2022 14:14:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Gregory Heytings Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 30 Jul 2022 18:14: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.165920480230831 (code B ref 56682); Sat, 30 Jul 2022 18:14:02 +0000 Original-Received: (at 56682) by debbugs.gnu.org; 30 Jul 2022 18:13:22 +0000 Original-Received: from localhost ([127.0.0.1]:35733 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oHqxm-00081D-7b for submit@debbugs.gnu.org; Sat, 30 Jul 2022 14:13:22 -0400 Original-Received: from heytings.org ([95.142.160.155]:59506) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oHqxj-000814-9v for 56682@debbugs.gnu.org; Sat, 30 Jul 2022 14:13:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=heytings.org; s=20220101; t=1659204798; bh=MNP6Hd16fWTd/HH0BQav9O3+lh0Db9YaShiLS3NDBZw=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References:From; b=71h1taQT0ODGFST6MIRwuBu4dKIwlhiYPVsK55zUf2DQ6tf0B/ysYEOxvIadSNDhx 4pL7f0aJEPFcYXgwqSOf/zP04sTL1LxumIHGBVMNMXBsRiZR8rSRiJ2jeeqpzppd4j XYGrO+HUJxDdbTsa/JptzxvXObMXWy8UM03wbiNYUO77mq/G9nvWI5PKeQeuiOXnwX ziV2y6buYr/GUzurucmJ8wrG1ZkpLG4S2Oh/dm40Cs3NT3ni9Nz/awIptIPZxf90Gm GPY0B9603IvYIoHUQfw6ULdZBa7/bwmarIGk1fngd2mk6DRXTWN1GeXjNq9cF2W0S/ TaBhxyYJeCMDA== In-Reply-To: <835yje62vz.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:238306 Archived-At: >> So the only remaining question is whether it is necessary to recompute >> narrowed_begv and narrowed_zv in init_iterator: > > I tend to think we should, but let me think about this some more. > Okay, I'll wait for your feedback. Wouldn't it make sense to also limit the portion of the buffer to which pre-/post-command-hook have access (see below)? With that patch, I was able to open and edit a file with a single 50 GB (!) line, in js-mode. Does that still not qualify as "arbitrarily large"? I compared that with a 50 GB JSON file with 80 character wide lines. With that file it was necessary to disable font-lock-mode, which took too much time. Apart from that, I did not see any significant performance differences while editing the file, compared to the single line one. diff --git a/src/keyboard.c b/src/keyboard.c index 2863058d63..ce529222a3 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -1461,7 +1461,22 @@ command_loop_1 (void) } Vthis_command = cmd; Vreal_this_command = cmd; - safe_run_hooks (Qpre_command_hook); + + if (current_buffer->long_line_optimizations_p) + { + specpdl_ref count = SPECPDL_INDEX (); + struct window *w = XWINDOW (selected_window); + ptrdiff_t begv = get_narrowed_begv (w, PT); + ptrdiff_t zv = get_narrowed_zv (w, PT); + if (!begv) begv = BEGV; + Fnarrow_to_region (make_fixnum (begv), make_fixnum (zv), Qt); + safe_run_hooks (Qpre_command_hook); + unbind_to (count, Qnil); + } + else + { + safe_run_hooks (Qpre_command_hook); + } already_adjusted = 0; @@ -1513,7 +1528,21 @@ command_loop_1 (void) } kset_last_prefix_arg (current_kboard, Vcurrent_prefix_arg); - safe_run_hooks (Qpost_command_hook); + if (current_buffer->long_line_optimizations_p) + { + specpdl_ref count = SPECPDL_INDEX (); + struct window *w = XWINDOW (selected_window); + ptrdiff_t begv = get_narrowed_begv (w, PT); + ptrdiff_t zv = get_narrowed_zv (w, PT); + if (!begv) begv = BEGV; + Fnarrow_to_region (make_fixnum (begv), make_fixnum (zv), Qt); + safe_run_hooks (Qpost_command_hook); + unbind_to (count, Qnil); + } + else + { + safe_run_hooks (Qpost_command_hook); + } /* If displaying a message, resize the echo area window to fit that message's size exactly. Do this only if the echo area