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

Coalesce some allocations #3747

Merged
merged 6 commits into from
Jul 3, 2024

Conversation

CookiePLMonster
Copy link
Contributor

@CookiePLMonster CookiePLMonster commented Jul 2, 2024

What's new

This PR coalesces memory allocations done by the firmware in several places by the use of Flexible Array Members, much like it's already done in a few other places in firmware, like Message Queues. The following structures have been modified to use FAM:

  • View - view models now are a single allocation instead of two. Memory footprint - 4 bytes (mutex ptr) + arbitrary (user) view model data.
  • SceneManager - array of AppScene coalesced with SceneManager. Footptint - 12 bytes? + array of scenes (4b each).
  • BufferStream - array of Buffer coalesced with BufferStream. Footprint - 16 bytes + array of buffer streams (16b each).
  • ProtocolDict - array of void* dict coalesced with ProtocolDict. Footptiny - 8 bytes + 4 bytes per dictionary entry.
  • DigitalSequence and DigitalSignal - data coalesced with the corresponding structs.

I verified memory usage in the main menu by rebooting the Flipper, and pressing OK once. Readings from the Release version of FW are as follows:

Before:

>: free
Free heap size: 141136
Total heap size: 185528
Minimum heap size: 137456
Maximum heap block: 141136
Pool free: 1368
Maximum pool block: 1340

>: free_blocks
A 2000C8E0 S 141080

After:

>: free
Free heap size: 141296
Total heap size: 185528
Minimum heap size: 140816
Maximum heap block: 141296
Pool free: 1368
Maximum pool block: 1340

>: free_blocks
A 2000C840 S 141240

I did not add static assets for FAMs because GCC already throws a compilation error if they are not the last member of the struct.

Verification

Verify that the menus work, and that NFC and RFID apps still work as intended.

Checklist (For Reviewer)

  • PR has description of feature/bug or link to Confluence/Jira task
  • Description contains actions to verify feature/bugfix
  • I've built this code, uploaded it to the device and verified feature/bugfix

@skotopes
Copy link
Member

skotopes commented Jul 2, 2024

free make sense only if you remove dolphin animations

@CookiePLMonster
Copy link
Contributor Author

free make sense only if you remove dolphin animations

Done, re-did the tests with the Release version of the FW, and with all animations disabled. Now those readings look very plausible, I expected memory savings close to those readings.

@hedger hedger added the Core+Services HAL, furi & core system services label Jul 2, 2024
Copy link
Member

@hedger hedger left a comment

Choose a reason for hiding this comment

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

./fbt format please

@CookiePLMonster
Copy link
Contributor Author

./fbt format please

Done.

@skotopes skotopes merged commit 7e0849b into flipperdevices:dev Jul 3, 2024
11 checks passed
@CookiePLMonster CookiePLMonster deleted the coalesce-allocation branch July 3, 2024 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core+Services HAL, furi & core system services
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants