core.async buffers alternative backend

79 views
Skip to first unread message

dimitris

unread,
Sep 10, 2020, 9:14:53 AM9/10/20
to Clojure
Hi folks,

`LinkedList` is used as the underlying data-structure for all core.async
buffers. However, looking closer reveals that what is really needed is a
`Deque` (for its .addFirst/.removeLast methods). So naturally then it
begs the question - why not `ArrayDeque` [1]? It should offer superior
insertion/removal/traversing performance, and in the context of
core.async it will never be resized (if initialised with `n`).

And since we're on the subject, why not even go crazy with a
(thread-safe) `ConcurrentLinkedDeque` [2] ? Leaving the counting
complication aside for a moment (something which I wouldn't mind
feedback on), having a thread-safe buffer opens up the door to safe
buffer snapshots.

Anything wrong with either of those approaches? Many thanks in advance...

Kind regards,

Dimitris

[1]:
https://github.com/jimpil/asynctopia/blob/master/src/asynctopia/buffers/array.clj

[2]:
https://github.com/jimpil/asynctopia/blob/master/src/asynctopia/buffers/thread_safe.clj



Alex Miller

unread,
Sep 10, 2020, 4:17:10 PM9/10/20
to Clojure
I don't actually remember now, but it's possible that when core.async was created we were still trying to accommodate an older version of Java before some of those existed. That's not an issue now as we only need to support Java 1.8+. So, I don't know of any reason these wouldn't be an option. Would be happy to see a core.async issue and/or patch (may need to sign the CA and become the contributor first).
Reply all
Reply to author
Forward
0 new messages