perf: Optimize SWAP and ROT operations to O(1)#556
Draft
Jim8y wants to merge 6 commits intoneo-project:masterfrom
Draft
perf: Optimize SWAP and ROT operations to O(1)#556Jim8y wants to merge 6 commits intoneo-project:masterfrom
Jim8y wants to merge 6 commits intoneo-project:masterfrom
Conversation
- Add slot bounds checks and stack-pop slot constructor - Add optimization benchmarks for slot operations - Add NewItems benchmarks
- Remove redundant null check for engine (caller responsibility) - Combine pop and AddStackReference into single loop - Remove unnecessary temporary variable
- Add EvaluationStack.Swap() method for in-place element swapping - SWAP now uses direct array swap instead of Remove()+Push() - ROT now uses two swaps instead of Remove()+Push() - No reference counting changes needed (items stay on stack) Performance improvement: - SWAP: O(n) -> O(1), ~70-130ns constant time regardless of stack depth - ROT: O(n) -> O(1), uses two O(1) swaps All 136 unit tests pass.
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.
Summary
Optimize SWAP and ROT stack operations from O(n) to O(1) complexity.
Changes
EvaluationStack.Swap(int index1, int index2)method for direct element exchangeSwap_Executeto use new O(1) swap methodRot_Executeto use two swap calls instead of Remove+PushPerformance
SWAP time is now constant regardless of stack depth.
Testing
All 136 unit tests pass.