I started work on dwimorberg to scratch an itch I had with basic math in Clojure. I wanted to have a ‘pluggable’ system so that numeric types eg apfloat, jscience could be added with minimal ceremony by the user. It would work similarly to the auto-promoting functions in c.c, transparently choosing appropriate types for any given function call.
The implementation so far is just a start: half-baked and not meeting any of the stated goals.
However, once the project was at a point where a benchmark could be performed, I was shocked to discover that perf was roughly 170% c.c’s +'
function, for a small benchmark which added some longs:
I have a run recorded in dwimorberg.core
;; (crit/with-progress-reporting (crit/bench (reduce add (range 1 10000)) :verbose))
;; Execution time sample mean : 176.989471 µs
;; (crit/with-progress-reporting (crit/bench (reduce +' (range 1 10000)) :verbose))
;; Execution time sample mean : 104.753399 µs
profiling (with jvisualvm & tufte) seemed to indicate that the latency was mostly due to dispatch. So I sprinkled type hints everywhere (which javap tells me are being ignored) and rewrote a few different ways without any performance improvement.
A performance penalty is expected, but this gap is too large. I wonder if the idea is dead-in-the-water, or if there is an approach which would yield better performance.
I don’t know what performance would be acceptable, but with this benchmark I would be happy with around 120% speed of +'