Skip to content

Improve Lightlist performance#2784

Draft
8Keep wants to merge 2 commits into
jMonkeyEngine:masterfrom
8Keep:lightlist-hotpath-copies
Draft

Improve Lightlist performance#2784
8Keep wants to merge 2 commits into
jMonkeyEngine:masterfrom
8Keep:lightlist-hotpath-copies

Conversation

@8Keep
Copy link
Copy Markdown
Contributor

@8Keep 8Keep commented May 17, 2026

Stack on my jmh harness PR in #2778
So ignore the first commit here

Summary

  • avoid copying and clearing unused retained LightList backing capacity
  • use bulk copy/fill paths for unfiltered world light-list updates
  • keep the retained sort buffer sized to active lights instead of backing-array capacity
  • add focused LightList tests for removal ordering, update ordering/filtering, and sorting after retained capacity
  • Main benefit is from Arrays.fill/etc which have intrinsics with SIMD

Benchmark Results

JMH results from the jme3-core benchmark harness, lower is better:

Before -> After

  • removeFromFront, 256 lights: 0.317 us/op -> 0.036 us/op
  • removeFromMiddle, 256 lights: 0.172 us/op -> 0.031 us/op
  • updateFromLocalAndParent, 256 lights: 0.738 us/op -> 0.195 us/op
  • sortTransformChanged, 256 lights, retained x1024: 94.191 us/op -> 25.909 us/op

Testing

  • ./gradlew :jme3-core:test --tests com.jme3.light.LightListTest :jme3-core:benchmarkClasses

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 introduces the Java Microbenchmark Harness (JMH) to the project, adding a dedicated benchmark source set and several performance tests for bounding volumes, light lists, and geometry lists. In LightList, several methods including remove, clear, sort, and update were optimized using System.arraycopy and Arrays.fill to improve efficiency. Feedback suggests removing the distToOwner array and its associated logic in LightList, as it is currently dead code and not correctly synchronized during element removal.

Comment on lines +140 to 143
int copyLength = listSize - index;
if (copyLength > 0) {
System.arraycopy(list, index + 1, list, index, copyLength);
}
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 distToOwner array is not updated when an element is removed, causing it to become out of sync with the list array. However, distToOwner appears to be dead code (it is written to but never read in the current codebase). Instead of fixing the synchronization by adding more logic to maintain it, the field and its associated logic should be removed entirely to improve maintainability.

References
  1. When an unused parameter is found in a method, first verify if the method is used. If it is unused, consider suggesting its removal as dead code instead of fixing the parameter usage.

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