Optimize main.js performance with algorithmic improvements for faster Wordle solving #8
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.
This PR significantly improves the performance of the Wordle solver algorithm in
main.jsby implementing several critical optimizations that reduce computational complexity and eliminate unnecessary operations.Key Performance Improvements
1. Optimized Entropy Calculation (
entrapyArray)The original implementation used multiple array passes with
filter(),reduce(), andmap():Before:
After:
This reduces complexity from O(3n) to O(n) and eliminates temporary array allocations.
2. Enhanced Color Map Generation (
createColourMap)Replaced inefficient nested loops and repeated string operations with a two-pass algorithm using frequency maps:
Before: Multiple iterations through word arrays for each letter position
After: Pre-compute letter frequencies, then process exact matches and wrong positions separately
3. Set-Based Lookups in Word Filtering
Converted expensive
Array.includes()operations to O(1) Set lookups inmakeSuggestionList():4. Eliminated String Conversions
Replaced string-based color map comparisons with direct array comparisons:
Before:
After:
Performance Impact
Testing
All optimizations maintain exact algorithmic correctness and preserve existing function signatures. The solver continues to provide the same high-quality word suggestions based on information theory principles, but with dramatically improved performance.
The Wordle solver now processes word suggestions much faster, especially noticeable when calculating optimal moves from large remaining word lists.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.