Optimize type checking and performance#49
Merged
NiceAndPeter merged 1 commit intomainfrom Nov 21, 2025
Merged
Conversation
Improvements:
1. ltable.cpp:999 - Safer unsigned decrement pattern in hash table search
- Changed from `while (i--)` to `while (i > 0) { i--; }`
- Prevents potential wraparound issues if nodeSize() returns 0
- More explicit loop termination condition
2. funcstate.cpp:238 - Explicit static_cast in variable search
- Extract loop count before loop initialization
- Use static_cast<int> instead of cast_int macro
- Improves code clarity and modern C++ style
Documentation:
- Added comprehensive loop analysis (docs/LOOP_OPTIMIZATION_ANALYSIS.md)
- Analyzed 45+ loop patterns across hot-path files
- Identified type safety improvements and modernization opportunities
Performance:
- Baseline: 4.60s average (range 4.33-4.87s)
- With optimizations: 4.54s average (range 4.24-4.82s)
- Result: 1.3% improvement, well within 3% tolerance
Testing:
- All tests passing ("final OK !!!")
- Zero warnings with -Werror
- Type safety improvements with no performance regression
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.
Improvements:
ltable.cpp:999 - Safer unsigned decrement pattern in hash table search
while (i--)towhile (i > 0) { i--; }funcstate.cpp:238 - Explicit static_cast in variable search
Documentation:
Performance:
Testing: