This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-29
Channels
- # aws (2)
- # bangalore-clj (2)
- # beginners (36)
- # boot (10)
- # cider (9)
- # cljs-dev (19)
- # clojure (47)
- # clojure-russia (4)
- # clojure-spec (18)
- # clojure-uk (4)
- # clojurescript (71)
- # core-async (20)
- # core-logic (2)
- # css (3)
- # cursive (5)
- # data-science (15)
- # datomic (7)
- # emacs (13)
- # figwheel (4)
- # klipse (1)
- # luminus (5)
- # lumo (1)
- # off-topic (33)
- # re-frame (17)
- # shadow-cljs (1)
- # spacemacs (5)
- # specter (21)
- # unrepl (1)
- # vim (7)
For small and specifically performance-sensitive sections in a program, is it possible to write "imperative with local mutable variables" style code using Clojure? In other words, is it possible to "write Java in Clojure"? The closest thing I could find were volatiles, and those are still one extra layer of boxing, right?
For what it's worth, I understand this goes heavily against the idioms of Clojure in the standard case.
@mingp, if you're thinking of writing "Java in Clojure", why not just write the Java code and call that? What I mean is, Java's a very good Java, if that's what you want 🙂
you can write “java in clojure”
@the2bears Yes, that's the other option. Mainly, the benefit from a theoretical "Java in Clojure" would be locality/organization of the source files, for whatever that's worth.
depending on how much performance you need to eek out
most of the code I’ve seen that focuses on performance talks about type hints to avoid reflection which is one of the slower parts
@smith.adriane I'm looking for on-par with writing regular imperative Java. Which is to say, I need mutable locals in an unboxed form.
are you creating lots of volatiles?
Yes, and using things like transient collections, as long as they don't leak outside the function.
you may be able to create them once and reuse them, depending on the context
For now, it's purely hypothetical. I want to know if I have this option available before I get into it.
Because, whether I do or don't have this option available will probably change what I do.
because other than creation, I think it’s the same as just regular java mutation
Can you be more clear by what you mean with "write Java in Clojure" though? There's a wide scope of what it could mean.
@the2bears Say I take a generic computer algorithms textbook. It has well-known algorithms in a form that can be translated near-verbatim into Java, same as any other traditional imperative language. If I wanted to do the same for Clojure, and maintain Java-level performance, my (admittedly limited) understanding is that I would need mutable locals.
I see. I haven't tried (at least on purpose) to program imperatively in Clojure having spent so much energy to leave Java behind 🙂 I can't think of anything beyond mutability you'd need, it seems all flow control mechanisms are there.
For the most part, I try to learn and write idiomatic Clojure. But for that low-single-digit percent of code that needs it, I'm exploring options for getting Java-level performance.
yeah - particularly because of the issues with boxed numerics, it's just easier to write a bit of java once you know which code has to be that fast
@noisesmith True. Although, it seems like (from what I can tell from http://insideclojure.org/2014/12/15/warn-on-boxed/), unboxed math is possible in Clojure.
it's possible, it's a pain to get right
@the2bears @smith.adriane @noisesmith Well, thank you for your responses. I think I should go reconsider what I am doing and why, as it sounds like I may be entering "when all you have is a hammer" territory.
I think one of the nice things for clojure is that if you do want to use some of the great work in the jvm ecosystem, you can use it as needed
So, I just went to look at the Benchmarks Game to see how they micro-optimized algorithms in Clojure. Unfortunately, it looks like, at some point recently, they removed Clojure from their languages list.
Looks like it was removed from the web site on sept 20th, along with scala?
32-bit core is available http://benchmarksgame.alioth.debian.org/u32/
@lovuikeng Looks like that one's full of dead links, unfortunately. I can click into the language pages, but not the implementation source code pages. It just returns 404 Not Found.
2016 clojure removed? Guess we'll have to wait until 2032... "abandoned in 2002...restarted in 2004...continued from 2008...Everything has changed; several times." https://benchmarksgame.alioth.debian.org/sometimes-people-just-make-up-stuff.html
By chance I happened across this yesterday: http://clj-me.cgrand.net/2013/03/18/tarjans-strongly-connected-components-algorithm/ It sounds like it's maybe not what you need, @U45T93RA6, but FYI just in case it's useful to you.
should be translated to clojure very quickly
can eventually try out, thanks!
meanwhile checking if I can steal something off stuartsierra/component
https://github.com/stuartsierra/dependency/blob/master/src/com/stuartsierra/dependency.cljc#L89
@vemv isn't http://aysy.lu/loom/loom.alg.html#var-dag.3F what you need ?
Does anyone know how to add accents or diacritical marks to characters? As in add ¨ to a to make ä?
https://github.com/funcool/clojure.jdbc Comparing to java.jdbc I like clearer docs and simpler API, especially that there's a difference between connections/dbspecs and how transactions are implemented. Other advantages are pointed out in the FAQ: http://funcool.github.io/clojure.jdbc/latest/#why-another-jdbc-wrapper
I'm not having much luck trying to write a pmap-like function that times-out after a specified number of milliseconds. I tried two implementations: one with futures and one with core.async. The more complicated futures one passes tests but doesn't stop processes when running in my project. The core.async one is even worse in that regard. I'm new to core.async. If you care to take a look, the code is here: https://github.com/pdenno/utils4pmap/blob/master/src/pdenno/utils4pmap.clj There are tests in utils4pmap_test.clj
future-cancel is unreliable, if you want something to be cancellable you need to ensure it regularly calls some cancellable method (the list is relatively short) https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Future.html#cancel(boolean)