korlibs / korge

KorGE Game Engine. Multiplatform Kotlin Game Engine
https://korge.org/
Other
2.57k stars 125 forks source link

macOS JVM Stuttering/Lags #374

Open ghost opened 3 years ago

ghost commented 3 years ago

KorGE version: 2.1.1.6 IntelliJ Version: 2021.1.2 Operating System: macOS Big Sur Beta 11.5 - Intel CPU

I found that using JVM on macOS is causing stuttering/lagging with a basic cube moving around the screen. I've tested the same code on a Windows machine and everything works fine without any performance issues. Native and JS on macOS works fine and has zero performance issues, no lagging or stuttering which to me sounds like a macOS JVM performance probem.

Please see two videos from two different operating systems: macOS Windows

As you can see on the videos, macOS is clearly stuttering with its movements while Windows is smooth 60FPS. Both look exactly the same even on recording and both also were recorded at 60FPS.

A very simple and primitive code I've used (I'm still a beginner to Kotlin/KorGE so bear with me.)


import com.soywiz.klock.milliseconds
import com.soywiz.korev.Key
import com.soywiz.korge.*
import com.soywiz.korge.view.*
import com.soywiz.korim.color.Colors

suspend fun main() = Korge(width = 512, height = 512, bgcolor = Colors["#2b2b2b"]) {
    var boxy = solidRect(20,20, Colors.WHITE) {
        position(256,256)
    }
    val input = views.input.keys
    addChild(boxy)
    boxy.addUpdater { time ->
        val scale = time / 16.milliseconds
        if (input[Key.LEFT]) x -= 3 * scale
        if (input[Key.RIGHT]) x += 3 * scale
        if (input[Key.UP]) y -= 3 * scale
        if (input[Key.DOWN]) y += 3 * scale
    }
}
davjhan commented 2 years ago

I'm seeing this issue as well.

Tried with JDK 1.8, 11. On MacOS.

With a seemingly simple program (1 shape moving around), I see a slight but noticeable stutter every ~10 seconds.

When I bring the debugger up, the tiny FPS marker in the corner drops from 120FPS to 50FPS when this happens.

Most likely has to do with garbage collection?

soywiz commented 2 years ago

I think GC should be similar in Windows and Mac. So might be related to vsync or something. Not sure. Will investigate