perf: enhance StyleCache with reverse index for style lookup#587
Merged
ochedru merged 1 commit intodhatim:masterfrom Feb 28, 2026
Merged
Conversation
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.
When merging styles in Excel workbooks, the code needs to find an existing style by its index. Previously, this was done by searching through all styles one by one (linear search). With many styles, this becomes slow.
Before: O(n) - searches through all styles to find the right one
After: O(1) - uses a hash map to instantly find the style
This change adds a reverse index map that tracks style index style object, allowing instant lookup instead of searching through all styles.
Performance Results
Real-World Scenario Test
=== Real-World Scenario: Many Unique Styles ===
Creating workbook with 2000 unique styles...
Completed in 64 ms
Average: 0.03 ms per style
Before/After Comparison Test
=== Style Cache Performance Comparison ===
Styles in cache: 1000
Merges per style: 10
Total operations: 10000
OLD (O(n) linear search):
Time: 18 ms (1866.02 ns per operation)
NEW (O(1) hash map lookup):
Time: 5 ms (517.61 ns per operation)
Speedup: 3.61x faster
Also you can remove the tests if you want, that is just to show before/after