Post #1480823
2026-04-19 17:01 UTC
Can anyone help with a JVM problem?
I have a very mysterious problem in my application that is caused by the JVM JIT compiler. And I'm hoping that maybe there's an expert here who might have an idea.
At a high level, this is what happens: I run some code, let's call it A (I'll explain the details below) and the execution time is 0.5 seconds. After that, I then run function B, which does almost the same thing (same as A plus another function call) and execution time is over 2 seconds (which is much more than expected). I run function A again, and the time taken is still 0.5 seconds.
I then restart the JVM and now begin by running function B. This now takes 0.55 seconds (which is what I expect). I then run function A and now it takes 2 seconds. Running B again gives me 0.55 seconds.
So the order in which the functions are called affects the performance. And it affects it by a lot. The first function called after the system is started always runs faster.
And no, this is not a GC issue. These functions do very few menory allocations. They're tight loops computing sums of number sequences.
In practice, the functions are not regular Java functions. They are Kap functions running in the JVM version of the Kap interpreter. But it all boils down to Java bytecode in the end. Note that the Kap runtime doesn't do any magic byte code tricks, so it should just be regular byte code from the point of view of analysing this issue.
Also, when running the Kap javascript or native implementations, this problem doesn't occur, so it's definitely a JVM issue.
Does anyone have any idea where to begin troubleshooting a problem like this? I looked into the JIT compiler log, but there's a lot in there and it's hard to tell what one should be looking for.
#jvm #java #kotlin #programming
Replies (3)
-
@harald@hub.volse.no 2026-04-19 17:12
@Elias Mårtenson Which version of the JVM are you using? You could try to run the test with the JVM flight recorder enabled. That can give you an idea about what's happeing.
-
@jbarop@chaos.social 2026-04-19 17:15
@loke Try running it with -Xint which disables the JIT compiler and check if you get consistent results. If both functions then take equally long, the JIT is confirmed as the cause.
-
@ghost_letters@fosstodon.org 2026-04-19 17:47
@loke I dont know about the Java JIT compiler, but would be curious if something from project Leyden would make it go away (or less varying) https://openjdk.org/projects/leyden/