On Fri, 20 Nov 2026 06:50:06 GMT, Jaikiran Pai <[email protected]> wrote:
>> Abstract >> -------- >> >> Most `javac` tool calls are short-lived, and for them the cost of the >> default tiered compilation can outweigh what it gives back. This PR adds a >> simple heuristic to the `javac` launcher: when the **total size** of the >> Java source files to be compiled is below a 2 MiB threshold, the launcher >> adds `-XX:TieredStopAtLevel=1` to the JVM options. On the 375 real-world >> projects we measured, all 148 projects that trigger the heuristic (under 2 >> MiB, compiled with `javac` directly) compile at least 5% faster, with >> speedups up to 56%, and no project regresses by 5% or more. >> >> Background >> ---------- >> >> Tiered compilation is costly for short-lived processes and can make up a >> large part of their wall time. For example, a build of tablesaw [1] (398 >> `.java` files, 1.74 MiB of sources) on an AMD Turin machine, with different >> JVM options: >> >> | JIT mode | 1 CPU | 16 CPUs | >> |------------------------------------------------|-------:|--------:| >> | default (C1 with profiling, then C2) | 23.41s | 8.33s | >> | default, speculative traps disabled (*) | 23.35s | 8.24s | >> | C1 with profiling, no C2 (TieredStopAtLevel=3) | 17.78s | 15.71s | >> | C1 only, no profiling (TieredStopAtLevel=1) | 12.07s | 7.42s | >> >> (*) -XX:PerMethodTrapLimit=0 -XX:PerBytecodeTrapLimit=0 >> -XX:PerMethodSpecTrapLimit=0; deoptimizations drop from 593 to 24 >> at 1 CPU and from 1686 to 59 at 16 CPUs. >> >> We can see that tiered compilation accounts for a large share of the cost. >> It first runs slower, profiled code to collect profiles, then spends CPU >> time on C2, and this pays off only over a long run. A short-lived process >> exits before it does. >> >> `javac` is usually such a process: it compiles a set of sources once and >> exits; it is not a long-running service. And while each `javac` run is >> short, frequent invocations in scripts, CI pipelines, and automated >> workflows (such as AI coding agents working on tasks like SWE-bench [2]) >> make the cumulative wall-time overhead significant. >> >> How to fix it >> ------------- >> >> Users expect a fix that works out of the box. The mechanisms that exist >> today do not provide one for `javac`: >> >> - The AOT cache of Project Leyden [3] can hold loaded classes, profiles and >> compiled code, but it has to be created by a training run, and the JDK does >> not ship one for `javac` currently. >> - The default CDS archive that ships with the JDK contains no `javac` >> classes, and ... > > On a general note, can you confirm that the PR description, comments and the > code in this PR weren't LLM generated and comply with the OpenJDK policy > https://openjdk.org/legal/ai? Hi @jaikiran @lahodaj Thank you both for the feedback. First, regarding to the AI policy, to be honest: English is not my first language, so I used an AI tool to help polish the PR description, commit message, and code comments, and also used an AI code review tool to review the code. I apologize for not following https://openjdk.org/legal/ai strictly, and I will close this PR. On the technical side, I agree with both of your points—putting this kind of heuristic into the launcher introduces coupling and ongoing maintenance cost. As a much simpler alternative, do you think it would be worthwhile to just document `-XX:TieredStopAtLevel=1` in the `java / javac` man page, noting that `-J-XX:TieredStopAtLevel=1` can help speed up short-lived javac tool calls? ------------- PR Comment: https://git.openjdk.org/jdk/pull/33991#issuecomment-7035068046
