LemonUIbyLemon / LemonUI

LemonUI for .NET (FiveM, RageMP, RagePluginHook and ScriptHookVDotNet 3)
MIT License
177 stars 40 forks source link

Improve performance of ProcessControls #109

Closed kagikn closed 1 year ago

kagikn commented 1 year ago

Uh, a ~Helmet~ Performance Inspection Officer.

When checking if some collections that has about 10 or more elements contains some other elememts, HashSet does the job fast (arrays or array lists would search faster if there are only like 2 elements). And get rid of redundant Controls.IsUsingController calls from the if (DisableControls) block since the result won't be changed and native calls are relatively expensive even without thread switching that was happened in SHVDN. Also explicitly call Dispose on OutputArgument so the finalizer won't be called.

If you don't mind using unsafe blocks, we could get rid of the use of OutputArgument so no dynamic heap allocation won't happen just for 4 byte values.

justalemon commented 1 year ago

I would need to test this, as only SHVDN has a proper .NET Framework implementation. Everything else is a bodged version of Mono and .NET Core as far as I know.

justalemon commented 1 year ago

Couldn't test RageMP, as C# is quite a bit broken over there. I was able to test everything else.

RagePluginHook: Works

image

ScriptHookVDotNet: Works

image

FiveM: Works

image