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

[RSDK-9344] Use snappy for robot configuration compression #366

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

acmorrow
Copy link
Member

  • Before adding snap: App/part. size: 3,452,128/4,128,767 bytes, 83.61%
  • After adding snap: App/part. size: 3,487,808/4,128,767 bytes, 84.48%

To test, I pasted a well-known large configuration (obtained by looking at the debug expansion of a fragment) into an attribute section of a sensor. Logs say:

I (8390) micro_rdk::esp32::nvs_storage: robot configuration compressed for NVS storage: 6510 bytes before, 3735 bytes after

So a 2,775 byte savings here, which isn't nothing given our NVS size bounds. The choice of snappy was somewhat arbitrary here, in that I tried it and it worked.

@acmorrow acmorrow requested a review from a team as a code owner December 18, 2024 20:20
@acmorrow acmorrow force-pushed the RSDK-9344-compress-robot-config branch from 6f0bd53 to d315660 Compare December 18, 2024 20:22
encoded_cfg.len(),
compressed.len()
);
self.set_blob(NVS_ROBOT_CONFIG_KEY, compressed.into())?;
Copy link
Member Author

Choose a reason for hiding this comment

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

One thing to contemplate here is what it might mean if we ever wanted to change this compression algorithm, or not do compression anymore. What would be the implications for upgrade? OTA?

Ok(())
}

fn get_robot_configuration(&self) -> Result<RobotConfig, Self::Error> {
let robot_config = self.get_blob(NVS_ROBOT_CONFIG_KEY)?;
RobotConfig::decode(&robot_config[..]).map_err(NVSStorageError::NVSValueDecodeError)
let mut decompressed_robot_config = vec![];
Copy link
Member Author

Choose a reason for hiding this comment

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

One thing we could do to harden this here would be that if we fail to decompress the buffer with snappy, that we then try to just feed the raw blob RobotConfig::decode. That'd protect against a situation where you had a non-compressed robot config in NVS, got OTA updated to a version that expected a compressed robot config, and then for some reason when you came back online were unable to reach app and the expectation would be to use the cached config.

@acmorrow acmorrow force-pushed the RSDK-9344-compress-robot-config branch from d315660 to c937107 Compare January 2, 2025 15:28
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.

1 participant