-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make decoupleItemsFromLocations use less allocations
- Loading branch information
Showing
5 changed files
with
132 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\UndertaleModTool\UndertaleModLib\UndertaleModLib.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using UndertaleModLib; | ||
using UndertaleModLib.Decompiler; | ||
using UndertaleModLib.Models; | ||
|
||
namespace BenchmarkTest; | ||
|
||
[MemoryDiagnoser] | ||
public class DecompileBenchmark | ||
{ | ||
public UndertaleData data; | ||
public GlobalDecompileContext decompileContext; | ||
|
||
[GlobalSetup] | ||
public void GlobalSetup() | ||
{ | ||
using (FileStream fs = new FileInfo(@"/home/narr/Dokumente/am2r 1.5.5/assets/game.unx_older").OpenRead()) | ||
{ | ||
data = UndertaleIO.Read(fs); | ||
} | ||
decompileContext = new GlobalDecompileContext(data, false); | ||
} | ||
|
||
[Benchmark] | ||
public void AppendVariableToEveryEntry() | ||
{ | ||
void AppendGML(UndertaleCode code, string appendedText) | ||
{ | ||
var codeText = Decompiler.Decompile(code, decompileContext); | ||
codeText = codeText + appendedText + "\n"; | ||
code.ReplaceGML(codeText, data); | ||
} | ||
|
||
foreach (UndertaleCode codeentry in data.Code.SkipLast((int)(data.Code.Count * 0.99))) | ||
{ | ||
if (codeentry.Name.Content == "gml_Object_oRm_a5c11lock_Collision_267") continue; | ||
|
||
AppendGML(codeentry, "var this_variable_is_not_used_and_thus_completely_uselesss = 1; if (!this_variable_is_not_used_and_thus_completely_uselesss) this_variable_is_not_used_and_thus_completely_uselesss = 1"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
|
||
using BenchmarkDotNet.Running; | ||
using BenchmarkTest; | ||
|
||
Console.WriteLine("Hello, World!"); | ||
BenchmarkRunner.Run<DecompileBenchmark>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
diff --git a/UndertaleModLib/Compiler/Compiler.cs b/UndertaleModLib/Compiler/Compiler.cs | ||
index 3fa2ae6b..72e3d7c9 100644 | ||
--- a/UndertaleModLib/Compiler/Compiler.cs | ||
+++ b/UndertaleModLib/Compiler/Compiler.cs | ||
@@ -142,8 +142,11 @@ namespace UndertaleModLib.Compiler | ||
for (int i = 0; i < list.Count; i++) | ||
{ | ||
string name = list[i].Name?.Content; | ||
- if (name != null) | ||
- assetIds[name] = i; | ||
+ if (name is not null) | ||
+ { | ||
+ assetIds.Add(name, i); | ||
+ } | ||
+ //assetIds[name] = i; | ||
} | ||
} | ||
} | ||
@@ -154,6 +157,8 @@ namespace UndertaleModLib.Compiler | ||
public delegate void MainThreadFunc(); | ||
public delegate void MainThreadDelegate(MainThreadFunc f); | ||
|
||
+ private static Dictionary<UndertaleData, CompileContext> codeToContextMapping = new Dictionary<UndertaleData, CompileContext>(); | ||
+ | ||
// A simple matching convenience | ||
public static bool In<T>(this T obj, params T[] args) | ||
{ | ||
@@ -169,7 +174,11 @@ namespace UndertaleModLib.Compiler | ||
|
||
public static CompileContext CompileGMLText(string input, UndertaleData data, UndertaleCode code) | ||
{ | ||
- return CompileGMLText(input, new CompileContext(data, code)); | ||
+ bool isInMapping = codeToContextMapping.TryGetValue(data, out CompileContext ctx); | ||
+ var returnedContext = CompileGMLText(input, ctx ?? new CompileContext(data, code)); | ||
+ if (!isInMapping) | ||
+ codeToContextMapping.Add(data, returnedContext); | ||
+ return returnedContext; | ||
} | ||
|
||
public static CompileContext CompileGMLText(string input, CompileContext context, bool redoAssets = false) |