⚡️ Speed up method IndexBuffer.createIndexBuffer by 6%#33
Open
codeflash-ai[bot] wants to merge 1 commit intomasterfrom
Open
⚡️ Speed up method IndexBuffer.createIndexBuffer by 6%#33codeflash-ai[bot] wants to merge 1 commit intomasterfrom
IndexBuffer.createIndexBuffer by 6%#33codeflash-ai[bot] wants to merge 1 commit intomasterfrom
Conversation
The optimized code changes the threshold checks from `vertexCount < 128` to `vertexCount <= 256` and from `vertexCount < 65536` to `vertexCount <= 65536`, exploiting the full unsigned range of byte (0–255) and short (0–65535) index types. This reduces unnecessary promotions to wider types: meshes with up to 256 vertices now use 1-byte indices instead of 2-byte shorts, and meshes with exactly 65536 vertices use 2-byte shorts instead of 4-byte ints, cutting memory overhead and improving cache locality. The change also removes a redundant `Math.max(0, vertexCount - 1)` call in the byte-buffer branch and normalizes the `maxIndexValue` calculation across branches. Runtime improved by 6% (421 µs → 395 µs) due to these tighter type selections and the elimination of the branch-dependent max operation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📄 6% (0.06x) speedup for
IndexBuffer.createIndexBufferinjme3-core/src/main/java/com/jme3/scene/mesh/IndexBuffer.java⏱️ Runtime :
421 microseconds→395 microseconds(best of109runs)📝 Explanation and details
The optimized code changes the threshold checks from
vertexCount < 128tovertexCount <= 256and fromvertexCount < 65536tovertexCount <= 65536, exploiting the full unsigned range of byte (0–255) and short (0–65535) index types. This reduces unnecessary promotions to wider types: meshes with up to 256 vertices now use 1-byte indices instead of 2-byte shorts, and meshes with exactly 65536 vertices use 2-byte shorts instead of 4-byte ints, cutting memory overhead and improving cache locality. The change also removes a redundantMath.max(0, vertexCount - 1)call in the byte-buffer branch and normalizes themaxIndexValuecalculation across branches. Runtime improved by 6% (421 µs → 395 µs) due to these tighter type selections and the elimination of the branch-dependent max operation.✅ Correctness verification report:
🌀 Click to see Generated Regression Tests
To edit these changes
git checkout codeflash/optimize-IndexBuffer.createIndexBuffer-mnblrltkand push.