From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Shankar Rao Newsgroups: gmane.emacs.devel Subject: Re: Is there utility in making hash-table-{keys, values} built-in functions? Date: Fri, 29 Nov 2024 15:25:20 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000077793706280df8d2" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24966"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: =?UTF-8?Q?Mattias_Engdeg=C3=A5rd?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Nov 29 16:45:06 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tH3B3-0006Pc-LO for ged-emacs-devel@m.gmane-mx.org; Fri, 29 Nov 2024 16:45:05 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tH3AG-0007uK-Ay; Fri, 29 Nov 2024 10:44:16 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tH1w3-0001TW-82 for emacs-devel@gnu.org; Fri, 29 Nov 2024 09:25:31 -0500 Original-Received: from mail-qt1-x829.google.com ([2607:f8b0:4864:20::829]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tH1w1-0000Q0-NY for emacs-devel@gnu.org; Fri, 29 Nov 2024 09:25:31 -0500 Original-Received: by mail-qt1-x829.google.com with SMTP id d75a77b69052e-466879f84ccso14193371cf.1 for ; Fri, 29 Nov 2024 06:25:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732890328; x=1733495128; darn=gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=U3cfSIFsCfS6zwT8y08J4uwKcDHx9EOUFmGjAmoiHRM=; b=HkHXiIVVEJAsgz5SQtW0/E+ThywKOZZSpzm0j2ryod0NCYm1ZIFBnWBqQ5s/WkQA+K CWwbM+vjtfDQdWTNdmxoeb5rA1T1EhghmpViq3r4SGRFdYO7U6EbJHzagvn4iScIJr0U lWHMn1fD0pHH5BZr+zDOd8gMqB859tjptlqfV0nGjMfsEs3FVmobO4hMQ7v0MZ1xIJqR g0v/IJVJy+CiWEuBP5XDkWC8Qn7RR7JZixzwhSvdmI7rgpncZ0Dy74mjsxiZd2ElBc5v BmTWhocPDuvUhz3clvZK/Bdx8IqMs90zifX9vYW9CMYie/zrxccRq9AdCViAbSEZccdE 4xXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732890328; x=1733495128; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=U3cfSIFsCfS6zwT8y08J4uwKcDHx9EOUFmGjAmoiHRM=; b=p+ND+Iz7stSon8orW7lCuMW4Qj/WARgRL3jAy/eEt0jiuG1RCPEW0t/zXmRklUiXEJ cBbzhQBtQoqhBY3aJubH4F0xaiJrSmqfdlPPQRfWxylYBfhHe4YOXZOKRvTxbKLiGa4x 5CVqL4cVI6bJsD6nFbpTRR4HfBw5tVHzIycdW/Z4GmzwFEFN9NGcG679uKyHMa0Vk/nW c9eDK3CD/I6OlLds1j3P0pQTOevu9KrwpRbBZyxPN+LRDJuuSy/nQdgFlhrG2NOZPwxq avkE9roiaCftRtG78fqTUhnXXMjxJnRcLdBJHkuVVCbHyixht7cvfeqn7fG9cR1p6IZC SueQ== X-Gm-Message-State: AOJu0YyL64loo9Clr9QFlXKIJwVi8oRT5FcWwpdibPV9Oxtr5Wcxvf3i 7BvioU9XIt04370GndTKfMV2S0n3AGnFZ2OKQcREgb2EyzZy0xkVkSl+T+D7KtiGlXhGIeyLdMU HIvk0Bh1rsljQ/OHZvEj9S1kE4hpEU7UJ X-Gm-Gg: ASbGnctvHEU2mAvukLn81dpKYSHVymtOZOHpKBwNOfEwmmoEHW7uMuFn5KZrZoTIAuc LbszJcz084E6Z4atCuSx7EfzRBz397RE= X-Google-Smtp-Source: AGHT+IHz6Pqvd+LXYkWAZJCnQrPvrIZl9fNV96ymqAKjdc6maTMdeMUCC+jre4QoZtrumrlBJ+ddxyzXXDVl6FzSxYA= X-Received: by 2002:a05:622a:588d:b0:458:256:bf7d with SMTP id d75a77b69052e-466b351fdf5mr171802591cf.22.1732890328526; Fri, 29 Nov 2024 06:25:28 -0800 (PST) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::829; envelope-from=shankar.rao@gmail.com; helo=mail-qt1-x829.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Fri, 29 Nov 2024 10:44:13 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:325854 Archived-At: --00000000000077793706280df8d2 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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=E2=80=AFPM Mattias Engdeg=C3=A5rd < mattias.engdegard@gmail.com> wrote: > 28 nov. 2024 kl. 12.53 skrev Shankar Rao : > > > 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. Othe= r > 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. > > --00000000000077793706280df8d2 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

I've been reading about the tradeoffs between different iteration=20 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=20 macro-expand (in almost all cases) to a while loop, while the latter=20 require a lambda, which are generally slower and harder to debug.=C2=A0=C2= =A0

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 iter= ating over hash-tables.

Shankar Rao

= On Thu, Nov 28, 2024 at 6:31=E2=80=AFPM Mattias Engdeg=C3=A5rd <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 o= ver a hash-table without using a lambda.
>
> Would it be useful or worthwhile to implement these directly in C? I d= on't know much about low-level Emacs development, but having these as b= uilt-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 purpo= se of a single iteration; the allocation costs alone would be too high. Oth= er ways of iterating through hash-tables have been tried with mostly disapp= ointing 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.

--00000000000077793706280df8d2--