David:
Here is a link to the exact source code of the program I was running
for my recently published results in the sister thread titled "Problem
with garbage collection? Was Euler 14".
https://github.com/jafingerhut/clojure-benchmarks/blob/master/collatz/collatz.clj-1.clj
Is this code also exhibiting the same problem, and if so, which top-
level def is causing it? The only top-level defs in my code are three
functions defined with defn.
Thanks,
Andy
On Jan 20, 2011, at 2:10 AM, David Powell wrote:
This same problem was raised recently:
https://groups.google.com/group/clojure/browse_thread/thread/df4ae16ab0952786?tvc=2&q=memory
It isn't a GC problem, it is an issue in the Clojure compiler.
The issue seems to only affect top-level defs. At the top-level:
(reduce + (range 10000000))
- runs quickly without using lots of memory
(def x (#(reduce + (range 10000000))))
- also runs quickly without using lots of memory
(def x (reduce + (range 10000000)))
- uses lots of memory due to the sequence getting forced
The problem seems to be caused by the clojure compiler forcing the
sequence when trying to figure out how to compile it, not
by the compiled code retaining the sequence at runtime.
It probably isn't a good idea to put expensive top-level defs in
your code, because they get run when you just try to aot
compile your code; but if you need to, a workaround at the moment is
to wrap your value in a function and call it as above.
I suspect that it is possible for us to fix the compiler not to
force these sequences. I think it is happening in the
InvokeExpr class.
--
Dave
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient
with your first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en