⚡️ Speed up method LuaUnpacker.getString by 5%#105
Open
codeflash-ai[bot] wants to merge 1 commit intofix/add-mockito-test-dependencyfrom
Open
⚡️ Speed up method LuaUnpacker.getString by 5%#105codeflash-ai[bot] wants to merge 1 commit intofix/add-mockito-test-dependencyfrom
LuaUnpacker.getString by 5%#105codeflash-ai[bot] wants to merge 1 commit intofix/add-mockito-test-dependencyfrom
Conversation
A small per-instance direct-mapped string cache was added to LuaUnpacker (256-entry power-of-two slot arrays), producing a ~5% end-to-end speedup (426 µs → 405 µs) by avoiding repeated LuaString allocations for recently seen values. The key insight is that many unpacked strings are repeated in hot paths, so computing a cheap hash/index and doing a single equals check is much cheaper than always calling LuaString.valueOf and allocating a new object, which reduces object churn and GC pressure. Trade-offs are a modest per-Unpacker memory cost (two small reference arrays) and the possibility of slot thrashing under extremely high-uniqueness workloads where the direct-mapped cache yields little benefit; the cache is instance-local and lock-free to avoid synchronization overhead. Null inputs are still passed through to LuaString.valueOf to retain the original exception/return semantics.
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.
📄 5% (0.05x) speedup for
LuaUnpacker.getStringinclient/src/com/aerospike/client/lua/LuaUnpacker.java⏱️ Runtime :
426 microseconds→405 microseconds(best of169runs)📝 Explanation and details
A small per-instance direct-mapped string cache was added to LuaUnpacker (256-entry power-of-two slot arrays), producing a ~5% end-to-end speedup (426 µs → 405 µs) by avoiding repeated LuaString allocations for recently seen values. The key insight is that many unpacked strings are repeated in hot paths, so computing a cheap hash/index and doing a single equals check is much cheaper than always calling LuaString.valueOf and allocating a new object, which reduces object churn and GC pressure. Trade-offs are a modest per-Unpacker memory cost (two small reference arrays) and the possibility of slot thrashing under extremely high-uniqueness workloads where the direct-mapped cache yields little benefit; the cache is instance-local and lock-free to avoid synchronization overhead. Null inputs are still passed through to LuaString.valueOf to retain the original exception/return semantics.
✅ Correctness verification report:
🌀 Click to see Generated Regression Tests
To edit these changes
git checkout codeflash/optimize-LuaUnpacker.getString-mmc7voetand push.