From 396e8763207dbab3bf2b7b10349125ebcbd41dff Mon Sep 17 00:00:00 2001 From: Morilli <35152647+Morilli@users.noreply.github.com> Date: Sun, 23 Apr 2023 00:09:28 +0200 Subject: [PATCH] Optimize TAStudio column drawing by caching PlayerNumber for each column name TAStudio previously called `PlayerNumber(...)` for each visible cell with the column's name, only to determine whether its player number is odd or even. Because that function uses regex and is potentially called extremely often, this had a noticable impact on fps. I've decided to just cache the odd/even playernumber result in a dictionary for faster access, which while not being my preferred way of handling this at least results in a decent speedup. --- .../tools/TAStudio/TAStudio.ListView.cs | 11 +++++++++-- .../Base Implementations/ControllerDefinition.cs | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs index 083ba75def..5bccfde705 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs @@ -62,6 +62,8 @@ namespace BizHawk.Client.EmuHawk private int? _seekStartFrame; private bool _unpauseAfterSeeking; + private readonly Dictionary _alternateRowColor = new(); + private ControllerDefinition ControllerType => MovieSession.MovieController.Definition; public bool WasRecording { get; set; } @@ -247,8 +249,13 @@ namespace BizHawk.Client.EmuHawk color = Palette.AnalogEdit_Col; } - int player = Emulator.ControllerDefinition.PlayerNumber(columnName); - if (player != 0 && player % 2 == 0) + if (!_alternateRowColor.ContainsKey(columnName)) + { + int playerNumber = ControllerDefinition.PlayerNumber(columnName); + _alternateRowColor[columnName] = playerNumber != 0 && playerNumber % 2 == 0; + } + + if (_alternateRowColor[columnName]) { color = Color.FromArgb(0x0D, 0x00, 0x00, 0x00); } diff --git a/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs b/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs index c9c5e54206..ad86188165 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs @@ -121,7 +121,7 @@ namespace BizHawk.Emulation.Common return this; } - public int PlayerNumber(string buttonName) + public static int PlayerNumber(string buttonName) { var match = PlayerRegex.Match(buttonName); return match.Success