Skip to content

Commit

Permalink
Added some internal documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
CptMoore committed Dec 28, 2024
1 parent 50e1c1e commit 2326d6b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ModTek/Features/Logging/FastBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 17 additions & 2 deletions ModTek/Features/Logging/LightWeightBlockingQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}

Expand Down
5 changes: 5 additions & 0 deletions ModTekInjector/ModTekInjector.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@
<Private>False</Private>
</Reference>
</ItemGroup>

<ItemGroup>
<!-- the injector requires the ModTek.dll to be built and accessible -->
<ProjectReference Include="..\ModTek\ModTek.csproj" ReferenceOutputAssembly="false" />
</ItemGroup>
</Project>

0 comments on commit 2326d6b

Please sign in to comment.