chrismaltby / gb-studio

A quick and easy to use drag and drop retro game creator for your favourite handheld video game system
https://www.gbstudio.dev
MIT License
8.38k stars 465 forks source link

Attached scripts use significantly more CPU in 4.0 than 3.2 #1478

Open becomingplural opened 1 month ago

becomingplural commented 1 month ago

Attached scripts (ie. Attach Script to Button) are using significantly more CPU when the same project is recreated or ported from 3.2. I am using the Emulicious emulator to profile CPU usage, and the increase seems to roughly double the impact of an attached script. The issue has been noted by a number of folks who are using the Platformer+ plugin with the Attach Script to State event, however, the issue appears to be broader.

Steps to reproduce the behavior:

Expected behavior The CPU graph in the 4.0 version should be several % higher than the 3.2 version.

Platform (please complete the following information):

Additional context I'm not sure if this counts as a bug, but when comparing CPU usage, it seems that 4.0 always uses a little more than 3.2. Roughly 2% of the DMG cpu and 1% of the GBColor. I mention that finding here because I've taken it into consideration in comparing the script usage.

chrismaltby commented 1 month ago

Hi @becomingplural (love the profile pic) thanks for raising this, I'm on vacation at the moment but will be looking into this when I get back!

chrismaltby commented 1 month ago

Oh wait are you the creator of Platformer Plus?? I've been meaning to find out how to reach out to you about potentially merging it (and Adventure Plus) with the GB Studio core for a future release and work out ways we could extend the application to better integrate it. If you're interested that is

becomingplural commented 1 month ago

Yup, that's me! Happy to chat sometime, probably the easiest way is to find me in the discord (@hauntology)

chrismaltby commented 4 weeks ago

Hi @becomingplural I spent some time looking into this and following those steps I also saw that version 4 had slightly higher CPU usage. Comparing the code generated by 3.2.1 and 4.0.0 there were a few inefficiencies especially around the code generated for if statements, where it was needlessly storing/reading values to temporary variables. I've managed to fix up the code generation and it's now performing similar to 3.2.1 for me, and in some cases slightly faster.

Debug builds are available here if you'd like to try it out before the next release: https://github.com/chrismaltby/gb-studio/actions/runs/9996147033

Got a few things I want to work on first but I'll be in touch on Discord about the other things when I'm ready to discuss more :-)