Skip to content

Commit d72afbc

Browse files
authored
Merge branch 'Development' into projectfilehandler
2 parents 5bdd30c + 8154070 commit d72afbc

6 files changed

Lines changed: 360 additions & 33 deletions

File tree

src/LogExpert.Core/Classes/Log/LogfileReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,8 +1709,8 @@ private ILogStreamReader CreateLogStreamReader (Stream stream, EncodingOptions e
17091709
ReaderType.Legacy => new PositionAwareStreamReaderLegacy(stream, encodingOptions, _maximumLineLength),
17101710
ReaderType.System => new PositionAwareStreamReaderSystem(stream, encodingOptions, _maximumLineLength),
17111711
ReaderType.SystemDirect => new PositionAwareStreamReaderDirect(stream, encodingOptions, _maximumLineLength),
1712-
//Default will be System
1713-
_ => new PositionAwareStreamReaderSystem(stream, encodingOptions, _maximumLineLength),
1712+
//Default will be SystemDirect, because it is the best performing reader and should be used if not explicitly overridden by user.
1713+
_ => new PositionAwareStreamReaderDirect(stream, encodingOptions, _maximumLineLength),
17141714
};
17151715
}
17161716

src/LogExpert.Core/Classes/Log/Streamreaders/PositionAwareStreamReaderDirect.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,15 @@ public List<char[]> DetachBlocks ()
159159

160160
// Rent a fresh block and carry over any unscanned data (partial line in progress)
161161
var tailLength = _readBlockLength - _scanOffset;
162-
var newBlock = ArrayPool<char>.Shared.Rent(BLOCK_SIZE);
162+
163+
// The tail may exceed BLOCK_SIZE after reading a long line (buffer was grown).
164+
var newBlockSize = BLOCK_SIZE;
165+
while (tailLength > newBlockSize)
166+
{
167+
newBlockSize *= 2;
168+
}
169+
170+
var newBlock = ArrayPool<char>.Shared.Rent(newBlockSize);
163171

164172
if (tailLength > 0)
165173
{
@@ -183,8 +191,17 @@ private void RefillBlock (StreamReader reader)
183191
{
184192
var tailLength = _readBlockLength - _scanOffset;
185193

186-
// Rent a new block
187-
var newBlock = ArrayPool<char>.Shared.Rent(BLOCK_SIZE);
194+
// Determine new block size: if the tail already fills a standard block,
195+
// grow the buffer so there's room to read more data. This handles lines
196+
// longer than BLOCK_SIZE (e.g. huge XML payloads).
197+
var newBlockSize = BLOCK_SIZE;
198+
while (tailLength >= newBlockSize)
199+
{
200+
newBlockSize *= 2;
201+
}
202+
203+
// Rent a new block (may be larger than BLOCK_SIZE for very long lines)
204+
var newBlock = ArrayPool<char>.Shared.Rent(newBlockSize);
188205

189206
// Copy the tail (partial line) to the start of the new block
190207
if (tailLength > 0)
@@ -199,7 +216,8 @@ private void RefillBlock (StreamReader reader)
199216
_scanOffset = 0;
200217

201218
// Fill the rest of the block from the stream
202-
var charsRead = reader.Read(newBlock, tailLength, BLOCK_SIZE - tailLength);
219+
var available = newBlock.Length - tailLength;
220+
var charsRead = reader.Read(newBlock, tailLength, available);
203221

204222
_readBlockLength = tailLength + charsRead;
205223

src/LogExpert.Core/Enums/ReaderType.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ namespace LogExpert.Core.Enums;
66
public enum ReaderType
77
{
88
/// <summary>
9-
/// System.IO.Pipelines based reader implementation (high performance).
9+
/// Direct-read implementation: reads decoded chars directly into pooled blocks via
10+
/// StreamReader.Read(char[], offset, count), eliminating per-line string allocation.
1011
/// </summary>
11-
Pipeline,
12+
SystemDirect,
1213

1314
/// <summary>
1415
/// Legacy reader implementation (original).
@@ -18,11 +19,5 @@ public enum ReaderType
1819
/// <summary>
1920
/// System.IO.StreamReader based implementation.
2021
/// </summary>
21-
System,
22-
23-
/// <summary>
24-
/// Direct-read implementation: reads decoded chars directly into pooled blocks via
25-
/// StreamReader.Read(char[], offset, count), eliminating per-line string allocation.
26-
/// </summary>
27-
SystemDirect
22+
System
2823
}

0 commit comments

Comments
 (0)