From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#64391: buffer narrowing slowdown regression in emacs 29 Date: Sat, 1 Jul 2023 13:37:08 +0200 Message-ID: <0AD15A09-F669-48C0-AF5C-971D52F5BF8E@gmail.com> References: <87r0psb51z.fsf@ust.hk> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_B174E89E-2A37-41AD-B518-C45C9760C5DD" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4113"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 64391@debbugs.gnu.org, Gregory Heytings , Eli Zaretskii To: Andrew Cohen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jul 01 13:38:20 2023 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 1qFYvi-0000nQ-Ac for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 01 Jul 2023 13:38:18 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qFYvU-0007Lx-Ux; Sat, 01 Jul 2023 07:38:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qFYvS-0007Kp-Qv for bug-gnu-emacs@gnu.org; Sat, 01 Jul 2023 07:38:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFYvS-0002CL-Ic for bug-gnu-emacs@gnu.org; Sat, 01 Jul 2023 07:38:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qFYvS-0007Og-2b; Sat, 01 Jul 2023 07:38:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bugs@gnus.org Resent-Date: Sat, 01 Jul 2023 11:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64391 X-GNU-PR-Package: emacs,gnus Original-Received: via spool by 64391-submit@debbugs.gnu.org id=B64391.168821143928381 (code B ref 64391); Sat, 01 Jul 2023 11:38:02 +0000 Original-Received: (at 64391) by debbugs.gnu.org; 1 Jul 2023 11:37:19 +0000 Original-Received: from localhost ([127.0.0.1]:56836 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qFYuk-0007Ng-P0 for submit@debbugs.gnu.org; Sat, 01 Jul 2023 07:37:18 -0400 Original-Received: from mail-lf1-f45.google.com ([209.85.167.45]:54750) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qFYuh-0007NQ-Us for 64391@debbugs.gnu.org; Sat, 01 Jul 2023 07:37:17 -0400 Original-Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-4f875b267d9so4564758e87.1 for <64391@debbugs.gnu.org>; Sat, 01 Jul 2023 04:37:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688211430; x=1690803430; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:sender:from:to:cc:subject:date:message-id:reply-to; bh=r8CFC5EefuTRyV7RmwIOFSHJ8WrZ78TQGG+LrZ0BhB0=; b=LDNHjiOdewuoZPJWQuiWbFXB7MBr3dabZzu4YR8GBme1fzJWuwQMwk0Hn4clMuexDf HiTDnuhwU1JDNP8BRqFFCYSwv03OsuKba7HjoOHX5sa1HWrSjmT9wRmNnNyNk6Xedb6X Td8+I1xxw8kVQK9RJhtiJPnfQ9ByF8fkKT+4YQ8a920RflIx/XQQCAwxS6l8qW/goDQ2 FGDnoMyTqRnQF7IVUohHJJ6vzUxAAso1934W7xt0CscLjSohxDvJgLLfzAZTO/RikGkF havMvtvphsq4myfpC7RwHojU5qJS4y/DmvE5SMIgENbF+NAlzJjcpybzTGKjBJczNIRz 65RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688211430; x=1690803430; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=r8CFC5EefuTRyV7RmwIOFSHJ8WrZ78TQGG+LrZ0BhB0=; b=llQZtLv4CJJfUe8koGs6Nji9UPWi+LOqbCUsSQeJIkh5kXWKq/ja9xNLVP/6wUvrsG J8RzqH8Roh8bzUNJS7zdC+VsZdG8vFU7xcuPaN0RaiUTyBkDmy+h4dLxWjEcIfCyroTF Y92YvbzxTcrcMx33lZ2tr7P0oZFctGDERhYYedT/WjF/D7ezMKpPj8rSP4oWiYggJpDt uwskUa6nzTAsgWUeJd6qamK6SDxmcOCV4QOZUQXJmVvjbCq/uOO48ZfbbzSEKTr9SCuo ThMwvNNzxQEcjnx3ooE1T+cHTqfjdtGQBZbMLsQxLcN+8FUe1PMA2jdwed1mSsiW7BlZ Ej4g== X-Gm-Message-State: ABy/qLY7uR93OM1Lg0Xkfnl6im6wWiQcEgnAOebc+8VRyIfKRqV0WUmk ZgwiRbmqGN8/+oahaZfqWvuoMzxkuEg= X-Google-Smtp-Source: APBJJlFm1q6YoWutrG9TZdXnxYtY3e2+FNRiLJm9StEMApGF4QIgeCLWpi9YbZkZWJZeDu89dYOsxA== X-Received: by 2002:a05:6512:3b0f:b0:4f8:6b57:87f9 with SMTP id f15-20020a0565123b0f00b004f86b5787f9mr5032137lfv.22.1688211429902; Sat, 01 Jul 2023 04:37:09 -0700 (PDT) Original-Received: from smtpclient.apple (c188-150-165-235.bredband.tele2.se. [188.150.165.235]) by smtp.gmail.com with ESMTPSA id i19-20020ac25233000000b004f6366cbe72sm3345485lfl.228.2023.07.01.04.37.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Jul 2023 04:37:09 -0700 (PDT) In-Reply-To: <87r0psb51z.fsf@ust.hk> X-Mailer: Apple Mail (2.3654.120.0.1.15) 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:264399 Archived-At: --Apple-Mail=_B174E89E-2A37-41AD-B518-C45C9760C5DD Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 1 juli 2023 kl. 06.59 skrev Andrew Cohen : > Just for fun I simply commented it out (since the test code doesn't = use > labeled restrictions) and ran the test code, and the problem = disappears: The attached patch combines narrow-to-region and = internal--label-restriction into a single function, = internal--narrow-to-region. (We could also add the label as an optional = argument to narrow-to-region.) As a result, the up-front consing and marker allocation disappear = entirely for normal (unlabelled) narrowing, as does the expensive = buffer-local `outermost-restriction` variable. Labelled narrowing is almost as expensive as before but is, we hope, = less common. Maybe we can work separately on reducing its cost. (And to those reading the patch: yes, some work on doc strings is = needed. Suggestions welcome.) --Apple-Mail=_B174E89E-2A37-41AD-B518-C45C9760C5DD Content-Disposition: attachment; filename=narrow-to-region-with-label.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="narrow-to-region-with-label.diff" Content-Transfer-Encoding: 7bit diff --git a/lisp/subr.el b/lisp/subr.el index 4c462830120..37c9a422e7f 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -4077,8 +4077,7 @@ with-restriction (defun internal--with-restriction (start end body &optional label) "Helper function for `with-restriction', which see." (save-restriction - (narrow-to-region start end) - (if label (internal--label-restriction label)) + (internal--narrow-to-region start end label) (funcall body))) (defmacro without-restriction (&rest rest) diff --git a/src/editfns.c b/src/editfns.c index b920857b664..c434fbd4d39 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -2682,7 +2682,7 @@ DEFUN ("delete-and-extract-region", Fdelete_and_extract_region, records the restriction bounds that were current when the first labeled restriction was entered (which may be a narrowing that was set by the user and is visible on display). This alist is used - internally by narrow-to-region, widen, internal--label-restriction, + internally by internal--narrow-to-region, widen, internal--unlabel-restriction and save-restriction. For efficiency reasons, an alist is used instead of a buffer-local variable: otherwise reset_outermost_restrictions, which is called during each @@ -2868,8 +2868,7 @@ unwind_labeled_narrow_to_region (Lisp_Object label) labeled_narrow_to_region (Lisp_Object begv, Lisp_Object zv, Lisp_Object label) { - Fnarrow_to_region (begv, zv); - Finternal__label_restriction (label); + Finternal__narrow_to_region (begv, zv, label); record_unwind_protect (restore_point_unwind, Fpoint_marker ()); record_unwind_protect (unwind_labeled_narrow_to_region, label); } @@ -2885,7 +2884,6 @@ DEFUN ("widen", Fwiden, Swiden, 0, 0, "", `without-restriction' with the same label. */) (void) { - Fset (Qoutermost_restriction, Qnil); Lisp_Object buf = Fcurrent_buffer (); Lisp_Object label = labeled_restrictions_peek_label (buf); @@ -2940,6 +2938,15 @@ positions (integers or markers) bounding the text that should argument. To gain access to other portions of the buffer, use `without-restriction' with the same label. */) (Lisp_Object start, Lisp_Object end) +{ + return Finternal__narrow_to_region (start, end, Qnil); +} + +DEFUN ("internal--narrow-to-region", Finternal__narrow_to_region, + Sinternal__narrow_to_region, 3, 3, 0, + doc: /* Labelled restriction of editing to a region. +Internal use only. */) + (Lisp_Object start, Lisp_Object end, Lisp_Object label) { EMACS_INT s = fix_position (start), e = fix_position (end); @@ -2968,11 +2975,11 @@ positions (integers or markers) bounding the text that should } /* Record the accessible range of the buffer when narrow-to-region - is called, that is, before applying the narrowing. That - information is used only by internal--label-restriction. */ - Fset (Qoutermost_restriction, list3 (Qoutermost_restriction, - Fpoint_min_marker (), - Fpoint_max_marker ())); + is called, that is, before applying the narrowing. */ + EMACS_INT begv = BEGV; + EMACS_INT begv_byte = BEGV_BYTE; + EMACS_INT zv = ZV; + EMACS_INT zv_byte = ZV_BYTE; if (BEGV != s || ZV != e) current_buffer->clip_changed = 1; @@ -2986,28 +2993,21 @@ positions (integers or markers) bounding the text that should SET_PT (e); /* Changing the buffer bounds invalidates any recorded current column. */ invalidate_current_column (); - return Qnil; -} -DEFUN ("internal--label-restriction", Finternal__label_restriction, - Sinternal__label_restriction, 1, 1, 0, - doc: /* Label the current restriction with LABEL. + if (!NILP (label)) + { + if (NILP (labeled_restrictions_peek_label (buf))) + labeled_restrictions_push (buf, + list3 (Qoutermost_restriction, + build_marker (current_buffer, + begv, begv_byte), + build_marker (current_buffer, + zv, zv_byte))); + labeled_restrictions_push (buf, list3 (label, + Fpoint_min_marker (), + Fpoint_max_marker ())); + } -This is an internal function used by `with-restriction'. */) - (Lisp_Object label) -{ - Lisp_Object buf = Fcurrent_buffer (); - Lisp_Object outermost_restriction - = buffer_local_value (Qoutermost_restriction, buf); - /* If internal--label-restriction is ever called without being - preceded by narrow-to-region, do nothing. */ - if (NILP (outermost_restriction)) - return Qnil; - if (NILP (labeled_restrictions_peek_label (buf))) - labeled_restrictions_push (buf, outermost_restriction); - labeled_restrictions_push (buf, list3 (label, - Fpoint_min_marker (), - Fpoint_max_marker ())); return Qnil; } @@ -4865,10 +4865,6 @@ syms_of_editfns (void) it to be non-nil. */); binary_as_unsigned = false; - DEFVAR_LISP ("outermost-restriction", Voutermost_restriction, - doc: /* Outermost narrowing bounds, if any. Internal use only. */); - Voutermost_restriction = Qnil; - Fmake_variable_buffer_local (Qoutermost_restriction); DEFSYM (Qoutermost_restriction, "outermost-restriction"); Funintern (Qoutermost_restriction, Qnil); @@ -4963,7 +4959,7 @@ syms_of_editfns (void) defsubr (&Sdelete_and_extract_region); defsubr (&Swiden); defsubr (&Snarrow_to_region); - defsubr (&Sinternal__label_restriction); + defsubr (&Sinternal__narrow_to_region); defsubr (&Sinternal__unlabel_restriction); defsubr (&Ssave_restriction); defsubr (&Stranspose_regions); --Apple-Mail=_B174E89E-2A37-41AD-B518-C45C9760C5DD--