unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Arthur Miller <arthur.miller@live.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Which is faster: narrow-to-region or delete-region?
Date: Wed, 22 Sep 2021 09:00:54 +0200	[thread overview]
Message-ID: <AM9PR09MB49775B785B69E2B9ABE2B36C96A29@AM9PR09MB4977.eurprd09.prod.outlook.com> (raw)
In-Reply-To: <83wnn9w43b.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 22 Sep 2021 08:51:04 +0300")

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Arthur Miller <arthur.miller@live.com>
>> Date: Tue, 21 Sep 2021 22:10:09 +0200
>> 
>> 
>> I have a DEFUN in the middle of a temporary buffer; which is faster to use to
>> eliminate the rest of the code from the calculations for font lock:
>> 
>> (narrow-to-region defun-begin defun-end)
>> 
>> or
>> 
>> (delete-region (point-min) defun-begin) +
>> (delete-region defun-end (point-max))
>
> The narrow-to-region method must be much faster, since it only sets a
> bunch of variables and does little else.

Thought so when saw the code, but wasn't sure.

> bunch of variables and does little else.  Moreover, it cannot trigger
> GC, whereas delete-region method very well can.

That too, wasn't even thinking about that. I am not so familiar how GC works
with code in C.

>> I have tried both and notice no differences.
>
> Maybe in a very small buffer.
I was just tested in help buffers with that patch I made. But it is interactive
so it is hard to see the difference; I haven't benchmarked.

Thank you. That was educative. And helpful.



  reply	other threads:[~2021-09-22  7:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-21 20:10 Which is faster: narrow-to-region or delete-region? Arthur Miller
2021-09-22  5:51 ` Eli Zaretskii
2021-09-22  7:00   ` Arthur Miller [this message]
2021-09-22  7:41     ` Eli Zaretskii
2021-09-22  8:53       ` Arthur Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AM9PR09MB49775B785B69E2B9ABE2B36C96A29@AM9PR09MB4977.eurprd09.prod.outlook.com \
    --to=arthur.miller@live.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).