Optimizing for Performance

In Clojure, it’s idiomatic to call Java using the techniques described in Calling Java. The resulting code will be fast enough for 90 percent of scenarios. When you need to, though, you can make localized changes to boost performance. These changes will not change how outside callers invoke your code, so you’re free to make your code work and then make it fast.

One of the most common ways to make Java interop faster is by adding type hints to remove reflective calls. We’ll look at that first, and then we’ll consider how to use Java primitives and arrays as a way to optimize memory use and numeric calculation performance.

Adding Type Hints

Clojure supports adding type hints to function parameters, let bindings, ...

Get Programming Clojure, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.