all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Petteri Hintsanen <petterih@iki.fi>
To: help-gnu-emacs@gnu.org
Cc: Stefan Monnier <monnier@iro.umontreal.ca>
Subject: Re: [External] : Passing buffers to function in elisp
Date: Tue, 07 Mar 2023 23:48:10 +0200	[thread overview]
Message-ID: <87jzzsjkrp.fsf@iki.fi> (raw)
In-Reply-To: <jwvsfelj2ul.fsf-monnier+emacs@gnu.org> (Stefan Monnier via Users list for the's message of "Fri, 03 Mar 2023 10:19:09 -0500")

Stefan Monnier via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:

> This is a typical a source of unnecessary O(N²) complexity: the above
> line takes O(N) time, so if you do it O(N) times, you got your
> N² blowup.  You're usually better off doing
>
>     (push (plist-get page :stream) stream-chunks)
>
> and then at the end get the `stream` with
>
>     (mapconcat #'identity (nreverse stream-chunks) nil)
> or
>     (apply #'vconcat (nreverse stream-chunks))

Right, I see.  Stream chunks are in this case byte vectors, so
just reversing those chunks does not do the trick.
But surely I can get from an order of N² to 2N or so.

> Of course that depends on what else happens with `stream` (I haven't
> really looked at your code, sorry).

It's ok, I'm not expecting any reviews here.  All these comments from
you and others have been valuable already.

>> No, it was not byte-compiled.
>
> Then stop right there and fix this problem.  There's absolutely no point
> worrying about performance (including memory use) if the code is
> not compiled because compilation can change the behavior drastically.
>
> The only reason to run interpreted code nowadays is when you're
> Edebugging a piece of code.

Okay, this is something I did not foresee.  But what about eval-defun
and eval-... in general?  They are very convenient when trying out
things.  Should I bind compile-defun to C-M-x then?  And instead of
eval-buffer use byte-compile-file?  Or emacs-lisp-byte-compile-and-load?
Manual is a bit spotty here; emacs-lisp-byte-compile-... functions are
not mentioned.

>> I'll try byte-compiling after the code is in good enough shape to do
>> controlled experiments.
>
> The compiler is your friend.  He can help you get the code in good shape :-)

I'm afraid that even the compiler cannot help against quadratic
complexity blunders.  But I think I got your point.

Thanks,
Petteri



  reply	other threads:[~2023-03-07 21:48 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-21 21:18 Passing buffers to function in elisp Petteri Hintsanen
2023-02-21 23:21 ` [External] : " Drew Adams
2023-02-22  5:35   ` tomas
2023-02-24 20:08     ` Petteri Hintsanen
2023-02-25  6:40       ` tomas
2023-02-25 11:23       ` Michael Heerdegen
2023-02-25 13:45         ` tomas
2023-02-25 18:31           ` Michael Heerdegen
2023-02-25 19:05             ` tomas
2023-02-25 23:52         ` Stefan Monnier via Users list for the GNU Emacs text editor
2023-02-27 20:44           ` Petteri Hintsanen
2023-02-28  5:37             ` tomas
2023-03-03 15:19             ` Stefan Monnier via Users list for the GNU Emacs text editor
2023-03-07 21:48               ` Petteri Hintsanen [this message]
2023-03-07 22:45                 ` Stefan Monnier
2023-03-08  5:38                   ` tomas
2023-09-06 19:05               ` Petteri Hintsanen
2023-09-06 21:12                 ` Stefan Monnier
2023-02-22  5:30 ` tomas
2023-02-23  9:34   ` Michael Heerdegen
2023-02-23  9:51     ` tomas
2023-02-23 16:19     ` Marcin Borkowski

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

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

  git send-email \
    --in-reply-to=87jzzsjkrp.fsf@iki.fi \
    --to=petterih@iki.fi \
    --cc=help-gnu-emacs@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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 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.