Skip to content

reduce flash use with switch case and helpers - #5927

Open
DedeHai wants to merge 1 commit into
wled:mainfrom
DedeHai:settings_flashoptimisation
Open

DedeHai wants to merge 1 commit into
wled:mainfrom
DedeHai:settings_flashoptimisation

Conversation

@DedeHai

@DedeHai DedeHai commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

These are pure flash saving measures by optimizing code duplication. The major savings come from using a helper function template, enabling the compiler to optimize.

ESP32 classic shows ~4k of flash saved, on C3 it saves ~2k and on ESP8266 it is less helpful, still saves ~1k.

Summary by CodeRabbit

  • Refactor
    • Configuration storage and settings-page handling have been reorganized. Existing settings, saved values, and settings-page behavior remain unchanged.
    • Usermod array settings continue to accept and store values as before.

@DedeHai DedeHai added the optimization re-working an existing feature to be faster, or use less memory label Oct 22, 2026
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: wled/WLED
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 3cdb510
  • Layers: Repository YAML (base), Repository UI (inherited), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8b9d8c53-7b2f-45bd-b078-13022a529dab
📥 Commits

Reviewing files that changed from the base of the PR and between 3cdb510 and 2c92b04.

📒 Files selected for processing: 2
  • wled00/cfg.cpp
  • wled00/set.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout: 31
  • GitHub Check: wled_build / Build Environments (lolin_s2_mini)
  • GitHub Check: wled_build / Build Environments (esp32s3dev_8MB_opi)
  • GitHub Check: wled_build / Build Environments (esp32c3dev_qio)
  • GitHub Check: wled_build / Build Environments (usermods)
  • GitHub Check: wled_build / Build Environments (esp32s3dev_16MB_opi_hub75)
  • GitHub Check: wled_build / Build Environments (esp32s3_4M_qspi)
  • GitHub Check: wled_build / Build Environments (esp32dev_debug)
  • GitHub Check: wled_build / Build Environments (esp32s3_4M_qspi)
  • GitHub Check: wled_build / Build Environments (esp32c6dev_4MB)
  • GitHub Check: wled_build / Build Environments (esp32s3dev_8MB_none)
  • GitHub Check: wled_build / Build Environments (esp32s3dev_8MB_qspi)
  • GitHub Check: wled_build / Build Environments (esp32s3dev_16MB_opi)
  • GitHub Check: wled_build / Build Environments (esp32dev)
  • GitHub Check: wled_build / Build Environments (esp32p4_16MB)
  • GitHub Check: wled_build / Build Environments (esp32s3dev_4MB_qspi_hub75)
  • GitHub Check: wled_build / Build Environments (esp32_eth_V4)
  • GitHub Check: wled_build / Build Environments (esp32dev_hub75_forum_pinout)
  • GitHub Check: wled_build / Build Environments (esp32c5dev)
  • GitHub Check: wled_build / Build Environments (esp32S3_wroom2)
  • GitHub Check: wled_build / Build Environments (esp32c3dev)
  • GitHub Check: wled_build / Build Environments (esp32c5dev_8MB_qspi)
  • GitHub Check: wled_build / Build Environments (esp32_wrover)
  • GitHub Check: wled_build / Build Environments (esp01_1m_full)
  • GitHub Check: wled_build / Build Environments (esp32dev_V4)
  • GitHub Check: wled_build / Build Environments (esp32_eth)
  • GitHub Check: wled_build / Build Environments (nodemcuv2_compat)
  • GitHub Check: wled_build / Build Environments (esp8266_2m_compat)
  • GitHub Check: wled_build / Build Environments (esp8266_2m)
  • GitHub Check: wled_build / Build Environments (esp01_1m_full_compat)
  • GitHub Check: wled_build / Build Environments (nodemcuv2)
  • GitHub Check: wled_build / Test cdata.js
🧰 Additional context used
📚 Code guidelines: 4
docs/hardening.instructions.md — configured
AGENTS.md — configured
.github/agent-build.instructions.md — auto-discovered
docs/cpp.instructions.md — configured
📓 Path-based instructions: 5
Apply the WLED security hardening rules from docs/hardening.instructions.md, and consult docs/securecode.instructions.md when more details are needed for actionable recommendations.

⚙️ CodeRabbit configuration file

Files:

  • wled00/set.cpp
  • wled00/cfg.cpp
Follow the C++ coding conventions documented in docs/cpp.instructions.md and the general project guidelines in AGENTS.md and .github/copilot-instructions.md.

⚙️ CodeRabbit configuration file

Files:

  • wled00/set.cpp
  • wled00/cfg.cpp
Applicability reference: AGENTS.md: # AGENTS.md — WLED AI Coding Agent & AI Code Review Reference See also: `.github/copilot-instructions.md`, `.github/agent-build.instructions.md`, `docs/cpp.instructions.md`, `docs/web.in...

📄 CodeRabbit inference engine (docs/hardening.instructions.md)

Files:

  • wled00/set.cpp
  • wled00/cfg.cpp
Source excerpt: Follow the existing style in the file you are editing Source excerpt: Avoid unexplained "magic numbers".

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • wled00/set.cpp
  • wled00/cfg.cpp
Applicability reference: AGENTS.md: # AGENTS.md — WLED AI Coding Agent & AI Code Review Reference See also: `.github/copilot-instructions.md`, `.github/agent-build.instructions.md`, `docs/cpp.instructions.md`, `docs/web.instructions.md`, `d...

📄 CodeRabbit inference engine (.github/agent-build.instructions.md)

Files:

  • wled00/set.cpp
  • wled00/cfg.cpp
🔇 Additional comments: 2
wled00/set.cpp: 2

24-24: LGTM!

Also applies to: 26-26, 173-173, 176-176, 426-426, 429-429, 436-436, 439-439, 548-548, 551-551, 641-641, 644-644, 688-688, 691-691, 716-716, 720-720, 851-851, 855-855, 888-888, 890-892

819-825: LGTM!

Walkthrough

Configuration JSON handling now uses local objects for selected deserialization and helper functions for serialization. Settings-page dispatch uses a switch, and usermod array parameters use JsonArray retrieval and append behavior.

Changes

Configuration JSON

Layer / File(s) Summary
Configuration JSON access and serialization
wled00/cfg.cpp
Deserialization reads IR and Alexa settings through local JSON objects. Serialization uses setConfigValue for existing fields; serialized keys and values remain unchanged.

Settings dispatch

Layer / File(s) Summary
Settings-page dispatch and usermod arrays
wled00/set.cpp
Settings-page branches now use switch cases, with a no-op default. Usermod array values are retrieved as a JsonArray, created when null, and appended.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Refactor

Suggested reviewers: softhack007

Merge Risk: ⚪ Minimal · up to 2c92b

The configuration and settings changes are ready to merge after normal checks; no actionable behavior regression remains identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the main changes: using a switch statement and helper functions to reduce flash usage.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@softhack007

Copy link
Copy Markdown
Member

The change from nested if to switch cases was overdue, thanks
If the settings page handlers work, fine for me to merge
👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimization re-working an existing feature to be faster, or use less memory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants