From 48c81511f4893385a28d8fda70d18b582de4597e Mon Sep 17 00:00:00 2001 From: Brad White Date: Thu, 16 Nov 2017 22:16:16 -0500 Subject: [PATCH] Fix Compile Stopwatch This helped validate that the previous fixes actually improved compile times CPU.cs * Modify compileWatch reset and addition to check if stopwatch is running * When we moved compiling to a separate thread, this wasn't modified to know that the compile may cross multiple updates YieldFinishedCompile.cs * Fixed call to stop the compile stopwatch so that it stops after any completed compilation. --- src/kOS.Safe/Execution/CPU.cs | 11 ++++++++--- src/kOS.Safe/Execution/YieldFinishedCompile.cs | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/kOS.Safe/Execution/CPU.cs b/src/kOS.Safe/Execution/CPU.cs index a15af5e20..4a35c0041 100644 --- a/src/kOS.Safe/Execution/CPU.cs +++ b/src/kOS.Safe/Execution/CPU.cs @@ -1205,8 +1205,10 @@ public void KOSFixedUpdate(double deltaTime) updateWatch.Reset(); executionWatch.Reset(); instructionWatch.Reset(); - compileWatch.Stop(); - compileWatch.Reset(); + if (!compileWatch.IsRunning) + { + compileWatch.Reset(); + } updateWatch.Start(); } @@ -1272,7 +1274,10 @@ public void KOSFixedUpdate(double deltaTime) totalUpdateTime += updateElapsed; executionElapsed = executionWatch.ElapsedTicks * 1000D / Stopwatch.Frequency; totalExecutionTime += executionElapsed; - totalCompileTime += compileWatch.ElapsedTicks * 1000D / Stopwatch.Frequency; + if (!compileWatch.IsRunning) + { + totalCompileTime += compileWatch.ElapsedTicks * 1000D / Stopwatch.Frequency; + } if (maxMainlineInstructionsSoFar < numMainlineInstructions) maxMainlineInstructionsSoFar = numMainlineInstructions; if (maxUpdateTime < updateElapsed) diff --git a/src/kOS.Safe/Execution/YieldFinishedCompile.cs b/src/kOS.Safe/Execution/YieldFinishedCompile.cs index ec1819f58..adaf00314 100644 --- a/src/kOS.Safe/Execution/YieldFinishedCompile.cs +++ b/src/kOS.Safe/Execution/YieldFinishedCompile.cs @@ -56,7 +56,6 @@ public override void ThreadFinish() { case CompileMode.RUN: programContext.AddParts(codeParts); - shared.Cpu.StopCompileStopwatch(); break; case CompileMode.LOAD: int programAddress = programContext.AddObjectParts(codeParts, path.ToString()); @@ -74,6 +73,7 @@ public override void ThreadFinish() default: break; } + shared.Cpu.StopCompileStopwatch(); } public static YieldFinishedCompile RunScript(GlobalPath scriptPath, int lineNumber, string fileContent, string contextIdentifier, CompilerOptions compilerOptions)