Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use concrete types when possible for improved performance #492

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 1 addition & 34 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -236,37 +236,4 @@ dotnet_naming_style.IPascalCase.required_suffix =
dotnet_naming_style.IPascalCase.word_separator =
dotnet_naming_style.IPascalCase.capitalization = pascal_case

# TODO:
# .NET 8 migration (new warnings are caused by the NET 8 C# compiler and analyzer)
# The following info messages might need to be fixed in the source code instead of hiding the actual message
# Without the following lines, dotnet format would fail
# Disable "Collection initialization can be simplified"
dotnet_diagnostic.IDE0028.severity = none
dotnet_diagnostic.IDE0300.severity = none
dotnet_diagnostic.IDE0301.severity = none
dotnet_diagnostic.IDE0302.severity = none
dotnet_diagnostic.IDE0305.severity = none
# Disable "'new' expression can be simplified"
dotnet_diagnostic.IDE0090.severity = none
# Disable "Use primary constructor"
dotnet_diagnostic.IDE0290.severity = none
# Disable "Member '' does not access instance data and can be marked as static"
dotnet_diagnostic.CA1822.severity = none
# Disable "Change type of field '' from '' to '' for improved performance"
dotnet_diagnostic.CA1859.severity = none
# Disable "Prefer 'static readonly' fields over constant array arguments if the called method is called repeatedly and is not mutating the passed array"
dotnet_diagnostic.CA1861.severity = none
# Disable "Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison, but keep in mind that this might cause subtle changes in behavior, so make sure to conduct thorough testing after applying the suggestion, or if culturally sensitive comparison is not required, consider using 'StringComparison.OrdinalIgnoreCase'"
dotnet_diagnostic.CA1862.severity = none

