Repository navigation
perf(LogIterator): Read long lines in linear time - #2327
Merged
Merged
Conversation
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>
DerDreschner
requested review from
icewind1991
and
a balanced review from Copilot
October 19, 2026 12:06
DerDreschner
enabled auto-merge
October 19, 2026 12:07
CarlSchwan
approved these changes
Oct 19, 2026
There was a problem hiding this comment.
馃煝 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
Contributor
Author
|
/backport to stable35 |
Contributor
Author
|
/backport to stable34 |
Contributor
Author
|
/backport to stable33 |
3 tasks done
3 tasks done
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.
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)