On Sun, Nov 02, 2025 at 12:52:30PM +0900, Nala Ginrut wrote:
> 
> Hi folks!
> I've made a simple benchmark to help to figure out, at what size does an
> alist’s performance start to degrade noticeably compared to a hash
> table.
> 
> It seems we can keep alist for simplicity if the size is under 50. And I
> think it's good enough for most small cases.
> 
> https://nalaginrut.com/archives/2025/11/02/hashtable_vs_alist

Hah. I tried this a while ago with Emacs Lisp and landed in a similar
ballpark.

Now they are not /necessarily/ equivalent: assoc-remove! removes the
first occurrence of a matching entry, whereas we don't know whether
a hash does this (or even allows double entries at all!): it doesn't
seem to be specified (is it? Correct me!).

That means that alists lend themselves beautifully to implement a
kind of "stacking shadowing", as you would get with nesting scopes
(think lexical or dynamic variables, namespaces in XML, yadda, yadda).

Not that it would be hard to implement hashes to do the trick (if
you do your hashes with chaining on collision you'd get that "for
free"). But the specs usually are mute about that...

Cheers
-- 
t

Attachment: signature.asc
Description: PGP signature

Reply via email to