mirror of
https://git.ryujinx.app/projects/Kenji-NX.git
synced 2026-11-19 17:21:15 +01:00
Memory changes 3
General memory improvements to decrease GC pressure and frequency. Pool big arrays and objects that are created and deleted often. Skip data copies when they aren't needed. Inline flag checks to skip unneeded allocations. From my testing the performance is about the same, but the GC frequency is much lower and collection is faster causing less and smaller spikes.
This commit is contained in:
1 parent
2c50fbcc1f
commit
e3ee28605d
42 files changed
+703
-331
No files matched your search
@@ -5,6 +5,7 @@ using Ryujinx.Common.Configuration.Hid.Controller.Motion;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.HLE.HOS.Services.Hid;
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
@@ -291,7 +292,7 @@ namespace Ryujinx.Input.HLE
|
||||
{
|
||||
if (controllerConfig.Motion.MotionBackend == MotionInputBackendType.GamepadDriver)
|
||||
{
|
||||
if (gamepad.Features.HasFlag(GamepadFeaturesFlag.Motion))
|
||||
if ((gamepad.Features & GamepadFeaturesFlag.Motion) != 0)
|
||||
{
|
||||
Vector3 accelerometer = gamepad.GetMotionData(MotionInputId.Accelerometer);
|
||||
Vector3 gyroscope = gamepad.GetMotionData(MotionInputId.Gyroscope);
|
||||
@@ -531,6 +532,8 @@ namespace Ryujinx.Input.HLE
|
||||
|
||||
hidKeyboard.Modifier |= value << entry.Target;
|
||||
}
|
||||
|
||||
ArrayPool<bool>.Shared.Return(keyboardState.KeysState);
|
||||
|
||||
return hidKeyboard;
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using Ryujinx.Common;
|
||||
using Ryujinx.Common.Configuration.Hid;
|
||||
using Ryujinx.Common.Configuration.Hid.Controller;
|
||||
using Ryujinx.Common.Configuration.Hid.Keyboard;
|
||||
using Ryujinx.HLE.HOS.Services.Hid;
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
@@ -17,6 +19,7 @@ namespace Ryujinx.Input.HLE
|
||||
{
|
||||
public class NpadManager : IDisposable
|
||||
{
|
||||
private static readonly ObjectPool<List<SixAxisInput>> _hleMotionStatesPool = new (() => new List<SixAxisInput>(NpadDevices.MaxControllers));
|
||||
private readonly CemuHookClient _cemuHookClient;
|
||||
|
||||
private readonly Lock _lock = new();
|
||||
@@ -204,8 +207,8 @@ namespace Ryujinx.Input.HLE
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
List<GamepadInput> hleInputStates = new();
|
||||
List<SixAxisInput> hleMotionStates = new(NpadDevices.MaxControllers);
|
||||
List<GamepadInput> hleInputStates = [];
|
||||
List<SixAxisInput> hleMotionStates = _hleMotionStatesPool.Allocate();
|
||||
|
||||
KeyboardInput? hleKeyboardInput = null;
|
||||
|
||||
@@ -309,6 +312,8 @@ namespace Ryujinx.Input.HLE
|
||||
var position = IMouse.GetScreenPosition(mouseInput.Position, mouse.ClientSize, aspectRatio);
|
||||
|
||||
_device.Hid.Mouse.Update((int)position.X, (int)position.Y, buttons, (int)mouseInput.Scroll.X, (int)mouseInput.Scroll.Y, true);
|
||||
|
||||
ArrayPool<bool>.Shared.Return(mouseInput.ButtonState);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -317,6 +322,8 @@ namespace Ryujinx.Input.HLE
|
||||
}
|
||||
|
||||
_device.TamperMachine.UpdateInput(hleInputStates);
|
||||
|
||||
_hleMotionStatesPool.Release(hleMotionStates);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Buffers;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Ryujinx.Input
|
||||
@@ -28,7 +29,8 @@ namespace Ryujinx.Input
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static KeyboardStateSnapshot GetStateSnapshot(IKeyboard keyboard)
|
||||
{
|
||||
bool[] keysState = new bool[(int)Key.Count];
|
||||
|
||||
bool[] keysState = ArrayPool<bool>.Shared.Rent((int)Key.Count);
|
||||
|
||||
for (Key key = 0; key < Key.Count; key++)
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Buffers;
|
||||
using System.Drawing;
|
||||
using System.Numerics;
|
||||
|
||||
@@ -47,7 +48,7 @@ namespace Ryujinx.Input
|
||||
/// <returns>A snaphost of the state of the mouse.</returns>
|
||||
public static MouseStateSnapshot GetMouseStateSnapshot(IMouse mouse)
|
||||
{
|
||||
bool[] buttons = new bool[(int)MouseButton.Count];
|
||||
bool[] buttons = ArrayPool<bool>.Shared.Rent((int)MouseButton.Count);
|
||||
|
||||
mouse.Buttons.CopyTo(buttons, 0);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Ryujinx.Input
|
||||
/// </summary>
|
||||
public class KeyboardStateSnapshot
|
||||
{
|
||||
private readonly bool[] _keysState;
|
||||
public readonly bool[] KeysState;
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="KeyboardStateSnapshot"/>.
|
||||
@@ -15,7 +15,7 @@ namespace Ryujinx.Input
|
||||
/// <param name="keysState">The keys state</param>
|
||||
public KeyboardStateSnapshot(bool[] keysState)
|
||||
{
|
||||
_keysState = keysState;
|
||||
KeysState = keysState;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -24,6 +24,6 @@ namespace Ryujinx.Input
|
||||
/// <param name="key">The key</param>
|
||||
/// <returns>True if the given key is pressed</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool IsPressed(Key key) => _keysState[(int)key];
|
||||
public bool IsPressed(Key key) => KeysState[(int)key];
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ namespace Ryujinx.Input
|
||||
/// </summary>
|
||||
public class MouseStateSnapshot
|
||||
{
|
||||
private readonly bool[] _buttonState;
|
||||
public readonly bool[] ButtonState;
|
||||
|
||||
/// <summary>
|
||||
/// The position of the mouse cursor
|
||||
@@ -28,7 +28,7 @@ namespace Ryujinx.Input
|
||||
/// <param name="scroll">The scroll delta</param>
|
||||
public MouseStateSnapshot(bool[] buttonState, Vector2 position, Vector2 scroll)
|
||||
{
|
||||
_buttonState = buttonState;
|
||||
ButtonState = buttonState;
|
||||
|
||||
Position = position;
|
||||
Scroll = scroll;
|
||||
@@ -40,6 +40,6 @@ namespace Ryujinx.Input
|
||||
/// <param name="button">The button</param>
|
||||
/// <returns>True if the given button is pressed</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool IsPressed(MouseButton button) => _buttonState[(int)button];
|
||||
public bool IsPressed(MouseButton button) => ButtonState[(int)button];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user