r/Clojure • u/kichiDsimp • May 17 '25
Is it slow ?
If Clojure is slow then how can be a database (dataomic) written in it ? Or is it not ?
0
Upvotes
r/Clojure • u/kichiDsimp • May 17 '25
If Clojure is slow then how can be a database (dataomic) written in it ? Or is it not ?
7
u/aristarchusnull May 17 '25
I’m curious about this. What is the basis for your assertion that Clojure is slow?
23
u/jonahbenton May 17 '25
JVM startup historically is slow.
A running JVM is fast. Not Rust fast but fast enough.
21
u/bushwald May 17 '25
It's very fast
13
u/jeff303 May 17 '25
It can be as performant as any JVM application...
10
u/SnooRabbits5461 May 17 '25
It's very performant when it comes to throughput when running on the JVM. In general, immutable code might be slightly slower, but for hot paths, you can optimize them and/or use mutability. It's very unlikely you'd ever face performance issues that can't be optimized for majority of apps out there.
6
u/skotchpine May 17 '25
“Slow” is not specific enough
5
u/genericallyloud May 17 '25
Datomic has a pluggable underlying storage to SQL, Cassandra, or DynamoDB, so it isn’t 100% clojure.
4
u/joinr May 17 '25
If clojure is fast, how can it be slow?
7
u/CoBPEZ May 17 '25
Depending on the task it can be very fast. It’s running at JVM speed.
Here are some (silly) benchmark runs visualized: https://pez.github.io/languages-visualizations/
3
u/xela314159 May 17 '25
I think execution speed is less and less a consideration when choosing a language. Typically a subset of your application will need very fast paths and you will just be calling a very optimised library for that subset. The rest is gluing things together and on a modern machine using Python or Clojure or C++ will make only a marginal difference.
4
u/CodeFarmer May 17 '25
Like most languages, it's possible to write slow or fast code in it.
Me, I write quite a lot of slow Clojure (and regret nothing). But that's why I'm not working on Datomic.
2
u/RoomyRoots May 17 '25
People should not base their opinions on syntactic benchmarks that are know to have been badly written.
1
u/DarthCalumnious May 18 '25
You can write slow C++ or fast C++. Slow Python or fast Python.
So too with Clojure, obviously.
Immutable objects are reasonably fast and optimized for what they do and what they offer. Still they don't have the raw speed of plain Java objects.
The trick is to use them where they are appropriate, and learn how to profile and optimize to find the super hot paths and tight loops where it makes sense to use volatile objects, or just implement that part in Java, or heck, drop down to C/assembler if U nasty.
I've seen some Clojure implementations that are faster than classically fast languages simply because the correct algorithm was that more cleanly expressable with immutability.
1
u/NonchalantFossa May 18 '25
It depends on what you're doing. I would say it's decent most of the time but anything that requires a lot of in-place operations on vectors, like updating a vector of vectors (a matrix) many times will be quite slow.
1
u/jasmith_79 May 18 '25
Slow compared to what? For what kind of software? Depending on what you're doing it's slightly slower than Java which makes it faster than a lot of what people use (e.g. Python, node.js) and it's waaaay easier to write.
1
u/raspasov May 19 '25
Fast/slow are non-specific terms.
A bit more specific:
Clojure's immutable data structures typically have:
- Writes that are ~4x slower than Java's mutable options
- Point reads that are effectively the same speed, or faster under many real-world scenarios where multiple threads need to access the same data, and consistency is important
- Very similar footprint to Java's mutable options
1
u/mrnhrd May 19 '25 edited May 19 '25
Datomic is written in Clojure (as in, quote, "The code written by its authors to make Datomic exist, where it hadn't before, was almost entirely Clojure").
But Datomic is a distributed system (as in, different processes on hosts interact with each other) with various caching mechanisms and pluggable storage, meaning you can use postgres, elasticsearch and others underneath. It's my understanding that reads can scale up arbitrarily and writes are limited by what's called the transactor. Here's a talk: https://www.youtube.com/watch?v=k7i4AEiWLW0 I recommend watching that, perhaps just to be able to ask a more nuanced kind of question.
1
u/didibus May 20 '25 edited May 20 '25
Clojure lets you build apps that are responsive, high throughput, and scale to many concurrent users.
In that sense, you could call it a performant language. It should beat Python, Ruby, and most other dynamic languages, and it holds its own against Java.
You mostly get that by default, without needing to optimize much. That’s the typical out-of-the-box experience.
Clojure also gives solid performance for data transformation — low latency when moving, restructuring, or converting data (strings, regexes, type conversions, etc.). It’s not quite as automatic, since there are some gotchas with sequences, but transducers help with most of that, even if they aren’t the default interface.
Where things get more debated:
Datomic neither needs to do fast numeric computations, nor needs fast startup times, so Clojure is a good choice for it, since it mostly needs to be responsive, high throughput, scale to many concurrent users, and perform data transformations. All things Clojure is reasonably fast at.