Improve Lightlist performance#2784
Conversation
There was a problem hiding this comment.
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.
| int copyLength = listSize - index; | ||
| if (copyLength > 0) { | ||
| System.arraycopy(list, index + 1, list, index, copyLength); | ||
| } |
There was a problem hiding this comment.
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
- 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.
Stack on my jmh harness PR in #2778
So ignore the first commit here
Summary
LightListbacking capacityLightListtests for removal ordering, update ordering/filtering, and sorting after retained capacityBenchmark Results
JMH results from the
jme3-corebenchmark harness, lower is better:Before -> After
removeFromFront, 256 lights:0.317 us/op->0.036 us/opremoveFromMiddle, 256 lights:0.172 us/op->0.031 us/opupdateFromLocalAndParent, 256 lights:0.738 us/op->0.195 us/opsortTransformChanged, 256 lights, retained x1024:94.191 us/op->25.909 us/opTesting
./gradlew :jme3-core:test --tests com.jme3.light.LightListTest :jme3-core:benchmarkClasses