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

Fix: Save flash by not inlining SubscriptionInterval::copy() #23395

Merged
merged 1 commit into from
Jul 12, 2024

Conversation

MaEtUgR
Copy link
Member

@MaEtUgR MaEtUgR commented Jul 12, 2024

Solved Problem

When porting the fix from #23384 to 1.15 with #23392 I saw that it uses 2.5 kilobytes more flash which is totally unexpected.

Big thanks to @niklaut who decompiled the binary and found that the unexpected impact comes from inlining the functions everywhere.

Solution

Move updated(), update(), copy() from SubscriptionInterval into a separate cpp file such that they are not inlined everywhere.
Saves 17.3 kilobytes of flash 😮

Changelog Entry

Fix: Save flash memory by not inlining SubscriptionInterval::copy()

Alternatives

Disadvantage is probably slightly more run time but I'd assume it's not worth that much flash 👀

Test coverage

I'm testing this now.

Context

image

Copy link
Member

@dagar dagar left a comment

Choose a reason for hiding this comment

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

Nice one!

@dagar
Copy link
Member

dagar commented Jul 12, 2024

As a quick check take a look at top before and after on the same board/config.

@MaEtUgR
Copy link
Member Author

MaEtUgR commented Jul 12, 2024

As a quick check take a look at top before and after on the same board/config.

ok, doing that.

@MaEtUgR
Copy link
Member Author

MaEtUgR commented Jul 12, 2024

@dagar ok, I tested two boards with logging on SD card started.
It's not super scientific but I don't see much of a difference.
v6x with random configuration:
before:
v6x_without
after:
v6x_with

v4 with standard VTOL config:
before:
v4_vtol_without
after:
v4_vtol_with

@dakejahl
Copy link
Contributor

epic! I wonder how much more flash is out there waiting to be saved... 🤑

@MaEtUgR MaEtUgR merged commit e2b3145 into main Jul 12, 2024
94 checks passed
@MaEtUgR MaEtUgR deleted the maetugr/fix-subscription-interval-flash-usage branch July 12, 2024 21:26
@MaEtUgR
Copy link
Member Author

MaEtUgR commented Jul 15, 2024

For completeness, I made another presumably close to worst case CPU load test: Original Pixracer with standard VTOL 1002 loaded and this time enabled all the logging options from SDLOG_PROFILE:
sdlog
Ran the logger (while not armed like before) and the CPU load increased by ~1.56%

Before:
1 15 v4 all log_inline

After:
1 15 v4 all log

@dagar
Copy link
Member

dagar commented Jul 16, 2024

epic! I wonder how much more flash is out there waiting to be saved... 🤑

Quite a lot, but at some point there will be performance tradeoffs. Take a look at bloaty, you can use it to see things like code size per file, symbol, or even how much template instantiations cost.
https://github.com/google/bloaty/blob/main/doc/using.md

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