Clojure time/memory stats seem wrong

  • 17
  • Problem
  • Updated 12 months ago
Clojure time/memory stats seem wrong. Looping through odd numbers from 1 to 99 says it takes more than 10 seconds and more than 60MB of RAM. On my machine it runs in less than 100ms. I don't even think it takes 10 seconds to show up in the score list. I don't see how anyone could ever make it to the leaderboard with clojure if this 3 line function is that bad.

Photo of wfreeman

wfreeman

  • 35 Posts
  • 0 Reply Likes
  • sad

Posted 4 years ago

  • 17
Photo of Yuri Sklar

Yuri Sklar

  • 222 Posts
  • 12 Reply Likes
It's true that Clojure takes too much resources. At least on our environment. We'll be investigating this soon.
Photo of wfreeman

wfreeman

  • 35 Posts
  • 0 Reply Likes
This is how long it takes to run in the REPL.
user=> (time (loop [x 1]

...)))
1
3
5
7
9
...
97
99
"Elapsed time: 4.424 msecs"
Photo of Flávio de Sousa

Flávio de Sousa

  • 0 Posts
  • 0 Reply Likes
Same problem here. Submitted a very simple code for the Swap Case problem and got more than 63MB of memory and more than 10500ms. Running on my box I got the following figures (that include the clojure loading overhead!):



% /usr/bin/time -v /usr/bin/clojure1.3 SwapCase.clj SwapCase.in
hELLO WORLD!
jAVAsCRIPT LANGUAGE 1.8
a LETTER
Command being timed: "/usr/bin/clojure1.3 SwapCase.clj SwapCase.in"
User time (seconds): 1.91
System time (seconds): 0.19
Percent of CPU this job got: 110%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:01.90
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 196752
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 14750
Voluntary context switches: 305
Involuntary context switches: 124
Swaps: 0
File system inputs: 0
File system outputs: 64
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
%
Photo of wfreeman

wfreeman

  • 35 Posts
  • 0 Reply Likes
Are you sure you guys aren't adding 10 seconds to the clojure run time? It seems like it completes/updates the score on the page much faster than the 10 seconds.
Photo of Yuri Sklar

Yuri Sklar

  • 222 Posts
  • 12 Reply Likes
Hey guys, we really want to improve Clojure support. At the moment we execute Clojure like this: "java -cp clojure-1.5.1.jar:contrib.jar clojure.main /souce.clj".
We've tried several options but Clojure executes slow at our environment (we don't utilize much resources for code execution).

We tend to compile Clojure submissions before execution. May be smb have experience with Clojure compilation and could help us? The best way would be compile Clojure code without modifications to existing Clojure submissions (to have it backward compatible)
Photo of Yuri Sklar

Yuri Sklar

  • 222 Posts
  • 12 Reply Likes
Having source file as clojure/main.clj and using the following command java -cp /path/to/clojure.jar -Dclojure.compile.path="." -Dclojure.compile.warn-on-reflection=true clojure.lang.Compile clojure.main we have the following output Compiling clojure.main to .

Looks OK, no errors. But we don't have any new files created on the filesystem...
Does anybody have some thoughts?
Photo of Yuri Sklar

Yuri Sklar

  • 222 Posts
  • 12 Reply Likes
We've checked the possibility of AOT compilation. Pretty much it doesn't help in our case, because anyway it "compiles" into bytecode which needs clojure.jar and so on.
We're thinking now about another solution: run the code with already started JVM
Photo of wfreeman

wfreeman

  • 35 Posts
  • 0 Reply Likes
I use leiningen for everything related to the build. It seems like overkill for this, but have you checked it out?
Photo of Yuri Sklar

Yuri Sklar

  • 222 Posts
  • 12 Reply Likes
Now we're checking about leiningen, nailgun, drip. An issue we'll have is about getting memory stats...
Photo of wfreeman

wfreeman

  • 35 Posts
  • 0 Reply Likes
How do you usually get memory stats for JVM languages?
Photo of wfreeman

wfreeman

  • 35 Posts
  • 0 Reply Likes