[src/Ryujinx/UI/ViewModels/**.cs]
# Disable "mark members as static" rule for ViewModels
dotnet_diagnostic.CA1822.severity = none

[src/Ryujinx.HLE/HOS/Services/**.cs]
# Disable "mark members as static" rule for services
dotnet_diagnostic.CA1822.severity = none

[src/Ryujinx.Tests/Cpu/*.cs]
# Disable naming rules for CPU tests
dotnet_diagnostic.IDE1006.severity = none
dotnet_diagnostic.CA1859.severity = error
3 changes: 2 additions & 1 deletion src/ARMeilleure/CodeGen/Arm64/CodeGenContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ARMeilleure.CodeGen.Linking;
using ARMeilleure.CodeGen.RegisterAllocators;
using ARMeilleure.IntermediateRepresentation;
using Microsoft.IO;
using Ryujinx.Common.Memory;
using System;
using System.Collections.Generic;
Expand All @@ -14,7 +15,7 @@ class CodeGenContext
private const int CbnzInstLength = 4;
private const int LdrLitInstLength = 4;

private readonly Stream _stream;
private readonly RecyclableMemoryStream _stream;

public int StreamOffset => (int)_stream.Length;

Expand Down
3 changes: 2 additions & 1 deletion src/ARMeilleure/CodeGen/X86/CodeGenContext.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ARMeilleure.CodeGen.RegisterAllocators;
using ARMeilleure.IntermediateRepresentation;
using Microsoft.IO;
using Ryujinx.Common.Memory;
using System.IO;
using System.Numerics;
Expand All @@ -8,7 +9,7 @@ namespace ARMeilleure.CodeGen.X86
{
class CodeGenContext
{
private readonly Stream _stream;
private readonly RecyclableMemoryStream _stream;
private readonly Operand[] _blockLabels;

public int StreamOffset => (int)_stream.Length;
Expand Down
2 changes: 1 addition & 1 deletion src/ARMeilleure/Instructions/InstEmitAluHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public static Operand GetAluM(ArmEmitterContext context, bool setCarry = true)
}
}

private static Exception InvalidOpCodeType(OpCode opCode)
private static InvalidOperationException InvalidOpCodeType(OpCode opCode)
{
return new InvalidOperationException($"Invalid OpCode type \"{opCode?.GetType().Name ?? "null"}\".");
}
Expand Down
2 changes: 1 addition & 1 deletion src/ARMeilleure/Instructions/InstEmitMemoryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ public static Operand GetMemM(ArmEmitterContext context, bool setCarry = true)
};
}

private static Exception InvalidOpCodeType(OpCode opCode)
private static InvalidOperationException InvalidOpCodeType(OpCode opCode)
{
return new InvalidOperationException($"Invalid OpCode type \"{opCode?.GetType().Name ?? "null"}\".");
}
Expand Down
5 changes: 3 additions & 2 deletions src/ARMeilleure/Translation/PTC/PtcProfiler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ARMeilleure.State;
using Humanizer;
using Microsoft.IO;
using Ryujinx.Common;
using Ryujinx.Common.Logging;
using Ryujinx.Common.Memory;
Expand Down Expand Up @@ -73,7 +74,7 @@ public PtcProfiler(Ptc ptc)
Enabled = false;
}

private void TimerElapsed(object _, ElapsedEventArgs __)
private void TimerElapsed(object _, ElapsedEventArgs __)
=> new Thread(PreSave) { Name = "Ptc.DiskWriter" }.Start();

public void AddEntry(ulong address, ExecutionMode mode, bool highCq)
Expand Down Expand Up @@ -191,7 +192,7 @@ private bool Load(string fileName, bool isBackup)
return false;
}

using MemoryStream stream = MemoryStreamManager.Shared.GetStream();
using RecyclableMemoryStream stream = MemoryStreamManager.Shared.GetStream();
Debug.Assert(stream.Seek(0L, SeekOrigin.Begin) == 0L && stream.Length == 0L);

try
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Common/Logging/Targets/ConsoleLogTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Ryujinx.Common.Logging.Targets
{
public class ConsoleLogTarget : ILogTarget
{
private readonly ILogFormatter _formatter;
private readonly DefaultLogFormatter _formatter;

private readonly string _name;

Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Common/Logging/Targets/FileLogTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Ryujinx.Common.Logging.Targets
public class FileLogTarget : ILogTarget
{
private readonly StreamWriter _logWriter;
private readonly ILogFormatter _formatter;
private readonly DefaultLogFormatter _formatter;
private readonly string _name;

string ILogTarget.Name { get => _name; }
Expand Down
8 changes: 4 additions & 4 deletions src/Ryujinx.Common/SystemInterop/StdErrAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ namespace Ryujinx.Common.SystemInterop
public partial class StdErrAdapter : IDisposable
{
private bool _disposable;
private Stream _pipeReader;
private Stream _pipeWriter;
private FileStream _pipeReader;
private FileStream _pipeWriter;
private CancellationTokenSource _cancellationTokenSource;
private Task _worker;

Expand Down Expand Up @@ -46,7 +46,7 @@ private void RegisterPosix()
[SupportedOSPlatform("macos")]
private async Task EventWorkerAsync(CancellationToken cancellationToken)
{
using TextReader reader = new StreamReader(_pipeReader, leaveOpen: true);
using StreamReader reader = new StreamReader(_pipeReader, leaveOpen: true);
string line;
while (cancellationToken.IsCancellationRequested == false && (line = await reader.ReadLineAsync(cancellationToken)) != null)
{
Expand Down Expand Up @@ -92,7 +92,7 @@ private static (int, int) MakePipe()

[SupportedOSPlatform("linux")]
[SupportedOSPlatform("macos")]
private static Stream CreateFileDescriptorStream(int fd)
private static FileStream CreateFileDescriptorStream(int fd)
{
return new FileStream(
new SafeFileHandle(fd, ownsHandle: true),
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Common/Utilities/StreamUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static MemoryOwner<byte> StreamToRentedMemory(Stream input)

public static async Task<byte[]> StreamToBytesAsync(Stream input, CancellationToken cancellationToken = default)
{
using MemoryStream stream = MemoryStreamManager.Shared.GetStream();
using RecyclableMemoryStream stream = MemoryStreamManager.Shared.GetStream();

await input.CopyToAsync(stream, cancellationToken);

Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Cpu/LightningJit/Translator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Translator(IMemoryManager memory, AddressTable<ulong> functionTable)
}
}

private static IStackWalker CreateStackWalker()
private static StackWalker CreateStackWalker()
{
if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ private bool LoadTocEntries(Stream tocFileStream, ref BinarySerializer reader)
/// <param name="hash">Code and constant buffer data hash</param>
/// <returns>Entry index</returns>
private int WriteNewEntry(
Stream tocFileStream,
Stream dataFileStream,
FileStream tocFileStream,
FileStream dataFileStream,
ref TocHeader header,
ReadOnlySpan<byte> data,
ReadOnlySpan<byte> cb1Data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ private void WriteHostCode(
/// <param name="magic">Magic value to be written</param>
/// <param name="codegenVersion">Shader codegen version, only valid for the host file</param>
/// <param name="timestamp">File creation timestamp</param>
private static void CreateToc(Stream tocFileStream, ref TocHeader header, uint magic, uint codegenVersion, ulong timestamp)
private static void CreateToc(FileStream tocFileStream, ref TocHeader header, uint magic, uint codegenVersion, ulong timestamp)
{
BinarySerializer writer = new(tocFileStream);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Microsoft.IO;
using Ryujinx.Common;
using Ryujinx.Common.Memory;
using Ryujinx.Graphics.GAL;
Expand All @@ -12,7 +13,7 @@ static class ShaderBinarySerializer
{
public static byte[] Pack(ShaderSource[] sources)
{
using MemoryStream output = MemoryStreamManager.Shared.GetStream();
using RecyclableMemoryStream output = MemoryStreamManager.Shared.GetStream();

output.Write(sources.Length);

Expand Down
18 changes: 9 additions & 9 deletions src/Ryujinx.Graphics.Metal/HelperShader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ class HelperShader : IDisposable
private readonly Pipeline _pipeline;
private MTLDevice _device;

private readonly ISampler _samplerLinear;
private readonly ISampler _samplerNearest;
private readonly IProgram _programColorBlitF;
private readonly IProgram _programColorBlitI;
private readonly IProgram _programColorBlitU;
private readonly IProgram _programColorBlitMsF;
private readonly IProgram _programColorBlitMsI;
private readonly IProgram _programColorBlitMsU;
private readonly SamplerHolder _samplerLinear;
private readonly SamplerHolder _samplerNearest;
private readonly Program _programColorBlitF;
private readonly Program _programColorBlitI;
private readonly Program _programColorBlitU;
private readonly Program _programColorBlitMsF;
private readonly Program _programColorBlitMsI;
private readonly Program _programColorBlitMsU;
private readonly List<IProgram> _programsColorClearF = new();
private readonly List<IProgram> _programsColorClearI = new();
private readonly List<IProgram> _programsColorClearU = new();
private readonly IProgram _programDepthStencilClear;
private readonly Program _programDepthStencilClear;
private readonly IProgram _programStrideChange;
private readonly IProgram _programConvertD32S8ToD24S8;
private readonly IProgram _programConvertIndexBuffer;
Expand Down
6 changes: 3 additions & 3 deletions src/Ryujinx.Graphics.Shader/Instructions/AttributeMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public AttributeEntry(
}
}

private static readonly IReadOnlyDictionary<int, AttributeEntry> _attributes;
private static readonly Dictionary<int, AttributeEntry> _attributes;
private static readonly IReadOnlyDictionary<int, AttributeEntry> _attributesPerPatch;

static AttributeMap()
Expand All @@ -55,7 +55,7 @@ static AttributeMap()
_attributesPerPatch = CreatePerPatchMap();
}

private static IReadOnlyDictionary<int, AttributeEntry> CreateMap()
private static Dictionary<int, AttributeEntry> CreateMap()
{
var map = new Dictionary<int, AttributeEntry>();

Expand All @@ -82,7 +82,7 @@ private static IReadOnlyDictionary<int, AttributeEntry> CreateMap()
return map;
}

private static IReadOnlyDictionary<int, AttributeEntry> CreatePerPatchMap()
private static Dictionary<int, AttributeEntry> CreatePerPatchMap()
{
var map = new Dictionary<int, AttributeEntry>();

Expand Down
4 changes: 2 additions & 2 deletions src/Ryujinx.Graphics.Shader/StructuredIr/GotoElimination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private static bool DirectlyRelated(AstBlock lBlock, AstBlock rBlock, int lLevel
return false;
}

IAstNode block;
AstBlock block;
IAstNode other;

int blockLvl, otherLvl;
Expand Down Expand Up @@ -441,7 +441,7 @@ private static AstBlock[] BackwardsPath(AstBlock top, AstBlock bottom)
return path.ToArray();
}

private static int Level(IAstNode node)
private static int Level(AstBlock node)
{
int level = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public int AddFunction(Operation baseOp, bool isMultiTarget, IReadOnlyList<uint>
return functionId;
}

public bool TryGetFunctionId(Operation baseOp, bool isMultiTarget, IReadOnlyList<uint> targetCbs, out int functionId)
public bool TryGetFunctionId(Operation baseOp, bool isMultiTarget, List<uint> targetCbs, out int functionId)
{
foreach (Entry entry in _entries)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private static bool IsSameOperand(Operand x, Operand y)
return x == y || x.Type == OperandType.Constant || x.Type == OperandType.ConstantBuffer;
}

private static bool AreAllSourcesEqual(INode node, INode otherNode)
private static bool AreAllSourcesEqual(Operation node, Operation otherNode)
{
if (node.SourcesCount != otherNode.SourcesCount)
{
Expand Down
46 changes: 23 additions & 23 deletions src/Ryujinx.Graphics.Vulkan/HelperShader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,29 @@ class HelperShader : IDisposable
private readonly PipelineHelperShader _pipeline;
private readonly ISampler _samplerLinear;
private readonly ISampler _samplerNearest;
private readonly IProgram _programColorBlit;
private readonly IProgram _programColorBlitMs;
private readonly IProgram _programColorBlitClearAlpha;
private readonly IProgram _programColorClearF;
private readonly IProgram _programColorClearSI;
private readonly IProgram _programColorClearUI;
private readonly IProgram _programDepthStencilClear;
private readonly IProgram _programStrideChange;
private readonly IProgram _programConvertD32S8ToD24S8;
private readonly IProgram _programConvertIndexBuffer;
private readonly IProgram _programConvertIndirectData;
private readonly IProgram _programColorCopyShortening;
private readonly IProgram _programColorCopyToNonMs;
private readonly IProgram _programColorCopyWidening;
private readonly IProgram _programColorDrawToMs;
private readonly IProgram _programDepthBlit;
private readonly IProgram _programDepthBlitMs;
private readonly IProgram _programDepthDrawToMs;
private readonly IProgram _programDepthDrawToNonMs;
private readonly IProgram _programStencilBlit;
private readonly IProgram _programStencilBlitMs;
private readonly IProgram _programStencilDrawToMs;
private readonly IProgram _programStencilDrawToNonMs;
private readonly ShaderCollection _programColorBlit;
private readonly ShaderCollection _programColorBlitMs;
private readonly ShaderCollection _programColorBlitClearAlpha;
private readonly ShaderCollection _programColorClearF;
private readonly ShaderCollection _programColorClearSI;
private readonly ShaderCollection _programColorClearUI;
private readonly ShaderCollection _programDepthStencilClear;
private readonly ShaderCollection _programStrideChange;
private readonly ShaderCollection _programConvertD32S8ToD24S8;
private readonly ShaderCollection _programConvertIndexBuffer;
private readonly ShaderCollection _programConvertIndirectData;
private readonly ShaderCollection _programColorCopyShortening;
private readonly ShaderCollection _programColorCopyToNonMs;
private readonly ShaderCollection _programColorCopyWidening;
private readonly ShaderCollection _programColorDrawToMs;
private readonly ShaderCollection _programDepthBlit;
private readonly ShaderCollection _programDepthBlitMs;
private readonly ShaderCollection _programDepthDrawToMs;
private readonly ShaderCollection _programDepthDrawToNonMs;
private readonly ShaderCollection _programStencilBlit;
private readonly ShaderCollection _programStencilBlitMs;
private readonly ShaderCollection _programStencilDrawToMs;
private readonly ShaderCollection _programStencilDrawToNonMs;

public HelperShader(VulkanRenderer gd, Device device)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Ryujinx.HLE/FileSystem/ContentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ private static IFile OpenPossibleFragmentedFile(IFileSystem filesystem, string p
return file.Release();
}

private static Stream GetZipStream(ZipArchiveEntry entry)
private static MemoryStream GetZipStream(ZipArchiveEntry entry)
{
MemoryStream dest = MemoryStreamManager.Shared.GetStream();

Expand Down Expand Up @@ -1058,7 +1058,7 @@ public void VerifyKeysFile(string filePath)
}

return;

bool VerifyKeys(string[] lines, string regex)
{
foreach (string line in lines)
Expand All @@ -1071,7 +1071,7 @@ bool VerifyKeys(string[] lines, string regex)
return true;
}
}

public bool AreKeysAlredyPresent(string pathToCheck)
{
string[] fileNames = { "prod.keys", "title.keys", "console.keys", "dev.keys" };
Expand Down
Loading
Loading