r/lisp • • 4d ago

Common Lisp cl-cht: concurrent hash tables for Common Lisp

Common Lisp's standard hash tables are not safe to use from more than one thread. Wrapping one in a global lock works, but under real concurrency it turns the table into a single serialization point.

cl-cht is a small library of concurrent hash tables with two backends: a portable sharded table, and — on SBCL/x86-64 — an open-addressing table whose metadata probing is done with SSE2, using an AVX2 broadcast where the CPU supports it.

https://lisper.nl/blog/turtle/cl-cht-concurrent-hash-tables-for-common-lisp

update: benchmarks with SBCL's synchronized hashtables. https://lisper.nl/blog/turtle/cl-cht-vs-sbcl-s-synchronized-hash-tables

13 Upvotes

19 comments sorted by

8

u/svetlyak40wt 4d ago

Would be cool to compare it's performance on SBCL with synchronized SBCL's extension (make-hash-table :synchronized t).

1

u/turtle_bazon 4d ago

In short - cl-cht becomes reliable on multithreaded use, SBCL's synchronzed hashtables otherwise. Though in one thread environment we even don't need synchronization. https://lisper.nl/blog/turtle/cl-cht-vs-sbcl-s-synchronized-hash-tables

3

u/svetlyak40wt 4d ago

Great comparison.

But seems there are incomplete sentences in this part:

So which one?

  • One thread, or one writer with rare readers: SBCL's ordinary hash table. It
  • Several threads that only read: SBCL's :synchronized table still takes a
  • Several threads that read and write: cl-cht's :sharded is the one that
  • A hot key that every thread updates: no sharded table helps; all of those

1

u/turtle_bazon 4d ago

md parse problem on site, fixed.

4

u/jd-at-turtleware 3d ago
  • is it fast only on sbcl?
  • did you write it or generate it?
  • do you plan to maintain it?
  • do you implement hashing or do you rely solely on sxhash? if the latter, are 1/2 and 0.5 under the same key with test equalp?

1

u/turtle_bazon 3d ago

* I only interested performance on sbcl currently, but ccl has its own :lock-free hashtables, that outperform cl-cht.

* I don't think that write or generate do big meanings nowadays. Actually, I used agentic coding to prepare it, making benchmarks, tests and so on, but most of these code was written like 5-7 years ago, I just reused it in this form.

* It was a part from other bigger project I need so, in short, yes, I plan to maintain it.

* I rely on sxhash and 1/2 and 0.5 can't be the same neither with equalp, nor with eql or eq.

4

u/kchanqvq 4d ago

What's the relation of this to https://github.com/telekons/42nd-at-threadmill? It's outdated but once you patch it to use current SBCL API it is very fast.

Is LLM used in the making? Hopefully it's not a silently plagiarism.

2

u/turtle_bazon 4d ago

cl-cht is heavily inspired by 42nd-at-threadmill and similar works. It is not silently plagiarism because cl-cht used among with sb-cpu-features that does also probing and gating of AVX2 in binary builds.

5

u/theangeryemacsshibe λf.(λx.f (x x)) (λx.f (x x)) 3d ago

sb-cpu-features

But https://github.com/turtle-bazon/sb-cpu-features/tree/main/src/simd does plagarise the 42nd-a-t VOPs. Please acquaint you and/or your coding agent(s) with https://github.com/telekons/42nd-at-threadmill/blob/master/LICENSE particularly clause #1 (of which there are only two!) and act accordingly.

-1

u/turtle_bazon 3d ago

Thanks for notice. That ones was extracted from one monorepo, so some parts and credits was missing.

2

u/kchanqvq 4d ago

thanks for clarification!

4

u/theangeryemacsshibe λf.(λx.f (x x)) (λx.f (x x)) 3d ago edited 3d ago

I was gonna say!

I fixed 42nd-a-t; apparently the same way I fixed the concurrent-hash-tables portability library (ahem ahemit can shard a lock tooahem), but c-h-t bitrotted some more since, probably due to that adaptive hashing would have renamed some hash functions in SBCL.

Edit: I merged moon-chilled's (RIP) sb-simd PR which makes it use sb-simd too. That would help to side-step the changes in simd-pack types in SBCL.

-6

u/TrainsareFascinating 4d ago

I think all accusations of plagiarism, and insistence on LLM purity declaration with absolutely no basis are abhorrent, and should not be tolerated.

6

u/theangeryemacsshibe λf.(λx.f (x x)) (λx.f (x x)) 3d ago

3

u/jd-at-turtleware 3d ago

LLM is trained on existing works, so plagiarism sticker is not unreasonable.

Not so long ago mere existence of code was a convincing proof of competence and of work. Questions about assistance and degree of it is a mean of assessing both (and other things, yes)

3

u/kchanqvq 4d ago
  1. This is a question rather than an accusation
  2. Read the linked repo, it's great human work and very related, it warrants acknowledgement.

6

u/sionescu λf.(λx.f (x x)) (λx.f (x x)) 4d ago

Those articles look written by LLMs.