Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devirtualize destructors #37708

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Damian-Nordic
Copy link
Contributor

According to the C++ Core Guideline C.35 [1], "A base class destructor should be either public and virtual, or protected and non-virtual".

Matter has a ton of virtual interfaces but objects are very rarely destroyed polymorphically. Hence, the virtual d-tors play no role but bloating the firmware.

Turn some virtual d-tors into non-virtual protected.

[1] https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-dtor-virtual

Testing

This is work in progress. I created this PR to see the reception of this proposal and assess the gain.
So far, I see over 0.5kB flash reduction on nRF lock-app by changing just a few d-tors, so I think it can give us a few K and the effort is pretty mechanical.

According to the C++ Core Guideline C.35 [1], "A base class
destructor should be either public and virtual, or protected
and non-virtual".

Matter has a ton of virtual interfaces but objects are very
rarely destroyed polymorphically. Hence, the virtual d-tors
play no role but bloating the firmware.

Turn some virtual d-tors into non-virtual protected.

[1] https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-dtor-virtual
Copy link

Review changes with  SemanticDiff

Copy link

PR #37708: Size comparison from 0d6b2fb to 234bc62

Full report (1 build for stm32)
platform target config section 0d6b2fb 234bc62 change % change
stm32 light STM32WB5MM-DK FLASH 459800 459268 -532 -0.1
RAM 141472 141456 -16 -0.0

Comment on lines +248 to +249
protected:
~OperationalKeystore() = default;
Copy link
Contributor

Choose a reason for hiding this comment

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

This one NEEDS to remain virtual as it is widely deployed by ecosystems with non-default operations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean that ecosystems destroy this object using the base pointer?

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

Successfully merging this pull request may close these issues.

2 participants