Why is any Java/Clojure program slowed down when run from Leiningen? -
while benchmarking clojure app , trying pin down performance problems, noticed peculiar behavior: when entire program written in java, when launched leiningen seems experience significant slowdown.
say have java program:
public class foo { public static void main(string[] args) throws exception { (int = 0; < 10; i++) run(); } public static void run() { final long start = system.nanotime(); random r = new random(); double x = 0; for(int i=0; i<50000000; i++) x += r.nextdouble(); final long time = timeunit.milliseconds.convert(system.nanotime() - start, timeunit.nanoseconds); system.out.println("time (ms): " + time + " total: " + x); } }
when run program, execution times (per run
) of 1s. however, when run leiningen so:
lein run -m foo
i run times of 2s! how clojure/leiningen manage slow down complete java program much? doing wrong?
i've tried examining system properties in both runs , couldn't find glaring (like different jit settings). in both cases use java 7 server compiler.
edit: don't know why question has been downvoted. i'm not against clojure. on contrary, love clojure , i'm going use it. have serious performance problem absolutely must solve.
update: running lein trampoline
solves issue! (though have no idea why) i've updated question reflect indeed leiningen issue, not clojure issue.
another update: happens clojure code well. running without trampoline slows down code 5x.
it's due different jit behaviour.
the performance of jit compiled can affected number of things, including:
- what startup code gets called, affect jit statistics
- what other classes have been loaded (e.g. other subclasses of random) affect compiler's optimisation of method call dispatch
Comments
Post a Comment