Repository navigation
Conversation
In XML mode GetLogStreamReader returns an XmlBlockSplitter, which only implements ILogStreamReader. ReadToBufferList and ReReadBuffer cast it to ILogStreamReaderMemory, got null and threw on reader.Position, so an XML log loaded no lines and the splitter was never disposed. Keep the reader as ILogStreamReader, read memory readers through TryReadLine and string readers through ReadLine (a null line after preprocessing counts as dropped, as before the memory path), and attach char blocks only for memory readers.
The reader rented a 32,768-char block in its constructor and handed it to the LogBuffer as soon as one char was used. Tail mode creates a new reader on every poll, so a log that grows by one line per poll pinned 64 KB per line, up to about 32 MB for a 500-line buffer. Rent the block lazily. After a short read the rest of the file is already buffered, so the block is sized to those bytes plus one (no encoding decodes n bytes to more than n + 1 chars), capped at the old block size. Full reads still get full blocks, and Stream.Length is not queried, which would be a round trip on SFTP streams.
A line was buffered and decoded whole before being cut to MaximumLineLength. Memory grew with the longest line: about 1 GB for a 300 MB run without a newline, the oversized char block stayed with the LogBuffer, and above about 1 GB the doubling byte buffer overflowed and the read threw. Once a line holds more bytes than any supported encoding needs for MaximumLineLength chars (4 per char, plus 4 so a cut character falls beyond the cap), decode only that prefix and drop the searched bytes up to the terminator. Position still counts every dropped byte, so it stays exact, and the byte buffer stays at about twice the prefix.
Both constructors set Text to the same memory as FullLine, so every resident line carried a second ReadOnlyMemory<char>: 40 bytes instead of 24 for every line of every loaded LogBuffer. Text is now a computed property returning FullLine. The public surface is unchanged (callers use the getter either way), and record equality is unchanged because the two were always equal.
Ten polls that each read one appended line must leave the buffers with char blocks sized to the text. Before the fix they held 360,448 chars, one 32,768-char block for the initial load and one per poll.
…r-improvements # Conflicts: # src/LogExpert.Core/Classes/Log/Streamreaders/PositionAwareStreamReaderDirect.cs
A line whose text may exceed MaximumLineLength, including the 4-bytes-per-char prefix of a truncated line, was decoded straight into the char block, so the block handed to the LogBuffer was sized for about 4x the cap (131,072 chars for a 20,000 cap in UTF-8). Such lines now decode into a pooled scratch buffer and only the capped text is copied into the block. The ASCII and UTF-16 LE fast paths convert only up to the cap. Adds DirectReaderLongLineMemoryTests (50 MB run allocation and block-size bounds, cut points in UTF-8, UTF-16 and GB18030, CR at refill boundaries, random bytes) and a maximum line length for RawByteLineOracle. Refs #758
Keep char blocks to the capped text on lines over the maximum
MaximumLineLength was static, so every reader's constructor overwrote the cap for all readers in the process: a reader truncated lines at the cap of whichever reader was created last. The Direct reader also sized its truncation prefix from the cap at its first read and cut the text at the cap current at decode time, so an over-long line could come out at neither length. Fixes #762
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.
Fixes #758. Fixes #762.
Memory and correctness fixes for the Direct stream reader and
LogfileReader, collected onfeature/stream-reader-improvements.Changes
XML-mode logs load again (dac321e)
In XML mode
GetLogStreamReaderreturns anXmlBlockSplitter, which only implementsILogStreamReader.ReadToBufferListandReReadBuffercast it toILogStreamReaderMemory, gotnulland threw onreader.Position. An XML log loaded no lines, and the splitter was never disposed.Now:
ILogStreamReader.TryReadLine, string readers throughReadLine.Tail mode no longer pins a full char block per poll (672dc6b, 39d6c16)
The reader rented a 32 768-char block in its constructor. The block was handed to the
LogBufferas soon as one char was used. Tail mode creates a reader on every poll, so a log that grows by one line per poll pinned 64 KB per line, up to about 32 MB for a 500-line buffer.The block is now rented lazily. After a short read, the rest of the file is already buffered, so the block is sized to those bytes plus one, capped at the old size.
Stream.Lengthis not queried, which matters on SFTP streams. ALogfileReadertest checks that ten one-line polls leave blocks sized to the text; before the fix they held 360 448 chars.Memory per line bounded by the maximum line length (86446fc, #761 / 794f20a), #758
A line was buffered and decoded whole, then cut to
MaxLineLength. Memory grew with the longest line: about 1 GB for a 300 MB run without a newline. The oversized char block stayed with theLogBuffer. Above about 1 GB, the doubling byte buffer overflowed and the read threw.Now:
MaxLineLength+ 4 bytes, only that prefix is decoded.Position, so the position stays exact.LogBufferstay atBLOCK_SIZE, or what the cap needs.Measured on a 50 MB run with
MaxLineLength= 20 000:LogBuffer.Each reader keeps its own maximum line length (38a4db3), #762
PositionAwareStreamReaderBase.MaximumLineLengthwasstatic. Every reader's constructor overwrote the cap for all readers, so a reader truncated lines at the cap of whichever reader was created last. It is now an instance property. This file also loses its UTF-8 BOM, becausesrc/.editorconfigrequirescharset = utf-8and the CI format check flags changed files.LogLinestores its text once (a4cf0b0)Both constructors set
Textto the same memory asFullLine, so every resident line carried a secondReadOnlyMemory<char>.Textis now a computed property returningFullLine: 24 bytes per line instead of 40. The public surface and record equality are unchanged.Cleanup (21e7b2d)
Drops a misspelled reader alias in
ReReadBuffer.Tests
DirectReaderLongLineMemoryTestscovers:Positionagainst the raw bytes;\rat refill boundaries;RawByteLineOracletakes an optional maximum line length.LogLine, and two readers with different caps.SelectionPainterTests.PaintedBlock_HasNoInternalEdge_AndErasesOldEdgesAfterSelectionChanges, which is on the known-flaky list.InactiveWindow_KeepsItsOwnSearchwas excluded, asCLAUDE.mdsays.Benchmarks
DirectReaderBenchmarksfor #761 against the branch before it showed no regression. Measured on a noisy machine. All results were within ±2.5 %, allocations were identical, and an 18 % Unicode outlier didn't reproduce in three alternating reruns. Details are in #761.Not in this PR
ReadChar()and overcounts the byte position on invalid bytes.