From db6dbb04d3ed3bab98808319390006d66a5b5c43 Mon Sep 17 00:00:00 2001 From: Pathompum Jirakarnpaisan <107536914+Saannddy@users.noreply.github.com> Date: Thu, 12 Mar 2026 03:43:05 +0700 Subject: [PATCH] perf: Optimize Java compilation and execution startup by adding JVM arguments to `javac` and `java` commands. --- src/core/executor.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/core/executor.py b/src/core/executor.py index 3513120..b791ef1 100644 --- a/src/core/executor.py +++ b/src/core/executor.py @@ -122,13 +122,28 @@ def _run_java(code, tests=None, timeout=None): f.write(code) try: - comp = subprocess.run(["javac", src, "-d", d], capture_output=True, text=True, timeout=max(timeout, 10), cwd=d) + # Added JVM args to javac to speed up its own startup time + comp = subprocess.run([ + "javac", + "-J-XX:+TieredCompilation", + "-J-XX:TieredStopAtLevel=1", + src, "-d", d + ], capture_output=True, text=True, timeout=max(timeout, 10), cwd=d) if comp.returncode: return {"status": "incorrect", "message": "Compilation failed", "compiler_output": comp.stderr} except subprocess.TimeoutExpired: return {"status": "error", "message": "Compilation timed out"} - cmd = ["java", "-cp", d, f"-Xmx{MAX_MEMORY_MB}m", class_name] + # Optimized JVM startup arguments + cmd = [ + "java", + "-cp", d, + f"-Xmx{MAX_MEMORY_MB}m", + "-XX:+TieredCompilation", + "-XX:TieredStopAtLevel=1", + "-noverify", + class_name + ] if tests is None: try: res = subprocess.run(