Repository navigation
fix(tui): bound log preview reads to avoid startup/shutdown memory spikes - #167
Merged
Merged
Conversation
oschwartz10612
approved these changes
Oct 26, 2026
Member
|
Thanks! |
Member
|
Error unrelated. LGTM. Thanks! |
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.
Community Contribution License Agreement
By creating this pull request, I grant the project maintainers an unlimited,
perpetual license to use, modify, and redistribute these contributions under any terms they
choose, including both the AGPLv3 and the Fossorial Commercial license terms. I
represent that I have the right to grant this license for all contributed content.
AI Disclosure
OpenAI Codex was used to investigate the runtime behavior and upstream source, implement the fix, write and run the regression tests and benchmarks, and prepare this description. A separate Codex session reviewed the patch.
Description
pangolin upandpangolin downshow only five log lines, but the first preview starts at offset zero, scans the entire log, and appends every line to a slice before keeping its final five entries. This makes startup/shutdown memory usage and UI blocking time scale with the accumulated log file. In an observed deployment, a 5.45 GiBclient.logdrove the foregroundpangolin upprocess to approximately 7.69 GiB RSS while the detached tunnel process remained around 100 MiB or less.Limit each preview read to the newest 64 KiB of the unread range, plus one byte to identify the first line boundary. Read up to the observed file size so concurrent appends cannot extend the work. Select lines backwards and allocate strings only for the lines returned. The same bound applies when a large amount of output arrives between refreshes.
Preserve small-file and incremental behavior, omit a leading line cut by the byte window, and reset the offset when the file shrinks. Since this is a bounded preview, fewer than five lines may be returned if the latest lines do not fit in the window. Full log output and log retention are unchanged.
With the same 16 MiB synthetic log on Linux/amd64 (Go 1.27.2), the included benchmark measured:
Incremental reads with a large unread backlog show the same bounded behavior.
How to test?
These checks pass. Regression tests cover normal and incremental reads, empty/unchanged files, CRLF, blank lines, missing trailing newlines, byte-window boundaries, oversized lines, truncation, and an 8 GiB sparse file for both initial and incremental reads. The TUI tests also cross-compile for Windows/amd64 and Darwin/arm64.
go test ./...on the currentdevbase (b53ccd5) is blocked by an existing, unrelated compilation error:cmd/up/client/client.go:774: unknown field OlmVersioninolm.OlmConfig. The unmodified base reproduces the same failure. Applying these two changed files to currentmain(8bcb8db) passesgo test ./...,go vet ./..., andgo build ./....