Speed up printing of time instants by adding type hints
Description
Environment
Attachments
Activity
Alex Miller October 10, 2013 at 10:48 PM
Setting that is not uncommon in core clojure code and seems fine to me here.
Andy Fingerhut October 10, 2013 at 10:06 PM
Alexander, Leiningen is not used for building Clojure itself. The two supported choices are Maven and ant. Several Clojure source files, e.g. core/protocols.clj and core/reducers.clj, set warn-on-reflection to true, I believe so that if code is changed in such a way as to introduce a warning, it will be caught more quickly.
If the screeners or Rich think it is inappropriate, it is easy enough to remove.
Alexander Kiel October 10, 2013 at 10:54 AM
Thanks for the patch Andy. But I don't like the (set! warn-on-reflection true). I think its better to use it only in the dev profile in leiningen. Not in real production code.
Andy Fingerhut October 10, 2013 at 6:07 AM
Patch clj-1277-1.txt adds 4 type hints that eliminate all reflection occurrences in source file instant.clj. Benchmarks show that it speeds up printing of java.util.Date and java.sql.Timestamp objects by a factor of about 3 to 4.5.
Latest Clojure master as of Oct 9 2013:
user=> (time (let [d (java.util.Date.)] (dotimes [i 3000000] (pr-str d))))
"Elapsed time: 24094.282 msecs"
user=> (import 'java.sql.Timestamp)
user=> (time (let [d (java.sql.Timestamp. 1300000000000)] (dotimes [i 2000000] (pr-str d))))
"Elapsed time: 20856.957 msecs"
That version of Clojure plus the patch clj-1277-1.txt:
user=> (time (let [d (java.util.Date.)] (dotimes [i 3000000] (pr-str d))))
"Elapsed time: 5085.847 msecs"
user=> (time (let [d (java.sql.Timestamp. 1300000000000)] (dotimes [i 2000000] (pr-str d))))
"Elapsed time: 7582.233 msecs"
Details
Details
Assignee
Reporter
Labels
Approval
Patch
Priority

There are several occurrences of reflection in instant.clj that slow down the printing of time instants.
Clojure Google group conversation link: https://mail.google.com/mail/u/0/?shva=1#label/clojure/1419e1e6f6cc5b3d
The addition of a few type hints is enough to speed the printing of time instants by a factor of about 3 to 4.5, in a few small benchmarks.
Patch: clj-1277-1.txt
Screened by: Alex Miller