hyperfiddle/electric

compile-time StackOverflowError on TodoMVC build

dustingetz opened this issue · 4 comments

TodoMVC's Photon compilation (macroexpansion) blows out the default JVM stack of 1m resulting in a stack overflow in the ClojureScript compiler at build time. :jvm-opts ["-Xss2m"] fixes it.

Happens only on certain machines.

teodorlu: As of 967f03d, I appear to be getting OutOfMemoryError Java heap space when running clj -A:dev -X user/main. Linux on a 16 GB thinkpad laptop. Happy to provide more details. slack

$ clj -A:dev -X user/main
Starting Electric compiler and server...
shadow-cljs - server version: 2.20.1 running at http://localhost:9630
shadow-cljs - nREPL server started on port 9001
[:dev] Configuring build.
[:dev] Compiling ...
[2023-02-17 16:12:39.602 - WARNING] :shadow.cljs.devtools.server.util/handle-ex - {:msg {:type :start-autobuild}}
OutOfMemoryError Java heap space
    java.util.Arrays.copyOf (Arrays.java:3537)
    java.lang.AbstractStringBuilder.ensureCapacityInternal (AbstractStringBuilder.java:241)
    java.lang.AbstractStringBuilder.append (AbstractStringBuilder.java:586)
    java.lang.StringBuffer.append (StringBuffer.java:313)
    java.io.StringWriter.write (StringWriter.java:106)
    cljs.compiler/emits (compiler.cljc:219)
    cljs.compiler/emits (compiler.cljc:206)
    cljs.compiler/emits (compiler.cljc:229)
    cljs.compiler/emits (compiler.cljc:206)
    cljs.compiler/emit-vector (compiler.cljc:560)
    cljs.compiler/emit-vector (compiler.cljc:555)
    cljs.compiler/fn--4192 (compiler.cljc:567)
👉 App server available at http://0.0.0.0:8080

teodorlu: It appears to be working fine when I set -Xmx1G.
:jvm-opts ["-Xss2m" "-Xmx1G" ...]

dustingetz: I believe that's a compile-time error, -Xss2m fixes it for us (the compiler uses a lot of stack - presumably will be less when we optimize it soon). Please confirm that -Xmx1g is needed as well? That I have not seen before (edited)

teodorlu: this is weird - I'm seeing a bit of different behavior.
Observations:
When I've already been able to compile the app once, I'm not able to reproduce any compile errors. But when I clj -A:dev -X user/main after a clean git clone or after I've removed untracked files (git clean -fxd), I see errors.
But after git clean -fxd, I see errors. (I need to run git clean -fxd between each time I test).
Neither opt: StackoverflowError.
Only -Xss2m: OutOfMemoryError Java heap space
Only -Xmx1G: Working
Both -Xss2m and -Xmx1G: Working.
So on my system, -Xss2m doesn't appear to have any effect other than giving me different errors, whereas -Xmx1G appears to solve eveything.

Saw happen today in electric-fiddle with too much e/def at top level

this has been seen today (post IC release) by wei

25.77 shadow-cljs - server version: 2.26.2 running at http://localhost:9630/
25.77 shadow-cljs - nREPL server started on port 7888
25.77 [:prod] Compiling ...
97.94 Exception in thread "async-dispatch-8" java.lang.OutOfMemoryError: Java heap space

Second user reports:

I was having this issue yesterday while compiling the client code (shadow-cljs build step). The issue only happened while building inside the docker container during github workflow I couldn’t replicate on my mac