unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: <tomas@tuxteam.de>
To: help-gnu-emacs@gnu.org
Subject: Re: [External] : Passing buffers to function in elisp
Date: Tue, 28 Feb 2023 06:37:32 +0100	[thread overview]
Message-ID: <Y/2THMmZ/7yEP0tz@tuxteam.de> (raw)
In-Reply-To: <87v8jmkfd0.fsf@iki.fi>

[-- Attachment #1: Type: text/plain, Size: 1578 bytes --]

On Mon, Feb 27, 2023 at 10:44:43PM +0200, Petteri Hintsanen wrote:

[...]

> Also, if I interpreted profiler's hieroglyphs correctly, it told me that
> this setq
> 
>   (setq stream (vconcat stream (plist-get page :stream)))
> 
> is a pig -- well, of course it is.  I'm accumulating byte vector by
> copying its parts.  Similarly bindat consumes a lot of memory.
> 
> I think I can replace vectors with strings, which should, according to
> the elisp manual, "occupy one-fourth the space of a vector of the same
> elements."  And I guess that accumulation would be best done with a
> buffer, not with strings or vectors.

I must admit I didn't look too closely into your code, but this one
stuck out too. Not only the copying, but the throwing away of so many
vectors.

I don't know whether it applies in your case, but one "classical"
Lispy pattern when you have to concatenate many things in order is
just consing them (at the front of the list) and nreversing the
list at the end, like so:

  (let ((result '()))
    (while (more)
      (setq result (cons (next) result)))
    (nreverse result))

(nreverse does things "in place", so it reuses the cons pairs:
never do that when someone else is looking ;-)

Another, more functional, of course is to arrange things so you
can use map or similar.

Then, at the end you can concatenate the whole list, if need be.

Basically it pays off when the "spine" of the whole thing (i.e.
all those cons pairs you are using) is significantly smaller than
whatever hangs off it

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

  reply	other threads:[~2023-02-28  5:37 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 [this message]
2023-03-03 15:19             ` Stefan Monnier via Users list for the GNU Emacs text editor
2023-03-07 21:48               ` Petteri Hintsanen
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

  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=Y/2THMmZ/7yEP0tz@tuxteam.de \
    --to=tomas@tuxteam.de \
    --cc=help-gnu-emacs@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.
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).