mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-04-21 05:13:14 +02:00
HLE: Slightly speed up IpcService creation
This is not a crazy speedup, we're talking fractions of a millisecond here (I had to measure in ticks; 10000000 ticks per second) - TIPC commands are opted-into for registration since they are only used for IUserInterface, but were still attempted to be initialized for every service which spent needless time. - Directly use GetType() instead of accessing all exported types, and Where()ing for equivalency to GetType(). This causes the logic for registration to be a lot faster.
This commit is contained in:
parent
86c2f261af
commit
2f064064ca
2 changed files with 34 additions and 11 deletions
|
@ -1,8 +1,10 @@
|
|||
using Gommon;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.HLE.Exceptions;
|
||||
using Ryujinx.HLE.HOS.Ipc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
@ -21,21 +23,42 @@ namespace Ryujinx.HLE.HOS.Services
|
|||
private int _selfId;
|
||||
private bool _isDomain;
|
||||
|
||||
public IpcService(ServerBase server = null)
|
||||
public IpcService(ServerBase server = null, bool registerTipc = false)
|
||||
{
|
||||
CmifCommands = GetType().Assembly.GetTypes()
|
||||
.Where(type => type == GetType())
|
||||
.SelectMany(type => type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public))
|
||||
Stopwatch sw = Stopwatch.StartNew();
|
||||
|
||||
CmifCommands = GetType()
|
||||
.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public)
|
||||
.SelectMany(methodInfo => methodInfo.GetCustomAttributes<CommandCmifAttribute>()
|
||||
.Select(command => (command.Id, methodInfo)))
|
||||
.ToDictionary(command => command.Id, command => command.methodInfo);
|
||||
|
||||
TipcCommands = GetType().Assembly.GetTypes()
|
||||
.Where(type => type == GetType())
|
||||
.SelectMany(type => type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public))
|
||||
.SelectMany(methodInfo => methodInfo.GetCustomAttributes<CommandTipcAttribute>()
|
||||
.Select(command => (command.Id, methodInfo)))
|
||||
.ToDictionary(command => command.Id, command => command.methodInfo);
|
||||
sw.Stop();
|
||||
|
||||
Logger.Notice.Print(
|
||||
LogClass.Emulation,
|
||||
$"{CmifCommands.Count} Cmif commands loaded in {sw.ElapsedTicks} ticks ({Stopwatch.Frequency} tps).",
|
||||
GetType().AsPrettyString()
|
||||
);
|
||||
|
||||
if (registerTipc)
|
||||
{
|
||||
sw.Start();
|
||||
|
||||
TipcCommands = GetType()
|
||||
.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public)
|
||||
.SelectMany(methodInfo => methodInfo.GetCustomAttributes<CommandTipcAttribute>()
|
||||
.Select(command => (command.Id, methodInfo)))
|
||||
.ToDictionary(command => command.Id, command => command.methodInfo);
|
||||
|
||||
sw.Stop();
|
||||
|
||||
Logger.Notice.Print(
|
||||
LogClass.Emulation,
|
||||
$"{TipcCommands.Count} Tipc commands loaded in {sw.ElapsedTicks} ticks ({Stopwatch.Frequency} tps).",
|
||||
GetType().AsPrettyString()
|
||||
);
|
||||
}
|
||||
|
||||
Server = server;
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace Ryujinx.HLE.HOS.Services.Sm
|
|||
|
||||
private bool _isInitialized;
|
||||
|
||||
public IUserInterface(KernelContext context, SmRegistry registry)
|
||||
public IUserInterface(KernelContext context, SmRegistry registry) : base(registerTipc: true)
|
||||
{
|
||||
_commonServer = new ServerBase(context, "CommonServer");
|
||||
_registry = registry;
|
||||
|
|
Loading…
Add table
Reference in a new issue