all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Which is faster: narrow-to-region or delete-region?
@ 2021-09-21 20:10 Arthur Miller
  2021-09-22  5:51 ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Arthur Miller @ 2021-09-21 20:10 UTC (permalink / raw)
  To: emacs-devel


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))

I appreciate if I can get A or B answer so I don't have to benchmark, if it even
matters for the speed?

I have tried both and notice no differences. Looking at the code it seems that
narrow-to-region is faster, but I am not familiar with all the C calls the
respective function does, so hard for me to tell. The feel say narrow-to-region.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Which is faster: narrow-to-region or delete-region?
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2021-09-22  5:51 UTC (permalink / raw)
  To: Arthur Miller; +Cc: emacs-devel

> 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.  Moreover, it cannot trigger
GC, whereas delete-region method very well can.

> I have tried both and notice no differences.

Maybe in a very small buffer.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Which is faster: narrow-to-region or delete-region?
  2021-09-22  5:51 ` Eli Zaretskii
@ 2021-09-22  7:00   ` Arthur Miller
  2021-09-22  7:41     ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Arthur Miller @ 2021-09-22  7:00 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

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.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Which is faster: narrow-to-region or delete-region?
  2021-09-22  7:00   ` Arthur Miller
@ 2021-09-22  7:41     ` Eli Zaretskii
  2021-09-22  8:53       ` Arthur Miller
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2021-09-22  7:41 UTC (permalink / raw)
  To: Arthur Miller; +Cc: emacs-devel

> From: Arthur Miller <arthur.miller@live.com>
> Cc: emacs-devel@gnu.org
> Date: Wed, 22 Sep 2021 09:00:54 +0200
> 
> > 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.

GC can be triggered in C code by any of the following:

  . calling Lisp
  . calling some primitives, like funcall, directly from C
  . modifying text of some buffer
  . calling a memory-allocation function such as xmalloc



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Which is faster: narrow-to-region or delete-region?
  2021-09-22  7:41     ` Eli Zaretskii
@ 2021-09-22  8:53       ` Arthur Miller
  0 siblings, 0 replies; 5+ messages in thread
From: Arthur Miller @ 2021-09-22  8:53 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Arthur Miller <arthur.miller@live.com>
>> Cc: emacs-devel@gnu.org
>> Date: Wed, 22 Sep 2021 09:00:54 +0200
>> 
>> > 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.
>
> GC can be triggered in C code by any of the following:
>
>   . calling Lisp
>   . calling some primitives, like funcall, directly from C
>   . modifying text of some buffer
>   . calling a memory-allocation function such as xmalloc

Allright, thank you. Noted in my notebook! :).



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-09-22  8:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2021-09-22  7:41     ` Eli Zaretskii
2021-09-22  8:53       ` Arthur Miller

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.