Skip to content

perf: enhance StyleCache with reverse index for style lookup#587

Merged
ochedru merged 1 commit intodhatim:masterfrom
prathzzzz:style-cache-performance-improvement
Feb 28, 2026
Merged

perf: enhance StyleCache with reverse index for style lookup#587
ochedru merged 1 commit intodhatim:masterfrom
prathzzzz:style-cache-performance-improvement

Conversation

@prathzzzz
Copy link

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

@ochedru ochedru merged commit eb806ad into dhatim:master Feb 28, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants