⚡️ Speed up method LuaInstance.getLuaValue by 7%#102
Open
codeflash-ai[bot] wants to merge 1 commit intofix/add-mockito-test-dependencyfrom
Open
⚡️ Speed up method LuaInstance.getLuaValue by 7%#102codeflash-ai[bot] wants to merge 1 commit intofix/add-mockito-test-dependencyfrom
LuaInstance.getLuaValue by 7%#102codeflash-ai[bot] wants to merge 1 commit intofix/add-mockito-test-dependencyfrom
Conversation
This change cuts getLuaValue runtime from 237µs to 221µs (≈7% speedup) by replacing repeated instanceof checks with a single cls = obj.getClass() and fast exact-class comparisons (cls == X.class) and by switching wrapper-object handling to primitive accessors (intValue(), longValue(), etc.). Exact-class checks avoid repeated virtual instanceof/type resolution and are significantly cheaper for final types and arrays, and hoisting getClass eliminates duplicated class lookup on the hot path. Using the primitive accessors removes extra boxing/unboxing and redundant casts, allowing the LuaInteger/LuaDouble valueOf overloads to be invoked with primitives instead of re-wrapping objects. There is no behavioral change for final JVM wrapper types (Integer, Long, Double, Float, Boolean) or byte[]; the only trade-off is a small, intentional narrowing of checks to exact classes (which is safe here) and a minor increase in code-specificity for a measurable per-call speed gain.
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.
📄 7% (0.07x) speedup for
LuaInstance.getLuaValueinclient/src/com/aerospike/client/lua/LuaInstance.java⏱️ Runtime :
237 microseconds→221 microseconds(best of149runs)📝 Explanation and details
This change cuts getLuaValue runtime from 237µs to 221µs (≈7% speedup) by replacing repeated instanceof checks with a single cls = obj.getClass() and fast exact-class comparisons (cls == X.class) and by switching wrapper-object handling to primitive accessors (intValue(), longValue(), etc.). Exact-class checks avoid repeated virtual instanceof/type resolution and are significantly cheaper for final types and arrays, and hoisting getClass eliminates duplicated class lookup on the hot path. Using the primitive accessors removes extra boxing/unboxing and redundant casts, allowing the LuaInteger/LuaDouble valueOf overloads to be invoked with primitives instead of re-wrapping objects. There is no behavioral change for final JVM wrapper types (Integer, Long, Double, Float, Boolean) or byte[]; the only trade-off is a small, intentional narrowing of checks to exact classes (which is safe here) and a minor increase in code-specificity for a measurable per-call speed gain.
✅ Correctness verification report:
🌀 Click to see Generated Regression Tests
To edit these changes
git checkout codeflash/optimize-LuaInstance.getLuaValue-mmbslsyqand push.