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:
LotP
2025-11-23 13:43:14 -06:00
committed by KeatonTheBot
parent c1e24961f9
commit 35bced8527
42 changed files with 703 additions and 331 deletions
+22 -22
View File
@@ -84,7 +84,7 @@ namespace Ryujinx.Input.SDL2
_triggerThreshold = 0.0f;
// Enable motion tracking
if (Features.HasFlag(GamepadFeaturesFlag.Motion))
if ((Features & GamepadFeaturesFlag.Motion) != 0)
{
if (SDL_GameControllerSetSensorEnabled(_gamepadHandle, SDL_SensorType.SDL_SENSOR_ACCEL, SDL_bool.SDL_TRUE) != 0)
{
@@ -145,7 +145,7 @@ namespace Ryujinx.Input.SDL2
public void Rumble(float lowFrequency, float highFrequency, uint durationMs)
{
if (Features.HasFlag(GamepadFeaturesFlag.Rumble))
if ((Features & GamepadFeaturesFlag.Rumble) == 0)
{
ushort lowFrequencyRaw = (ushort)(lowFrequency * ushort.MaxValue);
ushort highFrequencyRaw = (ushort)(highFrequency * ushort.MaxValue);
@@ -184,32 +184,32 @@ namespace Ryujinx.Input.SDL2
sensorType = SDL_SensorType.SDL_SENSOR_GYRO;
}
if (Features.HasFlag(GamepadFeaturesFlag.Motion) && sensorType != SDL_SensorType.SDL_SENSOR_INVALID)
if ((Features & GamepadFeaturesFlag.Motion) == 0 || sensorType is SDL_SensorType.SDL_SENSOR_INVALID)
return Vector3.Zero;
const int ElementCount = 3;
unsafe
{
const int ElementCount = 3;
float* values = stackalloc float[ElementCount];
unsafe
int result = SDL_GameControllerGetSensorData(_gamepadHandle, sensorType, (nint)values, ElementCount);
if (result == 0)
{
float* values = stackalloc float[ElementCount];
Vector3 value = new(values[0], values[1], values[2]);
int result = SDL_GameControllerGetSensorData(_gamepadHandle, sensorType, (nint)values, ElementCount);
if (result == 0)
if (inputId == MotionInputId.Gyroscope)
{
Vector3 value = new(values[0], values[1], values[2]);
if (inputId == MotionInputId.Gyroscope)
{
return RadToDegree(value);
}
if (inputId == MotionInputId.Accelerometer)
{
return GsToMs2(value);
}
return value;
return RadToDegree(value);
}
if (inputId == MotionInputId.Accelerometer)
{
return GsToMs2(value);
}
return value;
}
}
+3 -3
View File
@@ -82,7 +82,7 @@ namespace Ryujinx.Input.SDL2
Features = GetFeaturesFlag();
// Enable motion tracking
if (Features.HasFlag(GamepadFeaturesFlag.Motion))
if ((Features & GamepadFeaturesFlag.Motion) != 0)
{
if (SDL_GameControllerSetSensorEnabled(_gamepadHandle, SDL_SensorType.SDL_SENSOR_ACCEL,
SDL_bool.SDL_TRUE) != 0)
@@ -163,7 +163,7 @@ namespace Ryujinx.Input.SDL2
public void Rumble(float lowFrequency, float highFrequency, uint durationMs)
{
if (!Features.HasFlag(GamepadFeaturesFlag.Rumble))
if ((Features & GamepadFeaturesFlag.Rumble) == 0)
return;
ushort lowFrequencyRaw = (ushort)(lowFrequency * ushort.MaxValue);
@@ -195,7 +195,7 @@ namespace Ryujinx.Input.SDL2
_ => SDL_SensorType.SDL_SENSOR_INVALID
};
if (!Features.HasFlag(GamepadFeaturesFlag.Motion) || sensorType is SDL_SensorType.SDL_SENSOR_INVALID)
if ((Features & GamepadFeaturesFlag.Motion) == 0 || sensorType is SDL_SensorType.SDL_SENSOR_INVALID)
return Vector3.Zero;
const int ElementCount = 3;