What happens with getVarRoot?
I am really surprised that any program spends a lot of time on getRawRoot (). This whole method returns a single field from Var, according to the source in clojure.lang.Var :
final public Object getRawRoot(){ return root; }
In addition, this is a small final method, so it should be built in by any modern JIT compiler ..... basically any getRawRoot calls should be insanely fast.
I suspect something strange is happening with your profiler: it may be adding debugging code to getRawRoot (), which takes a lot of time. Therefore, I suggest comparing your code without a profiler and java -server to see how the function really works.
Other performance tips
Make sure you use Clojure 1.3 + , as there are some optimizations for accessing var that you will almost certainly want to use in this low-level code.
If I thought about what is actually the biggest bottleneck in this code, I think it will be the fact that the grid #(blocked? maze [%1 %2]) function #(blocked? maze [%1 %2]) constructs a new vector each time called to check the square of the grid. It would be much better if you could reorganize it so that it does not need a vector, and you could just use #(blocked? maze %1 %2) directly. Building new collections is expensive compared to simple math operations, so you want to do it sparingly in your internal loops.
You must also make sure that you use primitive operations where possible and with (set! *unchecked-math* true) . Make sure you declare your local residents as primitives, so you want, for example. (let [u0 (int (if x-long x0 y0)) .....] .....) etc. The main reason for this is to avoid the overhead of primitives with boxes, which again involves allocating memory that you want to avoid in internal loops.
source share