[minor size decrease] Force autorelease to free stuff inline.#43188
[minor size decrease] Force autorelease to free stuff inline.#43188andy31415 wants to merge 2 commits intoproject-chip:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds compiler hints to force inlining of the destructor and Release() method in the AutoRelease template class to reduce code size on embedded targets like STM32. The change leverages the compiler's ability to optimize out function calls when the underlying Release() operation is simple.
Changes:
- Added
__attribute__((always_inline))to AutoRelease destructor to force inline compilation - Added
__attribute__((always_inline))to AutoRelease::Release() method for the same optimization
There was a problem hiding this comment.
Code Review
The pull request introduces __attribute__((always_inline)) to the AutoRelease destructor and Release method. This change aims to force the compiler to inline these functions, which the author has verified leads to a minor decrease in flash size on stm32. This is a targeted optimization to improve code efficiency, and given the context of embedded development, such compiler-specific attributes are often used for performance gains. The use of __attribute__ aligns with existing practices in the codebase, as seen in CodeUtils.h.
|
PR #43188: Size comparison from 4dbe59f to cfe0fbb Full report (26 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, nxp, psoc6, qpg, realtek, stm32)
|
|
PR #43188: Size comparison from 8f0e573 to d5001c2 Full report (35 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, nrfconnect, nxp, psoc6, qpg, realtek, stm32, telink)
|
Summary
When testing compile output for stm32, I found that AutoRelease always generates ::Release functions, which seem to bloat code since most code can reason out to only be a final "free".
Testing
Trivial force compiler to always inline these, resulting in minor flash decreases.
Locally stm32 light saves 56 bytes of text.