Repository navigation
refactor(fl/gfx): lazy-init rgb_2_rgbw user function via Singleton<T> - #2426
Conversation
Replaces the previous static-init form rgb_2_rgbw_function g_user_function = rgb_2_rgbw_exact; with a Singleton<Rgb2RgbwUserState> wrapper that is lazily constructed on first call to set_rgb_2_rgbw_function() or rgb_2_rgbw_user_function(). Empirical impact (ESP32-S3 Blink, default release): binary 830272 -> 830304 bytes (+32 bytes) rgb_2_rgbw_* family stays in binary (still kept by the runtime switch in pixel_controller.h:613 over rgbw_mode, which references all 5 algorithm functions; the Singleton change only addresses the static init reference) Wins are structural rather than size-related: - no static init order dependency on rgb_2_rgbw_exact - cleaner override pattern (instance().fn = userFn) - matches the singleton pattern already used elsewhere in fl/ Refs #2424. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe PR refactors RGB-to-RGBW conversion function storage from a static global variable to a lazy-initialized singleton pattern. The setter now stores the function pointer directly without eager defaulting, and the getter defers fallback selection to call time. ChangesRGB→RGBW Function State Management
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
Summary
Replaces the static-init form
with a lazily-constructed
fl::Singleton<Rgb2RgbwUserState>wrapper. The Singleton's instance is only constructed on first call toset_rgb_2_rgbw_function()orrgb_2_rgbw_user_function()— never at static init.Refs #2424 (recommended source-level cleanup from cross-TU references analysis).
Empirical impact (be honest)
Measured on
bash compile esp32s3 --examples Blink(default release, current master):.flash.text.flash.rodatargb_2_rgbw_*family present in binaryThis refactor does NOT shrink the binary. The 5
rgb_2_rgbw_*algorithm functions remain in the binary becausepixel_controller.h:613callsrgb_2_rgbw(rgbw_mode, ...)— a runtime switch overrgbw_modethat ODR-uses all 5 algorithm functions regardless of the static-init form. The lazy-init only addresses the static-init reference; the runtime-switch reference is unchanged.The +32 bytes are: Singleton's init-guard variable + the new null-check fallback in
rgb_2_rgbw_user_function.Why merge anyway
Structural improvements that are independent of binary size:
rgb_2_rgbw_exact. The previous form referenced it at static init time; the Singleton form doesn't reference any algorithm function until the first runtime call.Singleton<Rgb2RgbwUserState>::instance().fn = userFnis the same Singleton pattern already used elsewhere infl/(e.g.CFastLED::channels()usesSingleton<vector<ChannelPtr>>).if (func == nullptr)reset semantics inset_rgb_2_rgbw_function— nownullptrsimply means "use the lazy default at call time" with no asymmetry.What this does NOT fix
The actual binary-size win for the rgbw family would require per-mode template dispatch for
loadAndScaleRGBWso the compiler can statically eliminate the unused branches of the runtime switch. That's a larger refactor and out of scope here. Filed for follow-up consideration in #2424.Test plan
bash lint --cppcleanbash test --cpp302/302 passbash compile esp32s3 --examples Blinksucceeds (binary 830,304 bytes)set_rgb_2_rgbw_functionandrgb_2_rgbw_user_functionstill present and callable🤖 Generated with Claude Code
Summary by CodeRabbit