From 2326d6b38cae717a03ea40e0465f0d42b9d258d4 Mon Sep 17 00:00:00 2001 From: CptMoore <39010654+CptMoore@users.noreply.github.com> Date: Sat, 28 Dec 2024 04:30:14 +0100 Subject: [PATCH] Added some internal documentation. --- ModTek/Features/Logging/FastBuffer.cs | 2 +- .../Logging/LightWeightBlockingQueue.cs | 19 +++++++++++++++++-- ModTekInjector/ModTekInjector.csproj | 5 +++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/ModTek/Features/Logging/FastBuffer.cs b/ModTek/Features/Logging/FastBuffer.cs index ad83cf84..5137e078 100644 --- a/ModTek/Features/Logging/FastBuffer.cs +++ b/ModTek/Features/Logging/FastBuffer.cs @@ -89,7 +89,7 @@ internal void Append(string value) // loop unrolling similar to Buffer.memcpy1 // parallelism isn't what makes it particular fast, it's the batching that is helpful (fewer ops overall) - // 8 is a sweat spot, for large amounts of data 4 is slower, 16 is slower + // 8 is a sweat spot, for large amounts of data: 4 is slower, 16 is slower { const int IterSize = 8; for (; processingCount >= IterSize; processingCount -= IterSize) diff --git a/ModTek/Features/Logging/LightWeightBlockingQueue.cs b/ModTek/Features/Logging/LightWeightBlockingQueue.cs index bfdcb16a..782d8a6c 100644 --- a/ModTek/Features/Logging/LightWeightBlockingQueue.cs +++ b/ModTek/Features/Logging/LightWeightBlockingQueue.cs @@ -58,11 +58,17 @@ internal ref MTLoggerMessageDto AcquireCommittedOrWait() { return ref item; } + else + { + // this branch hits 0 times, since the log writer runs in a single-thread + // still made the whole thing thread safe, to allow for future multithreaded log writing + } } else { - // this branch happens 292 times for 157187 dispatches (0.19%) - // for now not worth it to optimize + // this branch happened 292 times for 157187 dispatches (0.19%) + // for now not worth it to optimize, especially since this is only on the log writer thread + // also only happens if the queue is empty and just was added to, so just a latency issue } spinWait.Reset(); // fast retry if something was found earlier @@ -97,6 +103,15 @@ internal ref MTLoggerMessageDto AcquireUncommitedOrWait() { return ref item; } + else + { + // this branch hits about 0 times, since it is overwhelmingly single-threaded (main thread) + } + } + else + { + // this branch hits 0 times if the queue never gets filled + // if it is full, any further optimizations would just wait for the slow I/O writer thread anyway } } diff --git a/ModTekInjector/ModTekInjector.csproj b/ModTekInjector/ModTekInjector.csproj index 408edba6..25f4dfaf 100644 --- a/ModTekInjector/ModTekInjector.csproj +++ b/ModTekInjector/ModTekInjector.csproj @@ -15,4 +15,9 @@ False + + + + + \ No newline at end of file