Fork me on GitHub

I have no use case for such a thing, but was curious whether anyone had considered storing Clojure data structures, e.g. vectors, maps, sets, inside of a Web Worker shared buffer? I guess not just considered, but actually tried it, and/or looked at any changes in the ClojureScript implementation that would be required to support it?


last time I checked transit to a string in a postMessage was much faster


(Admittedly many years ago now. Since then structured cloning and dataview apis have gotten faster, maybe the situation is different now)


Fressian-cljs and transit msgpack both exist in browser so in theory you could use shared buffers, but shared buffers offer nothing over arraybuffer transferin these cases


Background on my question: I am writing up an article on Java synchronization techniques used in the Clojure/Java implementation to ensure that data is written by one thread in a way that other threads are guaranteed to get the most up to date version. In the introduction I have written a brief note that these issues do not apply for single-threaded ClojureScript, and then remembered that Web Workers and shared memory proposals exist for JavaScript, and was curious if anything had been done in ClojureScript to take advantage of that.


To really leverage sharedbuffer would require some in-memory layout for cljs data structures like eg captnproto (and some memory management!)


Makes sense. It certainly doesn't appear that doing what I asked about is any kind of sweet spot for any use case that anyone right now wants to write lots of tricky code for. I was primarily curious if anyone knew whether someone had tried going that route.


Java/Clojure concurrency is mostly about publishing pointer updates assuming all memory is shared


In js, there’s no way to share a pointer, threads are already fully isolated. All sharing and concurrency features are concerned with zero-copy array/memory publishing and sharing


So I doubt anyone has done this in cljs land because the problem doesn’t even make sense


I mean, if someone wanted to get tricky, they could use integers in shared memory as indices into arrays, effectively using them like "pointers", so could create potential inter-thread synchronization problems.