Clojure tests are slow

In Clojure, execution time of a test is much longer than with most other languages. Thus it is quite difficult to finish a clash of code in time.

1 Like

The tests could be running way faster if the code was interpreted instead of run in a new JVM instance each time.
It is possible to interpret it instantly (with no JVM starting wait time) using a library called SCI GitHub - borkdude/sci: Configurable Clojure interpreter suitable for scripting and Clojure DSLs.</ compiled using GraalVM.

1 Like

Unfortunately, itā€™s not possible. Thatā€™s not how our environment works. Sorry :confused:

What kind of constraints do you have?

Basically, they say that they donā€™t know how to do, because if they understood what I proposed they would not answer that.

Iā€™m really pleased with Codingame and I find it super useful to train on problem solving. Now Iā€™d like to improve in using functional programming languages and mostly Clojure, but right now the tests being slow limits quite a bit its use for Clash of Code.

I read that you donā€™t have a Clojure dev on the team, and Iā€™m willing to help as much as I can to improve the support.


babashka has really demonstrated solid performances and stability, and is still improving quickly.

It might be possible (given your infrastructure constraints) to swap the ā€œclassicā€ Clojure compiler for babashka.

Possible solution

:warning: Complete assumptions :warning:

Iā€™m assuming Codingame is running the userā€™s code in some form of container (Docker, LXC?). Iā€™m also assuming that thereā€™s a common template for running the code against the tests, namely something of the form:

interpreter user-code.txt < test1-input.txt

and then the output of the command is checked against the expected result.

And I suspect that for Clojure itā€™s something along the lines of

clojure user-code.clj < test1-input.txt

If all these assumptions are somewhat correct, it would then be relatively straightforward (possibly) to swap for babashka.

:arrow_down:

bb -i -o -f user-code.clj < test1-input.txt   # the binary for babashka is `bb`

Advantages

  • Babashka has been created as a fast starting alternative for Clojure.
  • No JVM slow startup time.
  • Most popular libraries have been ā€œportedā€, and the standard library is available. Since only the builtin libs can be used on CG, thatā€™s not an issue.

I ran some tests to ensure that thereā€™s a benefit to swapping, and I used my Clojure solution to the puzzle ā€œMIME typeā€ (measured it with hyperfine).

clojure test.clj < cloj-test

  Time (mean Ā± Ļƒ):     887.9 ms Ā±  26.0 ms
bb -i -o -f test.clj < cloj-test

  Time (mean Ā± Ļƒ):      13.4 ms Ā±   2.1 ms 
3 Likes