I'm running some stress tests that require a bunch of jframes to be created, and am running into some serious performance issues after ~25 jframes have been created, it starts to take 5-10 seconds per JFrame to create and dispose, which seems terribly outside of expectations.
Tested on a Macbook Pro running Mojave and Java jdk1.8.0_111
fun main(args: Array<String>) {
fun createFrame(): JFrame {
val frame = JFrame("FrameDemo")
System.out.println("created frame" + frame)
frame.setSize(1000, 600)
frame.isVisible = true
return frame
}
val frames = mutableListOf<JFrame>()
for(i in 0..35) SwingUtilities.invokeAndWait { frames.add(createFrame()) }
for(i in 1..50) {
val start = System.currentTimeMillis()
var frame: JFrame? = null
SwingUtilities.invokeAndWait {
frame = createFrame()
}
System.out.println("started in ${System.currentTimeMillis()-start}")
SwingUtilities.invokeAndWait {
frame!!.dispose()
}
System.out.println("done in ${System.currentTimeMillis()-start}")
}
for(frame in frames)
SwingUtilities.invokeAndWait { frame.dispose() }
}
The first loop creates a bunch of JFrames just so they exist, and the second loop creates+destroys jframes to collect some performance numbers.
If I comment out the first loop, then each jframe takes O(100ms) to create+destroy. With the first loop, the same create+destroy operation takes two orders of magnitude longer O(10000ms).
At first, I thought maybe I was running out of memory, but there doesn't appear to be any GC/CPU pressure and increasing -Xmx
dosen't appear to improve the situation. None of my other metrics (eg. iops) seem impacted, but my whole machine does feel slow as a snail.
What is going on here? Other non-swing applications (sublime, chrome, etc) seem able to have many large windows open no problem, so I don't think it is anything inherent to the machine. Is there a setting that will allow me to avoid the performance cliff?