Maybe have people define a -main function and run it via the REPL (guarantees JVM is loaded), like so:

https://github.com/wfreeman/codeevall...
Photo of dpimka

dpimka

  • 2 Posts
  • 0 Reply Likes
Hey! I'm just registered and having a *very* basic fizz-buzz problem solution written in clojure. it works, but it does not count as completed, because complains that I need to lower memory usage to 20Mb, which is currently 60-70Mb.

This is due to the way clojure is run - it needs whole JVM, which is rather memory hungry, so I'd say that solution would be either to lower memory requirements needed for clojure solution to be accepted or to improve your memory counting mechanisms to take this specifics into account!

Otherwise it's not really fun - to have this very basic problems not solvable :)
Photo of eaxour

eaxour

  • 1 Post
  • 0 Reply Likes
Same problem. Despite correct solutions the memory and timing measurements make Clojure a completely non competitive choice.

3 Clojure Feb 23, 2014 Partially 100 6612 70946816 no ---try again Delete
2 Clojure Feb 23, 2014 Partially 100 6310 66809856 no ---try again Delete
1 Clojure Feb 23, 2014 Partially 100 6330 71098368 no ---try again Delete
Photo of Andrei Kozlovskiy

Andrei Kozlovskiy

  • 315 Posts
  • 34 Reply Likes
Thank you for reporting. It's a known issue with clojure. We're working on some solid solution for it.
Photo of dpimka

dpimka

  • 2 Posts
  • 0 Reply Likes
Thank you Andrei. I would be grateful if you'd drop a note to this thread when this issue is somehow resolved, so I would continue to play with codeeval (my primary interest is currently to try solving some problems in Clojure, not other languages).
Photo of motoom

motoom

  • 3 Posts
  • 0 Reply Likes
Same here. Even the simplest Clojure program takes at least 50M or so, because of the JVM. Too bad! I was already wondering why I saw no Clojure solutions on the website... now I know the reason ;-(
Photo of Andrei Kozlovskiy

Andrei Kozlovskiy

  • 315 Posts
  • 34 Reply Likes
Currently we're working on some improvements in our measurement system, and definitely will update you as soon as we'll find some solid solution for Clojure.
Photo of Igor Chubin

Igor Chubin

  • 9 Posts
  • 0 Reply Likes
Hi, the problem is still there? May be we could help somehow?
Photo of Igor Pomaranskiy

Igor Pomaranskiy

  • 270 Posts
  • 37 Reply Likes
Hi Igor,

Unfortunately, the problem still remains unresolved. We will notify you as soon as we have a solution.
Photo of Igor Chubin

Igor Chubin

  • 9 Posts
  • 0 Reply Likes
Hi Igor,

Thank you for the reply.

Will our partial Clojure soultions automatically resubmitted then,
or we need to resubmitted all of them manually?
Photo of Igor Pomaranskiy

Igor Pomaranskiy

  • 270 Posts
  • 37 Reply Likes
We will try to resubmit it automatically.
Photo of motoom

motoom

  • 3 Posts
  • 0 Reply Likes
I just retried my solution for the 'sum of first 1000 primes problem'; the JVM now takes 118M memory, and the solution is not accepted: "Reduce memory usage to 20MB". I don't know how to do that. A simple "Hello World' program in Clojure already takes a baseline of 100MB memory for the JVM and libraries.
Photo of Igor Chubin

Igor Chubin

  • 9 Posts
  • 0 Reply Likes
It would be probably reasonable to use another method to check how much memory a clojure program takes. I'm curious how it works for the scala tests
Photo of martin.clausen

martin.clausen

  • 4 Posts
  • 0 Reply Likes
An plans to fix this? I just spent time doing a solution in Clojure just to see the memory issue preventing me from solving challenge 144 even with a score of 100.
(Edited)
Photo of David Bergman

David Bergman

  • 1 Post
  • 1 Reply Like
This is basically ejecting all Clojure coders. Well, well, back to the grind (using Python or Ruby etc...) What a waste of time.