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

[Photon] Memory usage optimizations #1635

Merged
merged 1 commit into from Dec 13, 2018

Conversation

@sergeuz
Copy link
Member

commented Dec 11, 2018

Problem

The decompression of the WiFi blob firmware, which is performed every time WiFi.on() is called, requires about 10K of heap memory in 0.8.0-rc.11, and such an increased memory usage can pose a problem for user applications.

Solution

  • Tweak miniz to reduce the size of the decompressor context structure (tinfl_decompressor). The fix in this PR reduces the size of the structure from 10 to 5K at the cost of some performance hit. I would appreciate double-checking if the proposed change is safe.
  • Do not reset the network interface on cloud connection errors on the Photon. The previous behavior can be enabled by setting SYSTEM_FLAG_RESET_NETWORK_ON_CLOUD_ERRORS in a user application.

Steps to Test

Flash the following application to a Photon and verify that the amount of free memory doesn't drop below 45K during network connection attempts:

#include "application.h"

SYSTEM_MODE(SEMI_AUTOMATIC)
SYSTEM_THREAD(ENABLED)

namespace {

const Serial1LogHandler logHandler(115200, LOG_LEVEL_WARN, {
    { "app", LOG_LEVEL_ALL }
});

system_tick_t lastMillis = 0;
bool wifiOn = false;

} // namespace

void setup() {
    Log.info("setup(): %u", (unsigned)System.freeMemory());
    lastMillis = millis();
}

void loop() {
    if (millis() - lastMillis >= 100) {
        Log.info("loop(): %u", (unsigned)System.freeMemory());
        lastMillis = millis();
    }
    if (millis() > 3000 && !wifiOn) {
        Log.info("WiFi.on()");
        WiFi.on();
        wifiOn = true;
    }
}

References


Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • (N/A) Added documentation
  • Added to CHANGELOG.md after merging (add links to docs and issues)
@@ -73,7 +73,11 @@ volatile uint8_t systemFlags[SYSTEM_FLAG_MAX] = {
0, // SYSTEM_FLAG_STARTUP_SAFE_LISTEN_MODE,
0, // SYSTEM_FLAG_SETUP_OVER_SERIAL1
1, // SYSTEM_FLAG_PUBLISH_RESET_INFO
#if PLATFORM_ID == PLATFORM_PHOTON_PRODUCTION

This comment has been minimized.

Copy link
@avtolstoy

avtolstoy Dec 11, 2018

Member

|| PLATFORM_ID == PLATFORM_P1 ?

@sergeuz sergeuz force-pushed the fix/wifi_on_mem branch from e61ca8d to b10a7ff Dec 11, 2018

@sergeuz sergeuz force-pushed the fix/wifi_on_mem branch from b10a7ff to fa2feef Dec 11, 2018

@technobly

This comment has been minimized.

Copy link
Member

commented Dec 11, 2018

Is the performance hit that it doesn't compress the object as much or does it take longer to uncompress? I'm curious what the numbers are.

@sergeuz

This comment has been minimized.

Copy link
Member Author

commented Dec 11, 2018

Is the performance hit that it doesn't compress the object as much or does it take longer to uncompress? I'm curious what the numbers are.

The decompression might have become slower. I don't have the numbers, but the difference is not noticeable

@sergeuz sergeuz force-pushed the fix/wifi_on_mem branch from fa2feef to df1ab05 Dec 13, 2018

@sergeuz sergeuz merged commit fd00e46 into develop Dec 13, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@sergeuz sergeuz deleted the fix/wifi_on_mem branch Dec 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.