Skip to main content

2 posts tagged with "lessons learned"

Things I've learned about programming the hard way.

View All Tags

JDK bug report

Hey everyone,

A few days ago, I watched a YouTube video on pixel snapping effects in 2D games, which are even present in highly popular games. I was curious if ScrewBox also suffers from these issues. Upon closer inspection, I noticed some strange effects on the edges of the game window. The effects were rarely visible and I didn't notice them before because they only appeare next to the screen edges.

After investigating for a few hours, I identified the error as the metal render on MacOs. However, I couldn’t find any workaround other than switching to OpenGL rendering, which is significantly slower on Mac because it’s outdated.

I shared this Java bug with a colleague, and she expressed indifference if it wasn’t officially reported. Of course, she was right, so I invested a few more hours to report the bug, which was reviewed and now is officially accepted as JDK-8371679.

So you could say I found a genuine edge case bug in the JDK.😏

Lessons on performance

I must have spends hundreds of hours on enhancing the performance of ScrewBox, but today I learned that I have missed some pretty obvious basics.

For context: I am working on a MacOs machine and when I started graphic programming with Java I learned that there was a pretty unavoidable system property that must be set to avoid software rendering and therefore low fps values: sun.java2d.opengl=true. When I discovered the option this massively enhanced the speed of apps created with ScrewBox.

When JDK 21 added support for the Metal API on MacOs I was quite disappointed that this didn't enhance the performance at all. But I simply missed removing the outdated property.

ScrewBox warns you, when you are not using the opengl setting and my local run configurations already packed these settings so I didn't question this after so many hours getting used to enforce this setting.

Today I discovered that removing the setting allows the JDK on MacOs to default to the Metal API and therefore push the performance from 800 to 1000 fps in one app and from 8000 to 11000 fps in another simpler one.

Version 3.8.0 removed the unnecessary warning on MacOs and automatically defaults to OpenGl on Windows machines. There is no longer a need to specify any JVM start parameters when working on Windows.