Skip to content

perf(LogIterator): Read long lines in linear time - #2327

Merged
DerDreschner merged 1 commit into
masterfrom
fix/log-iterator-long-lines
Oct 19, 2026
Merged

DerDreschner merged 1 commit into
masterfrom
fix/log-iterator-long-lines

Conversation

@DerDreschner

Copy link
Copy Markdown
Contributor

LogIterator reads the log backwards in chunks of 8 KB. When a line spans several chunks, every chunk is prepended to the whole buffer before the whole buffer is searched for a newline again. Reading a line of length L therefore takes O(L虏) time. Such long lines can be written, for example by occ upgrade, which forces the debug log level. A log with a few of them stalls the "Errors in the log" setup check and the log viewer.

Remember where the line ends, only search the newly read chunk for its start, and then read the whole line at once. This reduces the time to O(L).

Related: #1025
Related: #1170

馃 AI (if applicable)

  • The content of this PR was partly or fully generated using AI (Claude Opus 5.5)

LogIterator reads the log backwards in chunks of 8 KB. When a line spans
several chunks, every chunk is prepended to the whole buffer before the
whole buffer is searched for a newline again. Reading a line of length L
therefore takes O(L虏) time. Such long lines can be written, for example
by occ upgrade, which forces the debug log level. A log with a few of
them stalls the "Errors in the log" setup check and the log viewer.

Remember where the line ends, only search the newly read chunk for its
start, and then read the whole line at once. This reduces the time to
O(L).

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: David Dreschner <david.dreschner@nextcloud.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃煝 Approval recommended

Static review found no blocking issues, and the added tests cover key boundary cases; tests were not executed.

No open issues 馃帀

What changed in this PR

Improves reverse log reading so very long lines take linear rather than quadratic time, addressing stalls in the log viewer and setup checks.

Changes:

  • Searches each chunk once, then rereads the complete line.
  • Adds regression tests for multi-chunk lines and trailing-newline boundaries.
File Description
tests/鈥婾nit/鈥婰og/鈥婰ogIteratorTest.php Tests long lines and newline boundary cases.
lib/鈥婰og/鈥婰ogIterator.php Replaces repeated buffer growth with offset-based line reconstruction.

Review effort: Balanced

@DerDreschner
DerDreschner merged commit 88a0803 into master Oct 19, 2026
28 checks passed
@DerDreschner
DerDreschner deleted the fix/log-iterator-long-lines branch October 19, 2026 12:09
@DerDreschner

Copy link
Copy Markdown
Contributor Author

/backport to stable35

@DerDreschner

Copy link
Copy Markdown
Contributor Author

/backport to stable34

@DerDreschner

Copy link
Copy Markdown
Contributor Author

/backport to stable33

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants