G4lile0 / tinyGS

📡 Open Ground Station Network 🛰
GNU General Public License v3.0
922 stars 175 forks source link

Custom board template repeatedly re-parsed #154

Closed mdkendall closed 1 year ago

mdkendall commented 2 years ago

If a custom board template is entered in the configuration, then ConfigManager::getBoardConfig() calls ConfigManager::parseBoardTemplate() to parse it using ArduinoJson, which is fairly expensive.

But it turns out getBoardConfig() is called a lot. Specifically, checkButton() calls it every time to discover the button pin, and checkButton() is called repeatedly in the main loop.

I set and cleared a GPIO pin inside parseBoardTemplate() and viewed it with a logic analyser. I measured parseBoardTemplate() being called 300 times per second and taking about 380us each time, consuming about 11% of the total CPU power.

parseBoardTemplate

It would be better if getBoardConfig() called parseBoardTemplate() once and cached the result.

4m1g0 commented 1 year ago

Thanks for the detailed description of this problem. It should be fixed now in beta.