TASEmulators / BizHawk

BizHawk is a multi-system emulator written in C#. BizHawk provides nice features for casual gamers such as full screen, and joypad support in addition to full rerecording and debugging tools for all system cores.
http://tasvideos.org/BizHawk.html
Other
2.2k stars 385 forks source link

Clearing frames is surprisingly non-performant #3969

Closed RetroEdit closed 4 months ago

RetroEdit commented 4 months ago

Background: tastudio.submitclearframes(int frame, int number) followed by tastudio.applyinputchanges() is a set of operations that can be applied in Lua.

However, it appears to be too inefficient to actually be that useful in practice. Take for instance some tests I did in the latest dev build using Gambatte with unthrottled clock clearing the current frame every frame in a new movie and having tastudio.submitinputchange run every other frame.

There is an alternate solution that's far more efficient: turning on recording mode and using joypad.set to press the buttons.

In practice, I end up using recording mode for the major efficiency gain, but it's not necessarily my favorite, since having recording mode accidentally toggled on can be destructive. It seems to me that clearing a single frame should be comparable speed since it's an equivalent operation.

Additional note

I found an old note I wrote down saying manually clearing 20,000 frames in BizHawk 2.9.1 took 10 seconds, so clearing multiple frames also seems excessively slow. But even clearing a single frame has a surprising performance hit.

Testing scripts

These are the Lua scripts I used for testing: clear_frames_test.zip

Host env.

(it's probably inefficient on versions prior to 2.8.0, but I haven't had as much experience using input entry scripts on those versions)

Morilli commented 4 months ago

To be fair, this sems to be mostly your own fault: #1799

If the logic were clever, it'd skip the RefreshDialog call when appropriate. I'll try to do that in the least offensive way, but it's not easy to ensure the behavior stays the same.

Morilli commented 4 months ago

Note: skipping the check in https://github.com/TASEmulators/BizHawk/blob/5fd3575c0f928c07d53b3903647fb4bae2d061a1/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs#L192 would allow using a single applyinputchanges call instead of requiring two... but it breaks the script completely. I have no idea why, it's probably some bullshit with invalidating greenzone.