clojure 2026-11-08

Does anyone in core have an appetite for improving the performance of numeric code in Clojure? The constant fight against boxing and the need to write type hints everywhere is a bummer when working on that kind of thing, but I do understand that most situated software use cases are not much impacted by this.

👀 3
➕ 3
Alex Miller (Clojure team) 2026-11-08T12:47:48.657809Z

What are you thinking about?

interested to hear more also because I’m guessing this is a problem/application where tech.ml.dataset + friends haven’t necessarily helped that much?

This also is probably best tackled after value types land. The constant fight against boxing is a pain that might be lessened in the future

Alex Miller (Clojure team) 2026-11-08T15:31:12.025539Z

it’s going to be many years before value types land and we use that as a basis for Clojure, so can still talk about things before then

i think @chris441 has worked on this

@alexmiller A small amount of type inference would go a long way to reducing the manual burden. My personal approach would be to use something along the lines of the Nimble type inference algorithm, which is not totalizing in the way of HM and works very well with the evaluation strategy of Lisps. It was originally made for Common Lisp, but the approach used by Chez Scheme is quite similar. I implemented it in Clojure for fun earlier this year, and it turned out fast and effective: https://berlin.social/@jack/116273315614370868

Alex Miller (Clojure team) 2026-11-08T17:16:08.964449Z

Do you have an example piece of code that demonstrates where you are looking for improvements?

Here’s a really short function where it should be pretty easy for the compiler to know the types without annotation. I have a fair few numerical functions that looks like this, but at >=100 lines of code. I know this is weird kink for most of the Clojure community, but there are at leasts dozens of us who do this sort of thing 🙂

(defn point-weight
  "Weight of a point (absolute value of e123 coefficient)."
  ^double [^MV p]
  (Math/abs (double (aget ^doubles (.-coeffs p) IDX-E123))))

Alex Miller (Clojure team) 2026-11-08T22:02:36.356039Z

my suspicion, without talking to Rich, is that it’s unlikely we’re going to add type inference. but I could see for this particular kind of thing, adding aget-double. Using the built-in clojure.core/abs here inlines to a polymorphic primitive double so could boil down to just:

(defn point-weight
  "Weight of a point (absolute value of e123 coefficient)."
  ^double [^MV p]
  (abs (aget-double (.-coeffs p) IDX-E123)))
which, imo would be pretty reasonable. QOL kinds of things like this are definitely doable. would help to have Ask Clojure issues for specific things so they can get logged+voted on.

I'll open an Ask for aget-double 👍🏻