From: Shankar Rao <shankar.rao@gmail.com>
To: "Mattias Engdegård" <mattias.engdegard@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Is there utility in making hash-table-{keys, values} built-in functions?
Date: Fri, 29 Nov 2024 15:25:20 +0100 [thread overview]
Message-ID: <CAGEgU=g+dGwu+Df1mcg+NdCRUia3FCDWp2JVx+Th7_x+k=-5TQ@mail.gmail.com> (raw)
In-Reply-To: <B0916A03-E1CC-4936-965A-12DCDE9CBE73@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1629 bytes --]
I've been reading about the tradeoffs between different iteration methods,
and the consensus seems to be that dolist, dotimes, and cl-loop are more
efficient than mapc and seq-do, because the former methods macro-expand (in
almost all cases) to a while loop, while the latter require a lambda, which
are generally slower and harder to debug.
I see what you're saying that allocating a list of keys just to iterate
once over a hash table would be wasteful. And I suppose it also wouldn't
make sense to have a built-in just for iterating over hash-tables.
Shankar Rao
On Thu, Nov 28, 2024 at 6:31 PM Mattias Engdegård <
mattias.engdegard@gmail.com> wrote:
> 28 nov. 2024 kl. 12.53 skrev Shankar Rao <shankar.rao@gmail.com>:
>
> > I noticed that the functions hash-table-keys and hash-table-values are
> just wrappers around maphash. This means that there is no way to iterate
> over a hash-table without using a lambda.
> >
> > Would it be useful or worthwhile to implement these directly in C? I
> don't know much about low-level Emacs development, but having these as
> built-ins could make iteration of a hash-table a little faster and easier
> to debug.
>
> It's unlikely that it would be faster to make a list just for the purpose
> of a single iteration; the allocation costs alone would be too high. Other
> ways of iterating through hash-tables have been tried with mostly
> disappointing results, although there might be some value in avoiding use
> of the C stack in some cases.
>
> If you tell us what you are trying to accomplish, it would be easier for
> us to help you.
>
>
[-- Attachment #2: Type: text/html, Size: 2084 bytes --]
next prev parent reply other threads:[~2024-11-29 14:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-28 11:53 Is there utility in making hash-table-{keys, values} built-in functions? Shankar Rao
2024-11-28 17:31 ` Mattias Engdegård
2024-11-29 14:25 ` Shankar Rao [this message]
2024-11-29 22:05 ` Tomas Hlavaty
2024-11-28 18:40 ` Gerd Möllmann
2024-11-29 13:47 ` Shankar Rao
2024-11-29 14:19 ` Gerd Möllmann
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='CAGEgU=g+dGwu+Df1mcg+NdCRUia3FCDWp2JVx+Th7_x+k=-5TQ@mail.gmail.com' \
--to=shankar.rao@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=mattias.engdegard@gmail.com \
/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.