Implement performance optimizations and caching improvements#567
Open
Hirogen wants to merge 23 commits intoDevelopmentfrom
Open
Implement performance optimizations and caching improvements#567Hirogen wants to merge 23 commits intoDevelopmentfrom
Hirogen wants to merge 23 commits intoDevelopmentfrom
Conversation
added 13 commits
April 14, 2026 17:20
Closed
added 3 commits
April 16, 2026 13:47
| var line = logBuffer.GetLineMemoryOfBlock(0); | ||
| Assert.That(line.FullLine.Span.Contains(enumerator.Current.AsSpan(), StringComparison.Ordinal)); | ||
| #pragma warning disable CS8629 // Nullable value type may be null. | ||
| Assert.That(line.Value.FullLine.Span.Contains(enumerator.Current.AsSpan(), StringComparison.Ordinal)); |
|
|
||
| // Create initial set of files | ||
| Console.WriteLine($"Creating initial files in '{Path.GetFullPath(baseDir)}'..."); | ||
| WriteLogFile(Path.Combine(baseDir, baseName), 0); |
|
|
||
| for (var i = 1; i <= maxBackups; i++) | ||
| { | ||
| WriteLogFile(Path.Combine(baseDir, $"{baseName}.{i}"), i); |
| Console.WriteLine($"\n--- Rotation #{rotationCount} ---"); | ||
|
|
||
| // Delete the oldest file (simulates maxBackups limit) | ||
| var oldest = Path.Combine(baseDir, $"{baseName}.{maxBackups}"); |
| // Shift all numbered files up by one | ||
| for (var i = maxBackups - 1; i >= 1; i--) | ||
| { | ||
| var src = Path.Combine(baseDir, $"{baseName}.{i}"); |
| for (var i = maxBackups - 1; i >= 1; i--) | ||
| { | ||
| var src = Path.Combine(baseDir, $"{baseName}.{i}"); | ||
| var dst = Path.Combine(baseDir, $"{baseName}.{i + 1}"); |
| } | ||
|
|
||
| // Rename current log to .1 | ||
| var current = Path.Combine(baseDir, baseName); |
| var line = logBuffer.GetLineMemoryOfBlock(0); | ||
| Assert.That(line.FullLine.Span.Contains(enumerator.Current.AsSpan(), StringComparison.Ordinal)); | ||
| Assert.That(line.HasValue, Is.True); | ||
| Assert.That(line.Value.FullLine.Span.Contains(enumerator.Current.AsSpan(), StringComparison.Ordinal)); |
Introduce LineOffsetIndex for efficient line start tracking and MemoryMappedFileReader for fast, scalable log file access using memory-mapped files. Supports tail mode and random line access, improving performance for large and growing log files.
…e reason does not work
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces significant performance and memory optimizations to the log buffer infrastructure, improves thread safety, and enhances code robustness with better null checking and minor API cleanups. The most notable changes are a complete refactoring of how log lines are stored and managed in
LogBuffer, the introduction of a buffer pool for efficient reuse, and improvements to utility methods for safer usage.Log buffer and memory management improvements:
LogBufferto use a pooled array (LogLine[]rented fromArrayPool<LogLine>) instead of aList<ILogLineMemory>, reducing heap allocations and improving performance for large log files. AddedReinitialiseand thread-safe locking methods, and changedAddLine/GetLineMemoryOfBlockto operate on the new structure. [1] [2]LogBufferPoolfor efficient pooling and reuse ofLogBufferinstances, further reducing memory churn and allocation overhead.API and type safety improvements:
LogLinefrom a class to areadonly record struct, making it a value type for better performance and immutability. Updated documentation accordingly.Thread safety and concurrency:
SpinLockfor protecting access to buffer content inLogBuffer, with explicit acquire/release methods.LogBufferCacheEntryto use an atomic field forLastUseTimeStampwithInterlockedoperations, ensuring thread-safe access.Robustness and utility improvements:
Utilastaticclass and added null checks to all utility methods (GetNameFromPath,StripExtension,GetExtension, andYetiLevenshtein), preventing possibleNullReferenceExceptions. EnhancedYetiLevenshteinwith fast paths for empty or identical strings. [1] [2] [3] [4] [5]Documentation and minor cleanups:
These changes collectively improve the performance, reliability, and maintainability of the log processing core.