Skip to content

Commit

Permalink
Don't prevent inlining of mod methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Popax21 committed Aug 10, 2023
1 parent 7b1748c commit a7d7c3f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Celeste.Mod.mm/Mod/Everest/Everest.Relinker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private static Assembly RelinkAssembly(EverestModuleMetadata meta, string asmnam
modder.AutoPatch();

if (!meta.IsNetCoreOnlyMod)
NETCoreifier.Coreifier.ConvertToNetCore(modder, sharedDeps: true);
NETCoreifier.Coreifier.ConvertToNetCore(modder, sharedDeps: true, preventInlining: false);

// Write patched assembly and debug symbols back to disk (always as portable PDBs though)
// Fall back to a temporary output path if the given one is unavailable for some reason
Expand Down
7 changes: 4 additions & 3 deletions NETCoreifier/Coreifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
namespace NETCoreifier {
public static class Coreifier {

public static void ConvertToNetCore(MonoModder modder, bool sharedDeps = false)
=> ConvertToNetCore(modder.Module, modder.AssemblyResolver, sharedDeps);
public static void ConvertToNetCore(MonoModder modder, bool sharedDeps = false, bool preventInlining = true)
=> ConvertToNetCore(modder.Module, modder.AssemblyResolver, sharedDeps, preventInlining);

public static void ConvertToNetCore(string inputAsm, string outputAsm = null) {
ModuleDefinition module = null;
Expand All @@ -38,7 +38,7 @@ public static void ConvertToNetCore(string inputAsm, string outputAsm = null) {
}
}

public static void ConvertToNetCore(ModuleDefinition module, IAssemblyResolver asmResolver = null, bool sharedDeps = false) {
public static void ConvertToNetCore(ModuleDefinition module, IAssemblyResolver asmResolver = null, bool sharedDeps = false, bool preventInlining = true) {
module.RuntimeVersion = System.Reflection.Assembly.GetExecutingAssembly().ImageRuntimeVersion;

// Clear 32 bit flags
Expand Down Expand Up @@ -83,6 +83,7 @@ public static void ConvertToNetCore(ModuleDefinition module, IAssemblyResolver a
modder.MissingDependencyThrow = false;

modder.SharedDependencies = sharedDeps;
modder.PreventInlining = preventInlining;

modder.MapDependencies();
modder.AutoPatch();
Expand Down
3 changes: 2 additions & 1 deletion NETCoreifier/NetFrameworkModder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class NetFrameworkModder : MonoModder {
// Patching RNG doesn't seem to be required (yet), as .NET Framework and .NET Core share their RNG implementation

public bool SharedAssemblyResolver, SharedDependencies;
public bool PreventInlining = true;
private ModuleDefinition _CoreifierModule;

private static readonly HashSet<string> _PrivateSystemLibs = new HashSet<string>() { "System.Private.CoreLib" };
Expand Down Expand Up @@ -91,7 +92,7 @@ public override void PatchRefsInMethod(MethodDefinition method) {

// The CoreCLR JIT is much more aggressive about inlining, so explicitly force it to not inline in some cases
// The performance penalty isn't that bad, and it makes modding easier
if ((method.ImplAttributes & MethodImplAttributes.AggressiveInlining) == 0 && method.Body is MethodBody body && !CanInlineLegacyCode(body))
if (PreventInlining && (method.ImplAttributes & MethodImplAttributes.AggressiveInlining) == 0 && method.Body is MethodBody body && !CanInlineLegacyCode(body))
method.ImplAttributes |= MethodImplAttributes.NoInlining;

// Resolve uninstantiated generic typeref/def tokens inside of member methods by replacing them with generic type instances
Expand Down

0 comments on commit a7d7c3f

Please sign in to comment.