Skip to content

Add JMH benchmark harness#2778

Draft
8Keep wants to merge 1 commit into
jMonkeyEngine:masterfrom
8Keep:jmh-benchmark-harness
Draft

Add JMH benchmark harness#2778
8Keep wants to merge 1 commit into
jMonkeyEngine:masterfrom
8Keep:jmh-benchmark-harness

Conversation

@8Keep
Copy link
Copy Markdown
Contributor

@8Keep 8Keep commented May 16, 2026

A jmh benchmark system could be pretty helpful when trying to optimize the engine. I'm adding a few sample tests here.

Right now, nothing is set up to run in CI, but we could do that at some point. It might be a bit flaky because the CI machine and load can vary... so I'm not sure we want to try to do that.

Test with

./gradlew :jme3-core:jmh

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request integrates JMH benchmarking into the jme3-core module, establishing the build infrastructure and adding benchmarks for bounding volumes, light lists, and geometry lists. Feedback suggests expanding the benchmark source set's classpath to include main runtime and test output dependencies to prevent potential compilation or runtime errors. Additionally, a more robust modulo-based offset calculation was recommended for the light list sorting benchmark to support arbitrary light counts.

Comment thread jme3-core/build.gradle Outdated
Comment on lines +20 to +21
compileClasspath += sourceSets.main.output
runtimeClasspath += output + compileClasspath
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The benchmark source set configuration is currently missing the dependencies of the main source set and the output of the test source set. This will likely cause compilation or runtime errors if the benchmarks depend on external libraries or test utilities (like NullComparator). Using main.runtimeClasspath and test.output ensures a complete classpath for the benchmarks.

        compileClasspath += sourceSets.main.runtimeClasspath + sourceSets.test.output
        runtimeClasspath += sourceSets.main.runtimeClasspath + sourceSets.test.output

@Setup(Level.Invocation)
public void setupInvocation() {
list.clear();
int offset = invocation++ & (lightCount - 1);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using a bitwise AND with lightCount - 1 to calculate the offset only works correctly when lightCount is a power of two. While the current parameters (8, 64, 256) are powers of two, this approach is fragile and will break if non-power-of-two sizes are added in the future. Using the modulo operator is more robust.

Suggested change
int offset = invocation++ & (lightCount - 1);
int offset = (invocation++ & Integer.MAX_VALUE) % lightCount;

@8Keep 8Keep force-pushed the jmh-benchmark-harness branch from 85d9391 to cc0750d Compare May 16, 2026 09:15
@github-actions
Copy link
Copy Markdown

🖼️ Screenshot tests have failed.

The purpose of these tests is to ensure that changes introduced in this PR don't break visual features. They are visual unit tests.

📄 Where to find the report:

⚠️ If you didn't expect to change anything visual:
Fix your changes so the screenshot tests pass.

If you did mean to change things:
Review the replacement images in jme3-screenshot-tests/build/changed-images to make sure they really are improvements and then replace and commit the replacement images at jme3-screenshot-tests/src/test/resources.

If you are creating entirely new tests:
Find the new images in jme3-screenshot-tests/build/changed-images and commit the new images at jme3-screenshot-tests/src/test/resources.

Note; it is very important that the committed reference images are created on the build pipeline, locally created images are not reliable. Similarly tests will fail locally but you can look at the report to check they are "visually similar".

See https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-screenshot-tests/README.md for more information

Contact @richardTingle (aka richtea) for guidance if required

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant