Skip to content

Reduce flash size of TetrisAI_V2 by 97%#5317

Merged
softhack007 merged 1 commit intowled:mainfrom
gustebeast:wled-gtb-flash-size
Jan 27, 2026
Merged

Reduce flash size of TetrisAI_V2 by 97%#5317
softhack007 merged 1 commit intowled:mainfrom
gustebeast:wled-gtb-flash-size

Conversation

@gustebeast
Copy link
Copy Markdown
Contributor

@gustebeast gustebeast commented Jan 24, 2026

Main branch without Tetris
Flash: [======== ] 79.8% (used 1255301 bytes from 1572864 bytes)

Main branch with Tetris (+196kb)
Flash: [========= ] 92.3% (used 1452049 bytes from 1572864 bytes)

This commit with Tetris (+6kb, 97% less flash)
Flash: [======== ] 80.2% (used 1261625 bytes from 1572864 bytes)

Summary by CodeRabbit

Release Notes

  • Refactor

    • Optimized internal code structure in Tetris AI module by removing unused dependencies and streamlining queue management implementation.
  • Chores

    • Removed a public method from TetrisBag class; verify compatibility if your code relies on queue piece indexing functionality.

✏️ Tip: You can customize this high-level summary in your review settings.

Main branch without Tetris
Flash: [========  ]  79.8% (used 1255301 bytes from 1572864 bytes)

Main branch with Tetris (+196kb)
Flash: [========= ]  92.3% (used 1452049 bytes from 1572864 bytes)

This commit with Tetris (+6kb, 97% less flash)
Flash: [========  ]  80.2% (used 1261625 bytes from 1572864 bytes)
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 24, 2026

Walkthrough

This PR removes unused include dependencies from three header files in the TetrisAI_v2 module and refactors the TetrisBag class by removing a public method overload and replacing std::rotate with a manual loop implementation.

Changes

Cohort / File(s) Summary
Dependency cleanup
usermods/TetrisAI_v2/gridbw.h, usermods/TetrisAI_v2/pieces.h
Removed unused include directives (<iterator> and <iostream> respectively); no logic or API changes.
API and implementation refactoring
usermods/TetrisAI_v2/tetrisbag.h
Removed public method overload void queuePiece(uint8_t idx), refactored void queuePiece() to use manual loop instead of std::rotate, and removed <algorithm> include.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the PR—reducing flash usage of the TetrisAI_V2 module through dependency removal and code optimization.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@usermods/TetrisAI_v2/tetrisbag.h`:
- Around line 86-92: queuePiece() can underflow when the queue is empty because
piecesQueue.size() - 1 will wrap and cause out-of-range access; fix by returning
early (or asserting) when the queue is empty (e.g., check piecesQueue.empty() or
queueLength == 0) before shifting elements and assigning getNextPiece(),
ensuring you guard the piecesQueue access in queuePiece().

Comment thread usermods/TetrisAI_v2/tetrisbag.h
Copy link
Copy Markdown
Member

@Aircoookie Aircoookie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you! Awesome that we can achieve such huge flash savings by avoiding these imports

@softhack007 softhack007 merged commit 9683896 into wled:main Jan 27, 2026
252 checks 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.

3 participants