Garmin Instinct 3 tamagotchi port 10x slower than MonkeyDo simulator

Hello everyone, first post in this forum.

I just started developing apps for Garmin watches for fun, and to show some love for the Instinct 3, I decided to port the tamalib Tamagotchi emulator from C to Monkey C and create custom black/white bitmaps to match the retro aesthetic of the MIP display.

Here is the published project if you are interested: https://github.com/Gualor/garmin-gotchi

After fighting with the watchdog timer and tight RAM budget I managed to have something somewhat working fine on the simulator, however, I was pretty disappointed to find out that the app doesn't run smooth at all on the watch when side loading the .prg file in release, on the contrary it is running 10x if not more slower. In addition to this, the watch functions are heavily delayed, such as backlight and other functionalities.

While I know this project is a bit odd to begin with, understanding some internal mechanics of the VM can also help others optimize and use the correct approach when dealing with async and multi-threading in this environment.

The overall architecture goes as follow:

  • GarminGotchiApp - main entry point, here we have all game resources such as the instance of the emulator, implementation of the HAL interface (methods needed by the emulator to be implemented), and a callback function called every 50ms (i understand this is the minimum timer period) that will run as many emulator.step() as possible without causing the watchdog timer to trip.

  • GarminGotchiView - here graphics is drawn and resources such as icons bitmaps are loaded, here again we have a timer with a period of 250ms that will request a screen update, at that point the screen is drawn

  • GarminGotchiDelegate - here button controls are handled using a timer once again (not really needed in this case since button presses are already async) but in any case here button events are queued, and a timer will check for events and issue button presses to the emulator

  • GarminGotchiMenuDelegate - functionalities for saving/loading game using storage APIs

  • tamalib - rewrite of tamalib from C to Monkey C using OOP style and mostly keeping 1:1 (aside few optimizations)

    Any suggestions on how to go about it? Or am i pushing the limits of this port?

    Thank you in advance!