<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div dir="ltr" style="font-family: Aptos, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Happy new year!</div>
<div dir="ltr" style="font-family: Aptos, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div dir="ltr" style="font-family: Aptos, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0);">
<span style="font-size: 12pt;">> </span><span style="font-size: 16px; background-color: rgb(255, 255, 255);">For example: a REST API. It has some initialization, port opening, reading configurations,</span></div>
<div dir="ltr" style="font-family: Aptos, Arial, Helvetica, sans-serif; font-size: 16px; color: rgb(0, 0, 0);">
<span style="background-color: rgb(255, 255, 255);">> etc... that run only once. So the code will never be trained. But it always runs at startup,</span></div>
<div dir="ltr" style="font-family: Aptos, Arial, Helvetica, sans-serif; font-size: 16px; color: rgb(0, 0, 0);">
<span style="background-color: rgb(255, 255, 255);">> impacting the time to first response.</span></div>
<div dir="ltr" style="font-family: Aptos, Arial, Helvetica, sans-serif; font-size: 16px; color: rgb(0, 0, 0);">
<span style="background-color: rgb(255, 255, 255);"><br>
</span></div>
<div dir="ltr"><span style="background-color: rgb(255, 255, 255);">Historically, JVMs have looked at run-once code - like the body of <clinit> -  as not being worth compiling as the return on the investment in compile time is too low.  There have always been
 exceptions but even template style jits have avoided run once code.</span></div>
<div dir="ltr"><span style="background-color: rgb(255, 255, 255);"><br>
</span></div>
<div dir="ltr" style="font-family: Aptos, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="background-color: rgb(255, 255, 255);">Can you quantify how much of the applications startup is spent in these run-once methods?</span></div>
<div dir="ltr" style="font-family: Aptos, Arial, Helvetica, sans-serif; font-size: 16px; color: rgb(0, 0, 0);">
<span style="background-color: rgb(255, 255, 255);"><br>
</span></div>
<div dir="ltr" style="font-family: Aptos, Arial, Helvetica, sans-serif; font-size: 16px; color: rgb(0, 0, 0);">
<span style="background-color: rgb(255, 255, 255);">> So, how can I tell Leyden to please compile and cache those functions, even if they are</span></div>
<div dir="ltr" style="font-family: Aptos, Arial, Helvetica, sans-serif; font-size: 16px; color: rgb(0, 0, 0);">
<span style="background-color: rgb(255, 255, 255);">> going to be run just once, even if they are not optimized at all, even if those compilations</span></div>
<div dir="ltr" style="font-family: Aptos, Arial, Helvetica, sans-serif; font-size: 16px; color: rgb(0, 0, 0);">
<span style="background-color: rgb(255, 255, 255);">> can get discarded after a couple of seconds?</span></div>
<div dir="ltr" style="font-family: Aptos, Arial, Helvetica, sans-serif; font-size: 16px; color: rgb(0, 0, 0);">
<span style="background-color: rgb(255, 255, 255);"><br>
</span></div>
<div dir="ltr"><span style="background-color: rgb(255, 255, 255);">Compiling the code isn’t enough.  There’s a lot of work with careful timing required to get the code ready for use before the first invocation.  If we miss that window, then the compiled code
 is just overhead.</span></div>
<div dir="ltr"><span style="background-color: rgb(255, 255, 255);"><br>
</span></div>
<div dir="ltr"><span style="font-size: 16px; background-color: rgb(255, 255, 255);">For
</span><span style="background-color: rgb(255, 255, 255);">“</span><span style="font-size: 16px; background-color: rgb(255, 255, 255);">expensive” or long running single use code, we may be able to precompile with C1 and get out of the interpreter earlier at
 the cost of some coordination overhead to ensure the methods are installed immediately.</span></div>
<div dir="ltr" style="font-size: 16px;"><span style="background-color: rgb(255, 255, 255);"><br>
</span></div>
<div dir="ltr"><span style="background-color: rgb(255, 255, 255);">I think we’d need to understand better where the time is being spent to see why this run once code is slowing down startup.</span></div>
<div dir="ltr"><span style="background-color: rgb(255, 255, 255);"><br>
</span></div>
<div dir="ltr"><span style="background-color: rgb(255, 255, 255);">—</span><span style="font-size: 16px; background-color: rgb(255, 255, 255);">Dan</span></div>
<div dir="ltr" style="font-family: Aptos, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="mail-editor-reference-message-container">
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing"></div>
<div class="ms-outlook-mobile-reference-message skipProofing" style="text-align: left; padding: 3pt 0in 0in; border-width: 1pt medium medium; border-style: solid none none; border-color: rgb(181, 196, 223) currentcolor currentcolor; font-family: Aptos; font-size: 12pt; color: black;">
<b>From: </b>leyden-dev <leyden-dev-retn@openjdk.org> on behalf of María Arias de Reyna Dominguez <mariasde@redhat.com><br>
<b>Date: </b>Tuesday, December 30, 2025 at 4:13 AM<br>
<b>To: </b>leyden-dev <leyden-dev@openjdk.org><br>
<b>Subject: </b>Initialization code that never got trained<br>
<br>
</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing">Happy New Year!</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing"><br>
</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing">I have been doing some experiments with Leyden and realized something: there is some code at startup/initialization that never gets optimized but is impacting on startup and warmup time.</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing"><br>
</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing">This was a realization while doing comparisons with native/graalvm images of the same code.</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing"><br>
</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing">For example: a REST API. It has some initialization, port opening, reading configurations, etc... that run only once. So the code will never be trained. But it always runs at startup, impacting
 the time to first response.</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing"><br>
</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing">Compared to a native image, the native image may not have it optimized, but at least it is already compiled, not interpreted. Therefore, the native image starts faster.</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing"><br>
</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing">So, how can I tell Leyden to please compile and cache those functions, even if they are going to be run just once, even if they are not optimized at all, even if those compilations can
 get discarded after a couple of seconds?</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing"><br>
</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing">Or are we just going to assume that that code, which is impacting startup time, doesn't need to be pre-compiled because we are focusing only on optimizations made by the JVM on runtime?</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing"><br>
</div>
<div dir="ltr" class="gmail_signature">Kind regards,<br>
María Arias de Reyna Domínguez<br>
Senior Software Engineer<br>
She / Her / Hers<br>
<a href="mailto:ariasdereyna@redhat.com" target="_blank" data-outlook-id="dce14828-6669-4d80-ad83-2088c3dc0f92">ariasdereyna@redhat.com</a></div>
</div>
</body>
</html>